Skip to content

Commit 4d9f935

Browse files
committed
query fix
1 parent 9a8be69 commit 4d9f935

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

src/main/java/com/romeh/ignitemanager/entities/AlertConfigEntry.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.romeh.ignitemanager.entities;
22

3+
import io.swagger.annotations.ApiModelProperty;
34
import lombok.EqualsAndHashCode;
45
import lombok.Getter;
56
import lombok.Setter;
67
import lombok.ToString;
78
import org.apache.ignite.cache.query.annotations.QuerySqlField;
89

10+
import javax.validation.constraints.NotNull;
911
import java.io.Serializable;
1012
import java.util.List;
1113

@@ -17,9 +19,13 @@
1719
@Setter
1820
@ToString
1921
public class AlertConfigEntry implements Serializable {
22+
@ApiModelProperty(notes = "alert service code required to be entered by user into REST API ", required = true)
2023
@QuerySqlField(index = true)
24+
@NotNull
2125
String serviceCode;
26+
@ApiModelProperty(notes = "alert error code required to be entered by user into REST API ", required = true)
2227
@QuerySqlField(index = true)
28+
@NotNull
2329
String errorCode;
2430
List<String> emails;
2531
int maxCount;

src/main/java/com/romeh/ignitemanager/entities/AlertEntry.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.romeh.ignitemanager.entities;
22

3+
import io.swagger.annotations.ApiModelProperty;
34
import lombok.*;
45
import org.apache.ignite.cache.query.annotations.QuerySqlField;
56

7+
import javax.validation.constraints.NotNull;
68
import java.io.Serializable;
79
import java.util.Map;
810

@@ -15,11 +17,18 @@
1517
@ToString
1618
@EqualsAndHashCode
1719
public class AlertEntry implements Serializable {
20+
@ApiModelProperty(notes = "the key value alert content for error description required to be entered by user into REST API ")
1821
private Map<String,String> alertContent;
22+
@ApiModelProperty(notes = "alert error code required to be entered by user into REST API ", required = true)
1923
@QuerySqlField(index = true)
24+
@NotNull
2025
private String errorCode;
26+
@ApiModelProperty(notes = "alert service code required to be entered by user into REST API ", required = true)
2127
@QuerySqlField(index = true)
28+
@NotNull
2229
private String serviceId;
30+
@ApiModelProperty(notes = "alert severity required to be entered by user into REST API ", required = true)
31+
@NotNull
2332
private String severity;
2433
@QuerySqlField(index = true)
2534
private Long timestamp;

src/main/java/com/romeh/ignitemanager/repositories/impl/IgniteAlertsStore.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.springframework.scheduling.annotation.Async;
1818
import org.springframework.stereotype.Component;
1919

20+
import javax.cache.Cache;
2021
import java.util.Collections;
2122
import java.util.HashSet;
2223
import java.util.List;
@@ -112,18 +113,19 @@ protected void sendMail(AlertEntry alertEntry, List<String> emails, String mailT
112113
}
113114
// clean all alerts for that service code and service id
114115
private void cleanAllAlertEntriesForThatErrorCodeAndServiceCode(String serviceId, String errorId) {
115-
// query the matching records first
116+
117+
// commenting it out for testing without clean-up
118+
/* // query the matching records first
116119
final String sql = "serviceId = ? and errorCode= ?";
117-
SqlFieldsQuery query = new SqlFieldsQuery(sql);
120+
SqlQuery<String,AlertEntry> query = new SqlQuery(AlertEntry.class,sql);
118121
query.setArgs(serviceId, errorId);
119-
final List<List<?>> to_Delete_Alerts = getAlertsCache().query(query).getAll();
122+
final List<Cache.Entry<String, AlertEntry>> to_Delete_Alerts = getAlertsCache().query(query).getAll();
120123
// then call remove all as this will remove the records from the cache and the persistent file system
121124
// as sql delete will just delete it from the cache layer not the file system
122125
// or the persistent store
123126
if(to_Delete_Alerts!=null && !to_Delete_Alerts.isEmpty()){
124-
List<AlertEntry> alertEntryListToDelete=(List<AlertEntry>)to_Delete_Alerts.get(0).get(0);
125-
getAlertsCache().removeAll(new HashSet(alertEntryListToDelete));
126-
}
127+
getAlertsCache().removeAll(new HashSet(to_Delete_Alerts.stream().map(stringAlertEntryEntry -> stringAlertEntryEntry.getKey()).collect(Collectors.toList())));
128+
}*/
127129

128130
}
129131

src/main/java/com/romeh/ignitemanager/services/CleanExpiredAlertsService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@
55
import org.apache.ignite.Ignite;
66
import org.apache.ignite.IgniteCache;
77
import org.apache.ignite.cache.query.SqlFieldsQuery;
8+
import org.apache.ignite.cache.query.SqlQuery;
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
1011
import org.springframework.beans.factory.annotation.Autowired;
1112
import org.springframework.scheduling.annotation.Scheduled;
1213
import org.springframework.stereotype.Service;
1314

15+
import javax.cache.Cache;
1416
import java.util.HashSet;
1517
import java.util.List;
18+
import java.util.stream.Collectors;
1619

1720
/**
1821
* Created by romeh on 22/08/2017.
@@ -32,15 +35,14 @@ public void cleanExpiredRecords(){
3235
long towMinutesRange = System.currentTimeMillis()-900000;
3336
final IgniteCache<String, List<AlertEntry>> alertsCache = getAlertsCache();
3437
final String sql = "select * from AlertEntry where timestamp <= ?";
35-
SqlFieldsQuery query = new SqlFieldsQuery(sql);
38+
SqlQuery<String,AlertEntry> query = new SqlQuery(AlertEntry.class,sql);
3639
query.setArgs(towMinutesRange);
37-
final List<List<?>> to_Delete_Alerts = alertsCache.query(query).getAll();
40+
final List<Cache.Entry<String, AlertEntry>> to_Delete_Alerts = alertsCache.query(query).getAll();
3841
// then call remove all as this will remove the records from the cache and the persistent file system as sql delete will just delete it from the cache layer not the file system
3942
// or the persistent store
4043
if(to_Delete_Alerts!=null && !to_Delete_Alerts.isEmpty()){
41-
List<AlertEntry> toDelete=(List<AlertEntry>) to_Delete_Alerts.get(0).get(0);
42-
logger.debug("Finished cleaning out {} records",toDelete.size());
43-
alertsCache.removeAll(new HashSet(toDelete));
44+
logger.debug("Finished cleaning out {} records",to_Delete_Alerts.size());
45+
alertsCache.removeAll(new HashSet(to_Delete_Alerts.stream().map(stringAlertEntryEntry -> stringAlertEntryEntry.getKey()).collect(Collectors.toList())));
4446

4547
}
4648

0 commit comments

Comments
 (0)