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);
}
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());
}
}
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);
}
}
}
}
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");
}
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;
}
Aggregations