Search in sources :

Example 1 with ConsistencyGroupSnapshotCreateResponse

use of com.emc.storageos.cinder.model.ConsistencyGroupSnapshotCreateResponse in project coprhd-controller by CoprHD.

the class ConsistencyGroupSnapshotService method createConsistencyGroupSnapshot.

/**
 * Create consistency group snapshot
 *
 * @param openstackTenantId
 *            openstack tenant Id
 * @param param
 *            Pojo class to bind request
 * @param isV1Call
 *            cinder V1 api
 * @param header
 *            HTTP header
 * @brief Create Consistency Group Snapshot
 * @return Response
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createConsistencyGroupSnapshot(@PathParam("tenant_id") String openstackTenantId, final ConsistencyGroupSnapshotCreateRequest param, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    // Query Consistency Group
    final String consistencyGroupId = param.cgsnapshot.consistencygroup_id;
    final BlockConsistencyGroup consistencyGroup = findConsistencyGroup(consistencyGroupId, openstackTenantId);
    if (consistencyGroup == null) {
        _log.error("Not Found : No Such Consistency Group Found {}", consistencyGroupId);
        return CinderApiUtils.createErrorResponse(404, "Not Found : No Such Consistency Group Found");
    } else if (!consistencyGroupId.equals(CinderApiUtils.splitString(consistencyGroup.getId().toString(), ":", 3))) {
        _log.error("Bad Request : Invalid Snapshot Id {} : Please enter valid or full Id", consistencyGroupId);
        return CinderApiUtils.createErrorResponse(400, "Bad Request : No such consistency id exist, Please enter valid or full Id");
    }
    if (!isSnapshotCreationpermissible(consistencyGroup)) {
        _log.error("Bad Request : vpool not being configured for the snapshots creation");
        return CinderApiUtils.createErrorResponse(400, "Bad Request : vpool not being configured for the snapshots creation");
    }
    // system types.
    if (!consistencyGroup.created()) {
        CinderApiUtils.createErrorResponse(400, "No such consistency group created");
    }
    Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    URI cgStorageControllerURI = consistencyGroup.getStorageController();
    if (!NullColumnValueGetter.isNullURI(cgStorageControllerURI)) {
        // No snapshots for VPLEX consistency groups.
        StorageSystem cgStorageController = _dbClient.queryObject(StorageSystem.class, cgStorageControllerURI);
        if ((DiscoveredDataObject.Type.vplex.name().equals(cgStorageController.getSystemType())) && (!consistencyGroup.checkForType(Types.LOCAL))) {
            CinderApiUtils.createErrorResponse(400, "can't create snapshot for VPLEX");
        }
    }
    // Get the block service implementation
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    // Get the volumes in the consistency group.
    List<Volume> volumeList = blockServiceApiImpl.getActiveCGVolumes(consistencyGroup);
    _log.info("Active CG volume list : " + volumeList);
    // Generate task id
    String taskId = UUID.randomUUID().toString();
    // Set snapshot type.
    String snapshotType = BlockSnapshot.TechnologyType.NATIVE.toString();
    if (consistencyGroup.checkForType(BlockConsistencyGroup.Types.RP)) {
        snapshotType = BlockSnapshot.TechnologyType.RP.toString();
    } else if ((!volumeList.isEmpty()) && (volumeList.get(0).checkForSRDF())) {
        snapshotType = BlockSnapshot.TechnologyType.SRDF.toString();
    }
    // Determine the snapshot volume for RP.
    Volume snapVolume = null;
    if (consistencyGroup.checkForType(BlockConsistencyGroup.Types.RP)) {
        for (Volume volumeToSnap : volumeList) {
            // Get the RP source volume.
            if (volumeToSnap.getPersonality() != null && volumeToSnap.getPersonality().equals(Volume.PersonalityTypes.SOURCE.toString())) {
                snapVolume = volumeToSnap;
                break;
            }
        }
    } else if (!volumeList.isEmpty()) {
        // Any volume.
        snapVolume = volumeList.get(0);
    }
    // Set the create inactive flag.
    Boolean createInactive = Boolean.FALSE;
    Boolean readOnly = Boolean.FALSE;
    // Validate the snapshot request.
    String snapshotName = param.cgsnapshot.name;
    blockServiceApiImpl.validateCreateSnapshot(snapVolume, volumeList, snapshotType, snapshotName, readOnly, getFullCopyManager());
    // Prepare and create the snapshots for the group.
    List<URI> snapIdList = new ArrayList<URI>();
    List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
    TaskList response = new TaskList();
    snapshotList.addAll(blockServiceApiImpl.prepareSnapshots(volumeList, snapshotType, snapshotName, snapIdList, taskId));
    for (BlockSnapshot snapshot : snapshotList) {
        response.getTaskList().add(toTask(snapshot, taskId));
    }
    blockServiceApiImpl.createSnapshot(snapVolume, snapIdList, snapshotType, createInactive, readOnly, taskId);
    auditBlockConsistencyGroup(OperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, param.cgsnapshot.name, consistencyGroup.getId().toString());
    ConsistencyGroupSnapshotCreateResponse cgSnapshotCreateRes = new ConsistencyGroupSnapshotCreateResponse();
    for (TaskResourceRep rep : response.getTaskList()) {
        URI snapshotUri = rep.getResource().getId();
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshotUri);
        snap.setId(snapshotUri);
        snap.setConsistencyGroup(consistencyGroup.getId());
        snap.setLabel(snapshotName);
        if (snap != null) {
            StringMap extensions = snap.getExtensions();
            if (extensions == null) {
                extensions = new StringMap();
            }
            extensions.put("status", CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase());
            extensions.put("taskid", rep.getId().toString());
            snap.setExtensions(extensions);
            ScopedLabelSet tagSet = new ScopedLabelSet();
            snap.setTag(tagSet);
            tagSet.add(new ScopedLabel(project.getTenantOrg().getURI().toString(), CinderApiUtils.splitString(snapshotUri.toString(), ":", 3)));
        }
        _dbClient.updateObject(snap);
        cgSnapshotCreateRes.id = CinderApiUtils.splitString(snapshotUri.toString(), ":", 3);
        cgSnapshotCreateRes.name = param.cgsnapshot.name;
    }
    return CinderApiUtils.getCinderResponse(cgSnapshotCreateRes, header, true, CinderConstants.STATUS_OK);
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ConsistencyGroupSnapshotCreateResponse(com.emc.storageos.cinder.model.ConsistencyGroupSnapshotCreateResponse) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

BlockServiceApi (com.emc.storageos.api.service.impl.resource.BlockServiceApi)1 ConsistencyGroupSnapshotCreateResponse (com.emc.storageos.cinder.model.ConsistencyGroupSnapshotCreateResponse)1 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)1 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)1 Project (com.emc.storageos.db.client.model.Project)1 ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)1 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)1 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1 StringMap (com.emc.storageos.db.client.model.StringMap)1 Volume (com.emc.storageos.db.client.model.Volume)1 TaskList (com.emc.storageos.model.TaskList)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1