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);
});
}
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;
}
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.");
}
}
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());
}
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));
}
Aggregations