Search in sources :

Example 1 with Image

use of org.openstack4j.model.compute.Image 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 2 with Image

use of org.openstack4j.model.compute.Image in project so by onap.

the class HeatBridgeImplTest method testUpdateVserversToAaiNoHypervisorName.

@Test
@Ignore
public void testUpdateVserversToAaiNoHypervisorName() throws HeatBridgeException, JsonProcessingException {
    AaiHelper aaiHelper = new AaiHelper();
    VfModule module = new VfModule();
    RelationshipList relationships = new RelationshipList();
    List<Relationship> listRelationships = relationships.getRelationship();
    Relationship vnfcRelationship = new Relationship();
    vnfcRelationship.setRelationshipLabel("org.onap.relationships.inventory.Uses");
    vnfcRelationship.setRelatedTo("vnfc");
    vnfcRelationship.setRelatedLink("/aai/v22/network/vnfcs/vnfc/test-server1-name");
    listRelationships.add(vnfcRelationship);
    module.setRelationshipList(relationships);
    AAIResultWrapper wrapper = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(module));
    when(aaiResourcesClient.get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test-genericVnf-id").vfModule("test-vfModule-id")))).thenReturn(wrapper);
    aaiHelper.setAAIResourcesClient(aaiResourcesClient);
    heatbridge.setAAIHelper(aaiHelper);
    // Arrange
    Server server1 = mock(Server.class);
    when(server1.getId()).thenReturn("test-server1-id");
    when(server1.getHypervisorHostname()).thenReturn("");
    when(server1.getName()).thenReturn("test-server1-name");
    when(server1.getStatus()).thenReturn(Status.ACTIVE);
    when(server1.getLinks()).thenReturn(new ArrayList<>());
    Server server2 = mock(Server.class);
    when(server2.getId()).thenReturn("test-server2-id");
    when(server2.getName()).thenReturn("test-server2-name");
    when(server2.getStatus()).thenReturn(Status.ACTIVE);
    when(server2.getLinks()).thenReturn(new ArrayList<>());
    List<Server> servers = Arrays.asList(server1, server2);
    Image image = mock(Image.class);
    when(server1.getImage()).thenReturn(image);
    when(server2.getImage()).thenReturn(image);
    when(image.getId()).thenReturn("test-image-id");
    Flavor flavor = mock(Flavor.class);
    when(server1.getFlavor()).thenReturn(flavor);
    when(server2.getFlavor()).thenReturn(flavor);
    when(flavor.getId()).thenReturn("test-flavor-id");
    // Act
    heatbridge.buildAddVserversToAaiAction("test-genericVnf-id", "test-vfModule-id", servers);
    // Assert
    ArgumentCaptor<AAIResourceUri> captor = ArgumentCaptor.forClass(AAIResourceUri.class);
    verify(transaction, times(2)).create(captor.capture(), any());
    List<AAIResourceUri> uris = captor.getAllValues();
    assertEquals(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(CLOUD_OWNER, REGION_ID).tenant(TENANT_ID).vserver(server1.getId())), uris.get(0));
    assertEquals(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(CLOUD_OWNER, REGION_ID).tenant(TENANT_ID).vserver(server2.getId())), uris.get(1));
}
Also used : RelationshipList(org.onap.aai.domain.yang.RelationshipList) Server(org.openstack4j.model.compute.Server) AaiHelper(org.onap.so.heatbridge.helpers.AaiHelper) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Image(org.openstack4j.model.compute.Image) VfModule(org.onap.aai.domain.yang.VfModule) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) Flavor(org.openstack4j.model.compute.Flavor) Relationship(org.onap.aai.domain.yang.Relationship) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Image

use of org.openstack4j.model.compute.Image in project so by onap.

the class HeatBridgeImplTest method testUpdateVserversToAai.

