This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(SpringRunner.class) | |
@SpringBootTest(classes = AlertManagerApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | |
@ActiveProfiles("INTEGRATION_TEST") | |
public class AlertManagerApplicationIT { | |
@LocalServerPort | |
private int port; | |
@Autowired | |
private TestRestTemplate template; | |
private URL base; | |
@Before |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(MockitoJUnitRunner.class) | |
public class IgniteAlertsSoreTest { | |
@Mock | |
private Ignite ignite; | |
@Mock | |
Cache<String, List<AlertEntry>> cache; | |
@Mock | |
IgniteCache IgniteCache; | |
@InjectMocks | |
private IgniteAlertsStore igniteAlertsStore; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.apache.ignite</groupId> | |
<artifactId>ignite-core</artifactId> | |
<version>${ignite.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.apache.ignite</groupId> | |
<artifactId>ignite-spring</artifactId> | |
<version>${ignite.version}</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class IgniteAlertConfigStore implements AlertsConfigStore { | |
private static final Logger logger = LoggerFactory.getLogger(IgniteAlertConfigStore.class); | |
// here it will be injected as a spring bean | |
@Autowired | |
private Ignite ignite; | |
@Override | |
public AlertConfigEntry getConfigForServiceIdCodeId(String serviceId, String codeId) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// durable file memory persistence | |
if(enableFilePersistence){ | |
PersistentStoreConfiguration persistentStoreConfiguration = new PersistentStoreConfiguration(); | |
persistentStoreConfiguration.setPersistentStorePath("./data/store"); | |
persistentStoreConfiguration.setWalArchivePath("./data/walArchive"); | |
persistentStoreConfiguration.setWalStorePath("./data/walStore"); | |
igniteConfiguration.setPersistentStoreConfiguration(persistentStoreConfiguration); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public List<AlertEntry> getAlertForServiceId(String serviceId) { | |
final String sql = "serviceId = ?"; | |
// create the sql query object with entity type of the value part of the key value cache | |
SqlQuery<String, AlertEntry> query = new SqlQuery<>(AlertEntry.class, sql); | |
// set the query params | |
query.setArgs(serviceId); | |
//then execute it over the cache | |
return Optional.ofNullable(getAlertsCache().query(query).getAll().stream().map(stringAlertEntryEntry -> stringAlertEntryEntry.getValue()).collect(Collectors.toList())) | |
.orElseThrow(() -> new ResourceNotFoundException(String.format("Alert for %s not found", serviceId))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void updateAlertEntry(String serviceId, String serviceCode, AlertEntry alertEntry) { | |
final IgniteCache<String, AlertEntry> alertsCache = getAlertsCache(); | |
// update the alert entry via cache invoke for atomicity | |
alertsCache.invoke(alertEntry.getAlertId(), (mutableEntry, objects) -> { | |
if (mutableEntry.exists() && mutableEntry.getValue() != null) { | |
logger.debug("updating alert entry into the cache store invoke: {},{}", serviceId, serviceCode); | |
mutableEntry.setValue(alertEntry); | |
} else { | |
throw new ResourceNotFoundException(String.format("Alert for %s with %s not found", serviceId, serviceCode)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class AlertManagerConfiguration { | |
@Value("${mail.service.baseUrl}") | |
private String baseUrl; | |
@Value("${mail.service.user}") | |
private String user; | |
@Value("${mail.service.password}") | |
private String password; | |
@Value("${enableFilePersistence}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Builder | |
@Getter | |
@Setter | |
@ToString | |
@EqualsAndHashCode | |
public class AlertEntry implements Serializable { | |
@ApiModelProperty(notes = "the key value alert content for error description required to be entered by user into REST API ", required = true) | |
@NotNull | |
private Map<String,String> alertContent; | |
@ApiModelProperty(notes = "alert error code required to be entered by user into REST API ", required = true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.ignite.*; | |
import org.apache.ignite.events.DiscoveryEvent; | |
import org.apache.ignite.events.EventType; | |
import javax.cache.expiry.CreatedExpiryPolicy; | |
import javax.cache.expiry.Duration; | |
public class NodeApp { |