Search in sources :

Example 1 with SnapshotGroup

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

the class HDSSnapshotOperations method getViPRSnapshotGroup.

private SnapshotGroup getViPRSnapshotGroup(HDSHost pairMgmtServer, String systemSerialNumber) {
    SnapshotGroup snapShotGrp = null;
    if (pairMgmtServer != null && pairMgmtServer.getSnapshotGroupList() != null) {
        for (SnapshotGroup snapshotGroup : pairMgmtServer.getSnapshotGroupList()) {
            if (snapshotGroup != null && HDSConstants.VIPR_SNAPSHOT_GROUP_NAME.equalsIgnoreCase(snapshotGroup.getGroupName()) && systemSerialNumber.equalsIgnoreCase(snapshotGroup.getSerialNumber())) {
                snapShotGrp = snapshotGroup;
                log.info("Snapshot Group Id :{}", snapShotGrp.getObjectID());
                break;
            }
        }
    }
    return snapShotGrp;
}
Also used : SnapshotGroup(com.emc.storageos.hds.model.SnapshotGroup)

Example 2 with SnapshotGroup

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

the class HDSSnapshotOperations method restoreSingleVolumeSnapshot.

/**
 * 1. Find pair management server.
 * 2. Get SnapshotGroup's Object Id.
 * 3. Get ReplicationInfo's Object Id.
 * 4. Perform ReplicationInfo Restore operation.
 */
@Override
public void restoreSingleVolumeSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot from = dbClient.queryObject(BlockSnapshot.class, snapshot);
        Volume to = dbClient.queryObject(Volume.class, volume);
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSHost pairMgmtServer = hdsApiClient.getSnapshotGroupPairManagementServer(storage.getSerialNumber());
        if (pairMgmtServer == null) {
            log.error("Unable to find snapshot group information/pair management server for Thin Image");
            throw HDSException.exceptions.snapshotGroupNotAvailable(storage.getNativeGuid());
        }
        SnapshotGroup snapShotGrp = getViPRSnapshotGroup(pairMgmtServer, storage.getSerialNumber());
        log.debug("to.getNativeId() :{}", to.getNativeId());
        log.debug("from.getNativeId() :{}", from.getNativeId());
        ReplicationInfo repInfo = getReplicationInfo(snapShotGrp, to.getNativeId(), from.getNativeId());
        hdsApiClient.restoreThinImagePair(pairMgmtServer.getObjectID(), snapShotGrp.getObjectID(), repInfo.getObjectID(), storage.getModel());
        taskCompleter.ready(dbClient);
        log.info("Restore Snapshot volume completed");
    } catch (Exception e) {
        String message = String.format("Generic exception when trying to restore from snapshot %s on array %s", snapshot.toString(), storage.getSerialNumber());
        log.error(message, e);
        ServiceError error = DeviceControllerErrors.hds.methodFailed("restoreSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HDSHost(com.emc.storageos.hds.model.HDSHost) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ReplicationInfo(com.emc.storageos.hds.model.ReplicationInfo) SnapshotGroup(com.emc.storageos.hds.model.SnapshotGroup) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 3 with SnapshotGroup

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

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

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

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