Search in sources :

Example 21 with CloudSite

use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.

the class CreateAAIInventory method heatbridge.

public void heatbridge(CloudInformation cloudInformation) throws HeatBridgeException, MsoCloudSiteNotFound {
    CloudSite cloudSite = cloudConfig.getCloudSite(cloudInformation.getRegionId()).orElseThrow(() -> new MsoCloudSiteNotFound(cloudInformation.getRegionId()));
    if (cloudSite.getOrchestrator() != null && MULTICLOUD_MODE.equalsIgnoreCase(cloudSite.getOrchestrator())) {
        logger.debug("Skipping Heatbridge as CloudSite orchestrator is: " + MULTICLOUD_MODE);
        return;
    }
    CloudIdentity cloudIdentity = cloudSite.getIdentityService();
    String heatStackId = cloudInformation.getTemplateInstanceId().split("/")[1];
    List<String> oobMgtNetNames = new ArrayList<>();
    HeatBridgeApi heatBridgeClient = createClient(getAaiClient(), cloudSite, cloudIdentity, cloudInformation);
    heatBridgeClient.authenticate();
    List<Resource> stackResources = heatBridgeClient.queryNestedHeatStackResources(cloudInformation.getTemplateInstanceId());
    List<Network> osNetworks = heatBridgeClient.getAllOpenstackProviderNetworks(stackResources);
    heatBridgeClient.buildAddNetworksToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osNetworks);
    List<Server> osServers = heatBridgeClient.getAllOpenstackServers(stackResources);
    heatBridgeClient.createPserversAndPinterfacesIfNotPresentInAai(stackResources);
    List<Image> osImages = heatBridgeClient.extractOpenstackImagesFromServers(osServers);
    List<Flavor> osFlavors = heatBridgeClient.extractOpenstackFlavorsFromServers(osServers);
    logger.debug("Successfully queried heat stack{} for resources.", heatStackId);
    // os images
    if (osImages != null && !osImages.isEmpty()) {
        heatBridgeClient.buildAddImagesToAaiAction(osImages);
        logger.debug("Successfully built AAI actions to add images.");
    } else {
        logger.debug("No images to update to AAI.");
    }
    // flavors
    if (osFlavors != null && !osFlavors.isEmpty()) {
        heatBridgeClient.buildAddFlavorsToAaiAction(osFlavors);
        logger.debug("Successfully built AAI actions to add flavors.");
    } else {
        logger.debug("No flavors to update to AAI.");
    }
    // compute resources
    heatBridgeClient.buildAddVserversToAaiAction(cloudInformation.getVnfId(), cloudInformation.getVfModuleId(), osServers);
    logger.debug("Successfully queried compute resources and built AAI vserver actions.");
    // neutron resources
    List<String> oobMgtNetIds = new ArrayList<>();
    // if no network-id list is provided, however network-name list is
    if (!CollectionUtils.isEmpty(oobMgtNetNames)) {
        oobMgtNetIds = heatBridgeClient.extractNetworkIds(oobMgtNetNames);
    }
    heatBridgeClient.buildAddVserverLInterfacesToAaiAction(stackResources, oobMgtNetIds, cloudInformation.getOwner());
    logger.debug("Successfully queried neutron resources and built AAI actions to add l-interfaces to vservers.");
    heatBridgeClient.buildAddVolumes(stackResources);
    // Update AAI
    logger.debug("Current Dry Run Value: {}", env.getProperty("heatBridgeDryrun", Boolean.class, false));
    heatBridgeClient.submitToAai(env.getProperty("heatBridgeDryrun", Boolean.class, false));
}
Also used : MsoCloudSiteNotFound(org.onap.so.openstack.exceptions.MsoCloudSiteNotFound) Server(org.openstack4j.model.compute.Server) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) ArrayList(java.util.ArrayList) Resource(org.openstack4j.model.heat.Resource) Image(org.openstack4j.model.compute.Image) Flavor(org.openstack4j.model.compute.Flavor) CloudSite(org.onap.so.db.catalog.beans.CloudSite) HeatBridgeApi(org.onap.so.heatbridge.HeatBridgeApi) Network(org.openstack4j.model.network.Network)

Example 22 with CloudSite

use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.

the class CloudConfigTest method createCloudSiteRest_TEST.

