-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addd bean creation for rest endpoint
- Loading branch information
1 parent
f2209dc
commit b489276
Showing
2 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
core/src/main/java/org/zenoss/zep/rest/IncManResource.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<EventTriggerSubscription> 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<String, String> updatesByKey = new HashMap<String, String>(); | ||
|
||
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(); | ||
} | ||
|
||
} |
This file contains 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