use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class HostService method updateBootVolume.
/**
* Updates the hosts boot volume Id
*
* @param id the URN of host
* @param hostUpdateParam
* @brief Update the host boot volume
* @return the task.
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/update-boot-volume")
public TaskResourceRep updateBootVolume(@PathParam("id") URI id, HostUpdateParam param) {
Host host = queryObject(Host.class, id, true);
boolean hasPendingTasks = hostHasPendingTasks(id);
boolean updateSanBootTargets = param.getUpdateSanBootTargets();
if (hasPendingTasks) {
throw APIException.badRequests.cannotUpdateHost("another operation is in progress for this host");
}
auditOp(OperationTypeEnum.UPDATE_HOST_BOOT_VOLUME, true, null, host.auditParameters());
String taskId = UUID.randomUUID().toString();
ComputeSystemController controller = getController(ComputeSystemController.class, null);
Operation op = _dbClient.createTaskOpStatus(Host.class, id, taskId, ResourceOperationTypeEnum.UPDATE_HOST_BOOT_VOLUME);
// The volume being set as the boot volume should be exported to the host and should not be exported to any other initiators.
// The controller call invoked below validates that before setting the volume as the boot volume.
controller.setHostBootVolume(host.getId(), param.getBootVolume(), updateSanBootTargets, taskId);
return toTask(host, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class HostService method createInitiator.
/**
* Creates a new initiator for a host.
*
* @param id
* the URN of a ViPR Host
* @param createParam
* the details of the initiator
* @brief Create host initiator
* @return the details of the host initiator when creation
* is successfully.
* @throws DatabaseException
* when a database error occurs.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/initiators")
public TaskResourceRep createInitiator(@PathParam("id") URI id, InitiatorCreateParam createParam) throws DatabaseException {
Host host = queryObject(Host.class, id, true);
Cluster cluster = null;
validateInitiatorData(createParam, null);
// create and populate the initiator
Initiator initiator = new Initiator();
initiator.setHost(id);
initiator.setHostName(host.getHostName());
if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
cluster = queryObject(Cluster.class, host.getCluster(), false);
initiator.setClusterName(cluster.getLabel());
}
initiator.setId(URIUtil.createId(Initiator.class));
populateInitiator(initiator, createParam);
_dbClient.createObject(initiator);
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Initiator.class, initiator.getId(), taskId, ResourceOperationTypeEnum.ADD_HOST_INITIATOR);
// if host in use. update export with new initiator
if (ComputeSystemHelper.isHostInUse(_dbClient, host.getId())) {
ComputeSystemController controller = getController(ComputeSystemController.class, null);
controller.addInitiatorsToExport(initiator.getHost(), Arrays.asList(initiator.getId()), taskId);
} else {
// No updates were necessary, so we can close out the task.
_dbClient.ready(Initiator.class, initiator.getId(), taskId);
}
auditOp(OperationTypeEnum.CREATE_HOST_INITIATOR, true, null, initiator.auditParameters());
return toTask(initiator, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method prepareSnapshots.
/**
* Prepares the snapshots for a snapshot request.
*
* @param volumes
* The volumes for which snapshots are to be created.
* @param snapshotType
* The snapshot technology type.
* @param snapshotName
* The snapshot name.
* @param snapshotURIs
* [OUT] The URIs for the prepared snapshots.
* @param taskId
* The unique task identifier
*
* @return The list of snapshots
*/
@Override
public List<BlockSnapshot> prepareSnapshots(List<Volume> volumes, String snapshotType, String snapshotName, List<URI> snapshotURIs, String taskId) {
List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
int count = 1;
for (Volume volume : volumes) {
// Attempt to create distinct labels here when creating >1 volumes (ScaleIO requirement)
String rgName = volume.getReplicationGroupInstance();
VolumeGroup application = volume.getApplication(_dbClient);
if (volume.isVPlexVolume(_dbClient)) {
Volume backendVol = VPlexUtil.getVPLEXBackendVolume(volumes.get(0), true, _dbClient);
if (backendVol != null && !backendVol.getInactive()) {
rgName = backendVol.getReplicationGroupInstance();
}
}
String label = snapshotName;
if (NullColumnValueGetter.isNotNullValue(rgName) && application != null) {
// There can be multiple RGs in a CG, in such cases generate unique name
if (volumes.size() > 1) {
label = String.format("%s-%s-%s", snapshotName, rgName, count++);
} else {
label = String.format("%s-%s", snapshotName, rgName);
}
} else if (volumes.size() > 1) {
label = String.format("%s-%s", snapshotName, count++);
}
BlockSnapshot snapshot = prepareSnapshotFromVolume(volume, snapshotName, label);
snapshot.setTechnologyType(snapshotType);
snapshot.setOpStatus(new OpStatusMap());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT);
snapshot.getOpStatus().createTaskStatus(taskId, op);
snapshotURIs.add(snapshot.getId());
snapshots.add(snapshot);
}
_dbClient.createObject(snapshots);
return snapshots;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method deleteVolumes.
/**
* {@inheritDoc}
*
* @throws InternalException
*/
@Override
public void deleteVolumes(URI systemURI, List<URI> volumeURIs, String deletionType, String task) throws InternalException {
// Get volume descriptor for all volumes to be deleted.
List<VolumeDescriptor> volumeDescriptors = getDescriptorsForVolumesToBeDeleted(systemURI, volumeURIs, deletionType);
// the controller and delete the volumes.
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deletionType)) {
// Do any cleanup necessary for the ViPR only delete.
cleanupForViPROnlyDelete(volumeDescriptors);
// Mark them inactive. Note that some of the volumes may be mirrors,
// which have a different database type.
List<VolumeDescriptor> descriptorsForMirrors = VolumeDescriptor.getDescriptors(volumeDescriptors, VolumeDescriptor.Type.BLOCK_MIRROR);
_dbClient.markForDeletion(_dbClient.queryObject(BlockMirror.class, VolumeDescriptor.getVolumeURIs(descriptorsForMirrors)));
List<VolumeDescriptor> descriptorsForVolumes = VolumeDescriptor.filterByType(volumeDescriptors, null, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.BLOCK_MIRROR });
_dbClient.markForDeletion(_dbClient.queryObject(Volume.class, VolumeDescriptor.getVolumeURIs(descriptorsForVolumes)));
// Delete the corresponding FCZoneReferences
for (URI volumeURI : volumeURIs) {
List<FCZoneReference> zoneReferences = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, FCZoneReference.class, "volumeUri", volumeURI.toString());
for (FCZoneReference zoneReference : zoneReferences) {
if (zoneReference != null) {
_dbClient.markForDeletion(zoneReference);
}
}
}
// Update the task status for each volume
for (URI volumeURI : volumeURIs) {
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
Operation op = volume.getOpStatus().get(task);
op.ready("Volume succesfully deleted from ViPR");
volume.getOpStatus().updateTaskStatus(task, op);
_dbClient.updateObject(volume);
}
} else {
BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
controller.deleteVolumes(volumeDescriptors, task);
}
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method deleteSnapshot.
/**
* {@inheritDoc}
*/
@Override
public void deleteSnapshot(BlockSnapshot requestedSnapshot, List<BlockSnapshot> allSnapshots, String taskId, String deleteType) {
if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
s_logger.info("Executing ViPR-only snapshot deletion");
// Do any cleanup necessary for the ViPR only delete.
cleanupForViPROnlySnapshotDelete(allSnapshots);
// Mark them inactive.
_dbClient.markForDeletion(allSnapshots);
// Note that we must go back to the database to get the latest snapshot status map.
for (BlockSnapshot snapshot : allSnapshots) {
BlockSnapshot updatedSnapshot = _dbClient.queryObject(BlockSnapshot.class, snapshot.getId());
Operation op = updatedSnapshot.getOpStatus().get(taskId);
op.ready("Snapshot succesfully deleted from ViPR");
updatedSnapshot.getOpStatus().updateTaskStatus(taskId, op);
_dbClient.updateObject(updatedSnapshot);
}
} else {
StorageSystem device = _dbClient.queryObject(StorageSystem.class, requestedSnapshot.getStorageController());
BlockController controller = getController(BlockController.class, device.getSystemType());
controller.deleteSnapshot(device.getId(), requestedSnapshot.getId(), taskId);
}
}
Aggregations