Search in sources :

Example 26 with JavaResult

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

the class HDSApiVolumeManager method createThinVolumes.

/**
 * Creates the Thin volume with the passed information.
 *
 * @param systemId : represents SystemObjectID.
 * @param arrayGroupId : represents StoragePoolObjectID.
 * @param luCapacityInBytes: Logical Unit Capacity in bytes.
 * @param noOfLus : No. of LU's to created
 * @param volumeName : Logical Unit name.
 * @param formatType : formatType.
 * @param model : model.
 * @return : asyncMessageId
 * @throws Exception
 */
public String createThinVolumes(String systemId, String arrayGroupId, Long luCapacityInBytes, int noOfLus, String volumeName, String formatType, String model) throws Exception {
    Long luCapacityInKB = luCapacityInBytes / 1024;
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray storageArray = new StorageArray(systemId);
        Pool arrayGroup = new Pool(null);
        Add addOp = new Add(HDSConstants.VIRTUALVOLUME, noOfLus, null);
        LogicalUnit logicalUnit = new LogicalUnit(arrayGroupId, String.valueOf(luCapacityInKB), volumeName, HDSConstants.EMULATION_OPENV, null);
        attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
        attributeMap.put(HDSConstants.ARRAY_GROUP, arrayGroup);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
        attributeMap.put(HDSConstants.MODEL, model);
        String createVolumeInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.CREATE_THIN_VOLUMES_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create thin Volume: {}", createVolumeInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, createVolumeInputXML);
        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 creation failed status messageID: {}", command.getMessageID());
                log.error("Thin Volume creation failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateVolume(error.getCode(), error.getDescription());
            }
        } else {
            log.error("Thin Volume creation failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Thin Volume creation 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 close thin volume 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) Pool(com.emc.storageos.hds.model.Pool) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 27 with JavaResult

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

the class HDSApiVolumeManager method deleteThickLogicalUnits.

public String deleteThickLogicalUnits(String systemObjectID, Set<String> logicalUnitIdList, String model) throws Exception {
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        // If the LogicalUnits are LUSE, we should release them.
        releaseLUSEVolumesIfPresent(systemObjectID, logicalUnitIdList);
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray storageArray = new StorageArray(systemObjectID);
        Delete deleteOp = new Delete(HDSConstants.LOGICALUNIT);
        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();
            } 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 28 with JavaResult

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

the class HDSApiVolumeManager method createThickVolumes.

/**
 * Creates the Thick volume with the passed information.
 *
 * @TODO we should add support for multi volume creation by constructing the xml with new attributes. rest will work fine.
 * @param systemId : represents SystemObjectID.
 * @param arrayGroupId : represents StoragePoolObjectID.
 * @param luCapacityInBytes: Logical Unit Capacity in bytes.
 * @param noOfLus : No. of LU's to created
 * @param volumeName : Logical Unit name.
 * @return : asyncMessageId
 * @throws Exception
 */
public String createThickVolumes(String systemId, String arrayGroupId, Long luCapacityInBytes, int noOfLus, String volumeName, String formatType, String model, Integer devNum) throws Exception {
    Long luCapacityInKB = luCapacityInBytes / 1024;
    InputStream responseStream = null;
    String asyncTaskMessageId = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray storageArray = new StorageArray(systemId);
        Pool arrayGroup = new Pool(arrayGroupId);
        Add addOp = new Add(HDSConstants.LOGICALUNIT, noOfLus, formatType);
        addOp.setBulk(Boolean.TRUE);
        LogicalUnit logicalUnit = new LogicalUnit(null, String.valueOf(luCapacityInKB), volumeName, null, devNum);
        attributeMap.put(HDSConstants.STORAGEARRAY, storageArray);
        attributeMap.put(HDSConstants.ARRAY_GROUP, arrayGroup);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.LOGICALUNIT, logicalUnit);
        String createVolumeInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.CREATE_THICK_VOLUMES_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create thick volume: {}", createVolumeInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, createVolumeInputXML);
        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("Volume creation failed status messageID: {}", command.getMessageID());
                log.error("Volume creation failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateVolume(error.getCode(), error.getDescription());
            }
        } else {
            log.error("LogicalUnit creation 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(), systemId));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while close volume 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) Pool(com.emc.storageos.hds.model.Pool) JavaResult(org.milyn.payload.JavaResult) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 29 with JavaResult

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

the class HDSBatchApiExportManager method deleteLUNPathsFromStorageSystem.

/**
 * This method makes HTTP POST call to delete LUN Paths's using a batch
 * query from the storage system.
 *
 * @param systemId
 *            - represents the storage system objectID.
 * @param pathList
 *            - List of Path objects to delete.
 * @param model - Model of the system
 * @throws Exception
 *             - Incase of processing error.
 */
public void deleteLUNPathsFromStorageSystem(String systemId, List<Path> pathList, String model) throws Exception {
    InputStream responseStream = null;
    try {
        boolean operationSucceeds = false;
        int retryCount = 0;
        StringBuilder errorDescriptionBuilder = new StringBuilder();
        while (!operationSucceeds && retryCount < MAX_RETRIES) {
            retryCount++;
            String deleteLUNsQuery = constructRemoveLUNsQuery(systemId, pathList, model);
            log.info("Batch query to deleteLUNs Query: {}", deleteLUNsQuery);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, deleteLUNsQuery);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
                try {
                    verifyErrorPayload(javaResult);
                    // If no exception then operation succeeds
                    operationSucceeds = true;
                } catch (HDSException hdsException) {
                    Error error = javaResult.getBean(Error.class);
                    if (error != null && (error.getDescription().contains("2010") || error.getDescription().contains("5132") || error.getDescription().contains("7473"))) {
                        log.error("Error response recieved from HiCommandManger: {}", error.getDescription());
                        log.info("Exception from HICommand Manager recieved during delete operation, retrying operation {} time", retryCount);
                        errorDescriptionBuilder.append("error ").append(retryCount).append(" : ").append(error.getDescription()).append("-#####-");
                        // Wait for a minute before retry
                        Thread.sleep(60000);
                        // Retry the operation again if retry count not exceeded
                        continue;
                    } else {
                        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete LunPaths due to invalid response from server: Code - %s Description - %s", error.getCode(), error.getDescription()));
                    }
                }
                log.info("Deleted {} LUN paths from system:{}", pathList.size(), systemId);
            } else {
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete Volume from HostGroups due to invalid response %1$s from server", response.getStatus()));
            }
        }
        if (!operationSucceeds) {
            // Delete operation failed ever after repeated retries
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete LunPaths due to repeated errors from HiCommand server, errors description are as %s", errorDescriptionBuilder.toString()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) InputStream(java.io.InputStream) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) HDSException(com.emc.storageos.hds.HDSException)

Example 30 with JavaResult

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

the class HDSBatchApiExportManager method deleteBatchHostStorageDomains.

/**
 * This method makes a HTTP POST call to delete all HostStorageDomain's
 * using a batch query.
 *
 * @param systemId
 *            - Represents storage system ObjectID.
 * @param hsdList
 *            - List of HostStorageDomain objects to delete.
 * @param model - Model of the system
 *
 * @throws Exception
 */
public void deleteBatchHostStorageDomains(String systemId, List<HostStorageDomain> hsdList, String model) throws Exception {
    InputStream responseStream = null;
    try {
        List<HostStorageDomain> unDeletedHSDs = new ArrayList<>();
        unDeletedHSDs.addAll(hsdList);
        boolean operationSucceeds = false;
        int retryCount = 0;
        StringBuilder errorDescriptionBuilder = new StringBuilder();
        while (!operationSucceeds && retryCount < MAX_RETRIES) {
            retryCount++;
            String deleteHSDsQuery = constructDeleteHSDsQuery(systemId, unDeletedHSDs, model);
            log.info("Batch Query to delete HSD's: {}", deleteHSDsQuery);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, deleteHSDsQuery);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
                try {
                    verifyErrorPayload(javaResult);
                    // If no exception then operation succeeds
                    operationSucceeds = true;
                } catch (HDSException hdsException) {
                    Error error = javaResult.getBean(Error.class);
                    if (error != null && (error.getDescription().contains("2010") || error.getDescription().contains("5132") || error.getDescription().contains("7473"))) {
                        log.error("Error response recieved from HiCommandManger: {}", error.getDescription());
                        log.info("Exception from HICommand Manager recieved during delete operation, retrying operation {} time", retryCount);
                        errorDescriptionBuilder.append("error ").append(retryCount).append(" : ").append(error.getDescription()).append("-#####-");
                        // Wait for a minute before retry
                        Thread.sleep(60000);
                        unDeletedHSDs.clear();
                        unDeletedHSDs.addAll(hsdList.stream().filter(hsd -> getHostStorageDomain(systemId, hsd.getObjectID()) != null).collect(Collectors.toList()));
                        if (unDeletedHSDs.isEmpty()) {
                            // Operation succeeded
                            operationSucceeds = true;
                            log.info("Deleted {} LUN paths from system:{}", hsdList.size(), systemId);
                        } else {
                            // Retry the operation again if retry count not exceeded
                            continue;
                        }
                    } else {
                        throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to invalid response from server. Error Code - %s Error Message - %s", error.getCode(), error.getDescription()));
                    }
                }
            } else {
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to invalid response %1$s from server", response.getStatus()));
            }
        }
        if (!operationSucceeds) {
            // Delete operation failed ever after repeated retries
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete HostStorageDomains due to repeated errors from HiCommand server, errors description are as %s", errorDescriptionBuilder.toString()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
    log.info("Batch Query to delete HSD's completed.");
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Logger(org.slf4j.Logger) ClientResponse(com.sun.jersey.api.client.ClientResponse) LoggerFactory(org.slf4j.LoggerFactory) HttpStatus(org.apache.http.HttpStatus) IOException(java.io.IOException) HashMap(java.util.HashMap) EchoCommand(com.emc.storageos.hds.model.EchoCommand) StorageArray(com.emc.storageos.hds.model.StorageArray) Collectors(java.util.stream.Collectors) HDSConstants(com.emc.storageos.hds.HDSConstants) JavaResult(org.milyn.payload.JavaResult) Path(com.emc.storageos.hds.model.Path) ArrayList(java.util.ArrayList) HDSException(com.emc.storageos.hds.HDSException) List(java.util.List) Error(com.emc.storageos.hds.model.Error) Map(java.util.Map) InputXMLGenerationClient(com.emc.storageos.hds.xmlgen.InputXMLGenerationClient) URI(java.net.URI) Delete(com.emc.storageos.hds.model.Delete) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) InputStream(java.io.InputStream) Add(com.emc.storageos.hds.model.Add) SmooksUtil(com.emc.storageos.hds.util.SmooksUtil) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Error(com.emc.storageos.hds.model.Error) IOException(java.io.IOException) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) JavaResult(org.milyn.payload.JavaResult) HDSException(com.emc.storageos.hds.HDSException)

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