use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class NetworkBBUtilsTest method isRelationshipRelatedToExistsTrueTest.
@Test
public void isRelationshipRelatedToExistsTrueTest() throws Exception {
final String aaiResponse = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "unassignNetworkBB_queryAAIResponse_.json")));
AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiResponse);
Optional<L3Network> l3network = aaiResultWrapper.asBean(L3Network.class);
boolean isVfModule = networkBBUtils.isRelationshipRelatedToExists(l3network, "vf-module");
assertTrue(isVfModule);
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class HeatBridgeImpl method deleteVfModuleData.
@Override
public void deleteVfModuleData(@Nonnull final String vnfId, @Nonnull final String vfModuleId) throws HeatBridgeException {
Objects.requireNonNull(vnfId, "Null vnf-id!");
Objects.requireNonNull(vfModuleId, "Null vf-module-id!");
try {
AAIResultWrapper vfModule = resourcesClient.get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId)).depth(Depth.ONE), NotFoundException.class);
Optional<Relationships> relationships = vfModule.getRelationships();
logger.debug("VfModule contains relationships in AAI: {}", relationships.isPresent());
if (relationships.isPresent()) {
deleteL3Networks(relationships.get());
List<AAIResourceUri> vserverUris = relationships.get().getRelatedUris(Types.VSERVER);
logger.debug("VServer contains {} relationships in AAI", vserverUris.size());
createTransactionToDeleteSriovPfFromPserver(vserverUris);
if (!vserverUris.isEmpty()) {
for (AAIResourceUri vserverUri : vserverUris) {
if (env.getProperty("heatBridgeDryrun", Boolean.class, false)) {
logger.debug("Would delete Vserver: {}", vserverUri.build().toString());
} else {
resourcesClient.deleteIfExists(vserverUri);
}
}
}
}
} catch (NotFoundException e) {
String msg = "Failed to commit delete heatbridge data transaction";
logger.debug(msg + " with error: " + e);
throw new HeatBridgeException(msg, e);
} catch (Exception e) {
String msg = "Failed to commit delete heatbridge data transaction";
logger.debug(msg + " with error: " + e);
throw new HeatBridgeException(msg, e);
}
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class HeatBridgeImpl method buildAddVserversToAaiAction.
@Override
public void buildAddVserversToAaiAction(final String genericVnfId, final String vfModuleId, final List<Server> servers) throws HeatBridgeException {
for (Server server : servers) {
Vserver vserver = aaiHelper.buildVserver(server.getId(), server);
// Build vserver relationships to: image, flavor, pserver, vf-module
vserver.setRelationshipList(aaiHelper.getVserverRelationshipList(cloudOwner, cloudRegionId, genericVnfId, vfModuleId, server));
AAIResourceUri vserverUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(vserver.getVserverId()));
if (resourcesClient.exists(vserverUri)) {
AAIResultWrapper existingVserver = resourcesClient.get(vserverUri);
AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
if (!existingVserver.hasRelationshipsTo(Types.VNFC)) {
AAIResultWrapper vfModule = resourcesClient.get(vfModuleUri);
if (vfModule.hasRelationshipsTo(Types.VNFC)) {
List<AAIResourceUri> vnfcUris = vfModule.getRelationships().get().getRelatedUris(Types.VNFC);
Optional<AAIResourceUri> foundVnfcURI = vnfcUris.stream().filter(resourceUri -> resourceUri.getURIKeys().get("vnfc-name").startsWith(vserver.getVserverName())).findFirst();
if (foundVnfcURI.isEmpty()) {
throw new HeatBridgeException("Cannot Find VNFC to create edge to VServer");
}
transaction.connect(vserverUri, foundVnfcURI.get());
} else {
/*
* throw new HeatBridgeException(
* "VF Module contains no relationships to VNFCS, cannot build edge to VServer");
*/
}
}
if (!existingVserver.hasRelationshipsTo(Types.VF_MODULE)) {
transaction.connect(vserverUri, vfModuleUri);
}
if (!existingVserver.hasRelationshipsTo(Types.PSERVER)) {
AAIResourceUri pServerUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(server.getHypervisorHostname()));
transaction.connect(vserverUri, pServerUri);
}
} else {
transaction.create(vserverUri, vserver);
}
}
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class AaiHelper method createVnfRelationshiptoVserver.
public Relationship createVnfRelationshiptoVserver(String vserverName, String genericVnfId, String vfModuleId) throws HeatBridgeException {
AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
AAIResultWrapper vfModule = resourcesClient.get(vfModuleUri);
if (vfModule.hasRelationshipsTo(Types.VNFC)) {
List<AAIResourceUri> vnfcUris = vfModule.getRelationships().get().getRelatedUris(Types.VNFC);
Optional<AAIResourceUri> foundVnfcURI = vnfcUris.stream().filter(resourceUri -> resourceUri.getURIKeys().get("vnfc-name").startsWith(vserverName)).findFirst();
if (!foundVnfcURI.isPresent()) {
throw new HeatBridgeException("Cannot Find VNFC to create edge to VServer");
} else {
return buildRelationship(foundVnfcURI.get());
}
} else {
throw new HeatBridgeException("VF Module contains no relationships to VNFCS, cannot build edge to VServer");
}
}
use of org.onap.aaiclient.client.aai.entities.AAIResultWrapper in project so by onap.
the class AAIQueryTasks method querySubnet.
public void querySubnet(BuildingBlockExecution execution) {
try {
L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
AAIResultWrapper aaiResultWrapper = aaiNetworkResources.queryNetworkWrapperById(l3network);
Optional<Relationships> networkRelationships = aaiResultWrapper.getRelationships();
if (!networkRelationships.isPresent()) {
throw (new Exception(ERROR_MSG));
}
List<AAIResourceUri> subnetsUriList = networkRelationships.get().getRelatedUris(Types.SUBNET);
if (!subnetsUriList.isEmpty()) {
for (AAIResourceUri subnetUri : subnetsUriList) {
Optional<Subnet> oSubnet = aaiNetworkResources.getSubnet(subnetUri);
if (oSubnet.isPresent()) {
l3network.getSubnets().add(modelMapper.map(oSubnet.get(), org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet.class));
}
}
}
} catch (Exception ex) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
}
}
Aggregations