Search in sources :

Example 1 with NetworkPolicies

use of org.onap.aai.domain.yang.NetworkPolicies 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 2 with NetworkPolicies

use of org.onap.aai.domain.yang.NetworkPolicies in project so by onap.

the class AAIDeleteTasksTest method deleteNetworkPolicyNeedToDeleteAllTest.

@Test
public void deleteNetworkPolicyNeedToDeleteAllTest() throws Exception {
    execution.setVariable("contrailNetworkPolicyFqdnList", "ABC123,DEF456");
    final String content0 = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAaiNetworkPoliciesForDelete0.json")));
    AAIResultWrapper aaiResultWrapper0 = new AAIResultWrapper(content0);
    NetworkPolicies networkPolicies0 = aaiResultWrapper0.asBean(NetworkPolicies.class).get();
    final String content1 = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "queryAaiNetworkPoliciesForDelete1.json")));
    AAIResultWrapper aaiResultWrapper1 = new AAIResultWrapper(content1);
    NetworkPolicies networkPolicies1 = aaiResultWrapper1.asBean(NetworkPolicies.class).get();
    doReturn(Optional.of(networkPolicies0), Optional.of(networkPolicies1)).when(aaiNetworkResources).getNetworkPolicies(any(AAIBaseResourceUri.class));
    doNothing().when(aaiNetworkResources).deleteNetworkPolicy(any(String.class));
    aaiDeleteTasks.deleteNetworkPolicies(execution);
    verify(aaiNetworkResources, times(2)).deleteNetworkPolicy(stringCaptor.capture());
    assertEquals("testNetworkPolicyId0", stringCaptor.getAllValues().get(0));
    assertEquals("testNetworkPolicyId1", stringCaptor.getAllValues().get(1));
}
Also used : AAIBaseResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIBaseResourceUri) NetworkPolicies(org.onap.aai.domain.yang.NetworkPolicies) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Aggregations

NetworkPolicies (org.onap.aai.domain.yang.NetworkPolicies)2 Test (org.junit.Test)1 NetworkPolicy (org.onap.aai.domain.yang.NetworkPolicy)1 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)1 AAIBaseResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIBaseResourceUri)1 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)1