From deeead449fb38be3a10d25cc59eb3246904af82f Mon Sep 17 00:00:00 2001 From: azam Date: Thu, 21 Mar 2024 10:23:29 +0200 Subject: [PATCH 1/7] Bump development version to 2.8.2-SNAPSHOT --- Dockerfile_test_image.in | 2 +- core/pom.xml | 2 +- dist/pom.xml | 2 +- dist/src/assembly/modules/server.mod | 2 +- pom.xml | 8 ++++---- webapp/pom.xml | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Dockerfile_test_image.in b/Dockerfile_test_image.in index 33c571ba..26031142 100644 --- a/Dockerfile_test_image.in +++ b/Dockerfile_test_image.in @@ -31,7 +31,7 @@ update-alternatives --install /usr/bin/python python /usr/bin/python2 2 mkdir -p /opt/zenoss EOT -ADD dist/target/zep-dist-2.8.1-SNAPSHOT.tar.gz /opt/zenoss +ADD dist/target/zep-dist-2.8.2-SNAPSHOT.tar.gz /opt/zenoss ENV TERM=xterm ZENHOME=/opt/zenoss PATH="/opt/zenoss/bin:${PATH}" diff --git a/core/pom.xml b/core/pom.xml index 82245577..c4def5c2 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -13,7 +13,7 @@ org.zenoss.zep zep-parent - 2.8.1-SNAPSHOT + 2.8.2-SNAPSHOT ../pom.xml diff --git a/dist/pom.xml b/dist/pom.xml index 9c01195b..38f72ff0 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -13,7 +13,7 @@ org.zenoss.zep zep-parent - 2.8.1-SNAPSHOT + 2.8.2-SNAPSHOT ../pom.xml diff --git a/dist/src/assembly/modules/server.mod b/dist/src/assembly/modules/server.mod index 74570101..e76993a8 100644 --- a/dist/src/assembly/modules/server.mod +++ b/dist/src/assembly/modules/server.mod @@ -12,7 +12,7 @@ logging bytebufferpool [ini] -zenoss-zep-core.version?=2.8.1-SNAPSHOT +zenoss-zep-core.version?=2.8.2-SNAPSHOT [lib] lib/jetty-http-${jetty.version}.jar diff --git a/pom.xml b/pom.xml index 27500a9a..03a0fb43 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.zenoss.zep zep-parent pom - 2.8.1-SNAPSHOT + 2.8.2-SNAPSHOT Zenoss Event Processor Parent http://www.zenoss.com @@ -67,7 +67,7 @@ 5.2.0 4.13.2 - 0.1.18-SNAPSHOT + 0.1.19 @@ -77,8 +77,8 @@ 2.24.0 1.115.2 1.12.3 - 2.1.9-SNAPSHOT - 2.1.1-SNAPSHOT + 2.1.9 + 2.1.1 11.1.2 3.1.0 diff --git a/webapp/pom.xml b/webapp/pom.xml index 40e1f63b..b606e072 100644 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -13,7 +13,7 @@ org.zenoss.zep zep-parent - 2.8.1-SNAPSHOT + 2.8.2-SNAPSHOT ../pom.xml From 8594cbc0f7b57838c9540301d91f3126ba417f39 Mon Sep 17 00:00:00 2001 From: azam Date: Fri, 17 May 2024 16:16:13 +0300 Subject: [PATCH 2/7] ZEN-34875: ZEP failing to start when IncidentManagement has been installed --- .../org/zenoss/zep/MetricsRegistryConfig.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/org/zenoss/zep/MetricsRegistryConfig.java b/core/src/main/java/org/zenoss/zep/MetricsRegistryConfig.java index 6f59cb10..d0453249 100644 --- a/core/src/main/java/org/zenoss/zep/MetricsRegistryConfig.java +++ b/core/src/main/java/org/zenoss/zep/MetricsRegistryConfig.java @@ -1,6 +1,7 @@ package org.zenoss.zep; import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.MetricSet; import com.codahale.metrics.jvm.GarbageCollectorMetricSet; import com.codahale.metrics.jvm.MemoryUsageGaugeSet; import com.codahale.metrics.jvm.ThreadStatesGaugeSet; @@ -15,30 +16,36 @@ public class MetricsRegistryConfig { private static final Logger logger = LoggerFactory.getLogger(MetricsRegistryConfig.class); + + private void skipOrRegister(MetricRegistry registry, String metricSetName, MetricSet metricSet) { + if (registry.getNames().stream().noneMatch(n->n.startsWith(metricSetName))) { + registry.register(metricSetName, metricSet); + logger.info("Register {} metrics set in zep registry", metricSetName); + } else { + logger.warn("Metrics set {} already exist in zep registry", metricSetName); + } + } @Bean public GarbageCollectorMetricSet garbageCollectorMetricSet(@Autowired MetricRegistry registry) { GarbageCollectorMetricSet metricSet = new GarbageCollectorMetricSet(); - String metricName = "jvm.gc"; - registry.register(metricName, metricSet); - logger.info("Register {} metric in zep registry", metricName); + String metricSetName = "jvm.gc"; + skipOrRegister(registry, metricSetName, metricSet); return metricSet; } @Bean public MemoryUsageGaugeSet memoryUsageGaugeSet(@Autowired MetricRegistry registry) { MemoryUsageGaugeSet metricSet = new MemoryUsageGaugeSet(); - String metricName = "jvm.memory"; - registry.register(metricName, metricSet); - logger.info("Register {} metric in zep registry", metricName); + String metricSetName = "jvm.memory"; + skipOrRegister(registry, metricSetName, metricSet); return metricSet; } @Bean public ThreadStatesGaugeSet threadStatesGaugeSet(@Autowired MetricRegistry registry) { ThreadStatesGaugeSet metricSet = new ThreadStatesGaugeSet(); - String metricName = "jvm.thread-states"; - registry.register(metricName, metricSet); - logger.info("Register {} metric in zep registry", metricName); + String metricSetName = "jvm.thread-states"; + skipOrRegister(registry, metricSetName, metricSet); return metricSet; } @@ -46,8 +53,12 @@ public ThreadStatesGaugeSet threadStatesGaugeSet(@Autowired MetricRegistry regis public FileDescriptorRatioGauge fileDescriptorRatioGauge(@Autowired MetricRegistry registry) { FileDescriptorRatioGauge metric = new FileDescriptorRatioGauge(); String metricName = "jvm.fd.usage"; - registry.register(metricName, metric); - logger.info("Register {} metric in zep registry", metricName); + if (!registry.getNames().contains(metricName)) { + registry.register(metricName, metric); + logger.info("Register {} metric in zep registry", metricName); + } else { + logger.warn("Metric {} already exist in zep registry", metricName); + } return metric; } } From e19bede661b217bc32fcb1c782aee4896609375f Mon Sep 17 00:00:00 2001 From: azam Date: Mon, 20 May 2024 11:12:59 +0300 Subject: [PATCH 3/7] ZEN-34875.1: fix long overflow --- core/src/main/java/org/zenoss/zep/impl/TriggerPlugin.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/zenoss/zep/impl/TriggerPlugin.java b/core/src/main/java/org/zenoss/zep/impl/TriggerPlugin.java index b6dee55e..30a1dffc 100644 --- a/core/src/main/java/org/zenoss/zep/impl/TriggerPlugin.java +++ b/core/src/main/java/org/zenoss/zep/impl/TriggerPlugin.java @@ -240,7 +240,9 @@ private void scheduleSpool() { Instant nextExecution = null; try { long nextFlushTime = signalSpoolDao.getNextFlushTime(); - if (nextFlushTime > 0) { + if (nextFlushTime == Long.MAX_VALUE) { + nextExecution = Instant.now().plusSeconds(31536000); // 10 years + } else if (nextFlushTime > 0) { nextExecution = Instant.ofEpochMilli(nextFlushTime); logger.debug("Next flush time: {}", nextExecution); } From 91357ea45a5ea7ffc0532c09c9f4d3b491325c7e Mon Sep 17 00:00:00 2001 From: azam Date: Wed, 22 May 2024 10:57:51 +0300 Subject: [PATCH 4/7] ZEN-34893: Event Flapping functionality is broken and breaks all event processing if a flapping event is identified remove spring-data-redis package --- core/pom.xml | 5 ---- .../zep/dao/impl/FlapTrackerDaoImpl.java | 24 ++++++++----------- core/src/main/resources/zep-config-daos.xml | 11 --------- pom.xml | 1 - 4 files changed, 10 insertions(+), 31 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index c4def5c2..e319d84a 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -322,11 +322,6 @@ - - org.springframework.data - spring-data-redis - ${spring-data-redis.version} - redis.clients jedis diff --git a/core/src/main/java/org/zenoss/zep/dao/impl/FlapTrackerDaoImpl.java b/core/src/main/java/org/zenoss/zep/dao/impl/FlapTrackerDaoImpl.java index ef4c2a55..4e146b04 100644 --- a/core/src/main/java/org/zenoss/zep/dao/impl/FlapTrackerDaoImpl.java +++ b/core/src/main/java/org/zenoss/zep/dao/impl/FlapTrackerDaoImpl.java @@ -12,11 +12,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.RedisConnectionFailureException; -import org.springframework.data.redis.core.StringRedisTemplate; import org.zenoss.zep.ZepException; import org.zenoss.zep.dao.FlapTrackerDao; import org.zenoss.zep.impl.FlapTracker; +import org.zenoss.zep.utils.JedisPoolUtil; +import redis.clients.jedis.params.SetParams; import java.util.concurrent.TimeUnit; @@ -27,7 +27,7 @@ public class FlapTrackerDaoImpl implements FlapTrackerDao{ private final String REDIS_FLAP_KEY = "zenoss_event_flapping"; @Autowired - private StringRedisTemplate template = null; + private JedisPoolUtil pool = null; private String createKey(String clearFingerPrintHash) { @@ -35,12 +35,7 @@ private String createKey(String clearFingerPrintHash) { } @Override public FlapTracker getFlapTrackerByClearFingerprintHash(String clearFingerPrintHash) throws ZepException { - String result; - try { - result = template.opsForValue().get(createKey(clearFingerPrintHash)); - } catch (RedisConnectionFailureException e) { - throw new ZepException(e); - } + String result = pool.useJedis(jedis -> jedis.get(createKey(clearFingerPrintHash))); if (result != null) { // return existing flap tracker logger.debug("String gotten back from redis " + result); @@ -54,10 +49,11 @@ public FlapTracker getFlapTrackerByClearFingerprintHash(String clearFingerPrintH @Override public void persistTracker(String clearFingerprintHash, FlapTracker tracker, long timeToKeep) throws ZepException { logger.debug("Setting string key {} value {}", createKey(clearFingerprintHash), tracker.convertToString()); - try { - template.opsForValue().set(createKey(clearFingerprintHash), tracker.convertToString(), timeToKeep, TimeUnit.SECONDS); - }catch (RedisConnectionFailureException e) { - throw new ZepException(e); - } + SetParams params = new SetParams(); + params.ex(timeToKeep); + pool.useJedis(jedis -> { + jedis.set(createKey(clearFingerprintHash), tracker.convertToString(), params); + return null; + }); } } diff --git a/core/src/main/resources/zep-config-daos.xml b/core/src/main/resources/zep-config-daos.xml index 3abbea70..fb634044 100644 --- a/core/src/main/resources/zep-config-daos.xml +++ b/core/src/main/resources/zep-config-daos.xml @@ -407,13 +407,6 @@ - - - - - - - @@ -426,10 +419,6 @@ - - - - diff --git a/pom.xml b/pom.xml index 03a0fb43..db2d7efa 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,6 @@ 4.2.23 3.7.1 - 3.2.1 5.1.15 1.1.7 9.0-801.jdbc4 From a845b083c1d5da4cff3f1a8b18b324e966f49da4 Mon Sep 17 00:00:00 2001 From: azam Date: Wed, 22 May 2024 13:43:54 +0300 Subject: [PATCH 5/7] ZEN-34889: Garfield env is missing the jetty.ini configuration file --- core/pom.xml | 16 ++++++++++ dist/pom.xml | 7 +++++ .../assembly/bin/zeneventserver-functions.sh | 7 +++++ .../zeneventserver/jetty/jetty-jmx-remote.xml | 20 +++++++++++++ .../etc/zeneventserver/jetty/jetty-jmx.xml | 30 +++++++++++++++++++ dist/src/assembly/modules/jmx-remote.mod | 26 ++++++++++++++++ dist/src/assembly/modules/jmx.mod | 11 +++++++ .../main/assembly/zeneventserver-webapp.xml | 1 + webapp/pom.xml | 11 +++++++ 9 files changed, 129 insertions(+) create mode 100644 dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx-remote.xml create mode 100644 dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx.xml create mode 100644 dist/src/assembly/modules/jmx-remote.mod create mode 100644 dist/src/assembly/modules/jmx.mod diff --git a/core/pom.xml b/core/pom.xml index e319d84a..04310cbb 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -304,6 +304,11 @@ jetty-deploy ${jetty.version} + + org.eclipse.jetty + jetty-jmx + ${jetty.version} + org.eclipse.jetty jetty-webapp @@ -401,7 +406,13 @@ ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-deploy.xml ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-http.xml ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-webapp.xml + ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx.xml + ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx-remote.xml + + ${project.basedir}/../dist/src/assembly/modules/jmx.mod + ${project.basedir}/../dist/src/assembly/modules/jmx-remote.mod + jar @@ -441,6 +452,11 @@ jetty-util-ajax ${jetty.version} + + org.eclipse.jetty + jetty-jmx + ${jetty.version} + org.eclipse.jetty.toolchain jetty-jakarta-servlet-api diff --git a/dist/pom.xml b/dist/pom.xml index 38f72ff0..3e523426 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -64,6 +64,13 @@ jar provided + + org.eclipse.jetty + jetty-jmx + ${jetty.version} + jar + provided + ch.qos.logback logback-core diff --git a/dist/src/assembly/bin/zeneventserver-functions.sh b/dist/src/assembly/bin/zeneventserver-functions.sh index 3d1d9c1b..4301e11e 100755 --- a/dist/src/assembly/bin/zeneventserver-functions.sh +++ b/dist/src/assembly/bin/zeneventserver-functions.sh @@ -14,6 +14,11 @@ JETTYSTART_JAR=`ls -1 ${JETTY_HOME}/lib/jetty-start*.jar` JETTY_ARGS="--module=centralized-webapp-logging,http,ext" PS="ps" +[ -n "$JETTY_MODULES" ] && { + JETTY_ARGS="$JETTY_ARGS,$JETTY_MODULES"; + echo "Additional modules added for jetty startup: $JETTY_ARGS"; + } + # Add --add-opens args to open modules to pre-module code. OPEN_PACKAGES="java.base/java.lang java.base/java.nio java.base/java.io" for pkg in ${OPEN_PACKAGES}; do @@ -307,6 +312,8 @@ Usage: $0 {start|stop|restart|status|run|run_quiet|threads} [options] threads - display thread status to stdout + for running jetty with additional modules export JETTY_MODULES variable, eg JETTY_MODULES="jmx,jmx-remote" + HELP exit 1 esac diff --git a/dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx-remote.xml b/dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx-remote.xml new file mode 100644 index 00000000..99ae64eb --- /dev/null +++ b/dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx-remote.xml @@ -0,0 +1,20 @@ + + + + + + + + + + rmi + + + /jndi/rmi://:/jmxrmi + + + org.eclipse.jetty.jmx:name=jmxconnectorserver + + + + diff --git a/dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx.xml b/dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx.xml new file mode 100644 index 00000000..25a2120c --- /dev/null +++ b/dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dist/src/assembly/modules/jmx-remote.mod b/dist/src/assembly/modules/jmx-remote.mod new file mode 100644 index 00000000..e0850ad1 --- /dev/null +++ b/dist/src/assembly/modules/jmx-remote.mod @@ -0,0 +1,26 @@ +[description] +Enables clear-text remote RMI access to platform MBeans. + +[depend] +jmx + +[xml] +etc/zeneventserver/jetty/jetty-jmx-remote.xml + +[ini-template] +# tag::documentation[] +## The host/address to bind the RMI server to. +# jetty.jmxremote.rmiserverhost=localhost + +## The port the RMI server listens to (0 means a random port is chosen). +# jetty.jmxremote.rmiserverport=1099 + +## The host/address to bind the RMI registry to. +# jetty.jmxremote.rmiregistryhost=localhost + +## The port the RMI registry listens to. +# jetty.jmxremote.rmiregistryport=1099 + +## The host name exported in the RMI stub. +-Djava.rmi.server.hostname=localhost +# end::documentation[] diff --git a/dist/src/assembly/modules/jmx.mod b/dist/src/assembly/modules/jmx.mod new file mode 100644 index 00000000..4c3da3dd --- /dev/null +++ b/dist/src/assembly/modules/jmx.mod @@ -0,0 +1,11 @@ +[description] +Enables local JMX support for Jetty components. + +[depend] +server + +[lib] +lib/jetty-jmx-${jetty.version}.jar + +[xml] +etc/zeneventserver/jetty/jetty-jmx.xml diff --git a/dist/src/main/assembly/zeneventserver-webapp.xml b/dist/src/main/assembly/zeneventserver-webapp.xml index 38ce7232..5592a9ea 100644 --- a/dist/src/main/assembly/zeneventserver-webapp.xml +++ b/dist/src/main/assembly/zeneventserver-webapp.xml @@ -27,6 +27,7 @@ org.eclipse.jetty:jetty-servlet org.eclipse.jetty:jetty-security org.eclipse.jetty:jetty-util-ajax + org.eclipse.jetty:jetty-jmx org.eclipse.jetty.toolchain:jetty-jakarta-servlet-api org.zenoss.zep:zep-core org.slf4j:slf4j-api diff --git a/webapp/pom.xml b/webapp/pom.xml index b606e072..873f3229 100644 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -152,7 +152,13 @@ ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-deploy.xml ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-http.xml ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-webapp.xml + ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx.xml + ${project.basedir}/../dist/src/assembly/etc/zeneventserver/jetty/jetty-jmx-remote.xml + + ${project.basedir}/../dist/src/assembly/modules/jmx.mod + ${project.basedir}/../dist/src/assembly/modules/jmx-remote.mod + /zeneventserver true @@ -191,6 +197,11 @@ jetty-util-ajax ${jetty.version} + + org.eclipse.jetty + jetty-jmx + ${jetty.version} + org.eclipse.jetty.toolchain jetty-jakarta-servlet-api From f2209dc43937efff0f7fa25c37ae156c94207e70 Mon Sep 17 00:00:00 2001 From: azam Date: Wed, 22 May 2024 16:43:10 +0300 Subject: [PATCH 6/7] Bump version to 2.8.2 --- core/pom.xml | 2 +- dist/pom.xml | 2 +- pom.xml | 2 +- webapp/pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 04310cbb..a6aa3cd5 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -13,7 +13,7 @@ org.zenoss.zep zep-parent - 2.8.2-SNAPSHOT + 2.8.2 ../pom.xml diff --git a/dist/pom.xml b/dist/pom.xml index 3e523426..f48ac6f1 100644 --- a/dist/pom.xml +++ b/dist/pom.xml @@ -13,7 +13,7 @@ org.zenoss.zep zep-parent - 2.8.2-SNAPSHOT + 2.8.2 ../pom.xml diff --git a/pom.xml b/pom.xml index db2d7efa..84e8e128 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ org.zenoss.zep zep-parent pom - 2.8.2-SNAPSHOT + 2.8.2 Zenoss Event Processor Parent http://www.zenoss.com diff --git a/webapp/pom.xml b/webapp/pom.xml index 873f3229..eb9643e9 100644 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -13,7 +13,7 @@ org.zenoss.zep zep-parent - 2.8.2-SNAPSHOT + 2.8.2 ../pom.xml From b489276872164c49cb3e108801d40b10a318d302 Mon Sep 17 00:00:00 2001 From: azam Date: Mon, 27 May 2024 11:56:27 +0300 Subject: [PATCH 7/7] addd bean creation for rest endpoint --- .../org/zenoss/zep/rest/IncManResource.java | 87 +++++++++++++++++++ core/src/main/resources/zep-config-rest.xml | 5 +- 2 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/zenoss/zep/rest/IncManResource.java diff --git a/core/src/main/java/org/zenoss/zep/rest/IncManResource.java b/core/src/main/java/org/zenoss/zep/rest/IncManResource.java new file mode 100644 index 00000000..3f1918ec --- /dev/null +++ b/core/src/main/java/org/zenoss/zep/rest/IncManResource.java @@ -0,0 +1,87 @@ +package org.zenoss.zep.rest; + +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; +import org.jboss.resteasy.annotations.GZIP; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.zenoss.protobufs.ProtobufConstants; +import org.zenoss.protobufs.zep.Zep.EventDetail; +import org.zenoss.protobufs.zep.Zep.EventDetailSet; +import org.zenoss.protobufs.zep.Zep.EventTriggerSubscription; +import org.zenoss.zep.ZepException; +import org.zenoss.zep.dao.EventSignalSpool; +import org.zenoss.zep.dao.EventSignalSpoolDao; +import org.zenoss.zep.dao.EventTriggerSubscriptionDao; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@Path("1.0/incman") +public class IncManResource { + private static final Logger logger = LoggerFactory.getLogger(IncManResource.class); + + public class TriggerSubscriptionNotFound extends ZepException {} + + private EventTriggerSubscriptionDao eventTriggerSubscriptionDao; + private EventSignalSpoolDao eventSignalSpoolDao; + + public void setEventTriggerSubscriptionDao(EventTriggerSubscriptionDao eventTriggerSubscriptionDao) { + this.eventTriggerSubscriptionDao = eventTriggerSubscriptionDao; + } + + public void setEventSignalSpoolDao(EventSignalSpoolDao eventSignalSpoolDao) { + this.eventSignalSpoolDao = eventSignalSpoolDao; + } + + private String getTriggerSubscriptionUuid(String triggerUuid, String notificationUuid) throws ZepException { + List triggerSubscriptions = + this.eventTriggerSubscriptionDao.findAll(); + + logger.debug("Searching for " + triggerUuid + "/" + notificationUuid); + for (EventTriggerSubscription triggerSubscription : + triggerSubscriptions) { + logger.debug("\tComparing to " + triggerSubscription.getTriggerUuid() + "/" + triggerSubscription.getSubscriberUuid()); + + if ((triggerSubscription.getTriggerUuid().equals(triggerUuid)) && + (triggerSubscription.getSubscriberUuid().equals(notificationUuid))) { + logger.debug("Found!"); + return triggerSubscription.getUuid(); + } + } + logger.debug("Not found!"); + throw new TriggerSubscriptionNotFound(); + } + + @POST + @Path("trigger_spool") + @Produces({ MediaType.APPLICATION_JSON, ProtobufConstants.CONTENT_TYPE_PROTOBUF }) + @GZIP + public Response insertTriggerSpool(EventDetailSet update) throws ZepException { + EventSignalSpool spool; + Map updatesByKey = new HashMap(); + + for (EventDetail detail : update.getDetailsList()) { + updatesByKey.put(detail.getName(), detail.getValue(0)); + } + + String triggerSubscriptionUuid = this.getTriggerSubscriptionUuid( + updatesByKey.get("trigger_uuid"), updatesByKey.get("notification_uuid")); + + spool = new EventSignalSpool(); + spool.setSubscriptionUuid(triggerSubscriptionUuid); + spool.setEventSummaryUuid(updatesByKey.get("event_summary_uuid")); + spool.setSentSignal(true); + spool.setCreated(System.currentTimeMillis()); + spool.setFlushTime(Long.MAX_VALUE); + + this.eventSignalSpoolDao.create(spool); + + return Response.noContent().build(); + } + +} diff --git a/core/src/main/resources/zep-config-rest.xml b/core/src/main/resources/zep-config-rest.xml index bf1321ea..e18e8fe0 100644 --- a/core/src/main/resources/zep-config-rest.xml +++ b/core/src/main/resources/zep-config-rest.xml @@ -40,6 +40,9 @@ - + + + +