Search in sources :

Example 36 with StorageArray

use of com.emc.storageos.hds.model.StorageArray in project coprhd-controller by CoprHD.

the class HDSApiVolumeManager method modifyVirtualVolume.

/**
 * Modify the Virtual Volumes with the passed information.
 *
 * @param systemId : represents SystemObjectID.
 * @param newLUCapacityInBytes: new VirtualVolume Capacity in bytes.
 * @return : asyncMessageId
 * @throws Exception
 */
public String modifyVirtualVolume(String systemId, String luObjectId, Long newLUCapacityInBytes, String model) throws Exception {
    Long luCapacityInKB = newLUCapacityInBytes / 1024;
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray storageArray = new StorageArray(systemId);
        Modify modifyOp = new Modify(HDSConstants.VIRTUALVOLUME, false);
        LogicalUnit logicalUnit = new LogicalUnit(luObjectId, String.valueOf(luCapacityInKB));
        attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.MODIFY, modifyOp);
        attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
        String modifyVolumeInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.MODIFY_THIN_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to modify Thin Volume: {}", modifyVolumeInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, modifyVolumeInputXML);
        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("Thin Volume modification failed status messageID: {}", command.getMessageID());
                log.error("Thin Volume modification failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateVolume(error.getCode(), error.getDescription());
            }
        } else {
            log.error("Thin Volume modification failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Thin Volume modification failed due to invalid response %1$s from server for system %2$s", response.getStatus(), systemId));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while closing Thin volume modification 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)

Example 37 with StorageArray

use of com.emc.storageos.hds.model.StorageArray in project coprhd-controller by CoprHD.

the class HDSApiVolumeManager method createSnapshotVolume.

public String createSnapshotVolume(String systemObjectId, Long luCapacityInBytes, String model) throws Exception {
    Long luCapacityInKB = luCapacityInBytes / 1024;
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        log.info("Creating snapshot with {}KB size on Storage System {}", luCapacityInKB, systemObjectId);
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Add addOp = new Add(HDSConstants.VIRTUALVOLUME);
        StorageArray storageArray = new StorageArray(systemObjectId);
        ArrayGroup arrayGroup = new ArrayGroup();
        arrayGroup.setType("2");
        LogicalUnit logicalUnit = new LogicalUnit();
        logicalUnit.setCapacityInKB(String.valueOf(luCapacityInKB));
        logicalUnit.setEmulation(HDSConstants.EMULATION_OPENV);
        attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.ARRAY_GROUP, arrayGroup);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
        String createSnapshotInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.CREATE_SNAPSHOT_VOLUME_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create 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("Thin snapshot creation failed status messageID: {}", command.getMessageID());
                log.error("Thin snapshot creation failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateSnapshot(error.getCode(), error.getDescription());
            }
        } else {
            log.error("Thin snapshot creation failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Thin snapshot creation failed due to invalid response %1$s from server for system %2$s", response.getStatus(), systemObjectId));
        }
        log.info("Snapshot creation initiated on Storage System {}", systemObjectId);
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while closing snapshot creation response stream");
            }
        }
    }
    return asyncTaskMessageId;
}
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) 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) ArrayGroup(com.emc.storageos.hds.model.ArrayGroup)

Example 38 with StorageArray

use of com.emc.storageos.hds.model.StorageArray in project coprhd-controller by CoprHD.

the class HDSBatchApiExportManager method constructAddLUNQuery.

/**
 * Constructs a batch query for the given Path objects to add LUN's to
 * storage system.
 *
 * @param systemId
 *            - represents storagesystem objectID.
 * @param pathList
 *            - List of Path objects.
 * @return - XML String to add LUN's to storage system.
 */
private String constructAddLUNQuery(String systemId, List<Path> pathList, String model) {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray array = new StorageArray(systemId);
    Add addOp = new Add(HDSConstants.LUN_TARGET);
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.ADD, addOp);
    attributeMap.put(HDSConstants.MODEL, model);
    attributeMap.put(HDSConstants.PATH_LIST, pathList);
    return InputXMLGenerationClient.getInputXMLString(HDSConstants.ADD_PATH_TO_HSD_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
}
Also used : Add(com.emc.storageos.hds.model.Add) HashMap(java.util.HashMap) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 39 with StorageArray

use of com.emc.storageos.hds.model.StorageArray in project coprhd-controller by CoprHD.

the class HDSBatchApiExportManager method constructRemoveLUNsQuery.

/**
 * Constructs a batch query for the given Path objects to remove LUN's from
 * storage system.
 *
 * @param systemId
 *            - represents storage system objectID.
 * @param pathList
 *            - List of Path objects.
 * @return - XML String to remove the Paths from storage system
 */
private String constructRemoveLUNsQuery(String systemId, List<Path> pathList, String model) {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray array = new StorageArray(systemId);
    Delete deleteOp = new Delete(HDSConstants.LUN_TARGET);
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.DELETE, deleteOp);
    attributeMap.put(HDSConstants.MODEL, model);
    attributeMap.put(HDSConstants.PATH_LIST, pathList);
    return InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_PATH_FROM_HSD_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
}
Also used : Delete(com.emc.storageos.hds.model.Delete) HashMap(java.util.HashMap) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 40 with StorageArray

use of com.emc.storageos.hds.model.StorageArray in project coprhd-controller by CoprHD.

the class HDSBatchApiExportManager method constructDeleteHSDsQuery.

/**
 * Constructs a batch query to delete given HSD's from the storage system.
 *
 * @param systemId
 *            - represents the storage system ObjectID.
 * @param hsdList
 *            - List of HostStorageDomain objects.
 * @return - XML string to delete the HostStorageDomain's
 */
private String constructDeleteHSDsQuery(String systemId, List<HostStorageDomain> hsdList, String model) {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray array = new StorageArray(systemId);
    Delete deleteOp = new Delete(HDSConstants.HOST_STORAGE_DOMAIN);
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.DELETE, deleteOp);
    attributeMap.put(HDSConstants.MODEL, model);
    attributeMap.put(HDSConstants.HOSTGROUP_LIST, hsdList);
    return InputXMLGenerationClient.getInputXMLString(HDSConstants.BATCH_DELETE_HSDS_FROM_SYSTEM, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
}
Also used : Delete(com.emc.storageos.hds.model.Delete) HashMap(java.util.HashMap) StorageArray(com.emc.storageos.hds.model.StorageArray)

Aggregations

StorageArray (com.emc.storageos.hds.model.StorageArray)41 HashMap (java.util.HashMap)37 ClientResponse (com.sun.jersey.api.client.ClientResponse)25 InputStream (java.io.InputStream)25 URI (java.net.URI)25 JavaResult (org.milyn.payload.JavaResult)25 IOException (java.io.IOException)19 Add (com.emc.storageos.hds.model.Add)13 Get (com.emc.storageos.hds.model.Get)12 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)12 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)10 Delete (com.emc.storageos.hds.model.Delete)9 EchoCommand (com.emc.storageos.hds.model.EchoCommand)9 Error (com.emc.storageos.hds.model.Error)9 ArrayList (java.util.ArrayList)7 Pool (com.emc.storageos.hds.model.Pool)5 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 HDSException (com.emc.storageos.hds.HDSException)3 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)3 Modify (com.emc.storageos.hds.model.Modify)3