use of com.emc.storageos.model.keystone.OSTenantListRestRep in project coprhd-controller by CoprHD.
the class KeystoneService method updateOpenstackTenants.
/**
* Updates representation of OpenStack Tenants in CoprHD.
* Creates Tenants and Projects for new Tenants and deletes them for excluded Tenants.
*
* @param param OpenStackTenantListParam OpenStack Tenants representation with all necessary elements for update.
* @brief Updates representation of OpenStack Tenants in CoprHD.
* @return Updated Tenants.
* @see
*/
@PUT
@Path("/ostenants")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public OSTenantListRestRep updateOpenstackTenants(OSTenantListRestRep param) {
_log.debug("Keystone Service - updateOpenstackTenants");
if (param.getOSTenantsRestRep() == null || param.getOSTenantsRestRep().isEmpty()) {
throw APIException.internalServerErrors.targetIsNullOrEmpty("Tenant list param");
}
OSTenantListRestRep resp = new OSTenantListRestRep();
List<OSTenant> tenantsToUpdate = new ArrayList<>();
List<OSTenant> tenantsToDelete = new ArrayList<>();
OSTenant osTenant;
for (OSTenantRestRep tenant : param.getOSTenantsRestRep()) {
osTenant = _dbClient.queryObject(OSTenant.class, tenant.getId());
if (!osTenant.getExcluded().equals(tenant.getExcluded())) {
// Tenant changed from included to excluded. Mark for deletion related Tenant and Project.
if (!osTenant.getExcluded()) {
tenantsToDelete.add(osTenant);
} else {
tenantsToUpdate.add(osTenant);
}
osTenant.setExcluded(tenant.getExcluded());
resp.getOSTenantsRestRep().add(mapToCoprhdOsTenant(osTenant));
}
}
if (!tenantsToUpdate.isEmpty()) {
// Create Tenant and Project for included Tenants.
for (OSTenant tenant : tenantsToUpdate) {
if (_keystoneUtils.getCoprhdTenantWithOpenstackId(tenant.getOsId()) == null) {
_authService.createTenantAndProjectForOpenstackTenant(tenant);
}
}
}
tenantsToUpdate.addAll(tenantsToDelete);
if (!tenantsToUpdate.isEmpty()) {
_dbClient.updateObject(tenantsToUpdate);
}
if (!tenantsToDelete.isEmpty()) {
for (OSTenant tenant : tenantsToDelete) {
TenantOrg tenantOrg = _keystoneUtils.getCoprhdTenantWithOpenstackId(tenant.getOsId());
if (tenantOrg != null && !TenantOrg.isRootTenant(tenantOrg)) {
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(Project.class, tenant.getOsId(), tenantOrg.getId()), uris);
for (URI projectUri : uris) {
Project project = _dbClient.queryObject(Project.class, projectUri);
ArgValidator.checkReference(Project.class, project.getId(), checkForDelete(project));
_dbClient.markForDeletion(project);
}
ArgValidator.checkReference(TenantOrg.class, tenantOrg.getId(), checkForDelete(tenantOrg));
_dbClient.markForDeletion(tenantOrg);
}
}
}
return resp;
}
use of com.emc.storageos.model.keystone.OSTenantListRestRep in project coprhd-controller by CoprHD.
the class Tenants method synchronizeOSTenants.
public static void synchronizeOSTenants(@As(",") String[] ids) {
List<OSTenantRestRep> tenants = OpenStackTenantsUtils.getOpenStackTenantsFromDataBase();
if (ids != null) {
List<String> idList = Arrays.asList(ids);
if (!idList.get(0).isEmpty()) {
for (OSTenantRestRep tenant : tenants) {
if (idList.contains(tenant.getId().toString())) {
if (tenant.getExcluded()) {
tenant.setExcluded(false);
} else {
tenant.setExcluded(true);
}
}
}
OSTenantListRestRep params = new OSTenantListRestRep();
params.setOSTenantsRestRep(tenants);
OpenStackTenantsUtils.updateOpenStackTenants(params);
}
}
flash.success(MessagesUtils.get(UPDATED));
list();
}
use of com.emc.storageos.model.keystone.OSTenantListRestRep in project coprhd-controller by CoprHD.
the class KeystoneService method map.
private OSTenantListRestRep map(List<OSTenant> tenants) {
OSTenantListRestRep response = new OSTenantListRestRep();
List<OSTenantRestRep> OSTenantsRestRep = new ArrayList<>();
for (OSTenant osTenant : tenants) {
OSTenantsRestRep.add(mapToCoprhdOsTenant(osTenant));
}
response.setOSTenantsRestRep(OSTenantsRestRep);
return response;
}
Aggregations