Search in sources :

Example 11 with ServiceInstance

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

the class AaiResourceIdValidatorTest method validateResourceIdInAAISITest.

@Test
public void validateResourceIdInAAISITest() throws Exception {
    RequestDetails reqDetails = setupRequestDetails();
    reqDetails.getModelInfo().setModelVersionId("1234567");
    ServiceInstance si = new ServiceInstance();
    si.setServiceInstanceId("siId123");
    si.setModelVersionId("1234567");
    ServiceInstances serviceInstances = new ServiceInstances();
    serviceInstances.getServiceInstance().add(si);
    Optional<ServiceInstance> siOp = Optional.of(si);
    ServiceInstance si2 = new ServiceInstance();
    si2.setServiceInstanceId("siId222");
    si2.setModelVersionId("22222");
    si2.setServiceInstanceName("siName222");
    Optional<ServiceInstance> siOp2 = Optional.of(si2);
    ServiceInstances serviceInstances2 = new ServiceInstances();
    serviceInstances2.getServiceInstance().add(si2);
    when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName123")).thenReturn(siOp);
    when(bbInputSetupUtilsMock.getAAIServiceInstanceByName("id123", "subServiceType123", "siName222")).thenReturn(siOp2);
    String id = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName123", reqDetails, new WorkflowResourceIds());
    assertEquals("siId123", id);
    String id2 = testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "111111", reqDetails, new WorkflowResourceIds());
    assertEquals("generatedId123", id2);
    this.expectedException.expect(DuplicateNameException.class);
    this.expectedException.expectMessage(containsString("serviceInstance with name (siName222) and different version id (1234567) already exists. The name must be unique."));
    testedObject.validateResourceIdInAAI("generatedId123", WorkflowType.SERVICE, "siName222", reqDetails, new WorkflowResourceIds());
}
Also used : ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) Test(org.junit.Test)

Example 12 with ServiceInstance

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

the class BBInputSetupUtils method getRelatedServiceInstanceFromInstanceGroup.

public Optional<ServiceInstance> getRelatedServiceInstanceFromInstanceGroup(String instanceGroupId) throws Exception {
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().instanceGroup(instanceGroupId)).relatedTo(Types.SERVICE_INSTANCES.getFragment());
    Optional<ServiceInstances> serviceInstances = injectionHelper.getAaiClient().get(ServiceInstances.class, uri);
    ServiceInstance serviceInstance = null;
    if (!serviceInstances.isPresent()) {
        logger.debug("No ServiceInstances were found");
        return Optional.empty();
    } else {
        if (serviceInstances.get().getServiceInstance().isEmpty()) {
            throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
        } else if (serviceInstances.get().getServiceInstance().size() > 1) {
            String message = String.format("Mulitple service instances were found for instance-group-id: %s.", instanceGroupId);
            throw new MultipleObjectsFoundException(message);
        } else {
            serviceInstance = serviceInstances.get().getServiceInstance().get(0);
        }
        return Optional.of(serviceInstance);
    }
}
Also used : MultipleObjectsFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException) ServiceInstances(org.onap.aai.domain.yang.ServiceInstances) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) NoServiceInstanceFoundException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException)

Example 13 with ServiceInstance

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

the class WorkflowActionTest method selectExecutionListMacroResumeTest.

@Test
public void selectExecutionListMacroResumeTest() throws Exception {
    String gAction = "createInstance";
    String resource = "Service";
    String bpmnRequest = readBpmnRequestFromFile(MACRO_ASSIGN_JSON);
    initExecution(gAction, bpmnRequest, false);
    execution.setVariable("requestUri", "v6/serviceInstances/123");
    NorthBoundRequest northBoundRequest = new NorthBoundRequest();
    List<OrchestrationFlow> orchFlows = createFlowList("AssignServiceInstanceBB");
    northBoundRequest.setOrchestrationFlowList(orchFlows);
    Service service = new Service();
    service.setModelUUID("3c40d244-808e-42ca-b09a-256d83d19d0a");
    ServiceInstance si = new ServiceInstance();
    when(bbSetupUtils.getAAIServiceInstanceById("123")).thenReturn(si);
    when(catalogDbClient.getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a")).thenReturn(service);
    String flowsToExecuteString = "[{\"buildingBlock\":{\"mso-id\":\"2f9ddc4b-4dcf-4129-a35f-be1625ae0176\",\"bpmn-flow-name\":\"AssignServiceInstanceBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}}]";
    ObjectMapper om = new ObjectMapper();
    List<ExecuteBuildingBlock> flowsToExecute = null;
    try {
        ExecuteBuildingBlock[] asArray = om.readValue(flowsToExecuteString, ExecuteBuildingBlock[].class);
        flowsToExecute = Arrays.asList(asArray);
    } catch (Exception e) {
        e.printStackTrace();
    }
    when(bbSetupUtils.loadOriginalFlowExecutionPath(anyString())).thenReturn(flowsToExecute);
    workflowAction.selectExecutionList(execution);
    List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
    assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB");
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow) Service(org.onap.so.db.catalog.beans.Service) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NorthBoundRequest(org.onap.so.db.catalog.beans.macro.NorthBoundRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DuplicateNameException(org.onap.so.bpmn.servicedecomposition.tasks.exceptions.DuplicateNameException) ExpectedException(org.junit.rules.ExpectedException) MalformedURLException(java.net.MalformedURLException) AAIEntityNotFoundException(org.onap.so.client.orchestration.AAIEntityNotFoundException) IOException(java.io.IOException) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 14 with ServiceInstance

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

the class WorkflowActionTest method selectExecutionListServiceMacroDeleteNetworkCollectionTest.

@Test
public void selectExecutionListServiceMacroDeleteNetworkCollectionTest() throws Exception {
    String gAction = "deleteInstance";
    String resource = "Service";
    String bpmnRequest = readBpmnRequestFromFile(MACRO_ACTIVATE_DELETE_UNASSIGN_JSON);
    initExecution(gAction, bpmnRequest, false);
    execution.setVariable("requestUri", "v6/serviceInstances/123");
    NorthBoundRequest northBoundRequest = new NorthBoundRequest();
    List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVolumeGroupBB", "DeleteVolumeGroupBB", "DeactivateVnfBB", "DeactivateNetworkBB", "DeleteNetworkBB", "DeleteNetworkCollectionBB", "DeactivateServiceInstanceBB", "UnassignVfModuleBB", "UnassignVolumeGroupBB", "UnassignVnfBB", "UnassignNetworkBB", "UnassignServiceInstanceBB");
    northBoundRequest.setOrchestrationFlowList(orchFlows);
    ServiceInstance serviceInstanceAAI = new ServiceInstance();
    serviceInstanceAAI.setServiceInstanceId("aaisi123");
    org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance();
    org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network = new org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network();
    network.setNetworkId("123");
    serviceInstanceMSO.getNetworks().add(network);
    org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network();
    network2.setNetworkId("321");
    serviceInstanceMSO.getNetworks().add(network2);
    Collection collection = new Collection();
    serviceInstanceMSO.setCollection(collection);
    doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123");
    doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
    when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "my-custom-cloud-owner")).thenReturn(northBoundRequest);
    workflowAction.selectExecutionList(execution);
    List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
    assertEqualsBulkFlowName(ebbs, "DeactivateNetworkBB", "DeleteNetworkBB", "UnassignNetworkBB", "DeactivateNetworkBB", "DeleteNetworkBB", "UnassignNetworkBB", "DeleteNetworkCollectionBB", "DeactivateServiceInstanceBB", "UnassignServiceInstanceBB");
}
Also used : OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NorthBoundRequest(org.onap.so.db.catalog.beans.macro.NorthBoundRequest) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) Collection(org.onap.so.bpmn.servicedecomposition.bbobjects.Collection) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 15 with ServiceInstance

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

