use of com.emc.storageos.db.client.model.uimodels.Order 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.Order in project coprhd-controller by CoprHD.
the class SortedIndexTest method createOrder.
private static Order createOrder(OrderStatus status) {
Order model = new Order();
model.setId(URIUtil.createId(Order.class));
model.setLabel("foo");
URI catalogServiceId = URIUtil.createId(CatalogService.class);
model.setCatalogServiceId(catalogServiceId);
Date d = new Date();
model.setDateCompleted(d);
model.setMessage("my message");
model.setOrderStatus(status.name());
model.setSubmittedByUserId("urn:User:1");
model.setSummary("my summary");
return model;
}
use of com.emc.storageos.db.client.model.uimodels.Order in project coprhd-controller by CoprHD.
the class ApprovalService method updateApproval.
/**
* Update approval
*
* @param param Approval update parameters
* @param id the URN the approval
* @prereq none
* @brief Update Approval
* @return No data returned in response body
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_APPROVER })
public ApprovalRestRep updateApproval(@PathParam("id") URI id, ApprovalUpdateParam param) {
ApprovalRequest approval = getApprovalById(id, true);
StorageOSUser user = getUserFromContext();
verifyAuthorizedInTenantOrg(uri(approval.getTenant()), user);
Order order = orderManager.getOrderById(approval.getOrderId());
if (order.getSubmittedByUserId().equals(user.getUserName()) && param.getApprovalStatus().equals(ApprovalStatus.APPROVED.toString())) {
throw APIException.badRequests.updateApprovalBySameUser(user.getUserName());
}
validateParam(param, approval);
updateObject(approval, param);
approvalManager.updateApproval(approval, user);
if (approval.getOrderId() != null) {
if (order != null) {
orderManager.processOrder(order);
}
}
auditOpSuccess(OperationTypeEnum.UPDATE_APPROVAL, approval.auditParameters());
approval = approvalManager.getApprovalById(approval.getId());
return map(approval);
}
use of com.emc.storageos.db.client.model.uimodels.Order in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelperTest method testClassNameTimeSeriesIndex.
@Test
public void testClassNameTimeSeriesIndex() throws Exception {
DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
Order order = new Order();
order.setId(URIUtil.createId(Order.class));
order.setLabel("order1");
order.setSubmittedByUserId("root");
getDbClient().createObject(order);
Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> indexCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>("UserToOrdersByTimeStamp", StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("Order", StringSerializer.get(), CompositeColumnNameSerializer.get());
IndexAndCf indexAndCf = new IndexAndCf(ClassNameTimeSeriesDBIndex.class, indexCF, keyspace);
CheckResult checkResult = new CheckResult();
mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(0, checkResult.getTotal());
keyspace.prepareQuery(cf).withCql(String.format("delete from \"Order\" where key='%s'", order.getId())).execute();
checkResult = new CheckResult();
mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(1, checkResult.getTotal());
keyspace.prepareQuery(indexCF).withCql(mockHelper.getCleanIndexCQL()).execute();
checkResult = new CheckResult();
mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
assertEquals(0, checkResult.getTotal());
}
use of com.emc.storageos.db.client.model.uimodels.Order in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelperTest method testCFIndexForOrder.
@Test
public void testCFIndexForOrder() throws Exception {
DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
Order order = new Order();
order.setId(URIUtil.createId(Order.class));
order.setLabel("order2");
order.setSubmittedByUserId("Tom");
order.setTenant("urn:storageos:TenantOrg:128e0354-c26e-438b-b1e6-1a6ceaa9b380:global");
order.setIndexed(true);
getDbClient().createObject(order);
Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> userToOrdersByTimeStampCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>("UserToOrdersByTimeStamp", StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
ColumnFamily<String, TimeSeriesIndexColumnName> allOrdersByTimeStampCF = new ColumnFamily<String, TimeSeriesIndexColumnName>("AllOrdersByTimeStamp", StringSerializer.get(), TimeSeriesColumnNameSerializer.get());
ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("Order", StringSerializer.get(), CompositeColumnNameSerializer.get());
IndexAndCf indexAndCf = new IndexAndCf(TimeSeriesDbIndex.class, userToOrdersByTimeStampCF, keyspace);
CheckResult checkResult = new CheckResult();
mockHelper.checkCFIndices(TypeMap.getDoType(Order.class), true, checkResult);
assertEquals(0, checkResult.getTotal());
keyspace.prepareQuery(userToOrdersByTimeStampCF).withCql(String.format("delete from \"UserToOrdersByTimeStamp\" where key='%s'", order.getSubmittedByUserId())).execute();
keyspace.prepareQuery(userToOrdersByTimeStampCF).withCql(String.format("delete from \"AllOrdersByTimeStamp\" where key='%s'", order.getTenant())).execute();
checkResult = new CheckResult();
mockHelper.checkCFIndices(TypeMap.getDoType(Order.class), true, checkResult);
assertEquals(2, checkResult.getTotal());
}
Aggregations