Search in sources :

Example 1 with DuplicateNameException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException 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 DuplicateNameException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException 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 DuplicateNameException

use of org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException in project so by onap.

the class WorkflowActionTest method selectExecutionListDuplicateNameExceptionTest.

@Test
public void selectExecutionListDuplicateNameExceptionTest() throws Exception {
    String gAction = "createInstance";
    String bpmnRequest = readBpmnRequestFromFile(MACRO_ASSIGN_JSON);
    initExecution(gAction, bpmnRequest, true);
    execution.setVariable("requestUri", "v6/serviceInstances");
    doThrow(new DuplicateNameException("serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique.")).when(aaiResourceIdValidator).validateResourceIdInAAI(anyString(), eq(WorkflowType.SERVICE), eq("test"), any(RequestDetails.class), any(WorkflowResourceIds.class));
    SPY_workflowAction.selectExecutionList(execution);
    assertEquals(execution.getVariable("WorkflowActionErrorMessage"), "Exception while setting execution list. serviceInstance with name (instanceName) and different version id (3c40d244-808e-42ca-b09a-256d83d19d0a) already exists. The name must be unique.");
    // verify default values are present in failure case
    assertEquals(true, execution.getVariable("isTopLevelFlow"));
    assertEquals(false, execution.getVariable("sentSyncResponse"));
}
Also used : DuplicateNameException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Aggregations

DuplicateNameException (org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 GenericVnf (org.onap.aai.domain.yang.GenericVnf)1 GenericVnfs (org.onap.aai.domain.yang.GenericVnfs)1 ServiceInstance (org.onap.aai.domain.yang.ServiceInstance)1 ServiceInstances (org.onap.aai.domain.yang.ServiceInstances)1 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)1 WorkflowResourceIds (org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds)1 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)1