Search in sources :

Example 1 with GenericVnfs

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

the class AaiResourceIdValidator method validateVnfResourceIdInAAI.

protected String validateVnfResourceIdInAAI(String generatedResourceId, String instanceName, RequestDetails reqDetails, WorkflowResourceIds workflowResourceIds) throws DuplicateNameException {
    Optional<GenericVnf> vnf = bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(workflowResourceIds.getServiceInstanceId(), instanceName);
    if (vnf.isPresent()) {
        if (vnf.get().getModelCustomizationId().equalsIgnoreCase(reqDetails.getModelInfo().getModelCustomizationId())) {
            return vnf.get().getVnfId();
        } else {
            throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_CUSTOMIZATION_ID, instanceName, vnf.get().getModelCustomizationId()));
        }
    }
    GenericVnfs vnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(instanceName);
    if (vnfs != null) {
        throw new DuplicateNameException("generic-vnf", String.format(NAME_EXISTS_WITH_DIFF_PARENT, instanceName, vnfs.getGenericVnf().get(0).getVnfId()));
    }
    return generatedResourceId;
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) DuplicateNameException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs)

Example 2 with GenericVnfs

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

the class BBInputSetupUtilsTest method getAAIVnfsGloballyByName_noAAIResourceTest.

@Test
public void getAAIVnfsGloballyByName_noAAIResourceTest() {
    final String vnfName = "vnfName";
    doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIPluralResourceUri.class));
    GenericVnfs actualGenericVnfs = bbInputSetupUtils.getAAIVnfsGloballyByName(vnfName);
    assertNull(actualGenericVnfs);
}
Also used : AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 3 with GenericVnfs

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

the class AAIResourcesClientTest method testGetFirstMultipleResults.

@Test
public void testGetFirstMultipleResults() {
    GenericVnf vnf = new GenericVnf();
    vnf.setVnfId("my-vnf-id");
    GenericVnf vnf2 = new GenericVnf();
    vnf2.setVnfId("my-vnf-id2");
    GenericVnfs vnfs = new GenericVnfs();
    vnfs.getGenericVnf().add(vnf);
    vnfs.getGenericVnf().add(vnf2);
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
    RestClient restClientMock = mock(RestClient.class);
    doReturn(restClientMock).when(client).createClient(uri);
    when(restClientMock.get(GenericVnfs.class)).thenReturn(Optional.of(vnfs));
    Optional<GenericVnf> result = aaiClient.getFirst(GenericVnfs.class, GenericVnf.class, uri);
    assertEquals("my-vnf-id", result.get().getVnfId());
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs) RestClient(org.onap.so.client.RestClient) Test(org.junit.Test)

Example 4 with GenericVnfs

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

the class AaiConnection method receiveGenericVnfId.

public String receiveGenericVnfId(final String href) {
    final AAIPluralResourceUri resourceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs()).queryParam(SELFLINK, href);
    final Optional<GenericVnfs> response = getResourcesClient().get(GenericVnfs.class, resourceUri);
    if (response.isPresent()) {
        final GenericVnfs vnfs = response.get();
        logger.info("The AAI replied with: {}", vnfs);
        final List<GenericVnf> genericVnfList = vnfs.getGenericVnf();
        final int size = genericVnfList.size();
        if (size == 1) {
            final GenericVnf genericVnf = genericVnfList.get(FIRST_INDEX);
            return genericVnf.getVnfId();
        } else if (size > 1) {
            logger.warn("more generic vnfs available");
        }
    }
    return null;
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs)

Example 5 with GenericVnfs

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

the class AaiResourceIdValidatorTest method validateResourceIdInAAIVnfNotGloballyUniqueTest.

@Test
public void validateResourceIdInAAIVnfNotGloballyUniqueTest() throws Exception {
    RequestDetails reqDetails = setupRequestDetails();
    GenericVnfs genericVnfs = new GenericVnfs();
    GenericVnf vnf3 = new GenericVnf();
    vnf3.setVnfId("id123");
    genericVnfs.getGenericVnf().add(vnf3);
    when(bbInputSetupUtilsMock.getAAIVnfsGloballyByName("vnfName333")).thenReturn(genericVnfs);
    this.expectedException.expect(DuplicateNameException.class);
    this.expectedException.expectMessage(containsString("generic-vnf with name (vnfName333) id (id123) and different parent relationship already exists. The name must be unique."));
    testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.VNF, "vnfName333", reqDetails, new WorkflowResourceIds());
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) GenericVnfs(org.onap.aai.domain.yang.GenericVnfs) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) Test(org.junit.Test)

Aggregations

GenericVnfs (org.onap.aai.domain.yang.GenericVnfs)10 GenericVnf (org.onap.aai.domain.yang.GenericVnf)9 Test (org.junit.Test)8 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)7 RestClient (org.onap.so.client.RestClient)5 WorkflowResourceIds (org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds)2 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 DuplicateNameException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException)1