Search in sources :

Example 11 with HDSHost

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

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

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

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

the class HDSSnapshotOperations method createSingleVolumeSnapshot.

/**
 * Creates ThinImage instance on HDS.
 * 1. Find pair management server.
 * 2. Find ViPR-Snapshot-Group instance from storage system
 * 3. Find ThinImage pool.
 * 4. Create Snapshot instance on ThinImage Pool.
 * 5. Add DummyLunPath into Snapshot.
 * 6. Create ThinImage pair
 */
@Override
public void createSingleVolumeSnapshot(StorageSystem storage, URI snapshot, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("Create Single Volume Snapshot Started");
    boolean isSnapshotCreated = false, isDummyLunPathAdded = false;
    HDSApiClient hdsApiClient = null;
    HDSHost pairMgmtServer = null;
    try {
        hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        log.info("createSingleVolumeSnapshot operation START");
        Volume volume = dbClient.queryObject(Volume.class, snapshotObj.getParent());
        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());
        }
        String systemObjectId = HDSUtils.getSystemObjectID(storage);
        log.debug("StorageSystem Object Id :{}", systemObjectId);
        List<Pool> thinImagePoolList = hdsApiClient.getThinImagePoolList(systemObjectId);
        if (thinImagePoolList == null || thinImagePoolList.isEmpty()) {
            log.error("ThinImage Pool is not available on Storage System :{}", storage.getNativeGuid());
            throw HDSException.exceptions.thinImagePoolNotAvailable(storage.getNativeGuid());
        }
        Pool selectedThinImagePool = selectThinImagePoolForPlacement(thinImagePoolList, snapshotObj);
        if (selectedThinImagePool == null) {
            log.error("No ThinImage Pool is having enough free capcity to create snapshot on storage system :{}", storage.getNativeGuid());
            throw HDSException.exceptions.notEnoughFreeCapacityOnthinImagePool(storage.getNativeGuid());
        }
        // Create snapshot volume
        hdsProtectionOperations.createSecondaryVolumeForSnapshot(storage, volume, snapshotObj);
        isSnapshotCreated = true;
        snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        // Add Dummy lun path
        hdsProtectionOperations.addDummyLunPath(hdsApiClient, snapshotObj);
        isDummyLunPathAdded = true;
        String snapShotGrpId = getViPRSnapshotGroup(pairMgmtServer, storage.getSerialNumber()).getObjectID();
        // Create Thin Image pair
        hdsApiClient.createThinImagePair(snapShotGrpId, pairMgmtServer.getObjectID(), volume.getNativeId(), snapshotObj.getNativeId(), selectedThinImagePool.getPoolID(), storage.getModel());
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        try {
            rollbackMethodForCreateSnapshot(isSnapshotCreated, isDummyLunPathAdded, hdsApiClient, storage, snapshot);
        } catch (Exception e1) {
            log.error("Exception occured while roll back snap creation", e1);
        }
        String errorMsg = String.format(CREATE_ERROR_MSG_FORMAT, snapshot);
        log.error(errorMsg, e);
        ServiceError serviceError = DeviceControllerErrors.hds.methodFailed("createSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("Create Single Volume Snapshot Completed");
}
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) Pool(com.emc.storageos.hds.model.Pool) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 15 with HDSHost

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

the class HDSSnapshotOperations method deleteSingleVolumeSnapshot.

/**
 * 1. Delete ThinImage Pair
 * 2. Delete Dummy lun path from snap volume
 * 3. Delete Snapshot
 */
@Override
public void deleteSingleVolumeSnapshot(StorageSystem storage, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("Delete Single Volume Snapshot Started");
    try {
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        log.info("deleteSingleVolumeSnapshot operation START");
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        // Get pair management server
        HDSHost pairMgmtServer = hdsApiClient.getSnapshotGroupPairManagementServer(storage.getSerialNumber());
        if (null == pairMgmtServer) {
            log.error("Unable to find snapshot group information/pair management server for Thin Image");
            throw HDSException.exceptions.snapshotGroupNotAvailable(storage.getNativeGuid());
        }
        // Get snapshot group id
        SnapshotGroup snapshotGroup = getViPRSnapshotGroup(pairMgmtServer, storage.getSerialNumber());
        String snapShotGrpId = snapshotGroup.getObjectID();
        // Get replication object ids
        Volume volume = dbClient.queryObject(Volume.class, snapshotObj.getParent());
        ReplicationInfo replicationInfo = getReplicationInfo(snapshotGroup, volume.getNativeId(), snapshotObj.getNativeId());
        if (replicationInfo != null) {
            String replicationInfoObjId = replicationInfo.getObjectID();
            // Delete ThinImage pair between volume and snapshot
            hdsApiClient.deleteThinImagePair(pairMgmtServer.getObjectID(), snapShotGrpId, replicationInfoObjId, storage.getModel());
        } else {
            log.info("Pair has been deleted already on storage system");
        }
        // Remove dummy lun path
        hdsProtectionOperations.removeDummyLunPath(storage, snapshot);
        // Delete snapshot vollume
        hdsProtectionOperations.deleteSecondaryVolumeSnapshot(storage, snapshotObj, taskCompleter);
        log.info("Delete Single Volume Snapshot Completed");
    } catch (Exception e) {
        String errorMsg = String.format(DELETE_ERROR_MSG_FORMAT, snapshot);
        log.error(errorMsg, e);
        ServiceError serviceError = DeviceControllerErrors.hds.methodFailed("deleteSingleVolumeSnapshot", e.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
}
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)

Aggregations

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