Search in sources :

Example 6 with ServiceDescriptor

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

the class CatalogCategoryManagerImpl method updateMatchingServices.

private void updateMatchingServices(CatalogCategory currentCategory, List<CatalogService> services, ServiceDef newService) {
    int pristineService = 0;
    for (CatalogService service : services) {
        if (isMatch(service, newService)) {
            if (pristineService == 0) {
                log.info(String.format("Updating Existing Matching Service %s: for tenant: %s", service.getLabel(), currentCategory.getTenant()));
                ServiceDescriptor descriptor = serviceDescriptors.getDescriptor(Locale.getDefault(), newService.baseService);
                if (descriptor != null) {
                    service.setLabel(StringUtils.deleteWhitespace(StringUtils.defaultString(getMessage(getLabel(newService)), descriptor.getTitle())));
                    service.setTitle(StringUtils.defaultString(getMessage(newService.title), descriptor.getTitle()));
                    service.setDescription(StringUtils.defaultString(getMessage(newService.description), descriptor.getDescription()));
                }
                service.setImage(newService.image);
                catalogServiceManager.updateCatalogService(service, catalogServiceManager.getCatalogServiceFields(service.getId()));
                pristineService++;
            } else {
                log.info(String.format("Removing Duplicate Service %s: for tenant: %s", service.getLabel(), currentCategory.getTenant()));
                catalogServiceManager.deleteCatalogService(service);
            }
        }
    }
}
Also used : ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService)

Example 7 with ServiceDescriptor

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

the class WorkflowServiceDescriptor method mapWorkflowToServiceDescriptor.

