Search in sources :

Example 6 with ReplicationInfo

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

the class HDSApiProtectionManager method getReplicationInfoFromSystem.

public Pair<ReplicationInfo, String> getReplicationInfoFromSystem(String sourceNativeId, String targetNativeId) throws Exception {
    log.info("sourceNativeId :{}", sourceNativeId);
    log.info("targetNativeId :{}", targetNativeId);
    List<HDSHost> hostList = getHDSHostList();
    if (hostList != null) {
        for (HDSHost hdsHost : hostList) {
            log.info("HDSHost :{}", hdsHost.toXMLString());
            if (hdsHost != null && hdsHost.getConfigFileList() != null && !hdsHost.getConfigFileList().isEmpty()) {
                for (ConfigFile configFile : hdsHost.getConfigFileList()) {
                    if (configFile != null) {
                        ReplicationGroup replicationGroup = configFile.getReplicationGroup();
                        if (replicationGroup != null && replicationGroup.getReplicationInfoList() != null) {
                            log.info("replicationGroup :{}", replicationGroup.toXMLString());
                            List<ReplicationInfo> replicationInfoList = replicationGroup.getReplicationInfoList();
                            if (replicationInfoList != null) {
                                for (ReplicationInfo replicationInfo : replicationInfoList) {
                                    log.debug("replicationInfo :{}", replicationInfo.toXMLString());
                                    if (sourceNativeId.equals(replicationInfo.getPvolDevNum()) && targetNativeId.equals(replicationInfo.getSvolDevNum())) {
                                        log.info("Found replicationInfo object from system:{}", replicationInfo.toXMLString());
                                        log.info("Host Object Id :{}", hdsHost.getObjectID());
                                        return (new Pair<ReplicationInfo, String>(replicationInfo, hdsHost.getObjectID()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // If we are here there is no matching replication info available on pair management server.
    log.error("Unable to find replication info details from device manager for the pvol {} svol {}", sourceNativeId, targetNativeId);
    return null;
}
Also used : HDSHost(com.emc.storageos.hds.model.HDSHost) ConfigFile(com.emc.storageos.hds.model.ConfigFile) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) ReplicationGroup(com.emc.storageos.hds.model.ReplicationGroup)

Example 7 with ReplicationInfo

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

the class HDSApiProtectionManager method modifyShadowImagePair.

/**
 * Modify ShadowImage pair operation .
 *
 * @param replicationGroupId
 * @param replicationInfoId
 * @param operationType
 * @return {@link ReplicationInfo}
 * @throws Exception
 */
public ReplicationInfo modifyShadowImagePair(String replicationGroupId, String replicationInfoId, ShadowImageOperationType operationType, String model) throws Exception {
    InputStream responseStream = null;
    ReplicationInfo replicationInfo = null;
    try {
        if (replicationGroupId != null && replicationInfoId != null) {
            Map<String, Object> attributeMap = new HashMap<String, Object>();
            Modify modifyOp = new Modify();
            modifyOp.setTarget(HDSConstants.REPLICATION);
            modifyOp.setOption(operationType.name());
            ReplicationGroup replicationGroup = new ReplicationGroup();
            replicationGroup.setObjectID(replicationGroupId);
            replicationInfo = new ReplicationInfo();
            replicationInfo.setObjectID(replicationInfoId);
            attributeMap.put(HDSConstants.MODIFY, modifyOp);
            attributeMap.put(HDSConstants.MODEL, model);
            attributeMap.put(HDSConstants.REPLICATION_GROUP, replicationGroup);
            attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
            String modifyPairQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.MODIFY_SHADOW_IMAGE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
            log.info("Query to {} shadow image pair  Query: {}", operationType.name(), modifyPairQuery);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, modifyPairQuery);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_REPLICATION_CONFIG_FILE);
                verifyErrorPayload(javaResult);
                log.info("Successfully {}ed pair", operationType.name());
                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 modify replication info 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 replicationInfo;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) Modify(com.emc.storageos.hds.model.Modify) IOException(java.io.IOException) ReplicationGroup(com.emc.storageos.hds.model.ReplicationGroup) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Example 8 with ReplicationInfo

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

the class HDSApiProtectionManager method createThinImagePair.

/**
 * Creates ThinImage pair for HDS Snapshot
 *
 * @param snapshotGroupObjId
 * @param hostObjId
 * @param sourNativeId
 * @param snapNativeId
 * @param thinImagePoolId
 * @return
 * @throws Exception
 */
public boolean createThinImagePair(String snapshotGroupObjId, String hostObjId, String sourNativeId, String snapNativeId, String thinImagePoolId, String model) throws Exception {
    log.info("Thin Image pair creation started");
    boolean status = false;
    InputStream responseStream = null;
    String syncTaskMessageId = null;
    try {
        log.info("snapshotGroupObjId {} ", snapshotGroupObjId);
        Map<String, Object> attributeMap = new HashMap<String, Object>();
        Add addOp = new Add(HDSConstants.REPLICATION);
        addOp.setOption(HDSConstants.INBAND2);
        HDSHost host = new HDSHost();
        host.setObjectID(hostObjId);
        SnapshotGroup snapshotGroup = new SnapshotGroup();
        snapshotGroup.setObjectID(snapshotGroupObjId);
        snapshotGroup.setReplicationFunction(HDSConstants.THIN_IMAGE);
        ReplicationInfo replicationInfo = new ReplicationInfo();
        replicationInfo.setPvolDevNum(sourNativeId);
        replicationInfo.setSvolDevNum(snapNativeId);
        replicationInfo.setPvolPoolID(thinImagePoolId);
        attributeMap.put(HDSConstants.ADD, addOp);
        attributeMap.put(HDSConstants.MODEL, model);
        attributeMap.put(HDSConstants.HOST, host);
        attributeMap.put(HDSConstants.SNAPSHOTGROUP, snapshotGroup);
        attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
        String createThinImagePairInputXML = InputXMLGenerationClient.getInputXMLString(HDSConstants.CREATE_THIN_IMAGE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
        log.info("Query to create thin image pair : {}", createThinImagePairInputXML);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, createThinImagePairInputXML);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult result = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_THINIMAGE_CONFIG_FILE);
            EchoCommand command = result.getBean(EchoCommand.class);
            if (HDSConstants.COMPLETED_STR.equalsIgnoreCase(command.getStatus())) {
                log.info("ThinImage Pair has been created successfully");
                status = true;
                SnapshotGroup snapshotGrpResponse = result.getBean(SnapshotGroup.class);
                if (null == snapshotGrpResponse) {
                    throw HDSException.exceptions.notAbleToCreateThinImagePair();
                }
            } else if (HDSConstants.PROCESSING_STR.equalsIgnoreCase(command.getStatus())) {
                syncTaskMessageId = command.getMessageID();
            } else if (HDSConstants.FAILED_STR.equalsIgnoreCase(command.getStatus())) {
                Error error = result.getBean(Error.class);
                log.error("Thin Image pair creation failed status messageID: {}", command.getMessageID());
                log.error("Thin Image pair creation failed with error code: {} with message: {}", error.getCode(), error.getDescription());
                throw HDSException.exceptions.notAbleToCreateThinImagePairError(error.getCode(), error.getDescription());
            }
        } else {
            log.error("Thin Image pair creation failed with invalid response code {}", response.getStatus());
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Thin Image pair creation failed due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("Exception occurred while close Thin Image Pair creation response stream");
            }
        }
    }
    log.info("Thin Image pair creation completed");
    return status;
}
Also used : Add(com.emc.storageos.hds.model.Add) ClientResponse(com.sun.jersey.api.client.ClientResponse) HDSHost(com.emc.storageos.hds.model.HDSHost) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Error(com.emc.storageos.hds.model.Error) 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) EchoCommand(com.emc.storageos.hds.model.EchoCommand)

Example 9 with ReplicationInfo

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

the class HDSApiProtectionManager method deleteShadowImagePair.

/**
 * Deletes SI replicationInfo instance from replication group
 *
 * @param replicationGroupObjId
 * @param replicationInfoObjId
 * @return {@link ReplicationInfo}
 * @throws Exception
 */
public ReplicationInfo deleteShadowImagePair(String replicationGroupObjId, String replicationInfoObjId, String model) throws Exception {
    InputStream responseStream = null;
    ReplicationInfo replicationInfo = null;
    try {
        if (replicationGroupObjId != null && replicationInfoObjId != null) {
            Map<String, Object> attributeMap = new HashMap<String, Object>();
            Delete deleteOp = new Delete(HDSConstants.REPLICATION);
            ReplicationGroup replicationGroup = new ReplicationGroup();
            replicationGroup.setObjectID(replicationGroupObjId);
            replicationInfo = new ReplicationInfo();
            replicationInfo.setObjectID(replicationInfoObjId);
            attributeMap.put(HDSConstants.DELETE, deleteOp);
            attributeMap.put(HDSConstants.MODEL, model);
            attributeMap.put(HDSConstants.REPLICATION_GROUP, replicationGroup);
            attributeMap.put(HDSConstants.REPLICATION_INFO, replicationInfo);
            String deletePairQuery = InputXMLGenerationClient.getInputXMLString(HDSConstants.DELETE_PAIR_OP, attributeMap, HDSConstants.HITACHI_INPUT_XML_CONTEXT_FILE, HDSConstants.HITACHI_SMOOKS_CONFIG_FILE);
            log.info("Query to delete shadow image pair  Query: {}", deletePairQuery);
            URI endpointURI = hdsApiClient.getBaseURI();
            ClientResponse response = hdsApiClient.post(endpointURI, deletePairQuery);
            if (HttpStatus.SC_OK == response.getStatus()) {
                responseStream = response.getEntityInputStream();
                JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.HITACHI_SMOOKS_REPLICATION_CONFIG_FILE);
                verifyErrorPayload(javaResult);
                log.info("Successfully Deleted pair");
                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 replicationInfo;
}
Also used : Delete(com.emc.storageos.hds.model.Delete) ClientResponse(com.sun.jersey.api.client.ClientResponse) HashMap(java.util.HashMap) InputStream(java.io.InputStream) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) IOException(java.io.IOException) ReplicationGroup(com.emc.storageos.hds.model.ReplicationGroup) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Example 10 with ReplicationInfo

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

Aggregations

ReplicationInfo (com.emc.storageos.hds.model.ReplicationInfo)16 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)7 HDSHost (com.emc.storageos.hds.model.HDSHost)7 HashMap (java.util.HashMap)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 IOException (java.io.IOException)6 InputStream (java.io.InputStream)6 URI (java.net.URI)6 JavaResult (org.milyn.payload.JavaResult)6 Volume (com.emc.storageos.db.client.model.Volume)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 HDSException (com.emc.storageos.hds.HDSException)5 HDSApiProtectionManager (com.emc.storageos.hds.api.HDSApiProtectionManager)5 ReplicationGroup (com.emc.storageos.hds.model.ReplicationGroup)5 SnapshotGroup (com.emc.storageos.hds.model.SnapshotGroup)5 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)5 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)2 Add (com.emc.storageos.hds.model.Add)2