use of org.onap.so.openstack.beans.MsoTenant in project so by onap.
the class MsoKeystoneUtils method queryTenant.
/**
* Query for a tenant by ID in the given cloud. If the tenant exists, return an MsoTenant object. If not, return
* null.
* <p>
* For the AIC Cloud (DCP/LCP): it is not clear that cloudId is needed, as all admin requests go to the centralized
* identity service in DCP. However, if some artifact must exist in each local LCP instance as well, then it will be
* needed to access the correct region.
* <p>
*
* @param tenantId The Openstack ID of the tenant to query
* @param cloudSiteId The cloud identifier (may be a region) in which to query the tenant.
* @return the tenant properties of the queried tenant, or null if not found
* @throws MsoOpenstackException Thrown if the Openstack API call returns an exception
*/
public MsoTenant queryTenant(String tenantId, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will query the tenant
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
Keystone keystoneAdminClient = getKeystoneAdminClient(cloudSite);
// Check if the tenant exists and return its Tenant Id
try {
Tenant tenant = findTenantById(keystoneAdminClient, tenantId);
if (tenant == null) {
return null;
}
Map<String, String> metadata = new HashMap<>();
if (cloudSite.getIdentityService().getTenantMetadata()) {
OpenStackRequest<Metadata> request = keystoneAdminClient.tenants().showMetadata(tenant.getId());
Metadata tenantMetadata = executeAndRecordOpenstackRequest(request);
if (tenantMetadata != null) {
metadata = tenantMetadata.getMetadata();
}
}
return new MsoTenant(tenant.getId(), tenant.getName(), metadata);
} catch (OpenStackBaseException e) {
// Convert Keystone OpenStackResponseException to MsoOpenstackException
throw keystoneErrorToMsoException(e, "QueryTenant");
} catch (RuntimeException e) {
// Catch-all
throw runtimeExceptionToMsoException(e, "QueryTenant");
}
}
use of org.onap.so.openstack.beans.MsoTenant in project so by onap.
the class MsoKeystoneUtils method queryTenantByName.
/**
* Query for a tenant with the specified name in the given cloud. If the tenant exists, return an MsoTenant object.
* If not, return null. This query is useful if the client knows it has the tenant name, skipping an initial lookup
* by ID that would always fail.
* <p>
* For the AIC Cloud (DCP/LCP): it is not clear that cloudId is needed, as all admin requests go to the centralized
* identity service in DCP. However, if some artifact must exist in each local LCP instance as well, then it will be
* needed to access the correct region.
* <p>
*
* @param tenantName The name of the tenant to query
* @param cloudSiteId The cloud identifier (may be a region) in which to query the tenant.
* @return the tenant properties of the queried tenant, or null if not found
* @throws MsoOpenstackException Thrown if the Openstack API call returns an exception
*/
public MsoTenant queryTenantByName(String tenantName, String cloudSiteId) throws MsoException {
// Obtain the cloud site information where we will query the tenant
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
Keystone keystoneAdminClient = getKeystoneAdminClient(cloudSite);
try {
Tenant tenant = findTenantByName(keystoneAdminClient, tenantName);
if (tenant == null) {
return null;
}
Map<String, String> metadata = new HashMap<>();
if (cloudSite.getIdentityService().getTenantMetadata()) {
OpenStackRequest<Metadata> request = keystoneAdminClient.tenants().showMetadata(tenant.getId());
Metadata tenantMetadata = executeAndRecordOpenstackRequest(request);
if (tenantMetadata != null) {
metadata = tenantMetadata.getMetadata();
}
}
return new MsoTenant(tenant.getId(), tenant.getName(), metadata);
} catch (OpenStackBaseException e) {
// Convert Keystone OpenStackResponseException to MsoOpenstackException
throw keystoneErrorToMsoException(e, "QueryTenantName");
} catch (RuntimeException e) {
// Catch-all
throw runtimeExceptionToMsoException(e, "QueryTenantName");
}
}
use of org.onap.so.openstack.beans.MsoTenant in project so by onap.
the class MsoKeystoneUtilsTest method queryTenantByNameTest.
@Test
public void queryTenantByNameTest() throws Exception {
StubOpenStack.mockOpenStackGetTenantByName(wireMockServer, "tenant");
MsoTenant msoTenant = msoKeystoneUtils.queryTenantByName("tenant", "MTN13");
Assert.assertEquals("testingTenantName", msoTenant.getTenantName());
}
use of org.onap.so.openstack.beans.MsoTenant in project so by onap.
the class MsoKeystoneUtilsTest method queryTenantTest.
@Test
public void queryTenantTest() throws Exception {
StubOpenStack.mockOpenStackGetTenantById(wireMockServer, "tenantId");
MsoTenant msoTenant = msoKeystoneUtils.queryTenant("tenantId", "MTN13");
Assert.assertEquals("testingTenantName", msoTenant.getTenantName());
}
Aggregations