use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class BaseRestTestUtils method setUp.
/**
* Before each test execution, updating IdentityUrl port value to the ramdom wireMockPort Since URL will be used as
* a rest call and required to be mocked in unit tests
*/
@Before
public void setUp() throws Exception {
wireMockServer.resetAll();
mapper = new ObjectMapper();
CloudIdentity identity = new CloudIdentity();
identity.setId("DEFAULT");
identity.setMsoId("m93945");
identity.setMsoPass("89C9F27833AC49FE4164F3608CADE7BCF40357977607A7E4B899F9A046C0071C75F7347A47308EF9FB6620214264B1");
identity.setAdminTenant("admin");
identity.setMemberRole("admin");
identity.setTenantMetadata(new Boolean(true));
identity.setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint);
identity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD);
CloudSite cloudSite = new CloudSite();
cloudSite.setId("MTN13");
cloudSite.setCloudVersion("3.0");
cloudSite.setClli("MDT13");
cloudSite.setRegionId("mtn13");
cloudSite.setOrchestrator(orchestrator);
identity.setIdentityServerType(ServerType.KEYSTONE);
cloudSite.setIdentityService(identity);
wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")).willReturn(aResponse().withBody(getBody(mapper.writeValueAsString(cloudSite), wireMockPort, "")).withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class CloudRegionRestImplTest method mapCloudRegionVersionGreaterThan3Test.
@Test
public void mapCloudRegionVersionGreaterThan3Test() {
CloudSite cloudSite2 = new CloudSite();
cloudSite2.setCloudVersion("3.0.1");
cloudSite2.setRegionId("region1");
cloudSite2.setCloudOwner("bob");
CloudRegion mappedRegion = cloudRestImpl.mapCloudRegion(cloudSite2);
CloudRegion testRegion2 = new CloudRegion();
testRegion2.setCloudOwner("bob");
testRegion2.setCloudRegionId("region1");
testRegion2.setCloudRegionVersion("3.0.1");
testRegion2.setInMaint(false);
testRegion2.setOrchestrationDisabled(false);
testRegion2.setOwnerDefinedType("cLCP");
testRegion2.setCloudType("openstack");
testRegion2.setCloudZone("region");
assertThat(mappedRegion, sameBeanAs(testRegion2));
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class MsoCommonUtils method getKeystoneAuthHolder.
/**
* Gets the Keystone Authorization
*
* @param cloudSite the cloud site
* @param tenantId the tenant id
* @return the Neutron client
* @throws MsoException the mso exception
*/
protected KeystoneAuthHolder getKeystoneAuthHolder(String cloudSiteId, String tenantId, String serviceName) throws MsoException {
CloudIdentity cloudIdentity = null;
try {
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
String cloudId = cloudSite.getId();
String region = cloudSite.getRegionId();
cloudIdentity = cloudSite.getIdentityService();
MsoTenantUtils tenantUtils = tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
Access access = getKeystone(tenantId, cloudIdentity, keystoneUrl);
try {
KeystoneAuthHolder keystoneAuthV2 = new KeystoneAuthHolder();
keystoneAuthV2.setServiceUrl(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), serviceName, region, "public"));
keystoneAuthV2.setId(access.getToken().getId());
return keystoneAuthV2;
} catch (RuntimeException e) {
String error = "Openstack did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
throw new MsoAdapterException(error, e);
}
} else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
try {
return keystoneV3Authentication.getToken(cloudSite, tenantId, serviceName);
} catch (ServiceEndpointNotFoundException e) {
String error = "cloud did not match an orchestration service for: region=" + region + ",cloud=" + cloudIdentity.getIdentityUrl();
throw new MsoAdapterException(error, e);
}
} else {
throw new MsoAdapterException("Unknown Keystone Server Type");
}
} catch (OpenStackResponseException e) {
if (e.getStatus() == 401) {
String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId();
throw new MsoAdapterException(error);
} else {
throw keystoneErrorToMsoException(e, TOKEN_AUTH);
}
} catch (OpenStackConnectException e) {
MsoIOException me = new MsoIOException(e.getMessage(), e);
me.addContext(TOKEN_AUTH);
throw me;
} catch (RuntimeException e) {
throw runtimeExceptionToMsoException(e, TOKEN_AUTH);
}
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class MsoKeystoneUtils method deleteTenant.
/**
* Delete the specified Tenant (by ID) in the given cloud. This method returns true or false, depending on whether
* the tenant existed and was successfully deleted, or if the tenant already did not exist. Both cases are treated
* as success (no Exceptions).
* <p>
* Note for the AIC Cloud (DCP/LCP): all admin requests go to the centralized identity service in DCP. So deleting a
* tenant from one cloudSiteId will remove it from all sites managed by that identity service.
* <p>
*
* @param tenantId The Openstack ID of the tenant to delete
* @param cloudSiteId The cloud identifier from which to delete the tenant.
* @return true if the tenant was deleted, false if the tenant did not exist.
* @throws MsoOpenstackException If the Openstack API call returns an exception.
*/
public boolean deleteTenant(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);
try {
// Check that the tenant exists. Also, need the ID to delete
Tenant tenant = findTenantById(keystoneAdminClient, tenantId);
if (tenant == null) {
LOGGER.error("{} Tenant id {} not found on cloud site id {}, {}", MessageEnum.RA_TENANT_NOT_FOUND, tenantId, cloudSiteId, ErrorCode.DataError.getValue());
return false;
}
OpenStackRequest<Void> request = keystoneAdminClient.tenants().delete(tenant.getId());
executeAndRecordOpenstackRequest(request);
LOGGER.debug("Deleted Tenant {} ({})", tenant.getId(), tenant.getName());
} catch (OpenStackBaseException e) {
// Convert Keystone OpenStackResponseException to MsoOpenstackException
throw keystoneErrorToMsoException(e, DELETE_TENANT);
} catch (RuntimeException e) {
// Catch-all
throw runtimeExceptionToMsoException(e, DELETE_TENANT);
}
return true;
}
use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.
the class MsoNeutronUtils method getNeutronPort.
public Optional<Port> getNeutronPort(String neutronPortId, String tenantId, String cloudSiteId) {
try {
logger.debug("Finding Neutron port:" + neutronPortId);
CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
Quantum neutronClient = getNeutronClient(cloudSite, tenantId);
Port port = findPortById(neutronClient, neutronPortId);
if (port == null) {
return Optional.empty();
}
return Optional.of(port);
} catch (RuntimeException | MsoException e) {
logger.error("Error retrieving neutron port", e);
return Optional.empty();
}
}
Aggregations