Search in sources :

Example 6 with SnapshotGroup

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

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

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