Search in sources :

Example 1 with ServiceInstance

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

the class ServiceLevelRequestDispatcher method getAndSetPnfNameFromServiceInstance.

private void getAndSetPnfNameFromServiceInstance(final String serviceInstanceId, final String serviceType, final String globalSubscriberId, DelegateExecution delegateExecution) {
    AAIRestClientI restClient = new AAIRestClientImpl();
    Optional<ServiceInstance> optionalSi = restClient.getServiceInstanceById(serviceInstanceId, serviceType, globalSubscriberId);
    optionalSi.ifPresentOrElse(serviceInstance -> {
        final List<String> pnfNameList = serviceInstance.getRelationshipList().getRelationship().stream().filter(x -> x.getRelatedTo().contains("pnf")).flatMap(x -> x.getRelationshipData().stream()).filter(data -> data.getRelationshipKey().contains("pnf.pnf-name")).map(x -> x.getRelationshipValue()).collect(Collectors.toList());
        if (pnfNameList == null || pnfNameList.size() == 0) {
            logger.warn("Unable to find the PNF for service instance id: " + serviceInstance.getServiceInstanceId());
            return;
        }
        delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME_LIST, pnfNameList);
        delegateExecution.setVariable(ServiceLevelConstants.PNF_SIZE, pnfNameList.size());
        delegateExecution.setVariable(ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.PNF);
    }, () -> {
        throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId);
    });
}
Also used : ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) AAIRestClientI(org.onap.aaiclient.client.aai.AAIRestClientI) Logger(org.slf4j.Logger) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) Relationship(org.onap.aai.domain.yang.Relationship) JsonUtils(org.onap.so.bpmn.core.json.JsonUtils) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Component(org.springframework.stereotype.Component) List(java.util.List) JavaDelegate(org.camunda.bpm.engine.delegate.JavaDelegate) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) Optional(java.util.Optional) ExecutionVariableNames(org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames) Collector(java.util.stream.Collector) AAIRestClientImpl(org.onap.aaiclient.client.aai.AAIRestClientImpl) AAIRestClientImpl(org.onap.aaiclient.client.aai.AAIRestClientImpl) AAIRestClientI(org.onap.aaiclient.client.aai.AAIRestClientI) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance)

Example 2 with ServiceInstance

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

the class AaiResourceIdValidator method validateServiceResourceIdInAAI.

protected String validateServiceResourceIdInAAI(String generatedResourceId, String instanceName, RequestDetails reqDetails) throws DuplicateNameException {
    String globalCustomerId = reqDetails.getSubscriberInfo().getGlobalSubscriberId();
    String serviceType = reqDetails.getRequestParameters().getSubscriptionServiceType();
    if (instanceName != null) {
        Optional<ServiceInstance> serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceByName(globalCustomerId, serviceType, instanceName);
        if (serviceInstanceAAI.isPresent()) {
            if (serviceInstanceAAI.get().getModelVersionId().equalsIgnoreCase(reqDetails.getModelInfo().getModelVersionId())) {
                return serviceInstanceAAI.get().getServiceInstanceId();
            } else {
                throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_VERSION_ID, instanceName, reqDetails.getModelInfo().getModelVersionId()));
            }
        } else {
            ServiceInstances aaiServiceInstances = bbInputSetupUtils.getAAIServiceInstancesGloballyByName(instanceName);
            if (aaiServiceInstances != null) {
                if (aaiServiceInstances.getServiceInstance() != null && !aaiServiceInstances.getServiceInstance().isEmpty()) {
                    if (aaiServiceInstances.getServiceInstance().size() > 1) {
                        throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_MULTIPLE, instanceName));
                    } else {
                        ServiceInstance si = aaiServiceInstances.getServiceInstance().stream().findFirst().get();
                        Map<String, String> keys = bbInputSetupUtils.getURIKeysFromServiceInstance(si.getServiceInstanceId());
                        throw new DuplicateNameException(SERVICE_INSTANCE, String.format(NAME_EXISTS_WITH_DIFF_COMBINATION, instanceName, keys.get(AAIFluentTypeBuilder.Types.CUSTOMER.getUriParams().globalCustomerId), keys.get(AAIFluentTypeBuilder.Types.SERVICE_SUBSCRIPTION.getUriParams().serviceType), si.getModelVersionId()));
                    }
                }
            }
        }
    }
    return generatedResourceId;
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) DuplicateNameException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance)

Example 3 with ServiceInstance

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

the class ServiceEBBLoader method traverseAAIService.