private ServiceDescriptor mapWorkflowToServiceDescriptor(final CustomServicesWorkflow from) {
    final ServiceDescriptor to = new ServiceDescriptor();
    try {
        final CustomServicesWorkflowDocument wfDocument = WorkflowHelper.toWorkflowDocument(from);
        if (StringUtils.isEmpty(from.getState()) || from.getState().equals(CustomServicesWorkflowStatus.NONE) || from.getState().equals(CustomServicesWorkflowStatus.INVALID)) {
            log.error("Workflow state is not valid. State:{} Workflow name:{}", from.getState(), from.getLabel());
            throw new IllegalStateException(String.format("Workflow state is not valid. State %s Workflow name: %s Workflow id: %s", from.getState(), from.getLabel(), from.getId()));
        }
        to.setCategory(CUSTOM_SERVICE_CATEGORY);
        to.setDescription(StringUtils.isNotBlank(wfDocument.getDescription()) ? wfDocument.getDescription() : wfDocument.getName());
        to.setDestructive(false);
        final String wfID = URIUtil.asString(from.getId());
        to.setServiceId(StringUtils.isNotBlank(wfID) ? wfID : wfDocument.getName());
        to.setTitle(wfDocument.getName());
        to.setWorkflowId(wfDocument.getName());
        to.setRoles(new ArrayList<String>(Arrays.asList(Role.SYSTEM_ADMIN.toString())));
        for (final Step step : wfDocument.getSteps()) {
            if (null != step.getInputGroups()) {
                // Looping through all input groups
                for (final InputGroup inputGroup : step.getInputGroups().values()) {
                    final MultiValueMap tableMap = new MultiValueMap();
                    for (final Input wfInput : inputGroup.getInputGroup()) {
                        final ServiceField serviceField = new ServiceField();
                        if (CustomServicesConstants.InputType.FROM_USER.toString().equals(wfInput.getType())) {
                            serviceField.setType(wfInput.getInputFieldType());
                        } else if (CustomServicesConstants.InputType.ASSET_OPTION_SINGLE.toString().equals(wfInput.getType())) {
                            serviceField.setType(wfInput.getValue());
                        } else if (CustomServicesConstants.InputType.ASSET_OPTION_MULTI.toString().equals(wfInput.getType())) {
                            serviceField.setType(wfInput.getValue());
                            serviceField.setSelect(ServiceField.SELECT_MANY);
                        } else if (CustomServicesConstants.InputType.FROM_USER_MULTI.toString().equals(wfInput.getType())) {
                            serviceField.setType(ServiceField.TYPE_CHOICE);
                            if (StringUtils.isNotBlank(wfInput.getDefaultValue())) {
                                // For list of options
                                final Map<String, String> options = new HashMap<>();
                                final List<String> defaultList = Arrays.asList(wfInput.getDefaultValue().split(","));
                                for (final String value : defaultList) {
                                    // making the key and value the same
                                    options.put(value, value);
                                }
                                serviceField.setOptions(options);
                                serviceField.setInitialValue(options.get(defaultList.get(0)));
                            } else if (MapUtils.isNotEmpty(wfInput.getOptions())) {
                                // For options Map
                                serviceField.setOptions(wfInput.getOptions());
                            }
                        } else {
                            continue;
                        }
                        final String inputName = wfInput.getName();
                        if (StringUtils.isNotBlank(wfInput.getDescription())) {
                            serviceField.setDescription(wfInput.getDescription());
                        }
                        final String friendlyName = StringUtils.isBlank(wfInput.getFriendlyName()) ? inputName : wfInput.getFriendlyName();
                        serviceField.setLabel(friendlyName);
                        serviceField.setName(friendlyName.replaceAll(CustomServicesConstants.SPACES_REGEX, StringUtils.EMPTY));
                        serviceField.setRequired(wfInput.getRequired());
                        if (!(CustomServicesConstants.InputType.FROM_USER_MULTI.toString().equals(wfInput.getType()))) {
                            // Initial value already set for FROM_USER_MULTI
                            serviceField.setInitialValue(wfInput.getDefaultValue());
                        }
                        // Setting all unlocked fields as lockable
                        if (!wfInput.getLocked()) {
                            serviceField.setLockable(true);
                        }
                        // if there is a table name we will build ServiceFieldTable later
                        if (null != wfInput.getTableName()) {
                            tableMap.put(wfInput.getTableName(), serviceField);
                        } else {
                            to.getItems().put(friendlyName, serviceField);
                        }
                    }
                    for (final String table : (Set<String>) tableMap.keySet()) {
                        final ServiceFieldTable serviceFieldTable = new ServiceFieldTable();
                        serviceFieldTable.setType(ServiceItem.TYPE_TABLE);
                        serviceFieldTable.setLabel(table);
                        serviceFieldTable.setName(table);
                        for (final ServiceField serviceField : (List<ServiceField>) tableMap.getCollection(table)) {
                            serviceFieldTable.addItem(serviceField);
                        }
                        to.getItems().put(table, serviceFieldTable);
                    }
                }
            }
        }
    } catch (final IOException io) {
        log.error("Error deserializing workflow", io);
        throw new IllegalStateException(String.format("Error deserializing workflow %s", from.getLabel()));
    }
    log.debug("Mapped workflow service descriptor for {}", from.getLabel());
    return to;
}
Also used : Set(java.util.Set) ServiceFieldTable(com.emc.sa.descriptor.ServiceFieldTable) CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument) Step(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Step) IOException(java.io.IOException) InputGroup(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.InputGroup) Input(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument.Input) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) ServiceField(com.emc.sa.descriptor.ServiceField) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) MultiValueMap(org.apache.commons.collections.map.MultiValueMap) Map(java.util.Map) MultiValueMap(org.apache.commons.collections.map.MultiValueMap)

Example 8 with ServiceDescriptor

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

the class CatalogServiceService method getCatalogService.

