Search in sources :

Example 6 with Delete

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

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

the class HDSApiExportManager method constructDeleteWWNQuery.

/**
 * Construct the WWN Query by adding multiple WWNs.
 * This query should be used to add FC initiators to the FC HSD.
 *
 * @param systemId
 * @param hsdId
 * @param wwnList
 * @return
 */
private String constructDeleteWWNQuery(String systemId, String hsdId, List<String> wwnList, String model) {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    StorageArray array = new StorageArray(systemId);
    Delete deleteOp = new Delete(HDSConstants.ADD_WWN_TO_HSD_TARGET);
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.DELETE, deleteOp);
    attributeMap.put(HDSConstants.MODEL, model);
    HostStorageDomain hsd = new HostStorageDomain(hsdId);
    attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, hsd);
    List<WorldWideName> wwnObjList = new ArrayList<WorldWideName>();
    if (null != wwnList && !wwnList.isEmpty()) {
        for (String initiatorWWN : wwnList) {
            WorldWideName wwn = new WorldWideName(initiatorWWN);
            wwnObjList.add(wwn);
        }
    }
    attributeMap.put(HDSConstants.WWN_LIST, wwnObjList);
    String deleteWWNFromHSDQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_WWN_FROM_HSD_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    return deleteWWNFromHSDQuery;
}
Also used : Delete(com.emc.storageos.hds.model.Delete) HashMap(java.util.HashMap) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) ArrayList(java.util.ArrayList) WorldWideName(com.emc.storageos.hds.model.WorldWideName) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 8 with Delete

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

the class HDSApiExportManager method constructDeleteLunPathsQuery.

/**
 * Construct the WWN Query by adding multiple WWNs.
 * This query should be used to add FC initiators to the FC HSD.
 *
 * @param systemId
 * @param hsdId
 * @param lunPathObjectIdList
 * @return
 */
private String constructDeleteLunPathsQuery(String systemId, List<String> lunPathObjectIdList, String model) {
    Map<String, Object> attributeMap = new HashMap<String, Object>();
    List<Path> pathList = new ArrayList<Path>();
    StorageArray array = new StorageArray(systemId);
    Delete deleteOp = new Delete(HDSConstants.LUN_TARGET);
    attributeMap.put(HDSConstants.STORAGEARRAY, array);
    attributeMap.put(HDSConstants.MODEL, model);
    attributeMap.put(HDSConstants.DELETE, deleteOp);
    if (null != lunPathObjectIdList && !lunPathObjectIdList.isEmpty()) {
        for (String pathObjectId : lunPathObjectIdList) {
            Path path = new Path(pathObjectId);
            pathList.add(path);
        }
    }
    attributeMap.put(HDSConstants.PATH_LIST, pathList);
    String deleteLunInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_PATH_FROM_HSD_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
    return deleteLunInputXML;
}
Also used : Path(com.emc.storageos.hds.model.Path) Delete(com.emc.storageos.hds.model.Delete) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 9 with Delete

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

the class HDSApiProtectionManager method deleteThinImagePair.

/**
 * Deletes ReplicationInfo instance from SnapshotGroup
 *
 * @param snapshotGroupObjId
 * @param replicationInfoObjId
 * @throws Exception
 */
public void deleteThinImagePair(String hostObjId, String snapshotGroupObjId, String replicationInfoObjId, String model) throws Exception {
    InputStream responseStream = null;
    ReplicationInfo replicationInfo = null;
    try {
        if (hostObjId != null && snapshotGroupObjId != null && replicationInfoObjId != null) {
            Map<String, Object> attributeMap = new HashMap<String, Object>();
            Delete deleteOp = new Delete(HDSConstants.REPLICATION, HDSConstants.INBAND2);
            HDSHost host = new HDSHost();
            host.setObjectID(hostObjId);
            SnapshotGroup snapshotGroup = new SnapshotGroup();
            snapshotGroup.setObjectID(snapshotGroupObjId);
            replicationInfo = new ReplicationInfo();
            replicationInfo.setObjectID(replicationInfoObjId);
            attributeMap.put(HDSConstants.DELETE, deleteOp);
            attributeMap.put(HDSConstants.HOST, host);
            attributeMap.put(HDSConstants.MODEL, model);
            attributeMap.put(HDSConstants.SNAPSHOTGROUP, snapshotGroup);
            attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
            String deleteThinImagePairInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_THIN_IMAGE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
            log.info("Query to delete thin image pair : {}", deleteThinImagePairInputXML);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, deleteThinImagePairInputXML);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_THINIMAGE_CONFIG_FILE);
                verifyErrorPayload(result);
                log.info("Thin Image pair deleted successfully.");
            } else {
                log.error("Thin Image pair deletion failed with invalid response code {}", response.getStatus());
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Thin Image pair deletion failed due to invalid response %1$s from server", response.getStatus()));
            }
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
}
Also used : Delete(com.emc.storageos.hds.model.Delete) ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) SnapshotGroup(com.emc.storageos.hds.model.SnapshotGroup) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) JavaResult(org.milyn.payload.JavaResult)

Example 10 with Delete

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

Aggregations

Delete (com.emc.storageos.hds.model.Delete)12 HashMap (java.util.HashMap)12 StorageArray (com.emc.storageos.hds.model.StorageArray)10 ClientResponse (com.sun.jersey.api.client.ClientResponse)7 IOException (java.io.IOException)7 InputStream (java.io.InputStream)7 URI (java.net.URI)7 JavaResult (org.milyn.payload.JavaResult)7 ArrayList (java.util.ArrayList)6 EchoCommand (com.emc.storageos.hds.model.EchoCommand)4 Error (com.emc.storageos.hds.model.Error)4 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)4 LogicalUnit (com.emc.storageos.hds.model.LogicalUnit)3 Path (com.emc.storageos.hds.model.Path)2 ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)2 HDSConstants (com.emc.storageos.hds.HDSConstants)1 HDSException (com.emc.storageos.hds.HDSException)1 Add (com.emc.storageos.hds.model.Add)1 HDSHost (com.emc.storageos.hds.model.HDSHost)1 ISCSIName (com.emc.storageos.hds.model.ISCSIName)1