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