use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.
the class ApiTest method prepareVdcTest.
/**
* test for API /vdc/prepare-vdc, which will remove all root's tenant roles and project ownerships
*
* before calling the API, prepare root to be:
* 1. Provider Tenant's tenant admin
* 2. owner of a project of Provider Tenant
* 3. Tenant Admin of a subtenant
* 4. owner of a project from subtenant
*/
public void prepareVdcTest() throws Exception {
ClientResponse resp = null;
BalancedWebResource rootUser = createHttpsClient(SYSADMIN, SYSADMIN_PASS_WORD, baseUrls);
UserInfo info = rootUser.path("/user/whoami").get(UserInfo.class);
String rootTenantId = info.getTenant();
String rootToken = (String) _savedTokens.get(SYSADMIN);
BalancedWebResource superSanity = createHttpsClient(SUPERUSER, AD_PASS_WORD, baseUrls);
superSanity.path("/tenant").get(TenantResponse.class);
String superSanityToken = (String) _savedTokens.get(SUPERUSER);
// prepare tenant roles and project ownership
// also assign TenantAdmin to superuser, so it can be used to verify afterwards
boolean bRootHasProviderTenantAdmin = true;
if (info.getHomeTenantRoles().isEmpty()) {
bRootHasProviderTenantAdmin = false;
resp = assignTenantRole(rootTenantId, SYSADMIN, "TENANT_ADMIN");
Assert.assertEquals(200, resp.getStatus());
resp = assignTenantRole(rootTenantId, SUPERUSER, "TENANT_ADMIN");
Assert.assertEquals(200, resp.getStatus());
}
// create a project of Provider Tenant by root, root will be its owner.
ProjectParam paramProj = new ProjectParam("project_" + new Random().nextInt());
ProjectEntry rootProject1 = rootUser.path(String.format(_projectsUrlFormat, rootTenantId.toString())).header(AUTH_TOKEN_HEADER, rootToken).post(ProjectEntry.class, paramProj);
Assert.assertTrue(rootProject1.name.equals(paramProj.getName()));
Assert.assertTrue(rootProject1.id != null);
// create a subtenant by root, root will be its TenantAdmin
String tenantLabel = "tenant_" + new Random().nextInt();
TenantOrgRestRep subtenant = createTenant(tenantLabel, "sanity.local", "key", tenantLabel);
resp = assignTenantRole(subtenant.getId().toString(), SUPERUSER, "TENANT_ADMIN");
Assert.assertEquals(200, resp.getStatus());
// create a project under the subtenant created above, root will be its owner
paramProj = new ProjectParam("project_" + new Random().nextInt());
ProjectEntry rootProject2 = rootUser.path(String.format(_projectsUrlFormat, subtenant.getId().toString())).header(AUTH_TOKEN_HEADER, rootToken).post(ProjectEntry.class, paramProj);
Assert.assertTrue(rootProject2.name.equals(paramProj.getName()));
Assert.assertTrue(rootProject2.id != null);
// call /vdc/prepare-vdc
ClientResponse response = rootUser.path("/vdc/prepare-vdc").header(AUTH_TOKEN_HEADER, rootToken).post(ClientResponse.class);
Assert.assertEquals(200, response.getStatus());
// verify root's tenant roles and project ownership be removed
resp = rootUser.path("/user/whoami").get(ClientResponse.class);
String output = resp.getEntity(String.class);
Assert.assertFalse(output.contains("TENANT_ADMIN"));
resp = superSanity.path(String.format(_projectUrl, rootProject1.id.toString())).get(ClientResponse.class);
output = resp.getEntity(String.class);
Assert.assertFalse(output.contains(SYSADMIN));
resp = superSanity.path(String.format(_projectUrl, rootProject2.id.toString())).get(ClientResponse.class);
output = resp.getEntity(String.class);
Assert.assertFalse(output.contains(SYSADMIN));
// test done, restore root's tenant role and remove the project
if (bRootHasProviderTenantAdmin) {
assignTenantRole(rootTenantId, SYSADMIN, "TENANT_ADMIN");
}
if (rootProject1 != null) {
superSanity.path(String.format(_projectUrl + "/deactivate", rootProject1.id.toString())).header(AUTH_TOKEN_HEADER, superSanityToken).post(ClientResponse.class);
}
if (rootProject2 != null) {
superSanity.path(String.format(_projectUrl + "/deactivate", rootProject2.id.toString())).header(AUTH_TOKEN_HEADER, superSanityToken).post(ClientResponse.class);
}
if (subtenant != null) {
superSanity.path("/tenants/" + subtenant.getId() + "/deactivate").header(AUTH_TOKEN_HEADER, superSanityToken).post();
}
}
use of com.emc.storageos.model.project.ProjectParam 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());
}
use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.
the class Projects method save.
@FlashException(keep = true, referrer = { "create", "edit" })
public static void save(ProjectForm project) {
if (project == null) {
Logger.error("No project parameters passed");
badRequest("No project parameters passed");
return;
}
project.validate("project");
if (Validation.hasErrors()) {
Common.handleError();
}
if (project.isNew()) {
project.id = stringId(ProjectUtils.create(project.tenantId, new ProjectParam(project.name)));
saveProjectQuota(project);
saveProjectACLs(project.id, project.aclEntries);
} else {
ProjectRestRep currentProject = ProjectUtils.getProject(project.id);
if (currentProject != null) {
saveProjectQuota(project);
saveProjectACLs(project.id, project.aclEntries);
ProjectUtils.update(project.id, new ProjectUpdateParam(project.name, project.owner));
}
}
flash.success(MessagesUtils.get("projects.saved", project.name));
JsonObject jobject = getCookieAsJson(VIPR_START_GUIDE);
if (jobject != null && jobject.get(GUIDE_COMPLETED_STEP) != null && jobject.get(GUIDE_VISIBLE) != null) {
if (jobject.get("completedSteps").getAsInt() == 7 && jobject.get("guideVisible").getAsBoolean()) {
JsonObject dataObject = getCookieAsJson(GUIDE_DATA);
JsonArray projects = dataObject.getAsJsonArray("projects");
if (projects == null) {
projects = new JsonArray();
}
boolean addToCookie = true;
for (Object projectObject : projects) {
JsonObject projectjson = (JsonObject) projectObject;
if (projectjson.get("id") != null) {
String projectId = projectjson.get("id").getAsString();
if (StringUtils.equals(projectId, project.id)) {
// update case, don't add in cookie
addToCookie = false;
break;
}
}
}
if (addToCookie) {
JsonObject projectObject = new JsonObject();
projectObject.addProperty("id", project.id);
projectObject.addProperty("name", project.name);
projects.add(projectObject);
dataObject.add("projects", projects);
saveJsonAsCookie("GUIDE_DATA", dataObject);
}
}
}
if (StringUtils.isNotBlank(project.referrerUrl)) {
redirect(project.referrerUrl);
} else {
list();
}
}
use of com.emc.storageos.model.project.ProjectParam in project coprhd-controller by CoprHD.
the class AbstractRequestWrapperFilter method createTenantNProject.
private void createTenantNProject(KeystoneTenant tenant) {
_internalTenantServiceClient.setServer(_keystoneUtils.getVIP());
// Create Tenant via internal API call.
TenantOrgRestRep tenantResp = _internalTenantServiceClient.createTenant(_keystoneUtils.prepareTenantParam(tenant));
// Create Project via internal API call.
ProjectParam projectParam = new ProjectParam(tenant.getName() + CinderConstants.PROJECT_NAME_SUFFIX);
ProjectElement projectResp = _internalTenantServiceClient.createProject(tenantResp.getId(), projectParam);
_keystoneUtils.tagProjectWithOpenstackId(projectResp.getId(), tenant.getId(), tenantResp.getId().toString());
// Creates OSTenant representation of Openstack Tenant
OSTenant osTenant = _keystoneUtils.mapToOsTenant(tenant);
osTenant.setId(URIUtil.createId(OSTenant.class));
_dbClient.createObject(osTenant);
}
use of com.emc.storageos.model.project.ProjectParam 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;
}
Aggregations