use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class ActionableEventFinder method findPendingByResource.
public List<ActionableEvent> findPendingByResource(URI resourceId) {
List<NamedElement> events = findIdsByResource(resourceId);
List<ActionableEvent> result = Lists.newArrayList();
for (ActionableEvent event : findByIds(toURIs(events))) {
if (event != null && event.getEventStatus() != null && (event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.pending.name().toString()) || event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.failed.name().toString()))) {
result.add(event);
}
}
return result;
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class EventUtils method createActionableEvent.
/**
* Creates an actionable event and persists to the database
*
* @param dbClient db client
* @param eventCode the code for the event
* @param tenant the tenant that owns the event
* @param name the name of the event
* @param description the description of what the event will do
* @param warning the warning message to display to the user if the event will cause data loss or other impacting change
* @param resource the resource that owns the event (host, cluster, etc)
* @param affectedResources the resources that are affected by this event (host, cluster, initiator, etc)
* @param approveMethod the method to invoke when approving the event
* @param approveParameters the parameters to pass to the approve method
* @param declineMethod the method to invoke when declining the event
* @param declineParameters the parameters to pass to the decline method
*/
public static void createActionableEvent(DbClient dbClient, EventUtils.EventCode eventCode, URI tenant, String name, String description, String warning, DataObject resource, Collection<URI> affectedResources, String approveMethod, Object[] approveParameters, String declineMethod, Object[] declineParameters) {
ActionableEvent duplicateEvent = null;
if (ALLOWED_DUPLICATE_EVENTS.contains(eventCode)) {
duplicateEvent = getDuplicateEvent(dbClient, eventCode.getCode(), resource.getId(), affectedResources);
} else {
duplicateEvent = getDuplicateEvent(dbClient, eventCode.getCode(), resource.getId(), null);
}
if (duplicateEvent != null) {
log.info("Duplicate event " + duplicateEvent.getId() + " is already in a pending state for resource " + resource.getId() + ". Will not create a new event");
duplicateEvent.setCreationTime(Calendar.getInstance());
duplicateEvent.setDescription(description);
duplicateEvent.setWarning(warning);
duplicateEvent.setAffectedResources(getAffectedResources(affectedResources));
setEventMethods(duplicateEvent, approveMethod, approveParameters, declineMethod, declineParameters);
dbClient.updateObject(duplicateEvent);
} else {
ActionableEvent event = new ActionableEvent();
event.setEventCode(eventCode.getCode());
event.setId(URIUtil.createId(ActionableEvent.class));
event.setTenant(tenant);
event.setDescription(description);
event.setWarning(warning);
event.setEventStatus(ActionableEvent.Status.pending.name());
event.setResource(new NamedURI(resource.getId(), resource.getLabel()));
event.setAffectedResources(getAffectedResources(affectedResources));
setEventMethods(event, approveMethod, approveParameters, declineMethod, declineParameters);
event.setLabel(name);
dbClient.createObject(event);
log.info("Created Actionable Event: " + event.getId() + " Tenant: " + event.getTenant() + " Description: " + event.getDescription() + " Warning: " + event.getWarning() + " Event Status: " + event.getEventStatus() + " Resource: " + event.getResource() + " Event Code: " + event.getEventCode() + " Approve Method: " + approveMethod + " Decline Method: " + declineMethod);
}
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class EventUtils method deleteResourceEvents.
/**
* Delete all actionable events for a given resource
*
* @param dbClient db client
* @param resourceId the resource id for events to delete
*/
public static void deleteResourceEvents(DbClient dbClient, URI resourceId) {
List<ActionableEvent> events = findResourceEvents(dbClient, resourceId);
log.info("Deleting actionable events for resource " + resourceId);
for (ActionableEvent event : events) {
log.info("Deleting Actionable Event: " + event.getId() + " Tenant: " + event.getTenant() + " Description: " + event.getDescription() + " Warning: " + event.getWarning() + " Event Status: " + event.getEventStatus() + " Resource: " + event.getResource() + " Event Code: " + event.getEventCode());
dbClient.markForDeletion(event);
}
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class EventUtils method getEvents.
private static List<ActionableEvent> getEvents(DbClient dbClient, Constraint constraint) {
URIQueryResultList results = new URIQueryResultList();
dbClient.queryByConstraint(constraint, results);
List<ActionableEvent> events = Lists.newArrayList();
Iterator<URI> it = results.iterator();
while (it.hasNext()) {
ActionableEvent event = dbClient.queryObject(ActionableEvent.class, it.next());
if (event != null) {
events.add(event);
}
}
return events;
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class ActionableEventFinder method findPendingByAffectedResources.
public List<ActionableEvent> findPendingByAffectedResources(URI affectedResourceId) {
List<NamedElement> events = findIdsByAffectedResources(affectedResourceId);
List<ActionableEvent> result = Lists.newArrayList();
for (ActionableEvent event : findByIds(toURIs(events))) {
if (event != null && event.getEventStatus() != null && (event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.pending.name().toString()) || event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.failed.name().toString()))) {
result.add(event);
}
}
return result;
}
Aggregations