@Test
@Transactional
public void createCloudSiteRest_TEST() {
    headers.set("Accept", MediaType.APPLICATION_JSON);
    headers.set("Content-Type", MediaType.APPLICATION_JSON);
    CloudSite cloudSite = new CloudSite();
    cloudSite.setId("MTN7");
    cloudSite.setClli("TESTCLLI");
    cloudSite.setRegionId("regionId");
    cloudSite.setCloudVersion("VERSION");
    cloudSite.setPlatform("PLATFORM");
    CloudIdentity cloudIdentity = new CloudIdentity();
    cloudIdentity.setId("RANDOMID-test");
    cloudIdentity.setIdentityUrl("URL");
    cloudIdentity.setMsoId("MSO_ID");
    cloudIdentity.setMsoPass("MSO_PASS");
    cloudIdentity.setAdminTenant("ADMIN_TENANT");
    cloudIdentity.setMemberRole("ROLE");
    cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
    cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
    cloudSite.setIdentityService(cloudIdentity);
    String uri = "/cloudSite";
    UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + uri);
    HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers);
    ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, request, String.class);
    assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
    builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + uri + "/" + cloudSite.getId());
    HttpEntity<String> entity = new HttpEntity<String>(null, headers);
    ResponseEntity<CloudSite> actualCloudSite = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, CloudSite.class);
    builder = UriComponentsBuilder.fromHttpUrl("http://localhost:" + port + uri);
    ResponseEntity<String> cloudSiteString = restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
    System.out.println(cloudSiteString.getBody());
    assertEquals(Response.Status.OK.getStatusCode(), actualCloudSite.getStatusCode().value());
    assertThat(actualCloudSite.getBody(), sameBeanAs(cloudSite).ignoring("created").ignoring("updated").ignoring("identityService.created").ignoring("identityService.updated"));
}
Also used : HttpEntity(org.springframework.http.HttpEntity) CloudSite(org.onap.so.db.catalog.beans.CloudSite) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest) Transactional(javax.transaction.Transactional)

Example 23 with CloudSite

use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.

the class CatalogDbClientTest method testGetCloudSiteByClliAndAicVersionNotFound.

@Test
public void testGetCloudSiteByClliAndAicVersionNotFound() throws Exception {
    CloudSite cloudSite = client.getCloudSiteByClliAndAicVersion("MDT13", "232496239746328");
    assertNull(cloudSite);
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

Example 24 with CloudSite

use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.

the class CatalogDbClientTest method testCloudSiteClient.

@Test
public void testCloudSiteClient() {
    CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger("http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort);
    CloudSite cloudSite = new CloudSite();
    cloudSite.setId("MTN6");
    cloudSite.setClli("TESTCLLI");
    cloudSite.setRegionId("regionId");
    cloudSite.setCloudVersion("VERSION");
    cloudSite.setPlatform("PLATFORM");
    CloudIdentity cloudIdentity = new CloudIdentity();
    cloudIdentity.setId("RANDOMID");
    cloudIdentity.setIdentityUrl("URL");
    cloudIdentity.setMsoId("MSO_ID");
    cloudIdentity.setMsoPass("MSO_PASS");
    cloudIdentity.setAdminTenant("ADMIN_TENANT");
    cloudIdentity.setMemberRole("ROLE");
    cloudIdentity.setIdentityServerType(ServerType.KEYSTONE);
    cloudIdentity.setIdentityAuthenticationType(AuthenticationType.RACKSPACE_APIKEY);
    cloudSite.setIdentityService(cloudIdentity);
    localClient.postCloudSite(cloudSite);
    CloudSite getCloudSite = this.client.getCloudSite("MTN6");
    assertNotNull(getCloudSite);
    assertNotNull(getCloudSite.getIdentityService());
    assertEquals("TESTCLLI", getCloudSite.getClli());
    assertEquals("regionId", getCloudSite.getRegionId());
    assertEquals("RANDOMID", getCloudSite.getIdentityServiceId());
    getCloudSite.setClli("clli2");
    getCloudSite.setRegionId("region2");
    CloudSite updatedCloudSite = this.client.updateCloudSite(getCloudSite);
    assertNotNull(updatedCloudSite);
    assertNotNull(updatedCloudSite.getIdentityService());
    assertEquals("clli2", updatedCloudSite.getClli());
    assertEquals("region2", updatedCloudSite.getRegionId());
    this.client.deleteCloudSite(getCloudSite.getId());
    getCloudSite = this.client.getCloudSite("MTN6");
    assertNull(getCloudSite);
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite) CloudIdentity(org.onap.so.db.catalog.beans.CloudIdentity) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

Example 25 with CloudSite

use of org.onap.so.db.catalog.beans.CloudSite in project so by onap.

the class CatalogDbClientTest method testGetCloudSiteHappyPath.

@Test
public void testGetCloudSiteHappyPath() throws Exception {
    CloudSite cloudSite = client.getCloudSite(MTN13);
    assertNotNull(cloudSite);
    assertNotNull(cloudSite.getIdentityService());
    assertEquals("MDT13", cloudSite.getClli());
    assertEquals("mtn13", cloudSite.getRegionId());
    assertEquals("MTN13", cloudSite.getIdentityServiceId());
}
Also used : CloudSite(org.onap.so.db.catalog.beans.CloudSite) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

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