use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.
the class XIVSmisCommandHelper method setTag.
public void setTag(DataObject object, String scope, String label) {
if (label == null) {
// shouldn't happen
label = "";
}
ScopedLabel newScopedLabel = new ScopedLabel(scope, label);
ScopedLabelSet tagSet = object.getTag();
if (tagSet == null) {
tagSet = new ScopedLabelSet();
tagSet.add(newScopedLabel);
object.setTag(tagSet);
} else if (tagSet.contains(newScopedLabel)) {
return;
} else {
removeLabel(tagSet, scope);
tagSet.add(newScopedLabel);
}
_dbClient.persistObject(object);
}
use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.
the class DbCli method dumpBeanProperties.
/**
* Dump the contents in xml format
*
* @param pds
* @param object
* @throws Exception
*/
private <T extends DataObject> void dumpBeanProperties(PropertyDescriptor[] pds, T object) throws Exception {
Element record = doc.createElement("record");
record.setAttribute("id", object.getId().toString());
schemaNode.appendChild(record);
// Add readOnlyField node.
Element readOnlyElement = doc.createElement("readOnlyField");
record.appendChild(readOnlyElement);
System.out.println("id: " + object.getId().toString());
Object objValue;
Class type;
for (PropertyDescriptor pd : pds) {
objValue = pd.getReadMethod().invoke(object);
if (objValue == null) {
continue;
}
// Skip password property.
if (pd.getName().toLowerCase().matches("[a-zA-Z\\d]*password[a-zA-Z\\d]*")) {
continue;
}
// Skip some properties.
if (pd.getName().equals("class") || pd.getName().equals("id")) {
Element readOnlyfieldNode = doc.createElement("field");
// delete the prefix string "class "
readOnlyfieldNode.setAttribute("type", pd.getPropertyType().toString().substring(6));
readOnlyfieldNode.setAttribute("name", pd.getName().toString());
readOnlyfieldNode.setAttribute("value", objValue.toString());
readOnlyElement.appendChild(readOnlyfieldNode);
continue;
}
// Skip the fields without @Name annotation
Name name = pd.getReadMethod().getAnnotation(Name.class);
if (name == null) {
log.info("Ignore data object fields without @Name annotation, fieldName={}.", pd.getName());
continue;
}
// use value from @Name instead of mtehod name
String objKey = name.value();
type = pd.getPropertyType();
if (DEBUG) {
System.out.print("\t" + pd.getPropertyType() + "\t" + objKey + " = ");
}
Element fieldNode = doc.createElement("field");
// delete the prefix string "class "
fieldNode.setAttribute("type", type.toString().substring(6));
fieldNode.setAttribute("name", objKey);
if (type == StringSetMap.class) {
StringSetMap stringSetMap = (StringSetMap) objValue;
FieldType.marshall(stringSetMap, fieldNode, StringSetMapWrapper.class);
} else if (type == StringSet.class) {
StringSet stringSet = (StringSet) objValue;
FieldType.marshall(stringSet, fieldNode, StringSetWrapper.class);
} else if (type == ScopedLabelSet.class) {
ScopedLabelSet scopedLabelSet = (ScopedLabelSet) objValue;
FieldType.marshall(scopedLabelSet, fieldNode, ScopedLabelSetWrapper.class);
} else if (type == OpStatusMap.class) {
OpStatusMap opStatusMap = (OpStatusMap) objValue;
FieldType.marshall(opStatusMap, fieldNode, OpStatusMapWrapper.class);
} else if (type == StringMap.class) {
StringMap stringMap = (StringMap) objValue;
FieldType.marshall(stringMap, fieldNode, StringMapWrapper.class);
} else if (type == FSExportMap.class) {
FSExportMap fSExportMap = (FSExportMap) objValue;
FieldType.marshall(fSExportMap, fieldNode, FSExportMapWrapper.class);
} else if (type == SMBShareMap.class) {
SMBShareMap sMBShareMap = (SMBShareMap) objValue;
FieldType.marshall(sMBShareMap, fieldNode, SMBShareMapWrapper.class);
} else {
fieldNode.setAttribute("value", objValue.toString());
}
record.appendChild(fieldNode);
}
}
use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.
the class FileOrchestrationUtils method getTargetHostPortForReplication.
public static String getTargetHostPortForReplication(DbClient dbClient, URI targetStorageSystemURI, URI targetVarrayURI, URI targetVNasURI) {
StorageSystem targetSystem = dbClient.queryObject(StorageSystem.class, targetStorageSystemURI);
String targetHost = targetSystem.getIpAddress();
StringSet targetNasVarraySet = null;
StringSet targetStoragePortSet = null;
if (targetVNasURI != null) {
VirtualNAS targetVNas = dbClient.queryObject(VirtualNAS.class, targetVNasURI);
targetStoragePortSet = targetVNas.getStoragePorts();
targetNasVarraySet = targetVNas.getTaggedVirtualArrays();
} else {
PhysicalNAS pNAS = FileOrchestrationUtils.getSystemPhysicalNAS(dbClient, targetSystem);
targetStoragePortSet = pNAS.getStoragePorts();
targetNasVarraySet = pNAS.getTaggedVirtualArrays();
}
List<String> drPorts = new ArrayList<String>();
for (String nasPort : targetStoragePortSet) {
StoragePort port = dbClient.queryObject(StoragePort.class, URI.create(nasPort));
if (port != null && !port.getInactive()) {
StringSet varraySet = port.getTaggedVirtualArrays();
if (varraySet == null || !varraySet.contains(targetVarrayURI.toString())) {
continue;
}
if (targetNasVarraySet != null) {
if (!targetNasVarraySet.contains(targetVarrayURI.toString())) {
continue;
}
}
targetHost = port.getPortNetworkId();
// iterate until dr port found!!
if (port.getTag() != null) {
ScopedLabelSet portTagSet = port.getTag();
if (portTagSet != null && !portTagSet.isEmpty()) {
for (ScopedLabel tag : portTagSet) {
if ("dr_port".equals(tag.getLabel())) {
_log.info("DR port {} found from storage system {} for replication", port.getPortNetworkId(), targetSystem.getLabel());
drPorts.add(port.getPortNetworkId());
}
}
}
}
}
}
if (!drPorts.isEmpty()) {
Collections.shuffle(drPorts);
return drPorts.get(0);
}
return targetHost;
}
use of com.emc.storageos.db.client.model.ScopedLabelSet in project coprhd-controller by CoprHD.
the class VolumeService method createVolume.
/**
* The fundamental abstraction in the Block Store is a
* volume. A volume is a unit of block storage capacity that has been
* allocated by a consumer to a project. This API allows the user to
* create one or more volumes. The volumes are created in the same
* storage pool.
*
* NOTE: This is an asynchronous operation.
*
* @prereq none
*
* @param param POST data containing the volume creation information.
*
* @brief Create volume
* @return Details of the newly created volume
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createVolume(@PathParam("tenant_id") String openstackTenantId, @HeaderParam("X-Cinder-V1-Call") String isV1Call, VolumeCreateRequestGen param, @Context HttpHeaders header) throws InternalException {
// Step 1: Parameter validation
Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
String snapshotId = param.volume.snapshot_id;
String sourceVolId = param.volume.source_volid;
String imageId = param.volume.imageRef;
String consistencygroup_id = param.volume.consistencygroup_id;
String volume_type = param.volume.volume_type;
boolean hasConsistencyGroup = false;
if (project == null) {
if (openstackTenantId != null) {
throw APIException.badRequests.projectWithTagNonexistent(openstackTenantId);
} else {
throw APIException.badRequests.parameterIsNullOrEmpty(PROJECT_TENANTID_NULL);
}
}
URI tenantUri = project.getTenantOrg().getURI();
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, tenantUri);
if (tenant == null)
throw APIException.notFound.unableToFindUserScopeOfSystem();
_log.debug("Create volume: project = {}, tenant = {}", project.getLabel(), tenant.getLabel());
if (param.volume.size <= 0) {
_log.error("volume size should not be zero or negative ={} ", param.volume.size);
return CinderApiUtils.createErrorResponse(400, "Bad Request : Invalid Volume size");
}
long requestedSize = param.volume.size * GB;
// convert volume type from name to vpool
VirtualPool vpool = getVpool(param.volume.volume_type);
Volume sourceVolume = null;
if (vpool == null) {
if (sourceVolId != null) {
sourceVolume = findVolume(sourceVolId, openstackTenantId);
if (sourceVolume == null) {
_log.error("Invalid Source Volume ID ={} ", sourceVolId);
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid Source Volume ID " + sourceVolId);
}
vpool = _dbClient.queryObject(VirtualPool.class, sourceVolume.getVirtualPool());
} else {
_log.error("Invalid Volume Type ={} ", volume_type);
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid Volume Type " + volume_type);
}
}
if (!validateVolumeCreate(openstackTenantId, null, requestedSize)) {
_log.info("The volume can not be created because of insufficient project quota.");
throw APIException.badRequests.insufficientQuotaForProject(project.getLabel(), "volume");
} else if (!validateVolumeCreate(openstackTenantId, vpool, requestedSize)) {
_log.info("The volume can not be created because of insufficient quota for virtual pool.");
throw APIException.badRequests.insufficientQuotaForVirtualPool(vpool.getLabel(), "virtual pool");
}
_log.debug("Create volume: vpool = {}", vpool.getLabel());
VirtualArray varray = getCinderHelper().getVarray(param.volume.availability_zone, getUserFromContext());
if ((snapshotId == null) && (sourceVolId == null) && (varray == null)) {
// otherwise availability_zone exception will be thrown
throw APIException.badRequests.parameterIsNotValid(param.volume.availability_zone);
}
// Validating consistency group
URI blockConsistencyGroupId = null;
BlockConsistencyGroup blockConsistencyGroup = null;
if (consistencygroup_id != null) {
_log.info("Verifying for consistency group : " + consistencygroup_id);
blockConsistencyGroup = (BlockConsistencyGroup) getCinderHelper().queryByTag(URI.create(consistencygroup_id), getUserFromContext(), BlockConsistencyGroup.class);
if (getCinderHelper().verifyConsistencyGroupHasSnapshot(blockConsistencyGroup)) {
_log.error("Bad Request : Consistency Group has Snapshot ");
return CinderApiUtils.createErrorResponse(400, "Bad Request : Consistency Group has Snapshot ");
}
blockConsistencyGroupId = blockConsistencyGroup.getId();
if (blockConsistencyGroup.getTag() != null && consistencygroup_id.equals(blockConsistencyGroupId.toString().split(":")[3])) {
for (ScopedLabel tag : blockConsistencyGroup.getTag()) {
if (tag.getScope().equals("volume_types")) {
if (tag.getLabel().equals(volume_type)) {
hasConsistencyGroup = true;
} else {
return CinderApiUtils.createErrorResponse(404, "Invalid volume: No consistency group exist for volume : " + param.volume.display_name);
}
}
}
} else {
return CinderApiUtils.createErrorResponse(404, "Invalid Consistency Group Id : No Such Consistency group exists");
}
}
BlockSnapshot snapshot = null;
URI snapUri = null;
if (snapshotId != null) {
snapshot = (BlockSnapshot) getCinderHelper().queryByTag(URI.create(snapshotId), getUserFromContext(), BlockSnapshot.class);
if (snapshot == null) {
_log.error("Invalid snapshot id ={} ", snapshotId);
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid snapshot id" + snapshotId);
} else {
snapUri = snapshot.getId();
URI varrayUri = snapshot.getVirtualArray();
if (varray == null) {
varray = _dbClient.queryObject(VirtualArray.class, varrayUri);
}
}
}
if (varray != null)
_log.info("Create volume: varray = {}", varray.getLabel());
String name = null;
String description = null;
_log.info("is isV1Call {}", isV1Call);
_log.info("name = {}, description = {}", name, description);
if (isV1Call != null) {
name = param.volume.display_name;
description = param.volume.display_description;
} else {
name = param.volume.name;
description = param.volume.description;
}
if (name == null) {
name = "volume-" + RandomStringUtils.random(10);
}
_log.info("param.volume.name = {}, param.volume.display_name = {}", param.volume.name, param.volume.display_name);
_log.info("param.volume.description = {}, param.volume.display_description = {}", param.volume.description, param.volume.display_description);
if (name == null || (name.length() <= 2))
throw APIException.badRequests.parameterIsNotValid(name);
URI projectUri = project.getId();
checkForDuplicateName(name, Volume.class, projectUri, "project", _dbClient);
// Step 2: Check if the user has rights for volume create
verifyUserIsAuthorizedForRequest(project, vpool, varray);
// Step 3: Check capacity Quotas
_log.debug(" volume name = {}, size = {} GB", name, param.volume.size);
int volumeCount = 1;
VolumeCreate volumeCreate = new VolumeCreate(name, Long.toString(requestedSize), volumeCount, vpool.getId(), varray.getId(), project.getId());
BlockServiceApi api = getBlockServiceImpl(vpool, _dbClient);
CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, requestedSize, "volume");
// Step 4: Call out placementManager to get the recommendation for placement.
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, volumeCount);
capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, requestedSize);
// Create a unique task id if one is not passed in the request.
String task = UUID.randomUUID().toString();
TaskList tasklist = null;
BlockFullCopyManager blkFullCpManager = new BlockFullCopyManager(_dbClient, _permissionsHelper, _auditMgr, _coordinator, _placementManager, sc, uriInfo, _request, null);
if (hasConsistencyGroup && blockConsistencyGroupId != null) {
try {
checkForConsistencyGroup(vpool, blockConsistencyGroup, project, api, varray, capabilities, blkFullCpManager);
volumeCreate.setConsistencyGroup(blockConsistencyGroupId);
} catch (APIException exp) {
return CinderApiUtils.createErrorResponse(400, "Bad Request : can't create volume for the consistency group : " + blockConsistencyGroupId);
}
}
if (sourceVolId != null) {
_log.debug("Creating New Volume from Volume : Source volume ID ={}", sourceVolId);
if (sourceVolume != null) {
Volume vol = findVolume(sourceVolId, openstackTenantId);
if (vol == null) {
_log.debug("Creating Clone Volume failed : Invalid source volume id ");
return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid source volume id" + sourceVolId);
}
tasklist = volumeClone(name, project, sourceVolId, varray, volumeCount, sourceVolume, blkFullCpManager);
} else {
_log.debug("Creating Clone Volume failed : Null Source volume ");
return CinderApiUtils.createErrorResponse(404, "Not Found : Null source volume ");
}
} else if (snapshotId != null) {
_log.debug("Creating New Volume from Snapshot ID ={}", snapshotId);
tasklist = volumeFromSnapshot(name, project, snapshotId, varray, param, volumeCount, blkFullCpManager, snapUri, snapshot);
} else if ((snapshotId == null) && (sourceVolId == null)) {
_log.debug("Creating New Volume where snapshotId and sourceVolId are null");
tasklist = newVolume(volumeCreate, project, api, capabilities, varray, task, vpool, param, volumeCount, requestedSize, name);
}
if (imageId != null) {
_log.debug("Creating New Volume from imageid ={}", imageId);
// will be implemented
tasklist = volumeFromImage(name, project, varray, param, volumeCount, blkFullCpManager, imageId);
}
if (!(tasklist.getTaskList().isEmpty())) {
for (TaskResourceRep rep : tasklist.getTaskList()) {
URI volumeUri = rep.getResource().getId();
Volume vol = _dbClient.queryObject(Volume.class, volumeUri);
if (vol != null) {
StringMap extensions = vol.getExtensions();
if (extensions == null)
extensions = new StringMap();
extensions.put("display_description", (description == null) ? "" : description);
vol.setExtensions(extensions);
ScopedLabelSet tagSet = new ScopedLabelSet();
vol.setTag(tagSet);
String[] splits = volumeUri.toString().split(":");
String tagName = splits[3];
if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
}
URI tenantOwner = vol.getTenant().getURI();
ScopedLabel tagLabel = new ScopedLabel(tenantOwner.toString(), tagName);
tagSet.add(tagLabel);
_dbClient.updateAndReindexObject(vol);
if (isV1Call != null) {
_log.debug("Inside V1 call");
return CinderApiUtils.getCinderResponse(getVolumeDetail(vol, isV1Call, openstackTenantId), header, true, CinderConstants.STATUS_OK);
} else {
return CinderApiUtils.getCinderResponse(getVolumeDetail(vol, isV1Call, openstackTenantId), header, true, CinderConstants.STATUS_ACCEPT);
}
} else {
throw APIException.badRequests.parameterIsNullOrEmpty("Volume");
}
}
}
return CinderApiUtils.getCinderResponse(new VolumeDetail(), header, true, CinderConstants.STATUS_ACCEPT);
}
Aggregations