Search in sources :

Example 6 with ServiceField

use of com.emc.sa.descriptor.ServiceField in project coprhd-controller by CoprHD.

the class OrderManagerImpl method createOrder.

public Order createOrder(Order order, List<OrderParameter> orderParameters, StorageOSUser user) {
    CatalogService catalogService = catalogServiceManager.getCatalogServiceById(order.getCatalogServiceId());
    ServiceDescriptor serviceDescriptor = ServiceDescriptorUtil.getServiceDescriptorByName(serviceDescriptors, workflowServiceDescriptor, catalogService.getBaseService());
    order.setOrderNumber(getNextOrderNumber());
    order.setSummary(catalogService.getTitle());
    if (order.getScheduledEventId() == null) {
        if (catalogService.getExecutionWindowRequired()) {
            if (catalogService.getDefaultExecutionWindowId() == null || catalogService.getDefaultExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
                // For default execution window, null is deemed as NEXT window as well.
                // But we always need to set order execution window to NEXT explicitly to different it
                // with INFINITE window in new scheduler framework.
                // Set schedule time to latest updated time.  It would still be scheduled in executed window
                Calendar scheduleTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                scheduleTime.setTime(new Date());
                order.setScheduledTime(scheduleTime);
                order.setExecutionWindowId(new NamedURI(ExecutionWindow.NEXT, "NEXT"));
            } else {
                // 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 = client.findById(catalogService.getDefaultExecutionWindowId().getURI());
                ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
                order.setScheduledTime(helper.getScheduledTime());
                order.setExecutionWindowId(catalogService.getDefaultExecutionWindowId());
            }
        } else {
            // If no execution window is indicated, order will be submitted to DQ immediately.
            ;
        }
    } else {
        // ExecutionWindow and ScheduleTime are already set via Parameter
        ;
    }
    order.setMessage("");
    order.setSubmittedByUserId(user.getUserName());
    order.setOrderStatus(OrderStatus.PENDING.name());
    createExecutionState(order, user);
    client.save(order);
    Map<String, String> assetOptions = getAssetValues(serviceDescriptor, orderParameters);
    for (OrderParameter orderParameter : orderParameters) {
        ServiceField serviceField = findServiceField(serviceDescriptor, orderParameter.getLabel());
        String friendlyLabel = serviceField.getLabel();
        StringBuilder friendlyValue = new StringBuilder();
        List<String> values = TextUtils.parseCSV(orderParameter.getValue());
        for (String value : values) {
            if (friendlyValue.length() > 0) {
                friendlyValue.append(",");
            }
            friendlyValue.append(getFriendlyValue(serviceField, value, assetOptions, user));
        }
        orderParameter.setFriendlyLabel(friendlyLabel);
        orderParameter.setFriendlyValue(friendlyValue.toString());
        createOrderParameter(orderParameter);
    }
    return order;
}
Also used : ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) ServiceField(com.emc.sa.descriptor.ServiceField)

Example 7 with ServiceField

use of com.emc.sa.descriptor.ServiceField in project coprhd-controller by CoprHD.

the class OrderManagerImpl method findServiceField.

private ServiceField findServiceField(ServiceDescriptor serviceDescriptor, String serviceFieldName) {
    for (ServiceField serviceField : serviceDescriptor.getAllFieldList()) {
        if (StringUtils.equalsIgnoreCase(serviceFieldName, serviceField.getName())) {
            return serviceField;
        }
    }
    log.info(String.format("Unexpected service field value found: %s", serviceFieldName));
    ServiceField field = new ServiceField();
    field.setName(serviceFieldName);
    field.setLabel(serviceFieldName);
    return field;
}
Also used : ServiceField(com.emc.sa.descriptor.ServiceField)

Aggregations

ServiceField (com.emc.sa.descriptor.ServiceField)7 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)4 AssetOptionsProvider (com.emc.sa.asset.AssetOptionsProvider)1 WorkflowServiceDescriptor (com.emc.sa.catalog.WorkflowServiceDescriptor)1 ServiceDefinition (com.emc.sa.descriptor.ServiceDefinition)1 ServiceFieldTable (com.emc.sa.descriptor.ServiceFieldTable)1 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 CatalogServiceField (com.emc.storageos.db.client.model.uimodels.CatalogServiceField)1 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)1 ExecutionWindowHelper (com.emc.storageos.db.client.util.ExecutionWindowHelper)1 CustomServicesWorkflowDocument (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)1 Input (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Input)1 InputGroup (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.InputGroup)1 Step (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step)1 CatalogServiceFieldParam (com.emc.vipr.model.catalog.CatalogServiceFieldParam)1 Parameter (com.emc.vipr.model.catalog.Parameter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1