Search in sources :

Example 11 with ServiceDescriptor

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

the class CatalogBuilder method createService.

public CatalogService createService(ServiceDef def, NamedURI parentId) {
    ServiceDescriptor descriptor = descriptors.getDescriptor(Locale.getDefault(), def.baseService);
    String label = StringUtils.defaultString(getMessage(getLabel(def)), descriptor.getTitle());
    String title = StringUtils.defaultString(getMessage(def.title), descriptor.getTitle());
    String description = StringUtils.defaultString(getMessage(def.description), descriptor.getDescription());
    CatalogService service = new CatalogService();
    service.setBaseService(def.baseService);
    service.setLabel(StringUtils.deleteWhitespace(label));
    service.setTitle(title);
    service.setDescription(description);
    service.setImage(def.image);
    service.setCatalogCategoryId(parentId);
    service.setSortedIndex(sortedIndexCounter++);
    log.info("Create new service" + def.baseService);
    if (AllowRecurringSchedulerMigration.RECURRING_ALLOWED_CATALOG_SERVICES.contains(def.baseService) || AllowRecurringSchedulerForApplicationServicesMigration.RECURRING_ALLOWED_CATALOG_SERVICES.contains(def.baseService)) {
        service.setRecurringAllowed(true);
    }
    models.save(service);
    if (def.lockFields != null) {
        for (Map.Entry<String, String> lockField : def.lockFields.entrySet()) {
            CatalogServiceField field = new CatalogServiceField();
            field.setLabel(lockField.getKey());
            field.setValue(lockField.getValue());
            field.setCatalogServiceId(new NamedURI(service.getId(), service.getLabel()));
            models.save(field);
        }
    }
    return service;
}
Also used : CatalogServiceField(com.emc.storageos.db.client.model.uimodels.CatalogServiceField) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) NamedURI(com.emc.storageos.db.client.model.NamedURI) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) Map(java.util.Map)

Example 12 with ServiceDescriptor

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

the class CatalogCategoryManagerImpl method upgradeServices.

private void upgradeServices(CatalogCategory currentCategory, com.emc.sa.catalog.CategoryDef newCategory) {
    List<CatalogService> services = client.catalogServices().findByCatalogCategory(currentCategory.getId());
    // Add or Update Missing Services
    if (newCategory.services != null) {
        for (com.emc.sa.catalog.ServiceDef newService : newCategory.services) {
            List<CatalogService> matchingServices = findServices(services, newService.baseService);
            if (matchingServices != null && !matchingServices.isEmpty()) {
                updateMatchingServices(currentCategory, matchingServices, newService);
            } else {
                ServiceDescriptor descriptor = serviceDescriptors.getDescriptor(Locale.getDefault(), newService.baseService);
                String label = "";
                if (descriptor != null) {
                    label = StringUtils.deleteWhitespace(StringUtils.defaultString(getMessage(getLabel(newService)), descriptor.getTitle()));
                }
                log.info(String.format("CREATING Missing Service %s: for tenant: %s", label, currentCategory.getTenant()));
                catalogServiceManager.createCatalogService(newService, currentCategory);
            }
        }
    }
    // Remove Old Services
    for (CatalogService service : services) {
        ServiceDescriptor serviceDescriptor = null;
        try {
            serviceDescriptor = serviceDescriptors.getDescriptor(Locale.getDefault(), service.getBaseService());
        } catch (IllegalStateException ese) {
        // getDescriptor throws exception when no descriptor found
        }
        if (serviceDescriptor == null) {
            log.info(String.format("REMOVING Service '%s' as base service '%s' no longer exists for tenant:%s", service.getTitle(), service.getBaseService(), currentCategory.getTenant()));
            catalogServiceManager.deleteCatalogService(service);
        }
    }
}
Also used : ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService)

Example 13 with ServiceDescriptor

use of com.emc.sa.descriptor.ServiceDescriptor 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 14 with ServiceDescriptor

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

the class WorkflowServiceDescriptor method listDescriptors.

// This method will only return service descriptors for PUBLISHED workflows
public Collection<ServiceDescriptor> listDescriptors() {
    List<ServiceDescriptor> wfServiceDescriptors = new ArrayList<>();
    List<NamedElement> oeElements = customServicesWorkflowManager.listByStatus(CustomServicesWorkflowStatus.PUBLISHED);
    if (null != oeElements) {
        CustomServicesWorkflow oeWorkflow;
        for (NamedElement oeElement : oeElements) {
            oeWorkflow = customServicesWorkflowManager.getById(oeElement.getId());
            wfServiceDescriptors.add(mapWorkflowToServiceDescriptor(oeWorkflow));
        }
    }
    return wfServiceDescriptors;
}
Also used : ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) ArrayList(java.util.ArrayList) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Aggregations

ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)14 CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)8 WorkflowServiceDescriptor (com.emc.sa.catalog.WorkflowServiceDescriptor)7 CatalogServiceField (com.emc.storageos.db.client.model.uimodels.CatalogServiceField)6 ServiceField (com.emc.sa.descriptor.ServiceField)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 ArrayList (java.util.ArrayList)3 CatalogCategory (com.emc.storageos.db.client.model.uimodels.CatalogCategory)2 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 Map (java.util.Map)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 ServiceDefinition (com.emc.sa.descriptor.ServiceDefinition)1 ServiceFieldTable (com.emc.sa.descriptor.ServiceFieldTable)1 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 NamedElement (com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 CatalogServiceAndFields (com.emc.storageos.db.client.model.uimodels.CatalogServiceAndFields)1