Search in sources :

Example 1 with Order

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

the class OrderScheduleTimeCallback method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("Handle Order schedule time ...");
    DbClient dbClient = getDbClient();
    List<URI> orders = dbClient.queryByType(Order.class, true);
    for (URI uri : orders) {
        Order order = dbClient.queryObject(Order.class, uri);
        if (order == null)
            continue;
        if (order.getScheduledEventId() == null) {
            if (order.getExecutionWindowId() == null || order.getExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
                Calendar scheduleTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                scheduleTime.setTime(order.getLastUpdated());
                order.setExecutionWindowId(new NamedURI(ExecutionWindow.NEXT, "NEXT"));
                order.setScheduledTime(scheduleTime);
            } else {
                // For original orders, set schedule time to
                // either 1) the next execution window starting time
                // or     2) the current time if it is in current execution window
                ExecutionWindow executionWindow = dbClient.queryObject(ExecutionWindow.class, order.getExecutionWindowId().getURI());
                if (executionWindow == null)
                    continue;
                ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
                order.setScheduledTime(helper.getScheduledTime());
            }
            dbClient.updateObject(order);
        }
    }
    return;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) DbClient(com.emc.storageos.db.client.DbClient) NamedURI(com.emc.storageos.db.client.model.NamedURI) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 2 with Order

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

the class DbConsistencyCheckerHelperTest method testTimeSeriesAlternateId.

@Test
public void testTimeSeriesAlternateId() throws Exception {
    DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
    Order order = new Order();
    order.setId(URIUtil.createId(Order.class));
    order.setLabel("order2");
    order.setTenant("tenant");
    order.setIndexed(true);
    getDbClient().createObject(order);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    ColumnFamily<String, TimeSeriesIndexColumnName> indexCF = 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, 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());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Example 3 with Order

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

the class OrderService method createOrder.

@POST
@Path("")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderRestRep createOrder(OrderCreateParam createParam) {
    StorageOSUser user = getUserFromContext();
    URI tenantId = createParam.getTenantId();
    if (tenantId != null) {
        verifyAuthorizedInTenantOrg(tenantId, user);
    } else {
        tenantId = uri(user.getTenantId());
    }
    Order order = createNewOrder(user, tenantId, createParam);
    orderManager.processOrder(order);
    order = orderManager.getOrderById(order.getId());
    List<OrderParameter> orderParameters = orderManager.getOrderParameters(order.getId());
    auditOpSuccess(OperationTypeEnum.CREATE_ORDER, order.auditParameters());
    return map(order, orderParameters);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) URI(java.net.URI) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 4 with Order

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

the class OrderService method getOrders.

/**
 * Gets the list of orders
 * @param tenantId the URN of a tenant
 * @brief List Orders
 * @return a list of orders
 * @throws DatabaseException when a DB error occurs
 */
@GET
@Path("/all")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public OrderList getOrders(@DefaultValue("") @QueryParam(SearchConstants.TENANT_ID_PARAM) String tenantId) throws DatabaseException {
    StorageOSUser user = getUserFromContext();
    if (StringUtils.isBlank(tenantId)) {
        tenantId = user.getTenantId();
    }
    verifyAuthorizedInTenantOrg(uri(tenantId), getUserFromContext());
    List<Order> orders = orderManager.getOrders(uri(tenantId));
    return toOrderList(orders);
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Order

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

the class OrderService method getOrderById.

private Order getOrderById(URI id, boolean checkInactive) {
    Order order = orderManager.getOrderById(id);
    ArgValidator.checkEntity(order, id, isIdEmbeddedInURL(id), checkInactive);
    return order;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order)

Aggregations

Order (com.emc.storageos.db.client.model.uimodels.Order)53 Test (org.junit.Test)15 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)12 URI (java.net.URI)12 Path (javax.ws.rs.Path)11 Produces (javax.ws.rs.Produces)9 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)8 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)7 GET (javax.ws.rs.GET)7 AbstractExecutionService (com.emc.sa.engine.service.AbstractExecutionService)6 ExecutionService (com.emc.sa.engine.service.ExecutionService)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 ServiceNotFoundException (com.emc.sa.engine.service.ServiceNotFoundException)5 Date (java.util.Date)5 ModelClient (com.emc.sa.model.dao.ModelClient)4 TimeSeriesConstraint (com.emc.storageos.db.client.constraint.TimeSeriesConstraint)4 ExecutionState (com.emc.storageos.db.client.model.uimodels.ExecutionState)4 Consumes (javax.ws.rs.Consumes)4 BaseModelTest (com.emc.sa.model.BaseModelTest)3 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)3