use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class ResourceService method listChildren.
/**
* This function is to retrieve the children of a given class.
*
* @param id the URN of parent
* @param clzz the child class
* @param nameField the name of the field of the child class that will be displayed as
* name in {@link NamedRelatedResourceRep}. Note this field should be a required
* field because, objects for which this field is null will not be returned by
* this function.
* @param linkField the name of the field in the child class that stored the parent id
* @return a list of children of tenant for the given class
*/
protected <T extends DataObject> List<NamedElementQueryResultList.NamedElement> listChildren(URI id, Class<T> clzz, String nameField, String linkField) {
@SuppressWarnings("deprecation") List<URI> uris = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getContainedObjectsConstraint(id, clzz, linkField));
if (uris != null && !uris.isEmpty()) {
Iterator<T> dataObjects = _dbClient.queryIterativeObjectField(clzz, nameField, uris);
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>();
while (dataObjects.hasNext()) {
T dataObject = dataObjects.next();
Object name = DataObjectUtils.getPropertyValue(clzz, dataObject, nameField);
elements.add(NamedElementQueryResultList.NamedElement.createElement(dataObject.getId(), name == null ? "" : name.toString()));
}
return elements;
} else {
return new ArrayList<NamedElementQueryResultList.NamedElement>();
}
}
use of com.emc.storageos.db.client.model.DataObject 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.DataObject in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method queryResource.
@Override
protected DataObject queryResource(final URI id) {
ArgValidator.checkUri(id);
final Class<? extends DataObject> clazz;
if (URIUtil.isType(id, BlockSnapshotSession.class)) {
clazz = BlockSnapshotSession.class;
} else if (URIUtil.isType(id, BlockSnapshot.class)) {
clazz = BlockSnapshot.class;
} else {
clazz = BlockConsistencyGroup.class;
}
final DataObject resource = _permissionsHelper.getObjectById(id, clazz);
ArgValidator.checkEntityNotNull(resource, id, isIdEmbeddedInURL(id));
return resource;
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method deactivateConsistencyGroupSnapshot.
/**
* Deactivate the specified Consistency Group Snapshot
*
* @prereq none
*
* @param consistencyGroupId
* - Consistency group URI
* @param snapshotId
* - Consistency group snapshot URI
*
* @brief Deactivate consistency group snapshot session
* @return TaskResourceRep
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots/{sid}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskList deactivateConsistencyGroupSnapshot(@PathParam("id") final URI consistencyGroupId, @PathParam("sid") final URI snapshotId) {
final BlockConsistencyGroup consistencyGroup = (BlockConsistencyGroup) queryResource(consistencyGroupId);
// Snapshots of RecoverPoint consistency groups is not supported.
if (isIdEmbeddedInURL(consistencyGroupId) && consistencyGroup.checkForType(Types.RP)) {
throw APIException.badRequests.snapshotsNotSupportedForRPCGs();
}
// 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 BlockSnapshot snapshot = (BlockSnapshot) queryResource(snapshotId);
verifySnapshotIsForConsistencyGroup(snapshot, consistencyGroup);
// We can ignore dependencies on BlockSnapshotSession. In this case
// the BlockSnapshot instance is a linked target for a BlockSnapshotSession
// and we will unlink the snapshot from the session and delete it.
List<Class<? extends DataObject>> excludeTypes = new ArrayList<Class<? extends DataObject>>();
excludeTypes.add(BlockSnapshotSession.class);
ArgValidator.checkReference(BlockSnapshot.class, snapshotId, checkForDelete(snapshot, excludeTypes));
// Snapshot session linked targets must be unlinked instead.
BlockSnapshotSession session = BlockSnapshotSessionUtils.getLinkedTargetSnapshotSession(snapshot, _dbClient);
if (session != null) {
return deactivateAndUnlinkTargetVolumesForSession(session, snapshot);
}
// Generate task id
final String task = UUID.randomUUID().toString();
TaskList response = new TaskList();
// Not an error if the snapshot we try to delete is already deleted
if (snapshot.getInactive()) {
Operation op = new Operation();
op.ready("The consistency group snapshot has already been deactivated");
op.setResourceType(ResourceOperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT);
_dbClient.createTaskOpStatus(BlockSnapshot.class, snapshot.getId(), task, op);
response.getTaskList().add(toTask(snapshot, task, op));
return response;
}
List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
snapshots = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
// Get the snapshot parent volume.
Volume parentVolume = _permissionsHelper.getObjectById(snapshot.getParent(), Volume.class);
// Check that there are no pending tasks for these snapshots.
checkForPendingTasks(Arrays.asList(parentVolume.getTenant().getURI()), snapshots);
for (BlockSnapshot snap : snapshots) {
Operation snapOp = _dbClient.createTaskOpStatus(BlockSnapshot.class, snap.getId(), task, ResourceOperationTypeEnum.DEACTIVATE_VOLUME_SNAPSHOT);
response.getTaskList().add(toTask(snap, task, snapOp));
}
addConsistencyGroupTask(consistencyGroup, response, task, ResourceOperationTypeEnum.DEACTIVATE_CONSISTENCY_GROUP_SNAPSHOT);
try {
BlockServiceApi blockServiceApiImpl = BlockService.getBlockServiceImpl(parentVolume, _dbClient);
blockServiceApiImpl.deleteSnapshot(snapshot, snapshots, task, VolumeDeleteTypeEnum.FULL.name());
} catch (APIException | InternalException e) {
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
_log.error(errorMsg);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(errorMsg);
@SuppressWarnings({ "unchecked" }) Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
_dbClient.error(clazz, taskResourceRep.getResource().getId(), task, e);
}
throw e;
} catch (Exception e) {
String errorMsg = String.format("Exception attempting to delete snapshot %s: %s", snapshot.getId(), e.getMessage());
_log.error(errorMsg);
APIException apie = APIException.internalServerErrors.genericApisvcError(errorMsg, e);
for (TaskResourceRep taskResourceRep : response.getTaskList()) {
taskResourceRep.setState(Operation.Status.error.name());
taskResourceRep.setMessage(apie.getMessage());
@SuppressWarnings("unchecked") Class<? extends DataObject> clazz = URIUtil.getModelClass(taskResourceRep.getResource().getId());
_dbClient.error(clazz, taskResourceRep.getResource().getId(), task, apie);
}
throw apie;
}
auditBlockConsistencyGroup(OperationTypeEnum.DELETE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), snapshot.getLabel());
return response;
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class BlockConsistencyGroupService method getConsistencyGroupSnapshots.
/**
* List snapshots in the consistency group
*
* @prereq none
*
* @param consistencyGroupId
* - Consistency group URI
*
* @brief List snapshots in the consistency group
* @return The list of snapshots in the consistency group
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getConsistencyGroupSnapshots(@PathParam("id") final URI consistencyGroupId) {
ArgValidator.checkUri(consistencyGroupId);
final Class<? extends DataObject> clazz = URIUtil.isType(consistencyGroupId, BlockSnapshot.class) ? BlockSnapshot.class : BlockConsistencyGroup.class;
final DataObject consistencyGroup = _permissionsHelper.getObjectById(consistencyGroupId, clazz);
ArgValidator.checkEntityNotNull(consistencyGroup, consistencyGroupId, isIdEmbeddedInURL(consistencyGroupId));
List<Volume> volumes = ControllerUtils.getVolumesPartOfCG(consistencyGroupId, _dbClient);
// if any of the source volumes are in an application, replica management must be done via the application
for (Volume srcVol : volumes) {
if (srcVol.getApplication(_dbClient) != null) {
return new SnapshotList();
}
}
SnapshotList list = new SnapshotList();
List<URI> snapshotsURIs = new ArrayList<URI>();
// Find all volumes assigned to the group
final URIQueryResultList cgSnapshotsResults = new URIQueryResultList();
_dbClient.queryByConstraint(getBlockSnapshotByConsistencyGroup(consistencyGroupId), cgSnapshotsResults);
if (!cgSnapshotsResults.iterator().hasNext()) {
return list;
}
while (cgSnapshotsResults.iterator().hasNext()) {
URI snapshot = cgSnapshotsResults.iterator().next();
snapshotsURIs.add(snapshot);
}
List<BlockSnapshot> snapshots = _dbClient.queryObject(BlockSnapshot.class, snapshotsURIs);
List<NamedRelatedResourceRep> activeSnapshots = new ArrayList<NamedRelatedResourceRep>();
List<NamedRelatedResourceRep> inactiveSnapshots = new ArrayList<NamedRelatedResourceRep>();
for (BlockSnapshot snapshot : snapshots) {
if (snapshot.getInactive()) {
inactiveSnapshots.add(toNamedRelatedResource(snapshot));
} else {
activeSnapshots.add(toNamedRelatedResource(snapshot));
}
}
list.getSnapList().addAll(inactiveSnapshots);
list.getSnapList().addAll(activeSnapshots);
return list;
}
Aggregations