Search in sources :

Example 6 with PrefixConstraint

use of com.emc.storageos.db.client.constraint.PrefixConstraint in project coprhd-controller by CoprHD.

the class VPlexBlockServiceApiImpl method getVplexProject.

/**
 * Returns the Project assigned to this VPlex for its artifacts.
 * If there is no existing Project, one is created.
 *
 * @param vplexSystem A StorageSystem instance representing a VPlex.
 * @param dbClient A reference to a database client.
 *
 * @return Project instance that was created for holding this VPlex's private volumes/export groups.
 */
public static Project getVplexProject(StorageSystem vplexSystem, DbClient dbClient, TenantsService tenantsService) {
    BasePermissionsHelper helper = new BasePermissionsHelper(dbClient);
    TenantOrg rootTenant = helper.getRootTenant();
    PrefixConstraint constraint = PrefixConstraint.Factory.getLabelPrefixConstraint(Project.class, vplexSystem.getNativeGuid());
    URIQueryResultList result = new URIQueryResultList();
    dbClient.queryByConstraint(constraint, result);
    Iterator<URI> iter = result.iterator();
    while (iter.hasNext()) {
        Project project = dbClient.queryObject(Project.class, iter.next());
        if (project == null || project.getInactive() == true) {
            continue;
        }
        if (project.getLabel().equals(vplexSystem.getNativeGuid()) && project.getTenantOrg().getURI().toString().equals(rootTenant.getId().toString())) {
            return project;
        }
    }
    // Create the project
    ProjectParam projectParam = new ProjectParam(vplexSystem.getNativeGuid());
    ProjectElement projectElement = tenantsService.createProject(rootTenant.getId(), projectParam, TenantOrg.PROVIDER_TENANT_ORG, rootTenant.getId().toString());
    URI projectId = projectElement.getId();
    Project project = dbClient.queryObject(Project.class, projectId);
    project.addInternalFlags(DataObject.Flag.INTERNAL_OBJECT);
    dbClient.updateObject(project);
    return project;
}
Also used : Project(com.emc.storageos.db.client.model.Project) ProjectParam(com.emc.storageos.model.project.ProjectParam) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ProjectElement(com.emc.storageos.model.project.ProjectElement) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FCTN_STRING_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FCTN_VPLEX_MIRROR_TO_URI(com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI) BasePermissionsHelper(com.emc.storageos.security.authorization.BasePermissionsHelper) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)6 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)5 URI (java.net.URI)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 Project (com.emc.storageos.db.client.model.Project)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 BasePermissionsHelper (com.emc.storageos.security.authorization.BasePermissionsHelper)2 Test (org.junit.Test)2 ContainmentLabelConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentLabelConstraintImpl)1 ContainmentPrefixConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentPrefixConstraintImpl)1 LabelConstraintImpl (com.emc.storageos.db.client.constraint.impl.LabelConstraintImpl)1 PrefixConstraintImpl (com.emc.storageos.db.client.constraint.impl.PrefixConstraintImpl)1 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 FCTN_STRING_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_STRING_TO_URI)1 FCTN_VPLEX_MIRROR_TO_URI (com.emc.storageos.db.client.util.CommonTransformerFunctions.FCTN_VPLEX_MIRROR_TO_URI)1 ProjectElement (com.emc.storageos.model.project.ProjectElement)1 ProjectParam (com.emc.storageos.model.project.ProjectParam)1