Search in sources :

Example 1 with ScopedLabel

use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.

the class TaggedResource method assignTags.

/**
 * @brief Assign tags to resource
 *        Assign tags
 *
 * @prereq none
 *
 * @param id the URN of a ViPR resource
 * @param assignment tag assignments
 * @return No data returned in response body
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/tags")
@InheritCheckPermission(writeAccess = true)
public Tags assignTags(@PathParam("id") URI id, TagAssignment assignment) {
    DataObject object = queryResource(id);
    ArgValidator.checkEntityNotNull(object, id, isIdEmbeddedInURL(id));
    InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_082);
    ScopedLabelSet tagSet = object.getTag();
    if (tagSet == null) {
        tagSet = new ScopedLabelSet();
        object.setTag(tagSet);
    }
    if (assignment.getAdd() != null && !assignment.getAdd().isEmpty()) {
        Iterator<String> it = assignment.getAdd().iterator();
        while (it.hasNext()) {
            String tagName = it.next();
            if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
                throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
            }
            ScopedLabel tagLabel = new ScopedLabel(getTenantOwnerIdString(id), tagName);
            tagSet.add(tagLabel);
        }
    }
    if (assignment.getRemove() != null && !assignment.getRemove().isEmpty()) {
        Iterator<String> it = assignment.getRemove().iterator();
        while (it.hasNext()) {
            String tagName = it.next();
            if (tagName == null || tagName.isEmpty()) {
                continue;
            }
            ScopedLabel tagLabel = new ScopedLabel(getTenantOwnerIdString(id), tagName);
            if (tagSet.contains(tagLabel)) {
                tagSet.remove(tagLabel);
            }
        }
    }
    _dbClient.updateAndReindexObject(object);
    return getTagsResponse(object);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) Path(javax.ws.rs.Path) InheritCheckPermission(com.emc.storageos.security.authorization.InheritCheckPermission) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with ScopedLabel

use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.

the class ExportGroupService method validateVolumesNotMounted.

/**
 * Verify that none of the volumes in the export group are mounted.
 * Unexporting a mounted volume is dangerous and should be avoided.
 *
 * @param exportGroup
 *            export group
 * @param boURIList
 *            URI list of block objects
 */
private void validateVolumesNotMounted(ExportGroup exportGroup, List<URI> boURIList) {
    if (exportGroup == null) {
        throw APIException.badRequests.exportGroupContainsMountedVolumesInvalidParam();
    }
    Map<URI, String> boToLabelMap = new HashMap<>();
    // It is valid for there to be no storage volumes in the EG, so only perform the check if there are volumes
    if (boURIList != null) {
        for (URI boID : boURIList) {
            BlockObject bo = BlockObject.fetch(_dbClient, boID);
            if (bo != null && bo.getTag() != null) {
                ScopedLabelSet tagSet = bo.getTag();
                Iterator<ScopedLabel> tagIter = tagSet.iterator();
                while (tagIter.hasNext()) {
                    ScopedLabel sl = tagIter.next();
                    if (sl.getLabel() != null && (sl.getLabel().startsWith(MOUNTPOINT) || sl.getLabel().startsWith(VMFS_DATASTORE))) {
                        if (exportGroup.getClusters() != null) {
                            for (String clusterID : exportGroup.getClusters()) {
                                if (sl.getLabel().contains(clusterID)) {
                                    boToLabelMap.put(boID, bo.forDisplay());
                                }
                            }
                        }
                        if (exportGroup.getHosts() != null) {
                            for (String hostID : exportGroup.getHosts()) {
                                if (sl.getLabel().contains(hostID)) {
                                    boToLabelMap.put(boID, bo.forDisplay());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    if (!boToLabelMap.isEmpty()) {
        _log.error("Export Group {} has volumes {} that are marked as mounted.  It is recommended to unmount via controller before unexport.  This validation check can be disabled if needed.  Contact EMC Support.", exportGroup.getId(), Joiner.on(",").join(boToLabelMap.values()));
        ValidatorConfig vc = new ValidatorConfig();
        vc.setCoordinator(_coordinator);
        if (vc.isValidationEnabled()) {
            throw APIException.badRequests.exportGroupContainsMountedVolumes(exportGroup.getId(), Joiner.on(",").join(boToLabelMap.values()));
        }
    }
}
Also used : HashMap(java.util.HashMap) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) ValidatorConfig(com.emc.storageos.volumecontroller.impl.validators.ValidatorConfig)

Example 3 with ScopedLabel

use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.

the class AbstractConsistencyGroupService method getConsistencyGroupDetail.

/**
 * This function return detail of consistency group in pojo class object
 *
 * @param blockConsistencyGroup
 * @return ConsistencyGroupDetail
 */
protected ConsistencyGroupDetail getConsistencyGroupDetail(BlockConsistencyGroup blockConsistencyGroup) {
    ConsistencyGroupDetail response = new ConsistencyGroupDetail();
    if (blockConsistencyGroup != null) {
        response.id = CinderApiUtils.splitString(blockConsistencyGroup.getId().toString(), ":", 3);
        response.name = blockConsistencyGroup.getLabel();
        response.created_at = CinderApiUtils.timeFormat(blockConsistencyGroup.getCreationTime());
        if (blockConsistencyGroup.getTag() != null) {
            for (ScopedLabel tag : blockConsistencyGroup.getTag()) {
                switch(tag.getScope()) {
                    case "availability_zone":
                        response.availability_zone = tag.getLabel();
                    case "status":
                        response.status = tag.getLabel();
                    case "description":
                        response.description = tag.getLabel();
                }
            }
        }
    }
    return response;
}
Also used : ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ConsistencyGroupDetail(com.emc.storageos.cinder.model.ConsistencyGroupDetail)

Example 4 with ScopedLabel

use of com.emc.storageos.db.client.model.ScopedLabel in project coprhd-controller by CoprHD.

the class AbstractConsistencyGroupService method isSnapshotCreationpermissible.

/**
 * To Check Snapshot creation allowed on ViPR or not
 * @param consistencyGroup consistency grp instance
 * @return
 */
protected boolean isSnapshotCreationpermissible(BlockConsistencyGroup consistencyGroup) {
    String volType = null;
    boolean isPermissible = false;
    ScopedLabelSet tagSet = consistencyGroup.getTag();
    if (tagSet != null) {
        for (ScopedLabel tag : tagSet) {
            if (tag.getScope().equals("volume_types")) {
                volType = tag.getLabel();
                break;
            }
        }
    }
    if (volType != null) {
        VirtualPool vPool = getCinderHelper().getVpool(volType);
        if (vPool.getMaxNativeSnapshots() > 0) {
            isPermissible = true;
        }
    }
    return isPermissible;
}
Also used : ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet)

Example 5 with ScopedLabel

use of com.emc.storageos.db.client.model.ScopedLabel 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

ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)23 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)14 URI (java.net.URI)9 Volume (com.emc.storageos.db.client.model.Volume)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 ArrayList (java.util.ArrayList)5 Host (com.emc.storageos.db.client.model.Host)4 Project (com.emc.storageos.db.client.model.Project)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Produces (javax.ws.rs.Produces)4 BlockServiceApi (com.emc.storageos.api.service.impl.resource.BlockServiceApi)3 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)3 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 StringMap (com.emc.storageos.db.client.model.StringMap)3 TaskList (com.emc.storageos.model.TaskList)3 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 BlockFullCopyManager (com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager)2 DbClient (com.emc.storageos.db.client.DbClient)2