use of com.emc.storageos.model.NamedRelatedResourceRep in project coprhd-controller by CoprHD.
the class TaskService method getLatestTasks.
// This method uses heap sort to return latest n tasks where n <= 10K.
private TasksList getLatestTasks(Set<URI> tenantIds, String startTime, String endTime, Integer maxCount) {
PriorityQueue<TimestampedURIQueryResult.TimestampedURI> taskHeap = new PriorityQueue<>(maxCount, new MinTaskComparator());
Date startWindowDate = TimeUtils.getDateTimestamp(startTime);
Date endWindowDate = TimeUtils.getDateTimestamp(endTime);
// Fetch index entries and load into sorted set
int taskCount = 0;
for (URI normalizedTenantId : tenantIds) {
log.debug("Retriving tasks from tenant {}", normalizedTenantId);
TimestampedURIQueryResult taskIds = new TimestampedURIQueryResult();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTimedTenantOrgTaskConstraint(normalizedTenantId, startWindowDate, endWindowDate), taskIds);
Iterator<TimestampedURIQueryResult.TimestampedURI> it = taskIds.iterator();
while (it.hasNext()) {
TimestampedURIQueryResult.TimestampedURI timestampedURI = it.next();
// Add first maxCount tasks to PQ
if (taskHeap.size() < maxCount) {
taskHeap.add(timestampedURI);
taskCount++;
} else {
// Add the rest tasks into PQ if task timestamp is >= than the lowest timestamp task in PQ
if (timestampedURI.getTimestamp() >= taskHeap.peek().getTimestamp()) {
taskHeap.poll();
taskHeap.add(timestampedURI);
}
taskCount++;
}
}
}
log.debug("The number of tasks of all tenants is {}, heap size is {}", taskCount, taskHeap.size());
List<NamedRelatedResourceRep> resourceReps = Lists.newArrayList();
while (!taskHeap.isEmpty()) {
TimestampedURIQueryResult.TimestampedURI uri = taskHeap.poll();
RestLinkRep link = new RestLinkRep("self", RestLinkFactory.newLink(ResourceTypeEnum.TASK, uri.getUri()));
resourceReps.add(new NamedRelatedResourceRep(uri.getUri(), link, uri.getName()));
}
return new TasksList(resourceReps);
}
use of com.emc.storageos.model.NamedRelatedResourceRep in project coprhd-controller by CoprHD.
the class TenantsService method listVolumeGroups.
/**
* List volume groups the user is authorized to see
*
* @param id the URN of a ViPR Tenant/Subtenant
* @prereq none
* @brief List volume groups
* @return List of volume groups
*/
@GET
@Path("/{id}/volume-groups")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VolumeGroupList listVolumeGroups(@PathParam("id") URI id) {
// tenant id and user permission will get validated in listProjects()
ProjectList projectList = listProjects(id);
Set<URI> projects = new HashSet<URI>();
for (NamedRelatedResourceRep projectRep : projectList.getProjects()) {
projects.add(projectRep.getId());
}
// for each project, get all volumes. Collect volume group ids for all volumes
StringSet volumeGroups = new StringSet();
for (URI project : projects) {
URIQueryResultList list = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(project), list);
Iterator<Volume> resultsIt = _dbClient.queryIterativeObjects(Volume.class, list);
while (resultsIt.hasNext()) {
volumeGroups.addAll(resultsIt.next().getVolumeGroupIds());
}
}
// form Volume Group list response
VolumeGroupList volumeGroupList = new VolumeGroupList();
for (String vg : volumeGroups) {
VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, URI.create(vg));
volumeGroupList.getVolumeGroups().add(toNamedRelatedResource(volumeGroup));
}
return volumeGroupList;
}
use of com.emc.storageos.model.NamedRelatedResourceRep 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;
}
use of com.emc.storageos.model.NamedRelatedResourceRep in project coprhd-controller by CoprHD.
the class ComputeSystemService method getServiceProfileTemplatesForComputeSystem.
public List<NamedRelatedResourceRep> getServiceProfileTemplatesForComputeSystem(ComputeSystem cs, DbClient dbClient) {
List<NamedRelatedResourceRep> serviceProfileTemplates = new ArrayList<NamedRelatedResourceRep>();
URIQueryResultList sptIdList = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfileTemplateConstraint(cs.getId()), sptIdList);
List<UCSServiceProfileTemplate> profileTemplateList = dbClient.queryObject(UCSServiceProfileTemplate.class, sptIdList, true);
for (UCSServiceProfileTemplate serviceProfileTemplate : profileTemplateList) {
if (!serviceProfileTemplate.getUpdating()) {
NamedRelatedResourceRep sptNamedRelatedResource = new NamedRelatedResourceRep();
sptNamedRelatedResource.setId(serviceProfileTemplate.getId());
sptNamedRelatedResource.setName(serviceProfileTemplate.getLabel() + " (Initial Template)");
serviceProfileTemplates.add(sptNamedRelatedResource);
} else {
_log.info(" updating service profile template:" + serviceProfileTemplate.getLabel() + " id:" + serviceProfileTemplate.getId().toString());
boolean valid = isUpdatingSPTValid(serviceProfileTemplate, dbClient);
if (valid) {
NamedRelatedResourceRep sptNamedRelatedResource = new NamedRelatedResourceRep();
sptNamedRelatedResource.setId(serviceProfileTemplate.getId());
sptNamedRelatedResource.setName(serviceProfileTemplate.getLabel() + " (Updating Template)");
serviceProfileTemplates.add(sptNamedRelatedResource);
} else {
_log.info("invalid uSPT");
}
}
// TODO: Check if SPT uses updating vnic templates here. If so, it is invalid for use.
}
return serviceProfileTemplates;
}
use of com.emc.storageos.model.NamedRelatedResourceRep in project coprhd-controller by CoprHD.
the class FilePolicyApiTest method testListFileSnapshotPolicies.
@Test
public void testListFileSnapshotPolicies() {
FilePolicyListRestRep filePolicyListResp = rSys.path(FILE_POLICIES).get(FilePolicyListRestRep.class);
Assert.assertNotNull(filePolicyListResp);
List<NamedRelatedResourceRep> filePolicies = filePolicyListResp.getFilePolicies();
for (Iterator<NamedRelatedResourceRep> iterator = filePolicies.iterator(); iterator.hasNext(); ) {
NamedRelatedResourceRep namedRelatedResourceRep = iterator.next();
if (namedRelatedResourceRep.getId().equals(createdFileSnapshotPolicyURI)) {
Assert.assertTrue(true);
return;
}
}
Assert.assertTrue(false);
}
Aggregations