Search in sources :

Example 1 with CustomServicesPrimitiveResourceList

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList in project coprhd-controller by CoprHD.

the class WorkflowBuilder method updateInventoryFiles.

// Keep only newInventoryFileNames - get existing and remove the ones that are not there in the newly sent list
private static boolean updateInventoryFiles(final URI packageId, final String newInventoryFileNames) {
    boolean updateDone = false;
    if (null == packageId) {
        return updateDone;
    }
    final Map<String, URI> inventoryFiles = new HashMap<String, URI>();
    final CustomServicesPrimitiveResourceList customServicesPrimitiveResourceList = getCatalogClient().customServicesPrimitives().getPrimitiveResourcesByType(CustomServicesConstants.ANSIBLE_INVENTORY_TYPE, packageId);
    if (null != customServicesPrimitiveResourceList.getResources()) {
        for (NamedRelatedResourceRep inventoryResource : customServicesPrimitiveResourceList.getResources()) {
            inventoryFiles.put(inventoryResource.getName(), inventoryResource.getId());
        }
    }
    final String[] fileNames = null != newInventoryFileNames ? newInventoryFileNames.split(",") : new String[0];
    final List<String> newInventoryFileNamesList = Arrays.asList(fileNames);
    inventoryFiles.keySet().removeAll(newInventoryFileNamesList);
    for (final URI inventoryId : inventoryFiles.values()) {
        getCatalogClient().customServicesPrimitives().deletePrimitiveResource(inventoryId);
        updateDone = true;
    }
    return updateDone;
}
Also used : CustomServicesPrimitiveResourceList(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList) HashMap(java.util.HashMap) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URI(java.net.URI)

Example 2 with CustomServicesPrimitiveResourceList

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList in project coprhd-controller by CoprHD.

the class WorkflowBuilder method getInventoryFilesForPackage.

public static void getInventoryFilesForPackage(final URI packageId) {
    final List<String> inventoryFileNames = new ArrayList<String>();
    if (null != packageId) {
        final CustomServicesPrimitiveResourceList customServicesPrimitiveResourceList = getCatalogClient().customServicesPrimitives().getPrimitiveResourcesByType(CustomServicesConstants.ANSIBLE_INVENTORY_TYPE, packageId);
        if (null != customServicesPrimitiveResourceList.getResources()) {
            for (NamedRelatedResourceRep inventoryResource : customServicesPrimitiveResourceList.getResources()) {
                inventoryFileNames.add(inventoryResource.getName());
            }
        }
    }
    renderJSON(inventoryFileNames);
}
Also used : CustomServicesPrimitiveResourceList(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep)

Example 3 with CustomServicesPrimitiveResourceList

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList in project coprhd-controller by CoprHD.

the class WorkflowBuilder method setAnsibleResources.

private static void setAnsibleResources() {
    final CustomServicesPrimitiveResourceList customServicesPrimitiveResourceList = getCatalogClient().customServicesPrimitives().getPrimitiveResourcesByType(StepType.LOCAL_ANSIBLE.toString(), null);
    final List<StringOption> ansibleResourceNames = new ArrayList<StringOption>();
    if (null != customServicesPrimitiveResourceList.getResources()) {
        for (final NamedRelatedResourceRep resourceRep : customServicesPrimitiveResourceList.getResources()) {
            ansibleResourceNames.add(new StringOption(resourceRep.getId().toString(), resourceRep.getName()));
        }
    }
    renderArgs.put("ansibleResourceNames", ansibleResourceNames);
}
Also used : CustomServicesPrimitiveResourceList(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList) StringOption(util.StringOption) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep)

Example 4 with CustomServicesPrimitiveResourceList

use of com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList in project coprhd-controller by CoprHD.

the class WorkflowBuilder method addInventoryFileInputs.

// For each ansible step in workflow this method will look for host_file input and set the options to <hostid, hostname>
private static void addInventoryFileInputs(final CustomServicesWorkflowDocument.Step step) {
    if (StringUtils.isNotEmpty(step.getType()) && StepType.LOCAL_ANSIBLE.toString().equals(step.getType())) {
        CustomServicesWorkflowDocument.InputGroup inputGroup = step.getInputGroups().get(CustomServicesConstants.ANSIBLE_OPTIONS);
        for (final CustomServicesWorkflowDocument.Input input : inputGroup.getInputGroup()) {
            if (StringUtils.equals(CustomServicesConstants.ANSIBLE_HOST_FILE, input.getName())) {
                // Setting type and options for host_file
                input.setType(CustomServicesConstants.InputType.FROM_USER_MULTI.toString());
                final CustomServicesPrimitiveRestRep primitiveRestRep = getCatalogClient().customServicesPrimitives().getPrimitive(step.getOperation());
                final CustomServicesPrimitiveResourceList customServicesPrimitiveResourceList = getCatalogClient().customServicesPrimitives().getPrimitiveResourcesByType(CustomServicesConstants.ANSIBLE_INVENTORY_TYPE, primitiveRestRep.getResource().getId());
                if (customServicesPrimitiveResourceList != null && CollectionUtils.isNotEmpty(customServicesPrimitiveResourceList.getResources())) {
                    final Map<String, String> options = new HashMap<String, String>();
                    for (NamedRelatedResourceRep n : customServicesPrimitiveResourceList.getResources()) {
                        options.put(n.getId().toString(), n.getName());
                    }
                    Logger.debug("Adding inventory file options {}", options);
                    input.setOptions(options);
                } else {
                    // remove inventory files that have been set previously but deleted.
                    Logger.debug("Removing all the inventory files");
                    input.setOptions(new HashMap<String, String>());
                }
                break;
            }
        }
    }
}
Also used : CustomServicesPrimitiveRestRep(com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep) CustomServicesPrimitiveResourceList(com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList) HashMap(java.util.HashMap) CustomServicesWorkflowDocument(com.emc.storageos.model.customservices.CustomServicesWorkflowDocument) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep)

Aggregations

NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)4 CustomServicesPrimitiveResourceList (com.emc.storageos.model.customservices.CustomServicesPrimitiveResourceList)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CustomServicesPrimitiveRestRep (com.emc.storageos.model.customservices.CustomServicesPrimitiveRestRep)1 CustomServicesWorkflowDocument (com.emc.storageos.model.customservices.CustomServicesWorkflowDocument)1 URI (java.net.URI)1 StringOption (util.StringOption)1