Search in sources :

Example 26 with CatalogService

use of com.emc.storageos.db.client.model.uimodels.CatalogService 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 27 with CatalogService

use of com.emc.storageos.db.client.model.uimodels.CatalogService 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 28 with CatalogService

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

the class CatalogCategoryManagerImpl method deleteCategoryContents.

private void deleteCategoryContents(CatalogCategory catalogCategory) {
    List<CatalogCategory> categories = getSubCategories(catalogCategory.getId());
    for (CatalogCategory subCategory : categories) {
        deleteCatalogCategory(subCategory);
    }
    List<CatalogService> services = catalogServiceManager.getCatalogServices(catalogCategory.getId());
    for (CatalogService service : services) {
        catalogServiceManager.deleteCatalogService(service);
    }
}
Also used : CatalogCategory(com.emc.storageos.db.client.model.uimodels.CatalogCategory) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService)

Example 29 with CatalogService

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

the class CatalogServiceManagerImpl method getCatalogServiceById.

public CatalogService getCatalogServiceById(URI id) {
    if (id == null) {
        return null;
    }
    CatalogService catalogService = client.catalogServices().findById(id);
    // For "Test Workflow" CustomServiceWorkflow ID is set as CatalogService.
    if (null == catalogService && id.toString().startsWith(CustomServicesWorkflow.ID_PREFIX)) {
        final CustomServicesWorkflow customServicesWorkflow = customServicesWorkflowManager.getById(id);
        if (customServicesWorkflow == null) {
            log.debug(String.format("Unable to get Catalog Service by Id [%s]. Workflow may have been deleted.", id));
            throw new IllegalStateException("Unable to get Catalog Service by Id" + id + "Workflow may have been deleted.");
        }
        catalogService = new CatalogService();
        catalogService.setId(id);
        catalogService.setTitle(customServicesWorkflow.getLabel());
        catalogService.setDescription(customServicesWorkflow.getLabel());
        catalogService.setImage("icon_orchestration.png");
        catalogService.setBaseService(URIUtil.asString(id));
    }
    return catalogService;
}
Also used : CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) CustomServicesWorkflow(com.emc.storageos.db.client.model.uimodels.CustomServicesWorkflow)

Example 30 with CatalogService

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

the class ExecutionUtils method createContext.

public static void createContext(ModelClient modelClient, Order order) {
    // Ensure there is no existing context
    destroyContext();
    // Initialize the execution state for this order
    ExecutionState state = modelClient.executionStates().findById(order.getExecutionStateId());
    state.setStartDate(new Date());
    ExecutionContext context = currentContext();
    context.setOrder(order);
    context.setModelClient(modelClient);
    context.setExecutionState(state);
    URI scheduledEventId = order.getScheduledEventId();
    if (scheduledEventId != null) {
        ScheduledEvent event = modelClient.findById(ScheduledEvent.class, scheduledEventId);
        context.setScheduledEvent(event);
    }
    CatalogService catalogService = modelClient.catalogServices().findById(order.getCatalogServiceId());
    if (null != catalogService) {
        context.setServiceName(catalogService.getLabel());
    }
    List<OrderParameter> orderParameters = modelClient.orderParameters().findByOrderId(order.getId());
    Map<String, Object> params = Maps.newLinkedHashMap();
    for (OrderParameter param : orderParameters) {
        params.put(param.getLabel(), param.getValue());
    }
    context.setParameters(params);
}
Also used : ExecutionState(com.emc.storageos.db.client.model.uimodels.ExecutionState) ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) CatalogService(com.emc.storageos.db.client.model.uimodels.CatalogService) URI(java.net.URI) Date(java.util.Date)

Aggregations

CatalogService (com.emc.storageos.db.client.model.uimodels.CatalogService)34 ServiceDescriptor (com.emc.sa.descriptor.ServiceDescriptor)8 URI (java.net.URI)8 NamedURI (com.emc.storageos.db.client.model.NamedURI)7 CatalogCategory (com.emc.storageos.db.client.model.uimodels.CatalogCategory)7 CatalogServiceField (com.emc.storageos.db.client.model.uimodels.CatalogServiceField)6 Path (javax.ws.rs.Path)6 WorkflowServiceDescriptor (com.emc.sa.catalog.WorkflowServiceDescriptor)5 Produces (javax.ws.rs.Produces)5 StorageOSUser (com.emc.storageos.security.authentication.StorageOSUser)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 Test (org.junit.Test)4 BaseModelTest (com.emc.sa.model.BaseModelTest)3 ExecutionState (com.emc.storageos.db.client.model.uimodels.ExecutionState)3 Order (com.emc.storageos.db.client.model.uimodels.Order)3 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)3 Consumes (javax.ws.rs.Consumes)3 ModelClient (com.emc.sa.model.dao.ModelClient)2 CatalogServiceAndFields (com.emc.storageos.db.client.model.uimodels.CatalogServiceAndFields)2 ArrayList (java.util.ArrayList)2