use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class BlockSnapIngestOrchestrator method createSnapshot.
private BlockSnapshot createSnapshot(IngestionRequestContext requestContext, String nativeGuid) throws IngestionException {
UnManagedVolume unManagedVolume = requestContext.getCurrentUnmanagedVolume();
BlockSnapshot snapShot = new BlockSnapshot();
snapShot.setId(URIUtil.createId(BlockSnapshot.class));
snapShot.setNativeGuid(nativeGuid);
updateBlockObjectNativeIds(snapShot, unManagedVolume);
StringSetMap unManagedVolumeInformation = unManagedVolume.getVolumeInformation();
String deviceLabel = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.DEVICE_LABEL.toString(), unManagedVolumeInformation);
if (null == deviceLabel || deviceLabel.trim().isEmpty()) {
deviceLabel = nativeGuid;
}
// In case of XIO snaps, the snapshots belong to a snapset which represents the snapshot CG. This will be
// populated in SNAPSHOT_CONSISTENCY_GROUP_NAME
// The same is applicable to external device snapshots
String snapsetName = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.SNAPSHOT_CONSISTENCY_GROUP_NAME.toString(), unManagedVolumeInformation);
if (null == snapsetName || snapsetName.trim().isEmpty()) {
snapsetName = deviceLabel;
}
snapShot.setSnapsetLabel(snapsetName);
snapShot.setStorageController(requestContext.getStorageSystem().getId());
String systemType = requestContext.getStorageSystem().checkIfVmax3() ? DiscoveredDataObject.Type.vmax3.name() : requestContext.getStorageSystem().getSystemType();
snapShot.setSystemType(systemType);
snapShot.setVirtualArray(requestContext.getVarray(unManagedVolume).getId());
snapShot.setProject(new NamedURI(requestContext.getProject().getId(), snapShot.getLabel()));
snapShot.setWWN(unManagedVolume.getWwn());
String allocatedCapacity = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.ALLOCATED_CAPACITY.toString(), unManagedVolume.getVolumeInformation());
String provisionedCapacity = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.PROVISIONED_CAPACITY.toString(), unManagedVolume.getVolumeInformation());
snapShot.setAllocatedCapacity(Long.parseLong(allocatedCapacity));
snapShot.setProvisionedCapacity(Long.parseLong(provisionedCapacity));
String syncActive = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.IS_SYNC_ACTIVE.toString(), unManagedVolume.getVolumeInformation());
Boolean isSyncActive = (null != syncActive) ? Boolean.parseBoolean(syncActive) : false;
snapShot.setIsSyncActive(isSyncActive);
String readOnly = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.IS_READ_ONLY.toString(), unManagedVolume.getVolumeInformation());
Boolean isReadOnly = (null != readOnly) ? Boolean.parseBoolean(readOnly) : false;
snapShot.setIsReadOnly(isReadOnly);
String settingsInstance = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.SETTINGS_INSTANCE.toString(), unManagedVolume.getVolumeInformation());
snapShot.setSettingsInstance(settingsInstance);
String needsCopyToTarget = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.NEEDS_COPY_TO_TARGET.toString(), unManagedVolumeInformation);
Boolean isNeedsCopyToTarget = (null != needsCopyToTarget) ? Boolean.parseBoolean(needsCopyToTarget) : false;
snapShot.setNeedsCopyToTarget(isNeedsCopyToTarget);
String techType = PropertySetterUtil.extractValueFromStringSet(SupportedVolumeInformation.TECHNOLOGY_TYPE.toString(), unManagedVolumeInformation);
snapShot.setTechnologyType(techType);
BlockConsistencyGroup cg = getConsistencyGroup(unManagedVolume, snapShot, requestContext, _dbClient);
if (null != cg) {
requestContext.getVolumeContext().getCGObjectsToCreateMap().put(cg.getLabel(), cg);
decorateCGInfoInVolumes(cg, snapShot, requestContext, unManagedVolume);
}
return snapShot;
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class RecoverPointVolumeIngestionContext method findExistingBlockConsistencyGroup.
/**
* Finds an existing BlockConsistencyGroup in any RecoverPoint volume ingestion context within the scope of this ingestion request.
*
* @param psetLabel the label of the associated ProtectionSet
* @param projectNamedUri the NamedUri of the Project for the BlockConsistencyGroup
* @param tenantOrg the Tenant for the BlockConsistencyGroup
* @return an existing BlockConsistencyGroup matching the arguments
*/
public BlockConsistencyGroup findExistingBlockConsistencyGroup(String psetLabel, NamedURI projectNamedUri, NamedURI tenantOrg) {
for (VolumeIngestionContext volumeContext : getRootIngestionRequestContext().getProcessedUnManagedVolumeMap().values()) {
if (volumeContext instanceof RecoverPointVolumeIngestionContext) {
RecoverPointVolumeIngestionContext rpContext = (RecoverPointVolumeIngestionContext) volumeContext;
BlockConsistencyGroup bcg = rpContext.getManagedBlockConsistencyGroup();
if (bcg != null) {
if ((bcg.getLabel().equals(psetLabel)) && (bcg.getProject().equals(projectNamedUri)) && (bcg.getTenant().equals(tenantOrg))) {
_logger.info("found already-instantiated BlockConsistencyGroup {} (hash {})", bcg.getLabel(), bcg.hashCode());
return bcg;
}
}
}
}
_logger.info("did not find an already-instantiated BlockConsistencyGroup for ", psetLabel);
return null;
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup 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.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class ConsistencyGroupService method deleteConsistencyGroup.
/**
* Delete consistency group
*
* @param openstackTenantId openstack tenant id
* @param consistencyGroupId consistency group id
* @param param pojo class to bind request
* @param isV1Call cinder V1 api
* @param header HTTP header
* @brief delete Consistency group
* @return Response
*/
@POST
@Path("/{consistencyGroup_id}/delete")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response deleteConsistencyGroup(@PathParam("tenant_id") String openstackTenantId, @PathParam("consistencyGroup_id") String consistencyGroupId, ConsistencyGroupDeleteRequest param, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
boolean isForced = param.consistencygroup.force;
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 : There is no consistency group with id {} , please retry with correct consistency group id", consistencyGroupId);
return CinderApiUtils.createErrorResponse(400, "Bad Request : There is no consistency group exist, please retry with correct consistency group id");
}
String task = UUID.randomUUID().toString();
TaskResourceRep taskRep = null;
if (getCinderHelper().verifyConsistencyGroupHasSnapshot(consistencyGroup)) {
_log.error("Bad Request : Consistency Group {} has Snapshot", consistencyGroupId);
return CinderApiUtils.createErrorResponse(400, "Bad Request : Consistency Group has Snapshot ");
}
if (isForced) {
final URIQueryResultList cgVolumesResults = new URIQueryResultList();
_dbClient.queryByConstraint(getVolumesByConsistencyGroup(consistencyGroup.getId()), cgVolumesResults);
while (cgVolumesResults.iterator().hasNext()) {
Volume volume = _dbClient.queryObject(Volume.class, cgVolumesResults.iterator().next());
if (!volume.getInactive()) {
BlockServiceApi api = BlockService.getBlockServiceImpl(volume, _dbClient);
URI systemUri = volume.getStorageController();
List<URI> volumeURIs = new ArrayList<URI>();
volumeURIs.add(volume.getId());
api.deleteVolumes(systemUri, volumeURIs, "FULL", null);
if (volume.getExtensions() == null) {
volume.setExtensions(new StringMap());
}
volume.getExtensions().put("status", CinderConstants.ComponentStatus.DELETING.getStatus().toLowerCase());
volume.setInactive(true);
_dbClient.updateObject(volume);
}
}
}
try {
ArgValidator.checkReference(BlockConsistencyGroup.class, consistencyGroup.getId(), checkForDelete(consistencyGroup));
} catch (APIException e) {
_log.error("Bad Request : Consistency Group Contains active references of type : {}", e.getMessage());
return CinderApiUtils.createErrorResponse(400, "Bad Request : Consistency Group Contains active references");
}
// RP + VPlex CGs cannot be be deleted without VPlex controller intervention.
if (!consistencyGroup.getTypes().contains(Types.VPLEX.toString()) || canDeleteConsistencyGroup(consistencyGroup)) {
final URIQueryResultList cgVolumesResults = new URIQueryResultList();
_dbClient.queryByConstraint(getVolumesByConsistencyGroup(consistencyGroup.getId()), cgVolumesResults);
while (cgVolumesResults.iterator().hasNext()) {
Volume volume = _dbClient.queryObject(Volume.class, cgVolumesResults.iterator().next());
if (!volume.getInactive()) {
return CinderApiUtils.createErrorResponse(400, "Bad Request : Try to delete consistency group with --force");
}
}
consistencyGroup.setStorageController(null);
consistencyGroup.setInactive(true);
_dbClient.updateObject(consistencyGroup);
taskRep = finishDeactivateTask(consistencyGroup, task);
if (taskRep.getState().equals("ready") || taskRep.getState().equals("pending")) {
return Response.status(202).build();
}
}
final StorageSystem storageSystem = consistencyGroup.created() ? _permissionsHelper.getObjectById(consistencyGroup.getStorageController(), StorageSystem.class) : null;
// If the consistency group has been created, and the system
// is a VPlex, then we need to do VPlex related things to destroy
// the consistency groups on the system. If the consistency group
// has not been created on the system or the system is not a VPlex
// revert to the default.
BlockServiceApi blockServiceApi = BlockService.getBlockServiceImpl("group");
if (storageSystem != null) {
String systemType = storageSystem.getSystemType();
if (DiscoveredDataObject.Type.vplex.name().equals(systemType)) {
blockServiceApi = BlockService.getBlockServiceImpl(systemType);
}
_log.info(String.format("BlockConsistencyGroup %s is associated to StorageSystem %s. Going to delete it on that array.", consistencyGroup.getLabel(), storageSystem.getNativeGuid()));
// Otherwise, invoke operation to delete CG from the array.
taskRep = blockServiceApi.deleteConsistencyGroup(storageSystem, consistencyGroup, task);
if (taskRep.getState().equals("ready") || taskRep.getState().equals("pending")) {
return Response.status(202).build();
}
}
if (taskRep == null) {
_log.info(String.format("BlockConsistencyGroup %s was not associated with any storage. Deleting it from ViPR only.", consistencyGroup.getLabel()));
TaskResourceRep resp = finishDeactivateTask(consistencyGroup, task);
if (resp.getState().equals("ready") || resp.getState().equals("pending")) {
return Response.status(202).build();
}
}
return CinderApiUtils.createErrorResponse(400, "Bad Request");
}
use of com.emc.storageos.db.client.model.BlockConsistencyGroup in project coprhd-controller by CoprHD.
the class ConsistencyGroupService method getCosistencyGroup.
/**
* This function handles Get request for a consistency group detail
*
* @param openstackTenantId Openstack tenant id
* @param consistencyGroupId Consistency group id
* @param isV1Call openstack cinder V1 call
* @param header HTTP header
* @brief Get Consistency Group Info
* @return Response
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{consistencyGroup_id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public Response getCosistencyGroup(@PathParam("tenant_id") String openstackTenantId, @PathParam("consistencyGroup_id") String consistencyGroupId, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
if (project == null) {
String message = "Bad Request: Project with the OpenStack Tenant Id : " + openstackTenantId + " does not exist";
_log.error(message);
return CinderApiUtils.createErrorResponse(400, message);
}
final BlockConsistencyGroup blockConsistencyGroup = findConsistencyGroup(consistencyGroupId, openstackTenantId);
if (blockConsistencyGroup == null) {
return CinderApiUtils.createErrorResponse(404, "Invalid Request: No Such Consistency Group Found");
} else if (!consistencyGroupId.equals(CinderApiUtils.splitString(blockConsistencyGroup.getId().toString(), ":", 3))) {
_log.error("Bad Request : There is no consistency group with id {} , please retry with correct consistency group id", consistencyGroupId);
return CinderApiUtils.createErrorResponse(400, "Bad Request : There is no consistency group exist, please retry with correct consistency group id");
} else {
ConsistencyGroupDetail response = getConsistencyGroupDetail(blockConsistencyGroup);
return CinderApiUtils.getCinderResponse(response, header, true, CinderConstants.STATUS_OK);
}
}
Aggregations