Search in sources :

Example 6 with ActionableEvent

use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.

the class EventService method approveEvent.

/**
 * Approve Event
 *
 * @param id
 * @brief Change an event to approved
 * @return
 * @throws DatabaseException
 */
@POST
@Path("/{id}/approve")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskList approveEvent(@PathParam("id") URI id) throws DatabaseException {
    ActionableEvent event = queryObject(ActionableEvent.class, id, false);
    verifyAuthorizedInTenantOrg(event.getTenant(), getUserFromContext());
    if (!StringUtils.equalsIgnoreCase(event.getEventStatus(), ActionableEvent.Status.pending.name()) && !StringUtils.equalsIgnoreCase(event.getEventStatus(), ActionableEvent.Status.failed.name())) {
        throw APIException.badRequests.eventCannotBeApproved(event.getEventStatus());
    }
    _log.info("Approving Actionable Event: " + event.getId() + " Tenant: " + event.getTenant() + " Description: " + event.getDescription() + " Warning: " + event.getWarning() + " Event Status: " + event.getEventStatus() + " Resource: " + event.getResource() + " Event Code: " + event.getEventCode());
    return executeEventMethod(event, true);
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with ActionableEvent

use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.

the class EventService method executeEventMethod.

/**
 * Executes an actionable event method
 *
 * @param event the event to execute
 * @param approve if true, the action is to approve, if false the action is to decline
 * @return list of tasks
 */
public TaskList executeEventMethod(ActionableEvent event, boolean approve) {
    TaskList taskList = new TaskList();
    byte[] method = approve ? event.getApproveMethod() : event.getDeclineMethod();
    String eventStatus = approve ? ActionableEvent.Status.approved.name() : ActionableEvent.Status.declined.name();
    event.setEventExecutionTime(Calendar.getInstance());
    event.setApproveDetails(new StringSet(getEventDetails(event, true)));
    event.setDeclineDetails(new StringSet(getEventDetails(event, false)));
    if (method == null || method.length == 0) {
        _log.info("Method is null or empty for event " + event.getId());
        event.setEventStatus(eventStatus);
        _dbClient.updateObject(event);
        return taskList;
    }
    ActionableEvent.Method eventMethod = ActionableEvent.Method.deserialize(method);
    if (eventMethod == null) {
        _log.info("Event method is null or empty for event " + event.getId());
        event.setEventStatus(eventStatus);
        _dbClient.updateObject(event);
        return taskList;
    }
    try {
        Method classMethod = getMethod(ActionableEventExecutor.class, eventMethod.getMethodName());
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        ActionableEventExecutor executor = new ActionableEventExecutor(_dbClient, controller);
        Object[] parameters = Arrays.copyOf(eventMethod.getArgs(), eventMethod.getArgs().length + 1);
        parameters[parameters.length - 1] = event.getId();
        event.setEventStatus(eventStatus);
        _dbClient.updateObject(event);
        TaskResourceRep result = (TaskResourceRep) classMethod.invoke(executor, parameters);
        if (result != null && result.getId() != null) {
            Collection<String> taskCollection = Lists.newArrayList(result.getId().toString());
            ActionableEvent updatedEvent = _dbClient.queryObject(ActionableEvent.class, event.getId());
            updatedEvent.setTaskIds(new StringSet(taskCollection));
            _dbClient.updateObject(updatedEvent);
        }
        taskList.addTask(result);
        return taskList;
    } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        _log.error(e.getMessage(), e.getCause());
        throw APIException.badRequests.errorInvokingEventMethod(event.getId(), eventMethod.getMethodName());
    }
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) TaskList(com.emc.storageos.model.TaskList) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringSet(com.emc.storageos.db.client.model.StringSet) DataObject(com.emc.storageos.db.client.model.DataObject)

Example 8 with ActionableEvent

use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.

the class InitiatorCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    super.complete(dbClient, status, coded);
    for (URI id : getIds()) {
        switch(status) {
            case error:
                dbClient.error(Initiator.class, this.getId(), getOpId(), coded);
                if (!NullColumnValueGetter.isNullURI(eventId)) {
                    ActionableEvent event = dbClient.queryObject(ActionableEvent.class, eventId);
                    if (event != null) {
                        event.setEventStatus(ActionableEvent.Status.failed.name());
                        dbClient.updateObject(event);
                    }
                }
                // be removed if it is no longer in use.
                if (op == InitiatorOperation.ADD) {
                    removeInitiator(id, dbClient);
                }
                break;
            default:
                dbClient.ready(Initiator.class, this.getId(), getOpId());
                // be removed if it is no longer in use.
                if (op == InitiatorOperation.REMOVE) {
                    removeInitiator(id, dbClient);
                }
        }
    }
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) URI(java.net.URI)

Example 9 with ActionableEvent

use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.

the class ActionableEventScrubberExecutor method deleteOldEvents.

private void deleteOldEvents() {
    log.info("Looking for completed events older than {} minutes", getConfigProperty(EVENT_TTL_MINS_PROPERTY, MINIMUM_PERIOD_MINS));
    long eventLifetimeMicroSeconds = getConfigProperty(EVENT_TTL_MINS_PROPERTY, MINIMUM_PERIOD_MINS) * MIN_TO_MICROSECS;
    long currentTimeMicroseconds = TimeUUIDUtils.getMicrosTimeFromUUID(TimeUUIDUtils.getUniqueTimeUUIDinMicros());
    long startTimeMicroSec = currentTimeMicroseconds - eventLifetimeMicroSeconds;
    Calendar startTimeMarker = Calendar.getInstance();
    startTimeMarker.setTimeInMillis(startTimeMicroSec / MINI_TO_MICROSECS);
    List<URI> ids = dbClient.queryByType(ActionableEvent.class, true);
    Iterator<ActionableEvent> events = dbClient.queryIterativeObjects(ActionableEvent.class, ids, true);
    List<ActionableEvent> toBeDeleted = Lists.newArrayList();
    while (events.hasNext()) {
        ActionableEvent event = events.next();
        if (event.getCreationTime().after(startTimeMarker)) {
            continue;
        }
        if (event != null && !ActionableEvent.Status.pending.name().equalsIgnoreCase(event.getEventStatus()) && !ActionableEvent.Status.failed.name().equalsIgnoreCase(event.getEventStatus())) {
            toBeDeleted.add(event);
        }
        if (toBeDeleted.size() >= DELETE_BATCH_SIZE) {
            log.info("Deleting {} Actionable Events", toBeDeleted.size());
            dbClient.markForDeletion(toBeDeleted);
            toBeDeleted.clear();
        }
    }
    if (!toBeDeleted.isEmpty()) {
        log.info("Deleting {} Actionable Events", toBeDeleted.size());
        dbClient.markForDeletion(toBeDeleted);
    }
    log.info("delete completed actionable events successfully");
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) Calendar(java.util.Calendar) URI(java.net.URI)

Example 10 with ActionableEvent

use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.

the class EventUtils method findAffectedResourcePendingEvents.

/**
 * Get list of pending events for an affected resource
 *
 * @param dbClient the dbclient
 * @param resourceId the resource to search for in affected resources
 * @return list of pending actionable events
 */
public static List<ActionableEvent> findAffectedResourcePendingEvents(DbClient dbClient, URI resourceId) {
    List<ActionableEvent> events = findAffectedResourceEvents(dbClient, resourceId);
    List<ActionableEvent> result = Lists.newArrayList();
    for (ActionableEvent event : events) {
        if (event != null && event.getEventStatus() != null && (event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.pending.name()) || event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.failed.name()))) {
            result.add(event);
        }
    }
    return result;
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent)

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