Search in sources :

Example 1 with ScopedLabelSet

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

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

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

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

Example 5 with ScopedLabelSet

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

ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)19 ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)14 URI (java.net.URI)8 StringMap (com.emc.storageos.db.client.model.StringMap)6 Volume (com.emc.storageos.db.client.model.Volume)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 Project (com.emc.storageos.db.client.model.Project)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)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 DataObject (com.emc.storageos.db.client.model.DataObject)3 Host (com.emc.storageos.db.client.model.Host)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 TaskList (com.emc.storageos.model.TaskList)3 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3