Search in sources :

Example 26 with CloudSite

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)));
}
Also used : CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) CloudSite(org.onap.so.db.catalog.beans.CloudSite) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 27 with CloudSite

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));
}
Also used : CloudRegion(org.onap.aai.domain.yang.CloudRegion) CloudSite(org.onap.so.db.catalog.beans.CloudSite) Test(org.junit.Test)

Example 28 with CloudSite

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);
    }
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) Access(com.woorea.openstack.keystone.model.Access) KeystoneAuthHolder(org.onap.so.cloud.authentication.KeystoneAuthHolder) MsoAdapterException(org.onap.so.openstack.exceptions.MsoAdapterException) ServiceEndpointNotFoundException(org.onap.so.cloud.authentication.ServiceEndpointNotFoundException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) CloudSite(org.onap.so.db.catalog.beans.CloudSite) MsoIOException(org.onap.so.openstack.exceptions.MsoIOException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException)

Example 29 with CloudSite

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;
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) MsoTenant(org.onap.so.openstack.beans.MsoTenant) Tenant(com.woorea.openstack.keystone.model.Tenant) Keystone(com.woorea.openstack.keystone.Keystone) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) CloudSite(org.onap.so.db.catalog.beans.CloudSite)

Example 30 with CloudSite

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();
    }
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Quantum(com.woorea.openstack.quantum.Quantum) MsoException(org.onap.so.openstack.exceptions.MsoException) CloudSite(org.onap.so.db.catalog.beans.CloudSite) Port(com.woorea.openstack.quantum.model.Port)

Aggregations

CloudSite (org.onap.so.db.catalog.beans.CloudSite)54 Test (org.junit.Test)25 MsoCloudSiteNotFound (org.onap.so.openstack.exceptions.MsoCloudSiteNotFound)13 CloudIdentity (org.onap.so.db.catalog.beans.CloudIdentity)12 MsoException (org.onap.so.openstack.exceptions.MsoException)12 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)9 StackInfo (org.onap.so.openstack.beans.StackInfo)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 BaseTest (org.onap.so.BaseTest)7 CatalogDbAdapterBaseTest (org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)6 Keystone (com.woorea.openstack.keystone.Keystone)5 Quantum (com.woorea.openstack.quantum.Quantum)5 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)5 OpenStackRequest (com.woorea.openstack.base.client.OpenStackRequest)4 Heat (com.woorea.openstack.heat.Heat)4 Tenant (com.woorea.openstack.keystone.model.Tenant)4 Network (com.woorea.openstack.quantum.model.Network)4 MsoTenant (org.onap.so.openstack.beans.MsoTenant)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)3