Search in sources :

Example 41 with JavaResult

use of org.milyn.payload.JavaResult 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 42 with JavaResult

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

the class HDSApiExportManager method addHostStorageDomain.

/**
 * Add new HostStorageDomain.
 *
 * @param systemId
 * @param targetPortID
 * @param hsdNickName
 * @param hostMode.
 * @param hostModeOption
 * @param model
 * @return
 * @throws Exception
 */
public HostStorageDomain addHostStorageDomain(String systemId, String targetPortID, String domainType, String hsdName, String hsdNickName, String hostMode, String hostModeOption, String model) throws Exception {
    InputStream responseStream = null;
    HostStorageDomain hsd = null;
    try {
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        StorageArray array = new StorageArray(systemId);
        Add addOp = new Add(HDSConstants.HOST_STORAGE_DOMAIN);
        attributeMap.put(HDSConstants.STORAGEARRAY, array);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        HostStorageDomain inputHsd = new HostStorageDomain(targetPortID, hsdName, domainType, hsdNickName);
        inputHsd.setHostMode(hostMode);
        inputHsd.setHostModeOption(hostModeOption);
        attributeMap.put(HDSConstants.HOST_STORAGE_DOMAIN, inputHsd);
        String addHSDToSystemQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.ADD_HSD_TO_SYSTEM_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create HostStorageDomain: {}", addHSDToSystemQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, addHSDToSystemQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            hsd = javaResult.getBean(HostStorageDomain.class);
            if (null == hsd) {
                throw HDSException.exceptions.notAbleToAddHSD(systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to add HostStorageDomain 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");
            }
        }
    }
    return hsd;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult) StorageArray(com.emc.storageos.hds.model.StorageArray)

Example 43 with JavaResult

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

the class HDSApiProtectionManager method getSnapshotGroupPairManagementServer.

/**
 * Get PairManagement Server for SnapshotGroup
 *
 * @param serialNumber
 * @return
 * @throws Exception
 */
public HDSHost getSnapshotGroupPairManagementServer(String serialNumber) throws Exception {
    InputStream responseStream = null;
    try {
        log.info("Started to collect Pair Mgmt Server details");
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Get getOp = new Get(HDSConstants.HOST);
        attributeMap.put(HDSConstants.GET, getOp);
        HDSHost host = new HDSHost();
        host.setName("*");
        attributeMap.put(HDSConstants.HOST, host);
        SnapshotGroup snapshotGroup = new SnapshotGroup();
        // snapshotGroup.setArrayType(arrayType);
        snapshotGroup.setSerialNumber(serialNumber);
        snapshotGroup.setGroupName(HDSConstants.VIPR_SNAPSHOT_GROUP_NAME);
        attributeMap.put(HDSConstants.SNAPSHOTGROUP, snapshotGroup);
        String getSnapshotGroupQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.GET_SNAPSHOT_GROUP_INFO_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to pair management server Host: {}", getSnapshotGroupQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, getSnapshotGroupQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_THINIMAGE_CONFIG_FILE);
            hdsApiClient.verifyErrorPayload(javaResult);
            List<HDSHost> hostList = (List<HDSHost>) javaResult.getBean(HDSConstants.HOST_LIST_BEAN_NAME);
            log.info("Host List size :{}", hostList.size());
            for (HDSHost hdsHost : hostList) {
                if (hdsHost != null && hdsHost.getSnapshotGroupList() != null) {
                    log.info("Host Name :{}", hdsHost.getName());
                    for (SnapshotGroup snapGroup : hdsHost.getSnapshotGroupList()) {
                        log.info("SnapshotGroup groupName :{}", snapGroup.getGroupName());
                        if (snapGroup != null && HDSConstants.VIPR_SNAPSHOT_GROUP_NAME.equalsIgnoreCase(snapGroup.getGroupName()) && serialNumber.equalsIgnoreCase(snapGroup.getSerialNumber())) {
                            log.info("Found ViPR snaphot group on pair mgmt server {}", hdsHost.getName());
                            return hdsHost;
                        }
                    }
                }
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to query HostStorageDomain's 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");
            }
        }
    }
    // If we are here there is no pair mgmt server available on storage system.
    return null;
}
Also used : 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) Get(com.emc.storageos.hds.model.Get) List(java.util.List) JavaResult(org.milyn.payload.JavaResult)

Example 44 with JavaResult

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

the class HDSApiProtectionManager method restoreThinImagePair.

/**
 * Restore's snapshot to source volume.
 *
 * @param pairMgmtServerHostObjId
 * @param snapshotGroupObjId
 * @param replicationInfoObjId
 * @return
 * @throws Exception
 */
public boolean restoreThinImagePair(String pairMgmtServerHostObjId, String snapshotGroupObjId, String replicationInfoObjId, String model) throws Exception {
    InputStream responseStream = null;
    ReplicationInfo replicationInfo = null;
    boolean status = false;
    try {
        if (pairMgmtServerHostObjId != null && snapshotGroupObjId != null && replicationInfoObjId != null) {
            log.info("Restore thin image pair started");
            Map<String, Object> attributeMap = new HashMap<String, Object>();
            Modify modifyOp = new Modify(HDSConstants.REPLICATION);
            modifyOp.setOption(HDSConstants.RESTORE_INBAND2);
            HDSHost host = new HDSHost();
            host.setObjectID(pairMgmtServerHostObjId);
            SnapshotGroup snapshotGroup = new SnapshotGroup();
            snapshotGroup.setObjectID(snapshotGroupObjId);
            replicationInfo = new ReplicationInfo();
            replicationInfo.setObjectID(replicationInfoObjId);
            attributeMap.put(HDSConstants.MODIFY, modifyOp);
            attributeMap.put(HDSConstants.MODEL, model);
            attributeMap.put(HDSConstants.HOST, host);
            attributeMap.put(HDSConstants.SNAPSHOTGROUP, snapshotGroup);
            attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
            String restoreThinImagePairQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.RESTORE_THIN_IMAGE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
            log.info("Query to restore thin image pair  Query: {}", restoreThinImagePairQuery);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, restoreThinImagePairQuery);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_THINIMAGE_CONFIG_FILE);
                verifyErrorPayload(javaResult);
                log.info("Successfully restored thin image pair");
                status = true;
                replicationInfo = javaResult.getBean(ReplicationInfo.class);
                log.info("replicationInfo :{}", replicationInfo);
            /*
                     * if (null == replicationInfo) {
                     * throw HDSException.exceptions.notAbleToCreateShadowImagePair();
                     * }
                     */
            } else {
                throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to delete shadow image pair due to invalid response %1$s from server", response.getStatus()));
            }
        } else {
            log.info("Replication info is not available on pair management server");
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
    return status;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Modify(com.emc.storageos.hds.model.Modify) 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 45 with JavaResult

use of org.milyn.payload.JavaResult 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)

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