use of com.emc.storageos.db.client.model.uimodels.ExecutionState in project coprhd-controller by CoprHD.
the class ServiceRunner method dumpOrder.
public static void dumpOrder(Order order) {
print("Order: %s", order.getId());
print(" Status: %s", order.getOrderStatus());
print(" Message: %s", order.getMessage());
CatalogService service = load(order.getCatalogServiceId(), CatalogService.class);
print(" Service: %s (%s)", service.getLabel(), service.getBaseService());
ExecutionState state = load(order.getExecutionStateId(), ExecutionState.class);
print(" Time: %s -> %s (%.1f s)", state.getStartDate(), state.getEndDate(), (state.getEndDate().getTime() - state.getStartDate().getTime()) / 1000.0);
List<ExecutionLog> logs = load(state.getLogIds(), ExecutionLog.class);
Collections.sort(logs, LOG_COMPARATOR);
if (!logs.isEmpty()) {
print(" Logs");
for (ExecutionLog log : logs) {
print(" - %s\t%s\t%s", log.getDate(), log.getLevel(), log.getMessage());
}
}
List<ExecutionTaskLog> taskLogs = load(state.getTaskLogIds(), ExecutionTaskLog.class);
Collections.sort(taskLogs, LOG_COMPARATOR);
if (!taskLogs.isEmpty()) {
print(" Task Logs");
for (ExecutionTaskLog log : taskLogs) {
print(" - %s\t%s\t%s\t%s", log.getDate(), log.getLevel(), log.getMessage(), log.getDetail());
}
}
}
use of com.emc.storageos.db.client.model.uimodels.ExecutionState in project coprhd-controller by CoprHD.
the class ExecutionStateTest method testPersistObject.
@Test
public void testPersistObject() throws Exception {
_logger.info("Starting persist ExecutionState test");
ExecutionState model = new ExecutionState();
model.setLabel("foo");
model.getAffectedResources().add("resource one");
model.getAffectedResources().add("resource two");
Date s = new Date();
Date e = new Date();
model.setStartDate(s);
model.setEndDate(e);
model.setCurrentTask("my current task");
model.setExecutionStatus(ExecutionStatus.COMPLETED.name());
URI logIdOne = URIUtil.createId(ExecutionLog.class);
URI logIdTwo = URIUtil.createId(ExecutionLog.class);
model.getLogIds().add(logIdOne.toString());
model.getLogIds().add(logIdTwo.toString());
URI taskLogIdOne = URIUtil.createId(ExecutionTaskLog.class);
URI taskLogIdTwo = URIUtil.createId(ExecutionTaskLog.class);
model.getTaskLogIds().add(taskLogIdOne.toString());
model.getTaskLogIds().add(taskLogIdTwo.toString());
save(model);
model = findById(model.getId());
Assert.assertNotNull(model);
Assert.assertEquals("foo", model.getLabel());
Assert.assertEquals(2, model.getAffectedResources().size());
Assert.assertTrue(model.getAffectedResources().contains("resource one"));
Assert.assertTrue(model.getAffectedResources().contains("resource two"));
Assert.assertEquals(s, model.getStartDate());
Assert.assertEquals(e, model.getEndDate());
Assert.assertEquals("my current task", model.getCurrentTask());
Assert.assertEquals(2, model.getLogIds().size());
Assert.assertTrue(model.getLogIds().contains(logIdOne.toString()));
Assert.assertTrue(model.getLogIds().contains(logIdTwo.toString()));
Assert.assertEquals(2, model.getTaskLogIds().size());
Assert.assertTrue(model.getTaskLogIds().contains(taskLogIdOne.toString()));
Assert.assertTrue(model.getTaskLogIds().contains(taskLogIdTwo.toString()));
}
use of com.emc.storageos.db.client.model.uimodels.ExecutionState in project coprhd-controller by CoprHD.
the class OrderTest method testSaveOrderAndExecutionState.
@Test
public void testSaveOrderAndExecutionState() throws Exception {
_logger.info("Starting save Order and Execution State test");
ModelClient modelClient = getModelClient();
Order model = new Order();
model.setLabel("foo");
URI catalogServiceId = new URI("urn:CatalogService:1");
model.setCatalogServiceId(catalogServiceId);
Date d = new Date();
model.setDateCompleted(d);
model.setMessage("my message");
model.setOrderStatus(OrderStatus.CANCELLED.name());
model.setSubmittedByUserId("urn:User:1");
model.setSummary("my summary");
ExecutionState executionState = new ExecutionState();
executionState.setExecutionStatus(ExecutionStatus.NONE.name());
executionState.setStartDate(d);
executionState.setCurrentTask("my task");
modelClient.save(executionState);
model.setExecutionStateId(executionState.getId());
ExecutionLog executionLog1 = new ExecutionLog();
executionLog1.setLevel(LogLevel.DEBUG.name());
executionLog1.setMessage("my message 1");
modelClient.save(executionLog1);
executionState.addExecutionLog(executionLog1);
ExecutionLog executionLog2 = new ExecutionLog();
executionLog2.setLevel(LogLevel.ERROR.name());
executionLog2.setMessage("my message 2");
modelClient.save(executionLog2);
executionState.addExecutionLog(executionLog2);
modelClient.save(executionState);
save(model);
Order order = findById(model.getId());
Assert.assertNotNull(order);
Assert.assertEquals("foo", order.getLabel());
Assert.assertEquals(catalogServiceId, order.getCatalogServiceId());
Assert.assertEquals(d, order.getDateCompleted());
Assert.assertEquals(executionState.getId(), order.getExecutionStateId());
Assert.assertEquals("my message", order.getMessage());
Assert.assertEquals(OrderStatus.CANCELLED.name(), order.getOrderStatus());
Assert.assertEquals("urn:User:1", order.getSubmittedByUserId());
Assert.assertEquals("my summary", order.getSummary());
ExecutionState exeState = modelClient.executionStates().findById(order.getExecutionStateId());
Assert.assertNotNull(exeState);
Assert.assertEquals(ExecutionStatus.NONE.name(), exeState.getExecutionStatus());
Assert.assertEquals(d, exeState.getStartDate());
Assert.assertEquals(2, exeState.getLogIds().size());
List<ExecutionLog> logs = modelClient.executionLogs().findByIds(exeState.getLogIds());
Assert.assertNotNull(logs);
Assert.assertEquals(2, logs.size());
}
use of com.emc.storageos.db.client.model.uimodels.ExecutionState in project coprhd-controller by CoprHD.
the class OrderService method dumpOrder.
private void dumpOrder(PrintStream out, Order order) {
out.print(order.toString());
out.println("Parameters");
out.println("----------");
List<OrderParameter> parameters = orderManager.getOrderParameters(order.getId());
for (OrderParameter parameter : parameters) {
out.print(parameter.toString());
}
out.println("Execution State");
out.println("---------------");
ExecutionState state = orderManager.getOrderExecutionState(order.getExecutionStateId());
if (state != null) {
out.print(state.toString());
}
out.println("Logs");
out.println("----");
out.println(" Execution Logs");
if (state != null) {
List<ExecutionLog> elogs = orderManager.getOrderExecutionLogs(order);
for (ExecutionLog elog : elogs) {
out.print(elog.toString());
}
}
out.println(" Execution Task Logs");
if (state != null) {
List<ExecutionTaskLog> tlogs = orderManager.getOrderExecutionTaskLogs(order);
for (ExecutionTaskLog tlog : tlogs) {
out.print(tlog.toString());
}
}
}
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);
}
}
Aggregations