Search in sources :

Example 16 with Error

use of com.emc.storageos.hds.model.Error 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 17 with Error

use of com.emc.storageos.hds.model.Error 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)

Example 18 with Error

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

the class HDSApiExportManager method verifyErrorPayload.

/**
 * Utility method to check if there are any errors or not.
 *
 * @param javaResult
 * @throws Exception
 */
private void verifyErrorPayload(JavaResult javaResult) throws Exception {
    EchoCommand command = javaResult.getBean(EchoCommand.class);
    if (null == command || null == command.getStatus() || HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
        Error error = javaResult.getBean(Error.class);
        log.info("Error response received from Hitachi server for messageID", command.getMessageID());
        log.info("Hitachi command failed with error code:{} with message:{} for request:{}", new Object[] { error.getCode().toString(), error.getDescription(), error.getSource() });
        throw HDSException.exceptions.errorResponseReceived(error.getCode(), error.getDescription());
    }
}
Also used : Error(com.emc.storageos.hds.model.Error) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Example 19 with Error

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

the class HDSApiExportManager method deleteLunPathsFromSystem.

/**
 * Delete the LUN Path from HSD of a given storage array.
 *
 * @param systemObjectId
 * @param pathObjectIdList
 * @param model
 *
 * @throws Exception
 */
public void deleteLunPathsFromSystem(String systemObjectId, List<String> pathObjectIdList, 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 = constructDeleteLunPathsQuery(systemObjectId, pathObjectIdList, 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:{}", pathObjectIdList.size(), systemObjectId);
            } 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 20 with Error

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

the class HDSApiProtectionManager method verifyErrorPayload.

/**
 * Utility method to check if there are any errors or not.
 *
 * @param javaResult
 * @throws Exception
 */
private void verifyErrorPayload(JavaResult javaResult) throws Exception {
    EchoCommand command = javaResult.getBean(EchoCommand.class);
    if (null == command || null == command.getStatus() || HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
        Error error = javaResult.getBean(Error.class);
        log.info("Error response received from Hitachi server for messageID", command.getMessageID());
        log.info("Hitachi command failed with error code:{} with message:{} for request:{}", new Object[] { error.getCode().toString(), error.getDescription(), error.getSource() });
        throw HDSException.exceptions.errorResponseReceived(error.getCode(), error.getDescription());
    }
}
Also used : Error(com.emc.storageos.hds.model.Error) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Aggregations

Error (com.emc.storageos.hds.model.Error)24 EchoCommand (com.emc.storageos.hds.model.EchoCommand)22 JavaResult (org.milyn.payload.JavaResult)17 ClientResponse (com.sun.jersey.api.client.ClientResponse)16 InputStream (java.io.InputStream)16 IOException (java.io.IOException)15 URI (java.net.URI)15 HashMap (java.util.HashMap)12 StorageArray (com.emc.storageos.hds.model.StorageArray)10 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)9 Add (com.emc.storageos.hds.model.Add)6 HDSException (com.emc.storageos.hds.HDSException)4 Delete (com.emc.storageos.hds.model.Delete)4 Modify (com.emc.storageos.hds.model.Modify)3 ArrayList (java.util.ArrayList)3 HDSHost (com.emc.storageos.hds.model.HDSHost)2 Pool (com.emc.storageos.hds.model.Pool)2 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 HDSConstants (com.emc.storageos.hds.HDSConstants)1