Search in sources :

Example 21 with JavaResult

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

the class HDSApiVolumeManager method getStoragePoolInfo.

/**
 * Return the storagepool information.
 *
 * @param systemObjectId
 * @param poolObjectId
 * @return
 * @throws Exception
 */
public Pool getStoragePoolInfo(String systemObjectId, String poolObjectId) throws Exception {
    InputStream responseStream = null;
    Pool storagePool = null;
    String poolMethodType = null;
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray storageArray = new StorageArray(systemObjectId);
    attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
    Get getOp = new Get(HDSConstants.STORAGEARRAY);
    attributeMap.put(HDSConstants.GET, getOp);
    Pool pool = new Pool(poolObjectId);
    if (poolObjectId.contains(HDSConstants.ARRAYGROUP)) {
        attributeMap.put(HDSConstants.ARRAY_GROUP, pool);
        poolMethodType = HDSConstants.GET_ARRAYGROUP_INFO_OP;
    } else if (poolObjectId.contains(HDSConstants.JOURNALPOOL)) {
        attributeMap.put(HDSConstants.JOURNAL_POOL, pool);
        poolMethodType = HDSConstants.GET_JOURNAL_POOL_INFO_OP;
    }
    String getStoragePoolInputXML = InputXMLGenerationClient.getInputXMLString(poolMethodType, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    URI endpointURI = hdsApiClient.getBaseURI();
    log.info("Storagepool info query payload :{}", getStoragePoolInputXML);
    ClientResponse response = hdsApiClient.post(endpointURI, getStoragePoolInputXML);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        storagePool = result.getBean(Pool.class);
    } else {
        log.error("Get StoragePool info failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query StoragePool info due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectId));
    }
    return storagePool;
}
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 22 with JavaResult

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

the class HDSApiVolumeManager method deleteSnapshotVolume.

public String deleteSnapshotVolume(String storageSystemObjId, String logicalUnitObjId, String model) throws Exception {
    String asyncTaskMessageId = null;
    InputStream responseStream = null;
    try {
        if (null != storageSystemObjId && null != logicalUnitObjId) {
            log.info("Deleting snapshot with id {} from Storage System {}", logicalUnitObjId, storageSystemObjId);
            Map<String, Object> attributeMap = new HashMap<String, Object>();
            Delete deleteOp = new Delete(HDSConstants.VIRTUALVOLUME);
            StorageArray storageArray = new StorageArray(storageSystemObjId);
            LogicalUnit logicalUnit = new LogicalUnit();
            logicalUnit.setObjectID(logicalUnitObjId);
            attributeMap.put(HDSConstants.DELETE, deleteOp);
            attributeMap.put(HDSConstants.MODEL, model);
            attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
            attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
            String createSnapshotInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_SNAPSHOT_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
            log.info("Query to delete snapshot Volume: {}", createSnapshotInputXML);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, createSnapshotInputXML);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
                EchoCommand command = result.getBean(EchoCommand.class);
                log.info("command Status :{} MessageId :{}", command.getStatus(), command.getMessageID());
                if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus()) || HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                    asyncTaskMessageId = command.getMessageID();
                } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                    Error error = result.getBean(Error.class);
                    log.error("Snapshot volume deletion failed status messageID: {}", command.getMessageID());
                    log.error("Snapshot volume failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                    throw HDSException.exceptions.notAbleToDeleteSnapshot(error.getCode(), error.getDescription());
                }
            } else {
                log.error("Snapshot deletion failed with invalid response code {}", response.getStatus());
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Snapshot deletion failed due to invalid response %1$s from server for system %2$s", response.getStatus(), storageSystemObjId));
            }
            log.info("Snapshot with id {} deleted from Storage System {}", logicalUnitObjId, storageSystemObjId);
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while closing snapshot deletion response stream");
            }
        }
    }
    return asyncTaskMessageId;
}
Also used : Delete(com.emc.storageos.hds.model.Delete) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 23 with JavaResult

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

the class HDSApiVolumeManager method getLogicalUnitInfo.

/**
 * Return the LogicalUnit info for the given logicalUnitObjectId.
 *
 * @param systemObjectId
 * @param logicalUnitObjectId
 * @return
 * @throws Exception
 */
public LogicalUnit getLogicalUnitInfo(String systemObjectId, String logicalUnitObjectId) throws Exception {
    InputStream responseStream = null;
    LogicalUnit logicalUnit = null;
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray storageArray = new StorageArray(systemObjectId);
    Get getOp = new Get(HDSConstants.STORAGEARRAY);
    attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
    attributeMap.put(HDSConstants.GET, getOp);
    LogicalUnit lu = new LogicalUnit(logicalUnitObjectId, null);
    attributeMap.put(HDSConstants.LOGICALUNIT, lu);
    String getLogicalUnitsInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_LOGICALUNITS_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    URI endpointURI = hdsApiClient.getBaseURI();
    log.info("Volume info query payload :{}", getLogicalUnitsInputXML);
    ClientResponse response = hdsApiClient.post(endpointURI, getLogicalUnitsInputXML);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        logicalUnit = (LogicalUnit) result.getBean(HDSConstants.LOGICALUNIT_BEAN_NAME);
    } else {
        log.error("Get LogicalUnit info failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query LogicalUnit info due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectId));
    }
    return logicalUnit;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) Get(com.emc.storageos.hds.model.Get) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 24 with JavaResult

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

the class HDSApiVolumeManager method getAllLogicalUnits.

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

Example 25 with JavaResult

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

the class HDSApiVolumeManager method formatLogicalUnit.

/**
 * Formats the LogicalUnit.
 *
 * @param systemObjectId
 * @param luObjectId
 * @return
 */
public String formatLogicalUnit(String systemObjectId, String luObjectId) {
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray storageArray = new StorageArray(systemObjectId);
        Modify modifyOp = new Modify(HDSConstants.LU_FORMAT_TARGET, true);
        LogicalUnit logicalUnit = new LogicalUnit(luObjectId, null);
        attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
        attributeMap.put(HDSConstants.MODIFY, modifyOp);
        attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
        String fromatVolumeInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.FORMAT_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to format LogicalUnit: {}", fromatVolumeInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, fromatVolumeInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            EchoCommand command = result.getBean(EchoCommand.class);
            log.info("command Status :{} MessageId :{}", command.getStatus(), command.getMessageID());
            if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus()) || HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                asyncTaskMessageId = command.getMessageID();
            } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = result.getBean(Error.class);
                log.error("Query to format LogicalUnit: failed status messageID: {}", command.getMessageID());
                log.error("LogicalUnit formatting failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateVolume(error.getCode(), error.getDescription());
            }
        } else {
            log.error("LogicalUnit format failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("LogicalUnit format failed due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectId));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while closing Formatting LogicalUnit response stream");
            }
        }
    }
    return asyncTaskMessageId;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) Error(com.emc.storageos.hds.model.Error) Modify(com.emc.storageos.hds.model.Modify) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) 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