/**
 * Get info for catalog category
 *
 * @param id the URN of a Catalog Category
 * @prereq none
 * @brief Show catalog category
 * @return Catalog Category details
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
public CatalogServiceRestRep getCatalogService(@PathParam("id") URI id) {
    CatalogService catalogService = queryResource(id);
    ServiceDescriptor serviceDescriptor = getServiceDescriptor(catalogService);
    List<CatalogServiceField> catalogServiceFields = catalogServiceManager.getCatalogServiceFields(catalogService.getId());
    return map(catalogService, serviceDescriptor, catalogServiceFields);
}
Also used : CatalogServiceField(com.emc.storageos.db.client.model.uimodels.CatalogServiceField) WorkflowServiceDescriptor(com.emc.sa.catalog.WorkflowServiceDescriptor) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with ServiceDescriptor

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

the class CatalogServiceService method updateCatalogService.

/**
 * Update catalog service
 *
 * @param param Catalog Service update parameters
 * @param id the URN the catalog service
 * @prereq none
 * @brief Update Catalog Service
 * @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_ADMIN }, acls = { ACL.OWN })
public CatalogServiceRestRep updateCatalogService(@PathParam("id") URI id, CatalogServiceUpdateParam param) {
    CatalogService catalogService = getCatalogServiceById(id, true);
    List<CatalogServiceField> catalogServiceFields = catalogServiceManager.getCatalogServiceFields(id);
    StorageOSUser user = getUserFromContext();
    CatalogCategory parentCatalogCategory = catalogCategoryManager.getCatalogCategoryById(param.getCatalogCategory());
    verifyAuthorizedInTenantOrg(uri(parentCatalogCategory.getTenant()), user);
    validateParam(param, catalogService);
    updateObject(catalogService, param, parentCatalogCategory);
    List<CatalogServiceField> updatedCatalogServiceFields = updateObjectList(catalogService, catalogServiceFields, param.getCatalogServiceFields());
    catalogServiceManager.updateCatalogService(catalogService, updatedCatalogServiceFields);
    auditOpSuccess(OperationTypeEnum.UPDATE_CATALOG_SERVICE, catalogService.auditParameters());
    // Refresh Objects
    catalogService = catalogServiceManager.getCatalogServiceById(catalogService.getId());
    catalogServiceFields = catalogServiceManager.getCatalogServiceFields(catalogService.getId());
    ServiceDescriptor serviceDescriptor = getServiceDescriptor(catalogService);
    return map(catalogService, serviceDescriptor, catalogServiceFields);
}
Also used : CatalogServiceField(com.emc.storageos.db.client.model.uimodels.CatalogServiceField) WorkflowServiceDescriptor(com.emc.sa.catalog.WorkflowServiceDescriptor) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with ServiceDescriptor

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

the class CatalogServiceService method validateParam.

private void validateParam(CatalogServiceCommonParam input, CatalogService existing) {
    ServiceDescriptor descriptor = getServiceDescriptor(input.getBaseService());
    if (descriptor == null) {
        throw APIException.badRequests.baseServiceNotFound(input.getBaseService());
    }
    if (null != input.getWorkflowName() && !input.getWorkflowName().isEmpty()) {
        if (null == catalogServiceManager.getWorkflowDocument(input.getWorkflowName())) {
            throw APIException.badRequests.workflowNotFound(input.getWorkflowName());
        }
    }
    for (CatalogServiceFieldParam field : input.getCatalogServiceFields()) {
        if (!field.getOverride()) {
            continue;
        }
        String fieldName = field.getName();
        String fieldValue = field.getValue();
        ServiceField descriptorField = descriptor.getField(fieldName);
        if (descriptorField != null) {
            ValidationUtils.validateField(input.getMaxSize(), descriptorField, fieldValue);
        }
    }
}
Also used : CatalogServiceFieldParam(com.emc.vipr.model.catalog.CatalogServiceFieldParam) WorkflowServiceDescriptor(com.emc.sa.catalog.WorkflowServiceDescriptor) ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) CatalogServiceField(com.emc.storageos.db.client.model.uimodels.CatalogServiceField) ServiceField(com.emc.sa.descriptor.ServiceField)

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