Search in sources :

Example 31 with JavaResult

use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.

the class HDSBatchApiExportManager method addHostStorageDomains.

/**
 * This method makes http POST call with a payload of bulk
 * HostStorageDomains.
 *
 * @param systemId
 *            - SystemObjectID.
 * @param hostGroups
 *            - List of HostStorageDomain objects.
 * @return - Returns a List of created HostStorageDomain on Array.
 * @throws Exception
 *             - In case processing errors.
 */
public List<HostStorageDomain> addHostStorageDomains(String systemId, List<HostStorageDomain> hostGroups, String model) throws Exception {
    InputStream responseStream = null;
    List<HostStorageDomain> hsdList = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray array = new StorageArray(systemId);
        Add addOp = new Add(HDSConstants.HOST_STORAGE_DOMAIN);
        attributeMap.put(HDSConstants.STORAGEARRAY, array);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.HOSTGROUP_LIST, hostGroups);
        String addHSDToSystemQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.BATCH_ADD_HSDS_TO_SYSTEM_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Batch query to create HostStorageDomains: {}", addHSDToSystemQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, addHSDToSystemQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            hsdList = (List<HostStorageDomain>) javaResult.getBean(HDSConstants.HSD_RESPONSE_BEAN_ID);
            if (null == hsdList || hsdList.isEmpty()) {
                throw HDSException.exceptions.notAbleToAddHSD(systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to add HostStorageDomains due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream addHostStorageDomains");
            }
        }
    }
    return hsdList;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 32 with JavaResult

use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.

the class SmooksUtil method getParsedXMLJavaResult.

/**
 * This initializes the Smooks & parse the given inputStream and returns the javaResult.
 *
 * @param inputStream : Response in inputStream received from server.
 * @param configFile : Smooks configuration file.
 * @return
 */
public static JavaResult getParsedXMLJavaResult(InputStream inputStream, String configFile) {
    Smooks smooks = null;
    JavaResult javaResult = null;
    try {
        smooks = new Smooks(configFile);
        log.debug("initialized smooks");
        ExecutionContext executionContext = smooks.createExecutionContext();
        // The result of this transform is a set of Java objects...
        javaResult = new JavaResult();
        // Filter the input message to extract, using the execution context...
        smooks.filterSource(executionContext, new StreamSource(inputStream), javaResult);
        log.debug("Parsing completed");
    } catch (Exception e) {
        log.error("Unable to parse the response received from server.", e);
        throw HDSException.exceptions.unableToParseResponse();
    } finally {
        if (null != smooks) {
            smooks.close();
        }
    }
    return javaResult;
}
Also used : ExecutionContext(org.milyn.container.ExecutionContext) Smooks(org.milyn.Smooks) StreamSource(javax.xml.transform.stream.StreamSource) JavaResult(org.milyn.payload.JavaResult) HDSException(com.emc.storageos.hds.HDSException)

Example 33 with JavaResult

use of org.milyn.payload.JavaResult in project tutorials by eugenp.

the class OrderValidator method validate.

public ValidationResult validate(String path) throws IOException, SAXException {
    Smooks smooks = new Smooks(OrderValidator.class.getResourceAsStream("/smooks/smooks-validation.xml"));
    try {
        StringResult xmlResult = new StringResult();
        JavaResult javaResult = new JavaResult();
        ValidationResult validationResult = new ValidationResult();
        smooks.filterSource(new StreamSource(OrderValidator.class.getResourceAsStream(path)), xmlResult, javaResult, validationResult);
        return validationResult;
    } finally {
        smooks.close();
    }
}
Also used : Smooks(org.milyn.Smooks) StreamSource(javax.xml.transform.stream.StreamSource) StringResult(org.milyn.payload.StringResult) ValidationResult(org.milyn.validation.ValidationResult) JavaResult(org.milyn.payload.JavaResult)

Example 34 with JavaResult

use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.

the class HDSApiDiscoveryManager method getStoragePoolTierInfo.

/**
 * Returns all storage system information.
 *
 * @return
 * @throws Exception
 */
public Pool getStoragePoolTierInfo(String systemObjectID, String poolObjectID) throws Exception {
    InputStream responseStream = null;
    Pool pool = null;
    URI endpointURI = hdsApiClient.getBaseURI();
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray inputStorageArray = new StorageArray(systemObjectID);
    Get getOp = new Get(HDSConstants.STORAGEARRAY);
    attributeMap.put(HDSConstants.STORAGEARRAY, inputStorageArray);
    Pool inputPool = new Pool(poolObjectID);
    attributeMap.put(HDSConstants.JOURNAL_POOL, inputPool);
    attributeMap.put(HDSConstants.GET, getOp);
    String getPoolTieringInfoInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_STORAGE_POOL_TIERING_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    log.info("Get StoragePool Tiering info query payload :{}", getPoolTieringInfoInputXML);
    ClientResponse response = hdsApiClient.post(endpointURI, getPoolTieringInfoInputXML);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        pool = result.getBean(Pool.class);
    } else {
        log.error("Get pool tiering info failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query pool tiering info due to invalid response %1$s from server", response.getStatus()));
    }
    return pool;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Get(com.emc.storageos.hds.model.Get) Pool(com.emc.storageos.hds.model.Pool) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 35 with JavaResult

use of org.milyn.payload.JavaResult in project coprhd-controller by CoprHD.

the class HDSApiDiscoveryManager method getStorageSystemDetails.

/**
 * Returns all storage system information.
 *
 * @return
 * @throws Exception
 */
public StorageArray getStorageSystemDetails(String systemObjectID) throws Exception {
    InputStream responseStream = null;
    StorageArray storageArray = null;
    URI endpointURI = hdsApiClient.getBaseURI();
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray inputStorageArray = new StorageArray(systemObjectID);
    Get getOp = new Get(HDSConstants.STORAGEARRAY);
    attributeMap.put(HDSConstants.STORAGEARRAY, inputStorageArray);
    attributeMap.put(HDSConstants.GET, getOp);
    String getSystemDetailsInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_SYSTEM_DETAILS_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    log.info("Get system details query payload :{}", getSystemDetailsInputXML);
    ClientResponse response = hdsApiClient.post(endpointURI, getSystemDetailsInputXML);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        storageArray = result.getBean(StorageArray.class);
    } else {
        log.error("Get system details failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query system details due to invalid response %1$s from server", response.getStatus()));
    }
    return storageArray;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Get(com.emc.storageos.hds.model.Get) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Aggregations

JavaResult (org.milyn.payload.JavaResult)57 InputStream (java.io.InputStream)53 ClientResponse (com.sun.jersey.api.client.ClientResponse)52 URI (java.net.URI)50 IOException (java.io.IOException)42 HashMap (java.util.HashMap)38 StorageArray (com.emc.storageos.hds.model.StorageArray)26 Error (com.emc.storageos.hds.model.Error)17 Get (com.emc.storageos.hds.model.Get)16 EchoCommand (com.emc.storageos.hds.model.EchoCommand)15 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)13 Add (com.emc.storageos.hds.model.Add)11 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)11 HDSHost (com.emc.storageos.hds.model.HDSHost)8 Delete (com.emc.storageos.hds.model.Delete)7 HDSException (com.emc.storageos.hds.HDSException)6 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)6 Modify (com.emc.storageos.hds.model.Modify)5 Pool (com.emc.storageos.hds.model.Pool)5 ArrayList (java.util.ArrayList)5