Search in sources :

Example 6 with ExecutionState

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

the class ExecutionEngineImpl method updateExecutionStatus.

protected void updateExecutionStatus(ExecutionStatus status) {
    ExecutionState state = ExecutionUtils.currentContext().getExecutionState();
    state.setExecutionStatus(status.name());
    if (modelClient != null) {
        modelClient.save(state);
    }
}
Also used : ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState)

Example 7 with ExecutionState

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

the class ExecutionEngineImpl method finishExecuting.

protected void finishExecuting(ExecutionStatus status) {
    ExecutionState state = ExecutionUtils.currentContext().getExecutionState();
    state.setCurrentTask("");
    state.setEndDate(new Date());
    state.setExecutionStatus(status.name());
    if (modelClient != null) {
        modelClient.save(state);
    }
}
Also used : ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState) Date(java.util.Date)

Example 8 with ExecutionState

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

the class ExecutionEngineMonitor method killOrder.

/**
 * Kills an order that was running within a dead engine.
 *
 * @param orderId
 *            the order ID.
 * @param detailedMessage
 *            message to be added to order log
 */
public void killOrder(URI orderId, String detailedMessage) {
    try {
        Order order = modelClient.orders().findById(orderId);
        if (order != null) {
            if (log.isInfoEnabled()) {
                log.info("Killing order: " + orderId);
            }
            // Mark the order as failed
            order.setOrderStatus(OrderStatus.ERROR.name());
            modelClient.save(order);
            if (order.getExecutionStateId() != null) {
                ExecutionState execState = modelClient.executionStates().findById(order.getExecutionStateId());
                // Mark the execution state as failed
                execState.setExecutionStatus(ExecutionStatus.FAILED.name());
                modelClient.save(execState);
                // Find any task logs that are 'in progress' (no elapsed time) and set the elapsed
                List<ExecutionTaskLog> logs = modelClient.executionTaskLogs().findByIds(execState.getTaskLogIds());
                for (ExecutionTaskLog log : logs) {
                    if (log.getElapsed() == null) {
                        // Mark any that were in progress as warnings
                        log.setLevel(LogLevel.WARN.name());
                        modelClient.save(log);
                    }
                }
                // Add a new log message indicating it failed due to engine termination
                addTerminationTaskLog(execState, detailedMessage);
            }
        }
    } catch (RuntimeException e) {
        log.error("Failed to terminate order: " + orderId, e);
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState) ExecutionTaskLog(com.emc.storageos.db.client.model.uimodels.ExecutionTaskLog)

Example 9 with ExecutionState

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

the class ExecutionUtils method createContext.

public static void createContext(ModelClient modelClient, Order order) {
    // Ensure there is no existing context
    destroyContext();
    // Initialize the execution state for this order
    ExecutionState state = modelClient.executionStates().findById(order.getExecutionStateId());
    state.setStartDate(new Date());
    ExecutionContext context = currentContext();
    context.setOrder(order);
    context.setModelClient(modelClient);
    context.setExecutionState(state);
    URI scheduledEventId = order.getScheduledEventId();
    if (scheduledEventId != null) {
        ScheduledEvent event = modelClient.findById(ScheduledEvent.class, scheduledEventId);
        context.setScheduledEvent(event);
    }
    CatalogService catalogService = modelClient.catalogServices().findById(order.getCatalogServiceId());
    if (null != catalogService) {
        context.setServiceName(catalogService.getLabel());
    }
    List<OrderParameter> orderParameters = modelClient.orderParameters().findByOrderId(order.getId());
    Map<String, Object> params = Maps.newLinkedHashMap();
    for (OrderParameter param : orderParameters) {
        params.put(param.getLabel(), param.getValue());
    }
    context.setParameters(params);
}
Also used : ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState) ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) URI(java.net.URI) Date(java.util.Date)

Example 10 with ExecutionState

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

the class ExecutionEngineImplTest method createOrder.

protected Order createOrder(String name, Map<String, String> params) {
    ExecutionState state = new ExecutionState();
    modelClient.save(state);
    Order order = new Order();
    order.setExecutionStateId(state.getId());
    CatalogService service = new CatalogService();
    service.setLabel(name);
    modelClient.save(service);
    order.setCatalogServiceId(service.getId());
    modelClient.save(order);
    int index = 0;
    for (Map.Entry<String, String> entry : params.entrySet()) {
        OrderParameter param = new OrderParameter();
        param.setLabel(entry.getKey());
        param.setValue(entry.getValue());
        param.setOrderId(order.getId());
        modelClient.save(param);
    }
    return order;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) Map(java.util.Map)

Aggregations

ExecutionState (com.emc.storageos.db.client.model.uimodels.ExecutionState)10 Order (com.emc.storageos.db.client.model.uimodels.Order)4 Date (java.util.Date)4 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)3 ExecutionLog (com.emc.storageos.db.client.model.uimodels.ExecutionLog)3 ExecutionTaskLog (com.emc.storageos.db.client.model.uimodels.ExecutionTaskLog)3 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)3 URI (java.net.URI)3 BaseModelTest (com.emc.sa.model.BaseModelTest)2 Test (org.junit.Test)2 ModelClient (com.emc.sa.model.dao.ModelClient)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 ScheduledEvent (com.emc.storageos.db.client.model.uimodels.ScheduledEvent)1 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)1 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1