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);
}
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()));
}
}
}
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;
}
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;
}
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");
}
}
Aggregations