Search in sources :

Example 1 with ProjectElement

use of com.emc.storageos.model.project.ProjectElement in project coprhd-controller by CoprHD.

the class TenantsService method createProject.

/**
 * Worker method for create project. Allows external requests (REST) as well as
 * internal requests that may not have a security context.
 *
 * @param id tenant id
 * @param param project params
 * @param owner name of owner of the request
 * @param ownerTenantId tenant id of the owner
 * @return project details
 */
public ProjectElement createProject(URI id, ProjectParam param, String owner, String ownerTenantId) {
    TenantOrg tenant = getTenantById(id, true);
    if (param.getName() != null && !param.getName().isEmpty()) {
        checkForDuplicateName(param.getName(), Project.class, id, "tenantOrg", _dbClient);
    }
    Project project = new Project();
    project.setId(URIUtil.createId(Project.class));
    project.setLabel(param.getName());
    project.setTenantOrg(new NamedURI(tenant.getId(), project.getLabel()));
    project.setOwner(owner);
    // set owner acl
    project.addAcl(new PermissionsKey(PermissionsKey.Type.SID, owner, ownerTenantId).toString(), ACL.OWN.toString());
    _dbClient.createObject(project);
    recordTenantEvent(OperationTypeEnum.CREATE_PROJECT, tenant.getId(), project.getId());
    return new ProjectElement(project.getId(), toLink(ResourceTypeEnum.PROJECT, project.getId()), project.getLabel());
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) ProjectElement(com.emc.storageos.model.project.ProjectElement) PermissionsKey(com.emc.storageos.security.authorization.PermissionsKey) TenantOrg(com.emc.storageos.db.client.model.TenantOrg)

Example 2 with ProjectElement

use of com.emc.storageos.model.project.ProjectElement in project coprhd-controller by CoprHD.

the class AuthnConfigurationService method createTenantAndProjectForOpenstackTenant.

public void createTenantAndProjectForOpenstackTenant(OSTenant tenant) {
    TenantCreateParam param = prepareTenantMappingForOpenstack(tenant);
    // Create a tenant.
    TenantOrgRestRep tenantOrgRestRep = _tenantsService.createSubTenant(_permissionsHelper.getRootTenant().getId(), param);
    // Create a project.
    ProjectParam projectParam = new ProjectParam(tenant.getName() + CinderConstants.PROJECT_NAME_SUFFIX);
    ProjectElement projectElement = _tenantsService.createProject(tenantOrgRestRep.getId(), projectParam);
    _keystoneUtils.tagProjectWithOpenstackId(projectElement.getId(), tenant.getOsId(), tenantOrgRestRep.getId().toString());
}
Also used : ProjectParam(com.emc.storageos.model.project.ProjectParam) ProjectElement(com.emc.storageos.model.project.ProjectElement) TenantOrgRestRep(com.emc.storageos.model.tenant.TenantOrgRestRep) TenantCreateParam(com.emc.storageos.model.tenant.TenantCreateParam)

Example 3 with ProjectElement

use of com.emc.storageos.model.project.ProjectElement in project coprhd-controller by CoprHD.

the class InternalApiTest method testFSReleaseUsingInternalClient.

@Test
public void testFSReleaseUsingInternalClient() throws Exception {
    // get tenant
    TenantResponse tenant = rSys.path("/tenant").get(TenantResponse.class);
    Assert.assertNotNull(tenant);
    // create a project to host a normal file system
    ProjectParam projectParam = new ProjectParam();
    projectParam.setName("test-internalapi-" + System.currentTimeMillis());
    ProjectElement projectResp = rSys.path("/tenants/" + tenant.getTenant().toString() + "/projects").post(ProjectElement.class, projectParam);
    Assert.assertNotNull(projectResp);
    // create a normal file system which we can then release
    FileSystemParam fsparam = new FileSystemParam();
    fsparam.setVpool(_cosId);
    fsparam.setLabel("test-internalapi-" + System.currentTimeMillis());
    fsparam.setVarray(_nhId);
    fsparam.setSize("20971520");
    TaskResourceRep taskResp = rSys.path("/file/filesystems").queryParam("project", projectResp.getId().toString()).post(TaskResourceRep.class, fsparam);
    Assert.assertTrue(taskResp != null);
    Assert.assertNotNull(taskResp.getOpId());
    Assert.assertNotNull(taskResp.getResource());
    URI fsId = taskResp.getResource().getId();
    String opId = taskResp.getOpId();
    // get the file system object we just created
    ClientResponse response = rSys.path("/file/filesystems/" + fsId.toString()).get(ClientResponse.class);
    Assert.assertTrue(response != null);
    Assert.assertEquals(200, response.getStatus());
    // wait for for the file system create to complete
    int checkCount = 1200;
    String status;
    do {
        // wait upto ~2 minute for fs creation
        Thread.sleep(100);
        taskResp = rSys.path("/file/filesystems/" + fsId + "/tasks/" + opId).get(TaskResourceRep.class);
        status = taskResp.getState();
    } while (status.equals("pending") && checkCount-- > 0);
    if (!status.equals("ready")) {
        Assert.assertTrue("Fileshare create timed out", false);
    }
    // a normal file system should be present in the bulk results
    BulkIdParam bulkIds = rSys.path("/file/filesystems/bulk").get(BulkIdParam.class);
    Assert.assertNotNull("bulk ids should not be null", bulkIds);
    FileShareBulkRep bulkFileShares = rSys.path("/file/filesystems/bulk").post(FileShareBulkRep.class, bulkIds);
    Assert.assertNotNull("bulk response should not be null", bulkFileShares);
    boolean found = false;
    for (FileShareRestRep fs : bulkFileShares.getFileShares()) {
        if (fs.getId().equals(fsId)) {
            found = true;
        }
    }
    Assert.assertTrue("unable to find public FileShare in the bulk results", found);
    // only token is used in release file system operation and hence
    // setting dummy strings for username and tenant ID do not matter
    StorageOSUser user = new StorageOSUser("dummyUserName", "dummyTeneatId");
    user.setToken(_rootToken);
    FileShareRestRep fileShareResponse = _internalFileClient.releaseFileSystem(fsId, user);
    Assert.assertNotNull(fileShareResponse);
    // after release, the file system should no longer be present in the bulk results
    bulkFileShares = rSys.path("/file/filesystems/bulk").post(FileShareBulkRep.class, bulkIds);
    Assert.assertNotNull("bulk response should not be null", bulkFileShares);
    found = false;
    for (FileShareRestRep fs : bulkFileShares.getFileShares()) {
        if (fs.getId().equals(fsId)) {
            found = true;
        }
    }
    Assert.assertFalse("found internal FileShare in the bulk results", found);
    // undo the release of the file system
    fileShareResponse = _internalFileClient.undoReleaseFileSystem(fsId);
    Assert.assertNotNull(fileShareResponse);
    // release it again
    fileShareResponse = _internalFileClient.releaseFileSystem(fsId, user);
    Assert.assertNotNull(fileShareResponse);
    // delete the file system via the internal api
    FileSystemDeleteParam deleteParam = new FileSystemDeleteParam();
    deleteParam.setForceDelete(false);
    taskResp = _internalFileClient.deactivateFileSystem(fsId, _rootToken, deleteParam);
    Assert.assertNotNull(taskResp);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) FileSystemParam(com.emc.storageos.model.file.FileSystemParam) ProjectParam(com.emc.storageos.model.project.ProjectParam) BulkIdParam(com.emc.storageos.model.BulkIdParam) FileShareBulkRep(com.emc.storageos.model.file.FileShareBulkRep) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) FileShareRestRep(com.emc.storageos.model.file.FileShareRestRep) FileSystemDeleteParam(com.emc.storageos.model.file.FileSystemDeleteParam) URI(java.net.URI) ProjectElement(com.emc.storageos.model.project.ProjectElement) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantResponse(com.emc.storageos.model.tenant.TenantResponse) Test(org.junit.Test)