public void traverseAAIService(DelegateExecution execution, List<Resource> resourceList, String resourceId, List<Pair<WorkflowType, String>> aaiResourceIds) {
    try {
        ServiceInstance serviceInstanceAAI = bbInputSetupUtils.getAAIServiceInstanceById(resourceId);
        org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = bbInputSetup.getExistingServiceInstance(serviceInstanceAAI);
        var serviceResource = new Resource(WorkflowType.SERVICE, serviceInstanceMSO.getServiceInstanceId(), false, null);
        serviceResource.setModelInvariantId(serviceInstanceAAI.getModelInvariantId());
        serviceResource.setModelVersionId(serviceInstanceAAI.getModelVersionId());
        resourceList.add(serviceResource);
        traverseServiceInstanceMSOVnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO);
        traverseServiceInstanceMSOPnfs(resourceList, serviceResource, aaiResourceIds, serviceInstanceMSO);
        if (serviceInstanceMSO.getNetworks() != null) {
            for (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network : serviceInstanceMSO.getNetworks()) {
                aaiResourceIds.add(new Pair<>(WorkflowType.NETWORK, network.getNetworkId()));
                Resource networkResource = new Resource(WorkflowType.NETWORK, network.getNetworkId(), false, serviceResource);
                ModelInfoNetwork modelInfoNetwork = network.getModelInfoNetwork();
                if (modelInfoNetwork != null) {
                    networkResource.setModelCustomizationId(modelInfoNetwork.getModelCustomizationUUID());
                    networkResource.setModelVersionId(modelInfoNetwork.getModelUUID());
                    networkResource.setModelCustomizationId(modelInfoNetwork.getModelCustomizationUUID());
                }
                resourceList.add(networkResource);
            }
        }
        if (serviceInstanceMSO.getCollection() != null) {
            logger.debug("found networkcollection");
            aaiResourceIds.add(new Pair<>(WorkflowType.NETWORKCOLLECTION, serviceInstanceMSO.getCollection().getId()));
            resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, serviceInstanceMSO.getCollection().getId(), false, serviceResource));
        }
        if (serviceInstanceMSO.getConfigurations() != null) {
            for (Configuration config : serviceInstanceMSO.getConfigurations()) {
                Optional<org.onap.aai.domain.yang.Configuration> aaiConfig = aaiConfigurationResources.getConfiguration(config.getConfigurationId());
                if (aaiConfig.isPresent() && aaiConfig.get().getRelationshipList() != null) {
                    for (Relationship relationship : aaiConfig.get().getRelationshipList().getRelationship()) {
                        if (relationship.getRelatedTo().contains("vnfc") || relationship.getRelatedTo().contains("vpn-binding")) {
                            aaiResourceIds.add(new Pair<>(WorkflowType.CONFIGURATION, config.getConfigurationId()));
                            resourceList.add(new Resource(WorkflowType.CONFIGURATION, config.getConfigurationId(), false, serviceResource));
                            break;
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        logger.error("Exception in traverseAAIService", ex);
        buildAndThrowException(execution, "Could not find existing Service Instance or related Instances to execute the request on.");
    }
}
Also used : Configuration(org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration) Resource(org.onap.so.bpmn.infrastructure.workflow.tasks.Resource) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) VrfBondingServiceException(org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Relationship(org.onap.aai.domain.yang.Relationship) ModelInfoNetwork(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork)

Example 4 with ServiceInstance

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

the class BBInputSetupUtilsTest method getRelatedServiceInstanceFromInstanceGroupTest.

@Test
public void getRelatedServiceInstanceFromInstanceGroupTest() throws Exception {
    Optional<ServiceInstances> expected = Optional.of(new ServiceInstances());
    ServiceInstance serviceInstance = new ServiceInstance();
    serviceInstance.setServiceInstanceId("serviceInstanceId");
    serviceInstance.setServiceInstanceName("serviceInstanceName");
    expected.get().getServiceInstance().add(serviceInstance);
    doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(ServiceInstances.class), any(AAIPluralResourceUri.class));
    Optional<ServiceInstance> actual = this.bbInputSetupUtils.getRelatedServiceInstanceFromInstanceGroup("ig-001");
    assertTrue(actual.isPresent());
    assertEquals(expected.get().getServiceInstance().get(0).getServiceInstanceId(), actual.get().getServiceInstanceId());
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) Test(org.junit.Test)

Example 5 with ServiceInstance

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

the class BBInputSetupUtilsTest method getAAIServiceInstanceByIdTest.

@Test
public void getAAIServiceInstanceByIdTest() {
    final String serviceInstanceId = "serviceInstanceId";
    ServiceInstance expectedServiceInstance = new ServiceInstance();
    doReturn(Optional.of(expectedServiceInstance)).when(MOCK_aaiResourcesClient).get(isA(Class.class), isA(AAIResourceUri.class));
    assertThat(bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId), sameBeanAs(expectedServiceInstance));
}
Also used : ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

ServiceInstance (org.onap.aai.domain.yang.ServiceInstance)33 Test (org.junit.Test)27 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)14 ArrayList (java.util.ArrayList)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 List (java.util.List)12 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)12 ServiceInstances (org.onap.aai.domain.yang.ServiceInstances)11 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)11 RelationshipList (org.onap.aai.domain.yang.RelationshipList)9 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)9 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)8 GenericVnf (org.onap.aai.domain.yang.GenericVnf)8 VfModule (org.onap.aai.domain.yang.VfModule)8 NorthBoundRequest (org.onap.so.db.catalog.beans.macro.NorthBoundRequest)8 OrchestrationFlow (org.onap.so.db.catalog.beans.macro.OrchestrationFlow)8 WorkflowResourceIds (org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds)6 IOException (java.io.IOException)4 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)4 Relationship (org.onap.aai.domain.yang.Relationship)4