Search in sources :

Example 46 with JavaResult

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

the class HDSApiVolumeManager method addLUSE.

/**
 * Form a single meta volume by concatenating multiple volumes.
 *
 * @param systemObjectId
 * @param ldevIds
 * @return
 * @throws Exception
 */
public LogicalUnit addLUSE(String systemObjectId, String metaHead, List<String> ldevIds) throws Exception {
    String addLUSEQuery = constructAddLUSEQuery(systemObjectId, metaHead, ldevIds);
    URI endpointURI = hdsApiClient.getBaseURI();
    InputStream responseStream = null;
    LogicalUnit logicalUnit = null;
    try {
        log.info("Add LUSE Query payload :{}", addLUSEQuery);
        ClientResponse response = hdsApiClient.post(endpointURI, addLUSEQuery);
        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("AddLUSE failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to Add LUSE 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("IOException occurred while closing the response stream");
            }
        }
    }
    return logicalUnit;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Example 47 with JavaResult

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

the class HDSApiVolumeManager method addLabelToObject.

/**
 * Adds the label to an Object in DeviceManager.
 * Currently this is supported for labeling LDEV.
 * So, targetID must be a LDEV ID of a LU.
 *
 * @param targetID
 * @param label
 * @return
 * @throws Exception
 */
public ObjectLabel addLabelToObject(String targetID, String label) throws Exception {
    InputStream responseStream = null;
    ObjectLabel objectLabel = null;
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    Add addOp = new Add(HDSConstants.OBJECTLABEL);
    addOp.setOverwrite(Boolean.TRUE);
    attributeMap.put(HDSConstants.ADD, addOp);
    ObjectLabel objectLabelReq = new ObjectLabel(targetID, label);
    attributeMap.put(HDSConstants.OBJECTLABEL, objectLabelReq);
    String addLabelToObject = InputXMLGenerationClient.getInputXMLString(HDSConstants.ADD_LABEL_TO_OBJECT_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    URI endpointURI = hdsApiClient.getBaseURI();
    log.info("Add Label to Object payload :{}", addLabelToObject);
    ClientResponse response = hdsApiClient.post(endpointURI, addLabelToObject);
    if (HttpStatus.SC_OK == response.getStatus()) {
        responseStream = response.getEntityInputStream();
        JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
        verifyErrorPayload(result);
        objectLabel = result.getBean(ObjectLabel.class);
    } else {
        log.error("Add label to Object failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to Add Label to object due to invalid response %1$s from server", response.getStatus()));
    }
    return objectLabel;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) ObjectLabel(com.emc.storageos.hds.model.ObjectLabel) HashMap(java.util.HashMap) InputStream(java.io.InputStream) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Example 48 with JavaResult

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

the class HDSApiVolumeManager method deleteThinLogicalUnits.

public String deleteThinLogicalUnits(String systemObjectID, Set<String> logicalUnitIdList, String model) throws Exception {
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray storageArray = new StorageArray(systemObjectID);
        Delete deleteOp = new Delete(HDSConstants.VIRTUALVOLUME, true);
        List<LogicalUnit> luList = new ArrayList<LogicalUnit>();
        for (String logicalUnitId : logicalUnitIdList) {
            LogicalUnit logicalUnit = new LogicalUnit(logicalUnitId, null);
            luList.add(logicalUnit);
        }
        attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
        attributeMap.put(HDSConstants.DELETE, deleteOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.LOGICALUNIT_LIST, luList);
        String deleteVolumesInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_VOLUMES_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("volume delete payload :{}", deleteVolumesInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, deleteVolumesInputXML);
        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();
                log.info("Async task id : {}", asyncTaskMessageId);
            } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = result.getBean(Error.class);
                log.info("command failed error code: {}", error.getCode());
                log.info("Command failed: messageID: {} {}", command.getMessageID(), error.getDescription());
                throw HDSException.exceptions.notAbleToDeleteVolume(error.getCode(), error.getDescription());
            }
        } else {
            log.error("LogicalUnit deletion failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("LogicalUnit creation 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.error(e.getMessage(), e);
            }
        }
    }
    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) ArrayList(java.util.ArrayList) 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 49 with JavaResult

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

the class HDSApiVolumeManager method modifyThinVolumeTieringPolicy.

public String modifyThinVolumeTieringPolicy(String systemObjectID, String luObjectID, String ldevObjectID, String tieringPolicyName, String model) {
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    Modify modifyOp = new Modify(HDSConstants.VIRTUALVOLUME);
    StorageArray array = new StorageArray(systemObjectID);
    LogicalUnit logicalUnit = new LogicalUnit();
    logicalUnit.setObjectID(luObjectID);
    LDEV ldev = new LDEV(ldevObjectID);
    ldev.setTierLevel(Integer.parseInt(tieringPolicyName));
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.MODIFY, modifyOp);
    attributeMap.put(HDSConstants.MODEL, model);
    attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
    attributeMap.put(HDSConstants.LDEV, ldev);
    String modifyThinVolumeTieringPolicyPayload = InputXMLGenerationClient.getInputXMLString(HDSConstants.MODIFY_THIN_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    URI endpointURI = hdsApiClient.getBaseURI();
    log.info("Modify Volume TieringPolicy payload:{}", modifyThinVolumeTieringPolicyPayload);
    ClientResponse response = hdsApiClient.post(endpointURI, modifyThinVolumeTieringPolicyPayload);
    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("Modify Volume TieringPolicy failed status messageID: {}", command.getMessageID());
            log.error("Modify Volume TieringPolicy failed with error code: {} with message: {}", error.getCode(), error.getDescription());
            throw HDSException.exceptions.notAbleToCreateVolume(error.getCode(), error.getDescription());
        }
    } else {
        log.error("Modify Volume TieringPolicy failed with invalid response code {}", response.getStatus());
        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Modify Volume TieringPolicy failed due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectID));
    }
    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) LDEV(com.emc.storageos.hds.model.LDEV) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 50 with JavaResult

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

the class HDSApiVolumeManager method releaseLUSE.

/**
 * This client method is responsible to release all the volumes in LUSE volume.
 *
 * @param systemObjectId
 * @param logicalUnitId
 * @return
 * @throws Exception
 */
public LogicalUnit releaseLUSE(String systemObjectId, String logicalUnitId) throws Exception {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray storageArray = new StorageArray(systemObjectId);
    attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
    Add addOp = new Add(HDSConstants.LUSE_TARGET);
    attributeMap.put(HDSConstants.GET, addOp);
    attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnitId);
    String releaseLUSEVolumeInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.RELEASE_LUSE_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    URI endpointURI = hdsApiClient.getBaseURI();
    InputStream responseStream = null;
    LogicalUnit logicalUnit = null;
    try {
        log.info("release LUSE Query payload :{}", releaseLUSEVolumeInputXML);
        ClientResponse response = hdsApiClient.post(endpointURI, releaseLUSEVolumeInputXML);
        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("deleteLUSE failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete LUSE 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("IOException occurred while closing the response stream");
            }
        }
    }
    return logicalUnit;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) IOException(java.io.IOException) 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