Search in sources :

Example 1 with ConsistencyGroupCreateResponse

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

the class ConsistencyGroupService method createConsistencyGroup.

/**
 * Create Consistency group
 *
 * @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
 * @return Response
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createConsistencyGroup(@PathParam("tenant_id") String openstackTenantId, ConsistencyGroupCreateRequest param, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    _log.info("Creating Consistency Group : " + param.consistencygroup.name);
    ConsistencyGroupCreateResponse cgResponse = new ConsistencyGroupCreateResponse();
    final Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    final String volumeTypes = param.consistencygroup.volume_types;
    VirtualPool vPool = getCinderHelper().getVpool(volumeTypes);
    if (null != project && vPool != null) {
        if (!vPool.getMultivolumeConsistency()) {
            _log.error("Bad Request : Multi volume consistency is not enabled in the volume type {}", volumeTypes);
            return CinderApiUtils.createErrorResponse(400, "Bad Request : Multi volume consistency is not enabled");
        }
        // Validate name
        ArgValidator.checkFieldNotEmpty(param.consistencygroup.name, "name");
        checkForDuplicateName(param.consistencygroup.name, BlockConsistencyGroup.class);
        // Validate name not greater than 64 characters
        ArgValidator.checkFieldLengthMaximum(param.consistencygroup.name, CG_MAX_LIMIT, "name");
        // Create Consistency Group in db
        final BlockConsistencyGroup consistencyGroup = new BlockConsistencyGroup();
        consistencyGroup.setId(URIUtil.createId(BlockConsistencyGroup.class));
        consistencyGroup.setLabel(param.consistencygroup.name);
        consistencyGroup.setProject(new NamedURI(project.getId(), project.getLabel()));
        consistencyGroup.setTenant(project.getTenantOrg());
        consistencyGroup.setCreationTime(Calendar.getInstance());
        ScopedLabelSet tagSet = new ScopedLabelSet();
        consistencyGroup.setTag(tagSet);
        tagSet.add(new ScopedLabel("volume_types", volumeTypes));
        tagSet.add(new ScopedLabel("status", "available"));
        tagSet.add(new ScopedLabel("availability_zone", (param.consistencygroup.availability_zone != null) ? param.consistencygroup.availability_zone : "nova"));
        tagSet.add(new ScopedLabel("description", (param.consistencygroup.description != null) ? param.consistencygroup.description : "No Description"));
        tagSet.add(new ScopedLabel(project.getTenantOrg().getURI().toString(), CinderApiUtils.splitString(consistencyGroup.getId().toString(), ":", 3)));
        _dbClient.createObject(consistencyGroup);
        cgResponse.id = CinderApiUtils.splitString(consistencyGroup.getId().toString(), ":", 3);
        cgResponse.name = consistencyGroup.getLabel();
        return CinderApiUtils.getCinderResponse(cgResponse, header, true, CinderConstants.STATUS_OK);
    } else {
        return CinderApiUtils.createErrorResponse(400, "Bad Request : can't create consistency group due to invalid argument");
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) ConsistencyGroupCreateResponse(com.emc.storageos.cinder.model.ConsistencyGroupCreateResponse) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

ConsistencyGroupCreateResponse (com.emc.storageos.cinder.model.ConsistencyGroupCreateResponse)1 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)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 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1