Search in sources :

Example 11 with ActionableEvent

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;
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 12 with ActionableEvent

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);
    }
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) NamedURI(com.emc.storageos.db.client.model.NamedURI)

Example 13 with ActionableEvent

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);
    }
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent)

Example 14 with ActionableEvent

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;
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 15 with ActionableEvent

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;
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Aggregations

ActionableEvent (com.emc.storageos.db.client.model.ActionableEvent)18 URI (java.net.URI)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 POST (javax.ws.rs.POST)3 ComputeSystemController (com.emc.storageos.computesystemcontroller.ComputeSystemController)2 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)2 TaskList (com.emc.storageos.model.TaskList)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 GET (javax.ws.rs.GET)2 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1 AggregationQueryResultList (com.emc.storageos.db.client.constraint.AggregationQueryResultList)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 DataObject (com.emc.storageos.db.client.model.DataObject)1 Host (com.emc.storageos.db.client.model.Host)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1