use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.
the class SRDFBlockServiceApiImpl method upgradeToSRDFTargetVolume.
/**
* Upgrade a local block volume to a protected SRDF volume
*
* @param volume
* -- srdf source volume (existing).
* @param vpool
* -- Requested vpool.
* @param taskId
* @throws InternalException
*/
private List<VolumeDescriptor> upgradeToSRDFTargetVolume(final Volume volume, final VirtualPool vpool, final VirtualPoolChangeParam cosChangeParam, final String taskId) throws InternalException {
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
capabilities.put(VirtualPoolCapabilityValuesWrapper.BLOCK_CONSISTENCY_GROUP, volume.getConsistencyGroup());
List<Recommendation> recommendations = getRecommendationsForVirtualPoolChangeRequest(volume, vpool, cosChangeParam);
if (recommendations.isEmpty()) {
throw APIException.badRequests.noStorageFoundForVolume();
}
// Call out to the respective block service implementation to prepare and create the
// volumes based on the recommendations.
Project project = _dbClient.queryObject(Project.class, volume.getProject());
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, volume.getVirtualArray());
// Generate a VolumeCreate object that contains the information that createVolumes likes to
// consume.
VolumeCreate param = new VolumeCreate(volume.getLabel(), String.valueOf(volume.getCapacity()), 1, vpool.getId(), volume.getVirtualArray(), volume.getProject().getURI());
capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
if (volume.getIsComposite()) {
// add meta volume properties to the capabilities instance
capabilities.put(VirtualPoolCapabilityValuesWrapper.IS_META_VOLUME, volume.getIsComposite());
capabilities.put(VirtualPoolCapabilityValuesWrapper.META_VOLUME_TYPE, volume.getCompositionType());
capabilities.put(VirtualPoolCapabilityValuesWrapper.META_VOLUME_MEMBER_COUNT, volume.getMetaMemberCount());
capabilities.put(VirtualPoolCapabilityValuesWrapper.META_VOLUME_MEMBER_SIZE, volume.getMetaMemberSize());
_log.debug(String.format("Capabilities : isMeta: %s, Meta Type: %s, Member size: %s, Count: %s", capabilities.getIsMetaVolume(), capabilities.getMetaVolumeType(), capabilities.getMetaVolumeMemberSize(), capabilities.getMetaVolumeMemberCount()));
}
TaskList taskList = new TaskList();
// Prepare the Bourne Volumes to be created and associated
// with the actual storage system volumes created. Also create
// a BlockTaskList containing the list of task resources to be
// returned for the purpose of monitoring the volume creation
// operation for each volume to be created.
String volumeLabel = param.getName();
final BlockConsistencyGroup consistencyGroup = capabilities.getBlockConsistencyGroup() == null ? null : _dbClient.queryObject(BlockConsistencyGroup.class, capabilities.getBlockConsistencyGroup());
// prepare the volumes
List<URI> volumeURIs = prepareRecommendedVolumes(taskId, taskList, project, varray, vpool, capabilities.getResourceCount(), recommendations, consistencyGroup, volumeLabel, param.getSize());
List<VolumeDescriptor> resultListVolumeDescriptors = new ArrayList<>();
// Execute the volume creations requests for each recommendation.
Iterator<Recommendation> recommendationsIter = recommendations.iterator();
while (recommendationsIter.hasNext()) {
Recommendation recommendation = recommendationsIter.next();
try {
List<VolumeDescriptor> volumeDescriptors = createVolumeDescriptors((SRDFRecommendation) recommendation, volumeURIs, capabilities);
// Log volume descriptor information
logVolumeDescriptorPrecreateInfo(volumeDescriptors, taskId);
resultListVolumeDescriptors.addAll(volumeDescriptors);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("Controller error", e);
}
String errorMsg = String.format("Controller error: %s", e.getMessage());
if (volumeURIs != null) {
for (URI volumeURI : volumeURIs) {
Volume volume1 = _dbClient.queryObject(Volume.class, volumeURI);
if (volume1 != null) {
Operation op = new Operation();
ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.API_RP_VOLUME_CREATE_ERROR, errorMsg.toString());
op.setMessage(errorMsg);
op.error(coded);
_dbClient.createTaskOpStatus(Volume.class, volumeURI, taskId, op);
TaskResourceRep volumeTask = toTask(volume1, taskId, op);
if (volume1.getPersonality() != null && volume1.getPersonality().equals(Volume.PersonalityTypes.SOURCE.toString())) {
taskList.getTaskList().add(volumeTask);
}
}
}
}
// the user what succeeded and what failed.
throw APIException.badRequests.cannotCreateSRDFVolumes(e);
}
}
return resultListVolumeDescriptors;
}
use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.
the class SRDFBlockServiceApiImpl method getDescriptorsForVolumesToBeDeleted.
/**
* {@inheritDoc}
*/
@Override
public List<VolumeDescriptor> getDescriptorsForVolumesToBeDeleted(URI systemURI, List<URI> volumeURIs, String deletionType) {
List<VolumeDescriptor> volumeDescriptors = new ArrayList<VolumeDescriptor>();
for (URI volumeURI : volumeURIs) {
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
VolumeDescriptor.Type descriptorType;
if (volume.getPersonality() == null || volume.getPersonality().contains("null")) {
descriptorType = VolumeDescriptor.Type.BLOCK_DATA;
} else if (Volume.PersonalityTypes.TARGET == getPersonality(volume)) {
if (isSRDFParentInactiveForTarget(volume)) {
descriptorType = VolumeDescriptor.Type.BLOCK_DATA;
} else {
_log.warn("Attempted to delete an SRDF target that had an active SRDF source");
throw APIException.badRequests.cannotDeleteSRDFTargetWithActiveSource(volumeURI, volume.getSrdfParent().getURI());
}
} else {
descriptorType = VolumeDescriptor.Type.SRDF_SOURCE;
}
VolumeDescriptor descriptor = new VolumeDescriptor(descriptorType, systemURI, volumeURI, null, null);
volumeDescriptors.add(descriptor);
// Add a descriptor for each of the associated volumes.
for (URI assocVolId : Volume.fetchSRDFVolumes(_dbClient, volumeURI)) {
Volume assocVolume = _dbClient.queryObject(Volume.class, assocVolId);
if (null == assocVolume) {
continue;
}
VolumeDescriptor assocDesc = new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, assocVolume.getStorageController(), assocVolume.getId(), null, null);
volumeDescriptors.add(assocDesc);
// If there were any Block Mirrors, add a descriptors for them.
addDescriptorsForMirrors(volumeDescriptors, assocVolume);
}
}
return volumeDescriptors;
}
use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.
the class SRDFBlockServiceApiImpl method createVolumes.
@Override
public TaskList createVolumes(final VolumeCreate param, final Project project, final VirtualArray varray, final VirtualPool vpool, final Map<VpoolUse, List<Recommendation>> recommendationMap, TaskList taskList, final String task, final VirtualPoolCapabilityValuesWrapper capabilities) throws InternalException {
List<Recommendation> volRecommendations = recommendationMap.get(VpoolUse.ROOT);
Long size = SizeUtil.translateSize(param.getSize());
BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
for (Recommendation volRecommendation : volRecommendations) {
List<VolumeDescriptor> existingDescriptors = new ArrayList<VolumeDescriptor>();
List<VolumeDescriptor> volumeDescriptors = createVolumesAndDescriptors(existingDescriptors, param.getName(), size, project, varray, vpool, volRecommendations, taskList, task, capabilities);
List<URI> volumeURIs = VolumeDescriptor.getVolumeURIs(volumeDescriptors);
try {
controller.createVolumes(volumeDescriptors, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("Controller error", e);
}
String errorMsg = String.format("Controller error: %s", e.getMessage());
if (volumeURIs != null) {
for (URI volumeURI : volumeURIs) {
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
if (volume != null) {
Operation op = new Operation();
ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.API_RP_VOLUME_CREATE_ERROR, errorMsg.toString());
op.setMessage(errorMsg);
op.error(coded);
_dbClient.createTaskOpStatus(Volume.class, volumeURI, task, op);
TaskResourceRep volumeTask = toTask(volume, task, op);
if (volume.getPersonality() != null && volume.getPersonality().equals(Volume.PersonalityTypes.SOURCE.toString())) {
taskList.getTaskList().add(volumeTask);
}
}
}
}
}
}
return taskList;
}
use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.
the class SRDFBlockServiceApiImpl method getVolumeDescriptorsForExpandVolume.
public List<VolumeDescriptor> getVolumeDescriptorsForExpandVolume(final Volume volume, final long newSize) {
// Build volume descriptors for the source and all targets.
// The targets are used for the construction of the completers.
List<VolumeDescriptor> descriptors = new ArrayList<VolumeDescriptor>();
VolumeDescriptor descriptor = new VolumeDescriptor(VolumeDescriptor.Type.SRDF_SOURCE, volume.getStorageController(), volume.getId(), volume.getPool(), volume.getConsistencyGroup(), null, newSize);
descriptors.add(descriptor);
StringSet targets = volume.getSrdfTargets();
for (String target : targets) {
Volume targetVolume = _dbClient.queryObject(Volume.class, URI.create(target));
descriptor = new VolumeDescriptor(VolumeDescriptor.Type.SRDF_TARGET, volume.getStorageController(), targetVolume.getId(), targetVolume.getPool(), targetVolume.getConsistencyGroup(), null, newSize);
descriptors.add(descriptor);
}
return descriptors;
}
use of com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor in project coprhd-controller by CoprHD.
the class HostService method deactivateHost.
/**
* Deactivates the host and all its interfaces.
*
* @param id
* the URN of a ViPR Host to be deactivated
* @param detachStorage
* if true, will first detach storage.
* @param detachStorageDeprecated
* Deprecated. Use detachStorage instead.
* @param deactivateBootVolume
* if true, and if the host was provisioned by ViPR the associated boot volume (if exists) will be
* deactivated
* @brief Deactivate host
* @return OK if deactivation completed successfully
* @throws DatabaseException
* when a DB error occurs
*/
@POST
@Path("/{id}/deactivate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskResourceRep deactivateHost(@PathParam("id") URI id, @DefaultValue("false") @QueryParam("detach_storage") boolean detachStorage, @DefaultValue("false") @QueryParam("detach-storage") boolean detachStorageDeprecated, @DefaultValue("true") @QueryParam("deactivate_boot_volume") boolean deactivateBootVolume) throws DatabaseException {
Host host = queryHost(_dbClient, id);
ArgValidator.checkEntity(host, id, true);
boolean hasPendingTasks = hostHasPendingTasks(id);
if (hasPendingTasks) {
throw APIException.badRequests.resourceCannotBeDeleted("Host with another operation in progress");
}
boolean isHostInUse = ComputeSystemHelper.isHostInUse(_dbClient, host.getId());
if (isHostInUse && !(detachStorage || detachStorageDeprecated)) {
throw APIException.badRequests.resourceHasActiveReferences(Host.class.getSimpleName(), id);
}
UCSServiceProfile serviceProfile = null;
if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
if (serviceProfile != null && !NullColumnValueGetter.isNullURI(serviceProfile.getComputeSystem())) {
ComputeSystem ucs = _dbClient.queryObject(ComputeSystem.class, serviceProfile.getComputeSystem());
if (ucs != null && ucs.getDiscoveryStatus().equals(DataCollectionJobStatus.ERROR.name())) {
throw APIException.badRequests.resourceCannotBeDeleted("Host has service profile on a Compute System that failed to discover; ");
}
}
}
Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "uuid", "serviceProfile", "computeElement", "registrationStatus", "inactive"), ControllerUtils.getFullyImplementedCollection(hostIds));
for (Host tempHost : hosts) {
if (!tempHost.getId().equals(host.getId()) && !tempHost.getInactive()) {
if (tempHost.getUuid() != null && tempHost.getUuid().equals(host.getUuid())) {
throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same uuid " + host.getUuid() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
}
if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement() == tempHost.getComputeElement()) {
throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same computeElement " + host.getComputeElement() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
}
if (!NullColumnValueGetter.isNullURI(host.getServiceProfile()) && host.getServiceProfile() == tempHost.getServiceProfile()) {
throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same serviceProfile " + host.getServiceProfile() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
}
}
}
if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
throw APIException.badRequests.resourceCannotBeDeletedVblock(host.getLabel(), "Host " + host.getLabel() + " has a compute element, but no service profile." + " Please re-discover the Vblock Compute System and retry.");
}
// VBDU [DONE]: COP-28452, Running host deactivate even if initiators == null or list empty seems risky
// If initiators are empty, we will not perform any export updates
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, ResourceOperationTypeEnum.DELETE_HOST);
ComputeSystemController controller = getController(ComputeSystemController.class, null);
List<VolumeDescriptor> bootVolDescriptors = new ArrayList<>();
if (deactivateBootVolume & !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
Volume vol = _dbClient.queryObject(Volume.class, host.getBootVolumeId());
if (vol.isVPlexVolume(_dbClient)) {
bootVolDescriptors.addAll(vplexBlockServiceApiImpl.getDescriptorsForVolumesToBeDeleted(vol.getStorageController(), Arrays.asList(host.getBootVolumeId()), null));
} else {
if (vol.getPool() != null) {
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, vol.getPool());
if (storagePool != null && storagePool.getStorageDevice() != null) {
bootVolDescriptors.add(new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, storagePool.getStorageDevice(), host.getBootVolumeId(), null, null));
}
}
}
}
controller.detachHostStorage(host.getId(), true, deactivateBootVolume, bootVolDescriptors, taskId);
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
host.setProvisioningStatus(Host.ProvisioningJobStatus.IN_PROGRESS.toString());
}
_dbClient.persistObject(host);
auditOp(OperationTypeEnum.DELETE_HOST, true, op.getStatus(), host.auditParameters());
return toTask(host, taskId, op);
}
Aggregations