Search in sources :

Example 1 with AAIPluralResourceUri

use of org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri in project so by onap.

the class AAICreateTasks method createNetworkPolicies.

/**
 * This method is used to put the network policy in A&AI.
 *
 * @param execution @throws
 */
public void createNetworkPolicies(BuildingBlockExecution execution) {
    try {
        String fqdns = execution.getVariable(CONTRAIL_NETWORK_POLICY_FQDN_LIST);
        if (fqdns != null && !fqdns.isEmpty()) {
            String[] fqdnList = fqdns.split(",");
            int fqdnCount = fqdnList.length;
            if (fqdnCount > 0) {
                for (int i = 0; i < fqdnCount; i++) {
                    String fqdn = fqdnList[i];
                    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicies());
                    uri.queryParam(NETWORK_POLICY_FQDN_PARAM, fqdn);
                    Optional<org.onap.aai.domain.yang.NetworkPolicy> oNetPolicy = aaiNetworkResources.getNetworkPolicy(uri);
                    if (!oNetPolicy.isPresent()) {
                        logger.debug("This network policy FQDN is not in AAI yet: {}", fqdn);
                        String networkPolicyId = UUID.randomUUID().toString();
                        logger.debug("Adding network-policy with network-policy-id {}", networkPolicyId);
                        NetworkPolicy networkPolicy = new NetworkPolicy();
                        networkPolicy.setNetworkPolicyId(networkPolicyId);
                        networkPolicy.setNetworkPolicyFqdn(fqdn);
                        networkPolicy.setHeatStackId(execution.getVariable(HEAT_STACK_ID));
                        aaiNetworkResources.createNetworkPolicy(networkPolicy);
                    }
                }
            }
        }
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) NetworkPolicy(org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy) BBObjectNotFoundException(org.onap.so.client.exception.BBObjectNotFoundException)

Example 2 with AAIPluralResourceUri

use of org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri in project so by onap.

the class AAIDeleteTasks method deleteNetworkPolicies.

public void deleteNetworkPolicies(BuildingBlockExecution execution) {
    try {
        String fqdns = execution.getVariable(contrailNetworkPolicyFqdnList);
        if (fqdns != null && !fqdns.isEmpty()) {
            String[] fqdnList = fqdns.split(",");
            int fqdnCount = fqdnList.length;
            if (fqdnCount > 0) {
                for (int i = 0; i < fqdnCount; i++) {
                    String fqdn = fqdnList[i];
                    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().networkPolicies());
                    uri.queryParam(networkPolicyFqdnParam, fqdn);
                    Optional<NetworkPolicies> oNetPolicies = aaiNetworkResources.getNetworkPolicies(uri);
                    if (oNetPolicies.isPresent()) {
                        NetworkPolicies networkPolicies = oNetPolicies.get();
                        List<NetworkPolicy> networkPolicyList = networkPolicies.getNetworkPolicy();
                        if (networkPolicyList != null && !networkPolicyList.isEmpty()) {
                            NetworkPolicy networkPolicy = networkPolicyList.get(0);
                            String networkPolicyId = networkPolicy.getNetworkPolicyId();
                            logger.debug("Deleting network-policy with network-policy-id {}", networkPolicyId);
                            aaiNetworkResources.deleteNetworkPolicy(networkPolicyId);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) NetworkPolicy(org.onap.aai.domain.yang.NetworkPolicy) NetworkPolicies(org.onap.aai.domain.yang.NetworkPolicies)

Example 3 with AAIPluralResourceUri

use of org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri in project so by onap.

the class CreateVFModule method getNodeType.

protected NodeType getNodeType(CloudRegion cloudRegion) {
    AAIResourceUri cloudRegionUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()));
    AAIResourcesClient client = getAAIClient();
    Optional<Relationships> relationships = client.get(cloudRegionUri).getRelationships();
    if (relationships.isPresent()) {
        AAIPluralResourceUri networkTechsGreenfieldUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId())).relatedTo(Types.NETWORK_TECHNOLOGIES.getFragment()).queryParam("network-technology-name", NodeType.GREENFIELD.getNetworkTechnologyName());
        AAIResultWrapper networkTechsGreenfield = client.get(networkTechsGreenfieldUri);
        if (networkTechsGreenfield != null && !networkTechsGreenfield.isEmpty()) {
            return NodeType.GREENFIELD;
        }
    }
    return NodeType.BROWNFIELD;
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 4 with AAIPluralResourceUri

use of org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri in project so by onap.

the class AAIDataRetrievalTest method getVolumeGroupsOfVnfTest.

@Test
public void getVolumeGroupsOfVnfTest() throws Exception {
    VolumeGroups volumeGroups = getVolumeGroups();
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId")).relatedTo(Types.VOLUME_GROUPS.getFragment());
    doReturn(Optional.of(volumeGroups)).when(aaiResourcesClient).get(VolumeGroups.class, uri);
    List<VolumeGroup> volumeGroupList = aaiDataRetrieval.getVolumeGroupsOfVnf("vnfId");
    assertEquals("vg1", volumeGroupList.get(0).getVolumeGroupId());
    Optional<String> volumeGroupIds = aaiDataRetrieval.getVolumeGroupIdsByVnfId("vnfId");
    assertEquals(Optional.of("vg1,vg2"), volumeGroupIds);
}
Also used : AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) VolumeGroup(org.onap.aai.domain.yang.VolumeGroup) VolumeGroups(org.onap.aai.domain.yang.VolumeGroups) Test(org.junit.Test)

Example 5 with AAIPluralResourceUri

use of org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri in project so by onap.

the class AAIDataRetrievalTest method getVfModulesOfVnfTest.

@Test
public void getVfModulesOfVnfTest() {
    VfModules vfModules = getVfModules();
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId").vfModules());
    doReturn(Optional.of(vfModules)).when(aaiResourcesClient).get(VfModules.class, uri);
    List<VfModule> vfModulesList = aaiDataRetrieval.getVfModulesOfVnf("vnfId");
    assertEquals("vfm1", vfModulesList.get(0).getVfModuleId());
    Optional<String> vfModuleIds = aaiDataRetrieval.getVfModuleIdsByVnfId("vnfId");
    assertEquals(Optional.of("vfm1,vfm2"), vfModuleIds);
}
Also used : VfModules(org.onap.aai.domain.yang.VfModules) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) VfModule(org.onap.aai.domain.yang.VfModule) Test(org.junit.Test)

Aggregations

AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)44 Test (org.junit.Test)29 GenericVnf (org.onap.aai.domain.yang.GenericVnf)7 GenericVnfs (org.onap.aai.domain.yang.GenericVnfs)6 RestClient (org.onap.so.client.RestClient)6 AAIResourcesClient (org.onap.aaiclient.client.aai.AAIResourcesClient)5 ArrayList (java.util.ArrayList)3 VfModule (org.onap.aai.domain.yang.VfModule)3 VfModules (org.onap.aai.domain.yang.VfModules)3 VolumeGroup (org.onap.aai.domain.yang.VolumeGroup)3 VolumeGroups (org.onap.aai.domain.yang.VolumeGroups)3 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)3 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)3 ServiceInstance (org.onap.aai.domain.yang.ServiceInstance)2 ServiceInstances (org.onap.aai.domain.yang.ServiceInstances)2 Relationships (org.onap.aaiclient.client.aai.entities.Relationships)2 MultipleObjectsFoundException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1