Search in sources :

Example 26 with Relationships

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;
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 27 with Relationships

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;
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Configuration(org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) VrfBondingServiceException(org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 28 with Relationships

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.");
    }
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 29 with Relationships

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);
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) VpnBinding(org.onap.aai.domain.yang.VpnBinding) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Example 30 with Relationships

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();
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Test(org.junit.Test)

Aggregations

Relationships (org.onap.aaiclient.client.aai.entities.Relationships)36 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)27 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)20 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)10 AAICommonObjectMapperProvider (org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider)6 Configuration (org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration)6 HashMap (java.util.HashMap)4 List (java.util.List)4 VpnBinding (org.onap.aai.domain.yang.VpnBinding)4 IPAddressString (inet.ipaddr.IPAddressString)3 RelationshipList (org.onap.aai.domain.yang.RelationshipList)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 NotFoundException (javax.ws.rs.NotFoundException)2