Search in sources :

Example 1 with ServiceField

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

the class ServiceDescriptorAssetTest method verifyAssetFields.

private void verifyAssetFields(ServiceDescriptor descriptor) {
    Set<String> allAssetTypes = descriptor.getAllAssetTypes();
    for (ServiceField field : descriptor.getAllFieldList()) {
        if (!field.isAsset()) {
            continue;
        }
        String assetType = field.getAssetType();
        AssetOptionsProvider provider = assetManager.getProviderForAssetType(assetType);
        if (provider == null) {
            Assert.fail(String.format("%s [%s]: No provider found for type: %s", descriptor.getTitle(), field.getName(), assetType));
        }
        try {
            List<String> assetDependencies = provider.getAssetDependencies(assetType, allAssetTypes);
            for (String assetDependency : assetDependencies) {
                AssetOptionsProvider dependencyProvider = assetManager.getProviderForAssetType(assetDependency);
                if (dependencyProvider == null) {
                    Assert.fail(String.format("%s [%s]: No provider found for dependency '%s' of type: %s", descriptor.getTitle(), field.getName(), assetDependency, assetType));
                }
            }
        } catch (IllegalStateException e) {
            Assert.fail(String.format("%s [%s]: Could not query dependencies of type: %s, provided: %s", descriptor.getTitle(), field.getName(), assetType, allAssetTypes));
        }
    }
}
Also used : ServiceField(com.emc.sa.descriptor.ServiceField) AssetOptionsProvider(com.emc.sa.asset.AssetOptionsProvider)

Example 2 with ServiceField

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

the class OrderService method addLockedFields.

private void addLockedFields(URI catalogServiceId, ServiceDescriptor serviceDescriptor, OrderCreateParam createParam) {
    Map<String, String> locked = catalogServiceManager.getLockedFields(catalogServiceId);
    for (ServiceField field : serviceDescriptor.getAllFieldList()) {
        if (locked.containsKey(field.getName())) {
            String lockedValue = locked.get(field.getName());
            Parameter parameter = createParam.findParameterByLabel(field.getName());
            if (parameter != null) {
                parameter.setValue(lockedValue);
            } else {
                Parameter newLockedParameter = new Parameter();
                newLockedParameter.setLabel(field.getName());
                newLockedParameter.setValue(lockedValue);
                createParam.getParameters().add(newLockedParameter);
            }
        }
    }
}
Also used : ServiceField(com.emc.sa.descriptor.ServiceField) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) Parameter(com.emc.vipr.model.catalog.Parameter) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString)

Example 3 with ServiceField

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

the class ServiceDescriptorTests method testLoadingAndRetrieving.

@Test
public void testLoadingAndRetrieving() throws Exception {
    ZkServiceDescriptors serviceDescriptors = new ZkServiceDescriptors();
    serviceDescriptors.setCoordinatorClient(coordinatorService.getCoordinatorClient());
    serviceDescriptors.start();
    List<ServiceDefinition> services = ServiceDefinitionLoader.load(ServiceDescriptorTests.class.getClassLoader());
    Assert.assertEquals(1, services.size());
    serviceDescriptors.addServices(services);
    ServiceDescriptor descriptor = serviceDescriptors.getDescriptor(Locale.getDefault(), "TestService");
    Assert.assertNotNull(descriptor);
    Assert.assertEquals("TestService", descriptor.getServiceId());
    List<ServiceField> fields = descriptor.getFieldList();
    Assert.assertEquals(3, fields.size());
    Assert.assertEquals("project", fields.get(0).getName());
    Assert.assertEquals("Project", fields.get(0).getLabel());
}
Also used : ServiceDescriptor(com.emc.sa.descriptor.ServiceDescriptor) ServiceField(com.emc.sa.descriptor.ServiceField) ServiceDefinition(com.emc.sa.descriptor.ServiceDefinition)

Example 4 with ServiceField

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

use of com.emc.sa.descriptor.ServiceField 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

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