Skip to content

Instantly share code, notes, and snippets.

View Romeh's full-sized avatar

MRomeh Romeh

View GitHub Profile
import lombok.*;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
//Sample job model
@Builder
@Getter
@Setter
@ToString
@EqualsAndHashCode
public class Job {
import org.apache.ignite.Ignite;
import org.apache.ignite.cache.CacheInterceptorAdapter;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.jetbrains.annotations.Nullable;
import javax.cache.Cache;
import static com.romeh.failover.demo.CacheNames.ICEP_JOBS;
mport org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cache.CacheInterceptorAdapter;
import org.apache.ignite.cache.query.SqlQuery;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.resources.IgniteInstanceResource;
import org.jetbrains.annotations.Nullable;
import javax.cache.Cache;
@Romeh
Romeh / IgniteCluster.xml
Created November 14, 2017 12:56
IgniteCluster.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
_________ _____ __________________ _____
__ ____/___________(_)______ /__ ____/______ ____(_)_______
_ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
/ /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
\____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
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 {
@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}")
@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));
@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)));
// 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);
}
@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) {