use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.
the class WorkflowAction method getRelatedResourcesInVfModule.
protected <T> List<T> getRelatedResourcesInVfModule(String vnfId, String vfModuleId, Class<T> resultClass, AAIObjectName name) {
List<T> vnfcs = new ArrayList<>();
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId));
AAIResultWrapper vfModuleResultsWrapper = bbInputSetupUtils.getAAIResourceDepthOne(uri);
Optional<Relationships> relationshipsOp = vfModuleResultsWrapper.getRelationships();
if (relationshipsOp.isEmpty()) {
logger.debug("No relationships were found for vfModule in AAI");
} else {
Relationships relationships = relationshipsOp.get();
List<AAIResultWrapper> vnfcResultWrappers = relationships.getByType(name);
for (AAIResultWrapper vnfcResultWrapper : vnfcResultWrappers) {
Optional<T> vnfcOp = vnfcResultWrapper.asBean(resultClass);
vnfcOp.ifPresent(vnfcs::add);
}
}
return vnfcs;
}
use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.
the class ServiceEBBLoader method getExistingAAIVrfConfiguration.
protected String getExistingAAIVrfConfiguration(RelatedInstance relatedVpnBinding, org.onap.aai.domain.yang.L3Network aaiLocalNetwork) throws JsonProcessingException, VrfBondingServiceException {
Optional<Relationships> relationshipsOp = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiLocalNetwork)).getRelationships();
if (relationshipsOp.isPresent()) {
List<AAIResultWrapper> configurationsRelatedToLocalNetwork = relationshipsOp.get().getByType(AAIFluentTypeBuilder.Types.CONFIGURATION);
if (configurationsRelatedToLocalNetwork.size() > 1) {
throw new VrfBondingServiceException("Network: " + aaiLocalNetwork.getNetworkId() + " has more than 1 configuration related to it");
}
if (configurationsRelatedToLocalNetwork.size() == 1) {
AAIResultWrapper configWrapper = configurationsRelatedToLocalNetwork.get(0);
Optional<Configuration> relatedConfiguration = configWrapper.asBean(Configuration.class);
if (relatedConfiguration.isPresent() && vrfConfigurationAlreadyExists(relatedVpnBinding, relatedConfiguration.get(), configWrapper)) {
return relatedConfiguration.get().getConfigurationId();
}
}
}
return null;
}
use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.
the class VnfEBBLoader method findConfigurationsInsideVfModule.
private void findConfigurationsInsideVfModule(DelegateExecution execution, org.onap.aai.domain.yang.VfModule aaiVfModule, List<Resource> resourceList, Resource vfModuleResource, List<Pair<WorkflowType, String>> aaiResourceIds) {
try {
AAIResultWrapper vfModuleWrapper = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(aaiVfModule));
Optional<Relationships> relationshipsOp;
relationshipsOp = vfModuleWrapper.getRelationships();
if (relationshipsOp.isPresent()) {
relationshipsOp = workflowActionUtils.extractRelationshipsVnfc(relationshipsOp.get());
addConfigToResources(relationshipsOp, resourceList, vfModuleResource, aaiResourceIds);
}
} catch (Exception ex) {
logger.error("Exception in findConfigurationsInsideVfModule", ex);
buildAndThrowException(execution, "Failed to find Configuration object from the vfModule.");
}
}
use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.
the class WorkflowActionExtractResourcesAAITest method extractRelationshipsVpnBindingSuccess.
@Test
public void extractRelationshipsVpnBindingSuccess() {
// given
Relationships relationships = mock(Relationships.class);
AAIResourceUri aaiResourceUri = mock(AAISimpleUri.class);
List<AAIResourceUri> aaiResourceUriList = new ArrayList<>();
aaiResourceUriList.add(aaiResourceUri);
when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(aaiResourceUriList);
AAIResultWrapper aaiResultWrapper = new AAIResultWrapper("{\"vpn-id\" : \"" + VPN_ID + "\"}");
when(bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri)).thenReturn(aaiResultWrapper);
// when
Optional<VpnBinding> resultOpt = testedObject.extractRelationshipsVpnBinding(relationships);
// then
assertThat(resultOpt).isNotEmpty();
assertThat(resultOpt.get().getVpnId()).isEqualTo(VPN_ID);
}
use of org.onap.aaiclient.client.aai.entities.Relationships in project so by onap.
the class WorkflowActionExtractResourcesAAITest method extractRelationshipsVnfc_noRelationFoundList.
@Test
public void extractRelationshipsVnfc_noRelationFoundList() {
// given
Relationships relationships = mock(Relationships.class);
when(relationships.getByType(Types.VNFC)).thenReturn(getConfigurationList("{\"jsonWithNoRelation\": {}}"));
// when
Optional<Relationships> resultOpt = testedObject.extractRelationshipsVnfc(relationships);
// then
assertThat(resultOpt).isEmpty();
}
Aggregations