use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class AbstractBlockServiceApiImpl method createTasksForVolumes.
/**
* Create a task list for the volumes sent in using the operation CHANGE_BLOCK_VOLUME_VPOOL.
*
* @param vPool
* virtual pool
* @param volumes
* volumes
* @param taskId
* task ID
* @return a task list
*/
protected TaskList createTasksForVolumes(VirtualPool vPool, List<Volume> volumes, String taskId) {
TaskList taskList = new TaskList();
if (volumes == null) {
s_logger.info("No volumes were presented to create task objects. This is a fatal error");
if (vPool != null && vPool.getLabel() != null) {
throw APIException.badRequests.noVolumesForTaskObjects(vPool.getLabel(), taskId);
}
throw APIException.badRequests.noVolumesForTaskObjects("None Specified", taskId);
}
for (Volume volume : volumes) {
// Associated resources are any resources that are indirectly affected by this
// volume's virtual pool change. The user should be notified if there are any.
List<? extends DataObject> associatedResources = getTaskAssociatedResources(volume, vPool);
List<URI> associatedResourcesURIs = new ArrayList<URI>();
if (associatedResources != null && !associatedResources.isEmpty()) {
for (DataObject obj : associatedResources) {
associatedResourcesURIs.add(obj.getId());
}
}
// New operation
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VPOOL);
op.setDescription("Change vpool operation");
if (!associatedResourcesURIs.isEmpty()) {
op.setAssociatedResourcesField(Joiner.on(',').join(associatedResourcesURIs));
}
op = _dbClient.createTaskOpStatus(Volume.class, volume.getId(), taskId, op);
TaskResourceRep volumeTask = null;
if (associatedResources != null) {
// We need the task to reflect that there are associated resources affected by this operation.
volumeTask = TaskMapper.toTask(volume, associatedResources, taskId, op);
} else {
volumeTask = TaskMapper.toTask(volume, taskId, op);
}
taskList.getTaskList().add(volumeTask);
}
return taskList;
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class ActionableEventExecutor method removeInitiator.
/**
* Method to remove an initiator from existing exports for a host.
* NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
*
* @param initiatorId the initiator to remove
* @param eventId the event id
* @return task for removing an initiator
*/
public TaskResourceRep removeInitiator(URI initiatorId, URI eventId) {
Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorId);
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Initiator.class, initiator.getId(), taskId, ResourceOperationTypeEnum.DELETE_INITIATOR);
if (ComputeSystemHelper.isInitiatorInUse(_dbClient, initiatorId.toString())) {
computeController.removeInitiatorFromExport(eventId, initiator.getHost(), initiator.getId(), taskId);
} else {
_dbClient.ready(Initiator.class, initiator.getId(), taskId);
_dbClient.markForDeletion(initiator);
}
return toTask(initiator, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class ActionableEventExecutor method hostClusterChange.
/**
* Method to move a host to a new cluster and update shared exports.
* NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
*
* @param hostId the host that is moving clusters
* @param clusterId the cluster the host is moving to
* @param vCenterDataCenterId the vcenter datacenter id to set
* @param isVcenter if true, vcenter api operations will be executed against the host to detach/unmount and attach/mount disks and
* datastores
* @param eventId the event id
* @return task for updating export groups
*/
public TaskResourceRep hostClusterChange(URI hostId, URI clusterId, URI vCenterDataCenterId, boolean isVcenter, URI eventId) {
Host hostObj = _dbClient.queryObject(Host.class, hostId);
URI oldClusterURI = hostObj.getCluster();
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Host.class, hostId, taskId, ResourceOperationTypeEnum.UPDATE_HOST);
if (!NullColumnValueGetter.isNullURI(oldClusterURI) && NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI)) {
// Remove host from shared export
computeController.removeHostsFromExport(eventId, Arrays.asList(hostId), oldClusterURI, isVcenter, vCenterDataCenterId, taskId);
} else if (NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, clusterId)) {
// Non-clustered host being added to a cluster
computeController.addHostsToExport(eventId, Arrays.asList(hostId), clusterId, taskId, oldClusterURI, isVcenter);
} else if (!NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && !oldClusterURI.equals(clusterId) && (ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI) || ComputeSystemHelper.isClusterInExport(_dbClient, clusterId))) {
// Clustered host being moved to another cluster
computeController.addHostsToExport(eventId, Arrays.asList(hostId), clusterId, taskId, oldClusterURI, isVcenter);
} else if (!NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(clusterId) && oldClusterURI.equals(clusterId) && ComputeSystemHelper.isClusterInExport(_dbClient, clusterId)) {
// Cluster hasn't changed but we should add host to the shared exports in case they weren't added to all of them
computeController.addHostsToExport(eventId, Arrays.asList(hostId), clusterId, taskId, oldClusterURI, isVcenter);
} else {
ComputeSystemHelper.updateHostAndInitiatorClusterReferences(_dbClient, clusterId, hostId);
ComputeSystemHelper.updateHostVcenterDatacenterReference(_dbClient, hostId, vCenterDataCenterId);
_dbClient.ready(Host.class, hostId, taskId);
}
return toTask(hostObj, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method performProtectionAction.
/**
* Since all of the protection operations are very similar, this method does all of the work.
* We keep the actual REST methods separate mostly for the purpose of documentation generators.
*
* @param consistencyGroupId the URI of the BlockConsistencyGroup to perform the protection action against.
* @param targetVarrayId the target virtual array.
* @param pointInTime any point in time, specified in UTC.
* Allowed values: "yyyy-MM-dd_HH:mm:ss" formatted date or datetime in milliseconds.
* @param op operation to perform (pause, stop, failover, etc)
* @return task resource rep
* @throws InternalException
*/
private TaskResourceRep performProtectionAction(URI consistencyGroupId, Copy copy, String op) throws InternalException {
ArgValidator.checkFieldUriType(consistencyGroupId, BlockConsistencyGroup.class, "id");
ArgValidator.checkFieldUriType(copy.getCopyID(), VirtualArray.class, "copyId");
// Get the BlockConsistencyGroup and target VirtualArray associated with the request.
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
final VirtualArray targetVirtualArray = _permissionsHelper.getObjectById(copy.getCopyID(), VirtualArray.class);
ArgValidator.checkEntity(consistencyGroup, consistencyGroupId, true);
ArgValidator.checkEntity(targetVirtualArray, copy.getCopyID(), true);
// The consistency group needs to be associated with RecoverPoint in order to perform the operation.
if (!consistencyGroup.checkForType(Types.RP)) {
// Attempt to do protection link management on unprotected CG
throw APIException.badRequests.consistencyGroupMustBeRPProtected(consistencyGroupId);
}
if (op.equalsIgnoreCase(ProtectionOp.SWAP.getRestOp()) && !NullColumnValueGetter.isNullURI(consistencyGroupId)) {
ExportUtils.validateConsistencyGroupBookmarksExported(_dbClient, consistencyGroupId);
}
// Catch any attempts to use an invalid access mode
if (op.equalsIgnoreCase(ProtectionOp.CHANGE_ACCESS_MODE.getRestOp()) && !Copy.ImageAccessMode.DIRECT_ACCESS.name().equalsIgnoreCase(copy.getAccessMode())) {
throw APIException.badRequests.unsupportedAccessMode(copy.getAccessMode());
}
// Verify that the supplied target Virtual Array is being referenced by at least one target volume in the CG.
List<Volume> targetVolumes = getTargetVolumes(consistencyGroup, copy.getCopyID());
if (targetVolumes == null || targetVolumes.isEmpty()) {
// The supplied target varray is not referenced by any target volumes in the CG.
throw APIException.badRequests.targetVirtualArrayDoesNotMatch(consistencyGroupId, copy.getCopyID());
}
// Get the first target volume
Volume targetVolume = targetVolumes.get(0);
String task = UUID.randomUUID().toString();
Operation status = new Operation();
status.setResourceType(ProtectionOp.getResourceOperationTypeEnum(op));
_dbClient.createTaskOpStatus(BlockConsistencyGroup.class, consistencyGroupId, task, status);
ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, targetVolume.getProtectionController());
String deviceType = system.getSystemType();
if (!deviceType.equals(DiscoveredDataObject.Type.rp.name())) {
throw APIException.badRequests.protectionForRpClusters();
}
RPController controller = getController(RPController.class, system.getSystemType());
controller.performProtectionOperation(system.getId(), consistencyGroupId, targetVolume.getId(), copy.getPointInTime(), copy.getAccessMode(), op, task);
/*
* auditOp(OperationTypeEnum.PERFORM_PROTECTION_ACTION, true, AuditLogManager.AUDITOP_BEGIN,
* op, copyID.toString(), id.toString(), system.getId().toString());
*/
return toTask(consistencyGroup, task, status);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method activateConsistencyGroupSnapshot.
/**
* Activate the specified Consistency Group Snapshot
*
* @prereq Create consistency group snapshot as inactive
*
* @param consistencyGroupId
* - Consistency group URI
* @param snapshotId
* - Consistency group snapshot URI
*
* @brief Activate consistency group snapshot
* @return TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/activate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep activateConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.ACTIVATE_CONSISTENCY_GROUP_SNAPSHOT);
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
final BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
// check for backend CG
if (BlockConsistencyGroupUtils.getLocalSystemsInCG(consistencyGroup, _dbClient).isEmpty()) {
_log.error("{} Group Snapshot operations not supported when there is no backend CG", consistencyGroup.getId());
throw APIException.badRequests.cannotCreateSnapshotOfCG();
}
final StorageSystem device = _dbClient.queryObject(StorageSystem.class, snapshot.getStorageController());
final BlockController controller = getController(BlockController.class, device.getSystemType());
final String task = UUID.randomUUID().toString();
// activate it again.
if (snapshot.getIsSyncActive()) {
op.ready();
op.setMessage("The consistency group snapshot is already active.");
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
return toTask(snapshot, task, op);
}
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
try {
final List<URI> snapshotList = new ArrayList<URI>();
// Query all the snapshots by snapshot label
final List<BlockSnapshot> snaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
// Build a URI list with all the snapshots ids
for (BlockSnapshot snap : snaps) {
snapshotList.add(snap.getId());
}
// Activate snapshots
controller.activateSnapshot(device.getId(), snapshotList, task);
} catch (final ControllerException e) {
throw new ServiceCodeException(CONTROLLER_ERROR, e, "An exception occurred when activating consistency group snapshot {0}. Caused by: {1}", new Object[] { snapshotId, e.getMessage() });
}
auditBlockConsistencyGroup(OperationTypeEnum.ACTIVATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
return toTask(snapshot, task, op);
}
Aggregations