Search in sources :

Example 1 with Operation

use of com.emc.storageos.hds.xmlgen.beans.Operation in project coprhd-controller by CoprHD.

the class InputXMLGenerationClient method getModelSupportedOperation.

/**
 * This method will make sure that if a new model is used to test then the
 * operation with model "default" will be used to execute commands.
 *
 * @param attributeMap
 * @param availableOperations
 * @return
 */
private static Operation getModelSupportedOperation(Map<String, Object> attributeMap, List<Operation> availableOperations) {
    String requestedSystemModel = getModelFromMap(attributeMap);
    Operation operationToUse = null;
    if (null != availableOperations && !availableOperations.isEmpty()) {
        for (Operation operation : availableOperations) {
            List<String> supportedModelsFromOperation = Arrays.asList(operation.getModels().split(XMLConstants.COMMA_OPERATOR));
            if (supportedModelsFromOperation.contains(requestedSystemModel)) {
                operationToUse = operation;
                break;
            } else if (supportedModelsFromOperation.contains(XMLConstants.DEFAULT_MODEL)) {
                operationToUse = operation;
            }
        }
    }
    return operationToUse;
}
Also used : Operation(com.emc.storageos.hds.xmlgen.beans.Operation)

Example 2 with Operation

use of com.emc.storageos.hds.xmlgen.beans.Operation in project coprhd-controller by CoprHD.

the class InputXMLGenerationClient method getInputXMLString.

public static String getInputXMLString(String requestedOperationName, Map<String, Object> attributeMap, String xmlInputContextFile, String smooksConfigFile) {
    String operationInputXMLString = null;
    InputStream stream = null;
    try {
        List<Operation> availableOperations = new ArrayList<Operation>();
        log.debug("XML Context File name to be loaded: {}", xmlInputContextFile);
        stream = InputXMLGenerationClient.class.getClass().getResourceAsStream(xmlInputContextFile);
        JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(stream, smooksConfigFile);
        @SuppressWarnings("unchecked") List<Operation> operationList = (List<Operation>) javaResult.getBean(XMLConstants.OPERATION_LIST_BEAN_NAME);
        if (null != operationList && !operationList.isEmpty()) {
            log.debug("{} operations found in configuration file", operationList.size());
            for (Operation operation : operationList) {
                if (operation.getName().equalsIgnoreCase(requestedOperationName)) {
                    log.debug("Found matching operation {}", operation.getName());
                    availableOperations.add(operation);
                }
            }
            Operation operation = getModelSupportedOperation(attributeMap, availableOperations);
            if (null != operation) {
                operationInputXMLString = generateXMLString(operation, attributeMap);
            } else {
                log.error("No Operation found with the given model");
                HDSException.exceptions.unableToGenerateInputXmlDueToUnSupportedModelFound();
            }
        } else {
            log.error("No operation list found to generate input xml.");
            HDSException.exceptions.unableToGenerateInputXmlDueToNoOperations();
        }
    } catch (Exception ex) {
        HDSException.exceptions.unableToGenerateInputXmlForGivenRequest(ex.getLocalizedMessage());
    }
    return operationInputXMLString;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Operation(com.emc.storageos.hds.xmlgen.beans.Operation) JavaResult(org.milyn.payload.JavaResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) HDSException(com.emc.storageos.hds.HDSException)

Aggregations

Operation (com.emc.storageos.hds.xmlgen.beans.Operation)2 HDSException (com.emc.storageos.hds.HDSException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 JavaResult (org.milyn.payload.JavaResult)1