the class ServiceEBBLoaderTest method traverseAAIServiceTest.

@Test
public void traverseAAIServiceTest() {
    List<Resource> resourceCounter = new ArrayList<>();
    String resourceId = "si0";
    List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
    ServiceInstance serviceInstanceAAI = new ServiceInstance();
    serviceInstanceAAI.setServiceInstanceId(resourceId);
    org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = setServiceInstance();
    GenericVnf genericVnf = setGenericVnf();
    setVfModule(true);
    setVolumeGroup();
    setL3Network();
    setCollection();
    setConfiguration();
    org.onap.aai.domain.yang.GenericVnf genericVnfAai = new org.onap.aai.domain.yang.GenericVnf();
    genericVnfAai.setModelCustomizationId(genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid());
    Configuration config = new Configuration();
    config.setConfigurationId("testConfigurationId2");
    serviceInstance.getConfigurations().add(config);
    Relationship relationship1 = new Relationship();
    relationship1.setRelatedTo("vnfc");
    RelationshipList relationshipList1 = new RelationshipList();
    relationshipList1.getRelationship().add(relationship1);
    Relationship relationship2 = new Relationship();
    relationship2.setRelatedTo("vpn-binding");
    RelationshipList relationshipList2 = new RelationshipList();
    relationshipList2.getRelationship().add(relationship2);
    org.onap.aai.domain.yang.Configuration aaiConfiguration1 = new org.onap.aai.domain.yang.Configuration();
    aaiConfiguration1.setConfigurationId("testConfigurationId");
    aaiConfiguration1.setRelationshipList(relationshipList1);
    org.onap.aai.domain.yang.Configuration aaiConfiguration2 = new org.onap.aai.domain.yang.Configuration();
    aaiConfiguration2.setConfigurationId("testConfigurationId2");
    aaiConfiguration2.setRelationshipList(relationshipList1);
    org.onap.aai.domain.yang.VfModule aaiVfModule = new org.onap.aai.domain.yang.VfModule();
    aaiVfModule.setIsBaseVfModule(true);
    try {
        doReturn(genericVnfAai).when(mockBbInputSetupUtils).getAAIGenericVnf(genericVnf.getVnfId());
        doReturn(serviceInstanceAAI).when(mockBbInputSetupUtils).getAAIServiceInstanceById(resourceId);
        doReturn(serviceInstance).when(mockBbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
        doReturn(Optional.of(aaiConfiguration1)).when(mockAaiConfigurationResources).getConfiguration("testConfigurationId");
        doReturn(Optional.of(aaiConfiguration2)).when(mockAaiConfigurationResources).getConfiguration("testConfigurationId2");
        doReturn(aaiVfModule).when(mockBbInputSetupUtils).getAAIVfModule(any(), any());
        serviceEBBLoader.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds);
        assertEquals(8, resourceCounter.size());
        assertTrue(resourceCounter.get(2).isBaseVfModule());
        assertThat(aaiResourceIds, sameBeanAs(getExpectedResourceIds()));
    } catch (Exception e) {
        fail("Unexpected exception was thrown.");
    }
}
Also used : RelationshipList(org.onap.aai.domain.yang.RelationshipList) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) Configuration(org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration) Resource(org.onap.so.bpmn.infrastructure.workflow.tasks.Resource) CollectionResource(org.onap.so.db.catalog.beans.CollectionResource) ArrayList(java.util.ArrayList) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) Mockito.anyString(org.mockito.Mockito.anyString) VrfBondingServiceException(org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException) ExpectedException(org.junit.rules.ExpectedException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Relationship(org.onap.aai.domain.yang.Relationship) Pair(org.javatuples.Pair) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) 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