@Test
@Ignore
public void testUpdateVserversToAai() throws HeatBridgeException, JsonProcessingException {
    AaiHelper helper = new AaiHelper();
    helper.setAAIResourcesClient(resourcesClient);
    heatbridge.setAAIHelper(helper);
    VfModule module = new VfModule();
    RelationshipList relationships = new RelationshipList();
    List<Relationship> listRelationships = relationships.getRelationship();
    Relationship vnfcRelationship = new Relationship();
    vnfcRelationship.setRelationshipLabel("org.onap.relationships.inventory.Uses");
    vnfcRelationship.setRelatedTo("vnfc");
    vnfcRelationship.setRelatedLink("/aai/v22/network/vnfcs/vnfc/test-server1-name");
    listRelationships.add(vnfcRelationship);
    module.setRelationshipList(relationships);
    AAIResultWrapper wrapper = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(module));
    when(aaiResourcesClient.get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test-genericVnf-id").vfModule("test-vfModule-id")))).thenReturn(wrapper);
    // Arrange
    Server server1 = mock(Server.class);
    when(server1.getId()).thenReturn("test-server1-id");
    when(server1.getHypervisorHostname()).thenReturn("test-hypervisor");
    when(server1.getName()).thenReturn("test-server1-name");
    when(server1.getStatus()).thenReturn(Status.ACTIVE);
    when(server1.getLinks()).thenReturn(new ArrayList<>());
    Server server2 = mock(Server.class);
    when(server2.getId()).thenReturn("test-server2-id");
    when(server2.getHypervisorHostname()).thenReturn("");
    when(server2.getName()).thenReturn("test-server2-name");
    when(server2.getStatus()).thenReturn(Status.ACTIVE);
    when(server2.getLinks()).thenReturn(new ArrayList<>());
    List<Server> servers = Arrays.asList(server1, server2);
    Image image = mock(Image.class);
    when(server1.getImage()).thenReturn(image);
    when(server2.getImage()).thenReturn(image);
    when(image.getId()).thenReturn("test-image-id");
    Flavor flavor = mock(Flavor.class);
    when(server1.getFlavor()).thenReturn(flavor);
    when(server2.getFlavor()).thenReturn(flavor);
    when(flavor.getId()).thenReturn("test-flavor-id");
    // Act
    heatbridge.buildAddVserversToAaiAction("test-genericVnf-id", "test-vfModule-id", servers);
    // Assert
    ArgumentCaptor<AAIResourceUri> captor = ArgumentCaptor.forClass(AAIResourceUri.class);
    verify(transaction, times(2)).create(captor.capture(), any());
    List<AAIResourceUri> uris = captor.getAllValues();
    assertEquals(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(CLOUD_OWNER, REGION_ID).tenant(TENANT_ID).vserver(server1.getId())), uris.get(0));
    assertEquals(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(CLOUD_OWNER, REGION_ID).tenant(TENANT_ID).vserver(server2.getId())), uris.get(1));
}
Also used : RelationshipList(org.onap.aai.domain.yang.RelationshipList) Server(org.openstack4j.model.compute.Server) AaiHelper(org.onap.so.heatbridge.helpers.AaiHelper) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Image(org.openstack4j.model.compute.Image) VfModule(org.onap.aai.domain.yang.VfModule) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) Flavor(org.openstack4j.model.compute.Flavor) Relationship(org.onap.aai.domain.yang.Relationship) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with Image

use of org.openstack4j.model.compute.Image in project so by onap.

the class HeatBridgeImplTest method testUpdateImagesToAai.

@Test
public void testUpdateImagesToAai() throws HeatBridgeException {
    // Arrange
    Image image1 = mock(Image.class);
    when(image1.getId()).thenReturn("test-image1-id");
    when(image1.getName()).thenReturn("test-image1-name");
    when(image1.getLinks()).thenReturn(new ArrayList<>());
    Image image2 = mock(Image.class);
    when(image2.getId()).thenReturn("test-image2-id");
    when(image2.getName()).thenReturn("test-image2-name");
    when(image2.getLinks()).thenReturn(new ArrayList<>());
    List<Image> images = Arrays.asList(image1, image2);
    // Act #1
    heatbridge.buildAddImagesToAaiAction(images);
    // Assert #1
    verify(transaction, times(2)).create(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.Image.class));
    // Act #2
    heatbridge.buildAddImagesToAaiAction(images);
    // Assert #2
    verify(transaction, times(4)).create(any(AAIResourceUri.class), any(org.onap.aai.domain.yang.Image.class));
}
Also used : AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Image(org.openstack4j.model.compute.Image) Test(org.junit.Test)

Aggregations

Image (org.openstack4j.model.compute.Image)4 Test (org.junit.Test)3 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)3 Flavor (org.openstack4j.model.compute.Flavor)3 Server (org.openstack4j.model.compute.Server)3 Ignore (org.junit.Ignore)2 Relationship (org.onap.aai.domain.yang.Relationship)2 RelationshipList (org.onap.aai.domain.yang.RelationshipList)2 VfModule (org.onap.aai.domain.yang.VfModule)2 AAICommonObjectMapperProvider (org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider)2 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)2 AaiHelper (org.onap.so.heatbridge.helpers.AaiHelper)2 ArrayList (java.util.ArrayList)1 CloudIdentity (org.onap.so.db.catalog.beans.CloudIdentity)1 CloudSite (org.onap.so.db.catalog.beans.CloudSite)1 HeatBridgeApi (org.onap.so.heatbridge.HeatBridgeApi)1 MsoCloudSiteNotFound (org.onap.so.openstack.exceptions.MsoCloudSiteNotFound)1 Resource (org.openstack4j.model.heat.Resource)1 Network (org.openstack4j.model.network.Network)1