Example 4 with ProjectElement

use of com.emc.storageos.model.project.ProjectElement in project coprhd-controller by CoprHD.

the class ApiTestUserGroup method createTestProject.

private URI createTestProject(URI tenantId) {
    ProjectParam createParam = apiTestTenants.getDefaultProjectParam("UserGroupProject");
    ProjectElement resp = rSys.path(getProjectCreateApi(tenantId)).post(ProjectElement.class, createParam);
    Assert.assertNotNull(resp.getId());
    // Add the created project to cleanup list, so that at the end of this test
    // the resource will be destroyed.
    final String deleteObjectURL = getDeleteProjectApi(resp.getId());
    CleanupResource projectToCleanup = new CleanupResource("post", deleteObjectURL, rSys, null);
    registerResourceForCleanup(projectToCleanup);
    return resp.getId();
}
Also used : ProjectParam(com.emc.storageos.model.project.ProjectParam) ProjectElement(com.emc.storageos.model.project.ProjectElement)

Example 5 with ProjectElement

use of com.emc.storageos.model.project.ProjectElement in project coprhd-controller by CoprHD.

the class ApiTest method projectSetup.

private void projectSetup() {
    ProjectParam paramProj = new ProjectParam("resourcetestproject");
    ProjectElement project1 = rSTAdminGr1.path(String.format(_projectsUrlFormat, subtenant1Id.toString())).post(ProjectElement.class, paramProj);
    _testProject = project1.getId();
    ACLEntry entry = new ACLEntry();
    entry.setSubjectId(SUBTENANT1_READER);
    entry.setAces(new ArrayList<String>());
    entry.getAces().add("backup");
    ACLEntry entry2 = new ACLEntry();
    entry2.setGroup(SUBTENANT1_USERS_GROUP);
    entry2.setAces(new ArrayList<String>());
    entry2.getAces().add("all");
    ACLAssignmentChanges changes = new ACLAssignmentChanges();
    changes.setAdd(new ArrayList<ACLEntry>());
    changes.getAdd().add(entry2);
    changes.getAdd().add(entry);
    ClientResponse resp = rSTAdmin1.path(String.format(_projectAclUrl, _testProject.toString())).post(ClientResponse.class, changes);
    Assert.assertEquals(200, resp.getStatus());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ProjectParam(com.emc.storageos.model.project.ProjectParam) ACLAssignmentChanges(com.emc.storageos.model.auth.ACLAssignmentChanges) ProjectElement(com.emc.storageos.model.project.ProjectElement) ACLEntry(com.emc.storageos.model.auth.ACLEntry)

Aggregations

ProjectElement (com.emc.storageos.model.project.ProjectElement)12 ProjectParam (com.emc.storageos.model.project.ProjectParam)8 ClientResponse (com.sun.jersey.api.client.ClientResponse)3 URI (java.net.URI)3 Test (org.junit.Test)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 Project (com.emc.storageos.db.client.model.Project)2 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)2 TenantOrgRestRep (com.emc.storageos.model.tenant.TenantOrgRestRep)2 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)1 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)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 BulkIdParam (com.emc.storageos.model.BulkIdParam)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1 ACLAssignmentChanges (com.emc.storageos.model.auth.ACLAssignmentChanges)1 ACLEntry (com.emc.storageos.model.auth.ACLEntry)1 FileShareBulkRep (com.emc.storageos.model.file.FileShareBulkRep)1 FileShareRestRep (com.emc.storageos.model.file.FileShareRestRep)1