Search in sources :

Example 1 with NamedRelatedResourceRep

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);
}
Also used : RestLinkRep(com.emc.storageos.model.RestLinkRep) TimestampedURIQueryResult(com.emc.storageos.db.client.TimestampedURIQueryResult) PriorityQueue(java.util.PriorityQueue) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Date(java.util.Date) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) TasksList(com.emc.storageos.model.tasks.TasksList)

Example 2 with NamedRelatedResourceRep

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;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) ProjectList(com.emc.storageos.model.project.ProjectList) StringSet(com.emc.storageos.db.client.model.StringSet) VolumeGroupList(com.emc.storageos.model.application.VolumeGroupList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with NamedRelatedResourceRep

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;
}
Also used : SnapshotList(com.emc.storageos.model.SnapshotList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) Volume(com.emc.storageos.db.client.model.Volume) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) SOURCE_TO_TARGET(com.emc.storageos.model.block.Copy.SyncDirection.SOURCE_TO_TARGET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with NamedRelatedResourceRep

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;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) ArrayList(java.util.ArrayList) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 5 with NamedRelatedResourceRep

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);
}
Also used : NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) FilePolicyListRestRep(com.emc.storageos.model.file.policy.FilePolicyListRestRep) Test(org.junit.Test)

Aggregations

NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)111 URI (java.net.URI)47 ArrayList (java.util.ArrayList)28 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)22 VolumeRestRep (com.emc.storageos.model.block.VolumeRestRep)18 Asset (com.emc.sa.asset.annotation.Asset)11 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)11 AssetOption (com.emc.vipr.model.catalog.AssetOption)9 HashMap (java.util.HashMap)8 GET (javax.ws.rs.GET)8 Produces (javax.ws.rs.Produces)8 NamedVolumesList (com.emc.storageos.model.block.NamedVolumesList)7 Path (javax.ws.rs.Path)7 RelatedResourceRep (com.emc.storageos.model.RelatedResourceRep)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 SnapshotList (com.emc.storageos.model.SnapshotList)5 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)5 StorageSystemRestRep (com.emc.storageos.model.systems.StorageSystemRestRep)5 HashSet (java.util.HashSet)5 List (java.util.List)5