use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class HeatBridgeImpl method getPserverToPciIdMap.
private Map<String, List<String>> getPserverToPciIdMap(List<AAIResourceUri> vserverUris) {
Map<String, List<String>> pserverToPciIdMap = new HashMap<>();
for (AAIResourceUri vserverUri : vserverUris) {
AAIResultWrapper vserverWrapper = resourcesClient.get(vserverUri.depth(Depth.TWO));
Optional<Relationships> vserverRelationships = vserverWrapper.getRelationships();
if (vserverRelationships.isPresent() && CollectionUtils.isNotEmpty(vserverRelationships.get().getRelatedLinks(Types.PSERVER))) {
Vserver vserver = vserverWrapper.asBean(Vserver.class).get();
List<String> pciIds = HeatBridgeUtils.extractPciIdsFromVServer(vserver);
if (CollectionUtils.isNotEmpty(pciIds)) {
List<AAIResourceUri> matchingPservers = vserverRelationships.get().getRelatedUris(Types.PSERVER);
if (matchingPservers != null && matchingPservers.size() == 1) {
pserverToPciIdMap.put(matchingPservers.get(0).getURIKeys().get("hostname"), pciIds);
}
}
}
}
return pserverToPciIdMap;
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper 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));
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper 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));
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class BBInputSetup method mapPlatform.
protected void mapPlatform(List<AAIResultWrapper> platforms, GenericVnf genericVnf) {
if (!platforms.isEmpty()) {
AAIResultWrapper platformWrapper = platforms.get(0);
Optional<org.onap.aai.domain.yang.Platform> aaiPlatformOp = platformWrapper.asBean(org.onap.aai.domain.yang.Platform.class);
if (aaiPlatformOp.isPresent()) {
Platform platform = this.mapperLayer.mapAAIPlatform(aaiPlatformOp.get());
genericVnf.setPlatform(platform);
}
}
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class BBInputSetup method mapPnf.
protected Pnf mapPnf(AAIResourceUri aaiResourceUri) {
AAIResultWrapper aaiPnfWrapper = this.bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri);
Optional<org.onap.aai.domain.yang.Pnf> aaiPnfWrapperOp = aaiPnfWrapper.asBean(org.onap.aai.domain.yang.Pnf.class);
return aaiPnfWrapperOp.map(pnf -> this.mapperLayer.mapAAIPnfIntoPnf(pnf)).orElse(null);
}
Aggregations