Search in sources :

Example 1 with VnfResourceCustomization

use of org.onap.so.db.catalog.beans.VnfResourceCustomization in project so by onap.

the class ControllerExecutionBB method getControllerActor.

/**
 * this method is used to get the controller actor, there could be few places to get the actor(ordered by priority),
 *
 * <ol>
 * <li>Execution Context, i.e, BuildingBlockExecution</li>
 * <li>Resource customization table, pnf_resource_customization for PNF or vnf_resource_customization for VNF</li>
 * <li>controller_selection_reference, resource_type and action will be used to fetch from this table</li>
 * </ol>
 *
 * @param execution BuildingBlockExecution instance
 * @param controllerScope controller scope, e.g, pnf, vnf, vfModule
 * @param resourceCustomizationUuid resource customization UUID, e.g, pnfCustomizationUuid, vnfCustomizationUuid
 * @param controllerAction controller action, e.g, configAssign, configDeploy
 * @return controller actor name
 */
@Override
protected String getControllerActor(BuildingBlockExecution execution, String controllerScope, String resourceCustomizationUuid, String controllerAction) {
    /**
     * Firstly, check the execution context for actor parameter.
     */
    String controllerActor = getParameterFromExecution(execution, CONTROLLER_ACTOR_PARAM);
    /**
     * If no meaningful controller actor value found in the execution context and the value is not SO-REF-DATA.
     */
    if (Strings.isNullOrEmpty(controllerActor) && !isSoRefControllerActor(controllerActor)) {
        /**
         * For BuildingBlockExecution, we should try to get the resource information from Cached metadata.
         *
         * As the current cached metadata doesn't support controller actor, we use the
         * {@link org.onap.so.db.catalog.client.CatalogDbClient} to fetch information. Once the change is done in
         * cached metadata, this part should be refactored as well.
         */
        if (isPnfResourceScope(controllerScope)) {
            PnfResourceCustomization pnfResourceCustomization = catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid);
            controllerActor = pnfResourceCustomization.getControllerActor();
        } else if (isServiceResourceScope(controllerScope)) {
            return controllerActor;
        } else if (isVnfResourceScope(controllerScope)) {
            VnfResourceCustomization vnfResourceCustomization = catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(resourceCustomizationUuid);
            controllerActor = vnfResourceCustomization.getControllerActor();
        } else {
            logger.warn("Unrecognized scope: {}", controllerScope);
        }
    }
    /**
     * Lastly, can NOT find the controller actor information from resource customization table or the return value
     * is SO-REF-DATA.
     */
    if (Strings.isNullOrEmpty(controllerActor) || isSoRefControllerActor(controllerActor)) {
        String resourceType = getParameterFromExecution(execution, RESOURCE_TYPE_PARAM);
        ControllerSelectionReference reference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(resourceType, controllerAction);
        controllerActor = reference.getControllerName();
    }
    return controllerActor;
}
Also used : PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) ControllerSelectionReference(org.onap.so.db.catalog.beans.ControllerSelectionReference) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization)

Example 2 with VnfResourceCustomization

use of org.onap.so.db.catalog.beans.VnfResourceCustomization in project so by onap.

the class ToscaResourceInstaller method createVnfResource.

protected VnfResourceCustomization createVnfResource(IEntityDetails entityDetails, ToscaResourceStructure toscaResourceStructure, Service service) throws ArtifactInstallerException {
    VnfResourceCustomization vnfResourceCustomization = null;
    if (vnfResourceCustomization == null) {
        VnfResource vnfResource = findExistingVnfResource(service, entityDetails.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
        if (vnfResource == null) {
            vnfResource = createVnfResource(entityDetails);
        }
        vnfResourceCustomization = createVnfResourceCustomization(entityDetails, toscaResourceStructure, vnfResource);
        vnfResourceCustomization.setVnfResources(vnfResource);
        vnfResourceCustomization.setService(service);
        // setting resource input for vnf customization
        vnfResourceCustomization.setResourceInput(getResourceInput(toscaResourceStructure, vnfResourceCustomization.getModelCustomizationUUID()));
    }
    return vnfResourceCustomization;
}
Also used : VnfResource(org.onap.so.db.catalog.beans.VnfResource) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization)

Example 3 with VnfResourceCustomization

use of org.onap.so.db.catalog.beans.VnfResourceCustomization in project so by onap.

the class ASDCRestInterfaceTest method test_Vcpe_Infra_Distribution.

@Test
public void test_Vcpe_Infra_Distribution() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    String resourceLocation = "src/test/resources/resource-examples/vcpe-infra/";
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File(resourceLocation + "demovcpeinfra-notification.json"), NotificationDataImpl.class);
    headers.add("resource-location", resourceLocation);
    HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    Optional<ToscaCsar> toscaCsar = toscaCsarRepo.findById("144606d8-a505-4ba0-90a9-6d1c6219fc6b");
    assertTrue(toscaCsar.isPresent());
    assertEquals("service-Demovcpeinfra-csar.csar", toscaCsar.get().getName());
    Optional<Service> service = serviceRepo.findById("8a77cbbb-9850-40bb-a42f-7aec8e3e6ab7");
    assertTrue(service.isPresent());
    assertEquals("demoVCPEInfra", service.get().getModelName());
    Optional<NetworkResource> networkResource = networkRepo.findById("89789b26-a46b-4cee-aed0-d46e21f93a5e");
    assertTrue(networkResource.isPresent());
    assertEquals("Generic NeutronNet", networkResource.get().getModelName());
    List<VnfResourceCustomization> vnfCustomizationResources = vnfCustRepo.findByModelCustomizationUUID("01564fe7-0541-4d92-badc-464cc35f83ba");
    for (VnfResourceCustomization vnfResourceCustomization : vnfCustomizationResources) {
        assertTrue(vnfResourceCustomization.getVfModuleCustomizations().stream().anyMatch(vfModuleCust -> "354b1e83-47db-4af1-8af4-9c14b03b482d".equals(vfModuleCust.getModelCustomizationUUID())));
    }
}
Also used : Matchers.sameBeanAs(com.shazam.shazamcrest.matcher.Matchers.sameBeanAs) ArgumentMatchers(org.mockito.ArgumentMatchers) Autowired(org.springframework.beans.factory.annotation.Autowired) DistributionClientEmulator(org.onap.so.asdc.client.test.emulators.DistributionClientEmulator) Service(org.onap.so.db.catalog.beans.Service) Spy(org.mockito.Spy) NetworkResourceRepository(org.onap.so.db.catalog.data.repository.NetworkResourceRepository) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) ConfigurationResourceCustomization(org.onap.so.db.catalog.beans.ConfigurationResourceCustomization) Transactional(javax.transaction.Transactional) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) HttpHeaders(org.springframework.http.HttpHeaders) Set(java.util.Set) List(java.util.List) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) HttpEntity(org.springframework.http.HttpEntity) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) VnfCustomizationRepository(org.onap.so.db.catalog.data.repository.VnfCustomizationRepository) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) HashSet(java.util.HashSet) AllottedResourceCustomizationRepository(org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository) WireMock.urlPathMatching(com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching) AllottedResourceRepository(org.onap.so.db.catalog.data.repository.AllottedResourceRepository) VnfResource(org.onap.so.db.catalog.beans.VnfResource) Before(org.junit.Before) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) WorkflowRepository(org.onap.so.db.catalog.data.repository.WorkflowRepository) Files(java.nio.file.Files) BaseTest(org.onap.so.asdc.BaseTest) Assert.assertNotNull(org.junit.Assert.assertNotNull) MatcherAssert.assertThat(com.shazam.shazamcrest.MatcherAssert.assertThat) VnfResourceRepository(org.onap.so.db.catalog.data.repository.VnfResourceRepository) HttpMethod(org.springframework.http.HttpMethod) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) File(java.io.File) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) Workflow(org.onap.so.db.catalog.beans.Workflow) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) Mockito(org.mockito.Mockito) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) Paths(java.nio.file.Paths) ServiceRepository(org.onap.so.db.catalog.data.repository.ServiceRepository) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) ResponseEntity(org.springframework.http.ResponseEntity) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) ToscaCsarRepository(org.onap.so.db.catalog.data.repository.ToscaCsarRepository) HttpEntity(org.springframework.http.HttpEntity) Service(org.onap.so.db.catalog.beans.Service) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) File(java.io.File) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 4 with VnfResourceCustomization

use of org.onap.so.db.catalog.beans.VnfResourceCustomization in project so by onap.

the class SkipCDSBuildingBlockListener method run.

/**
 * Skip the CDS Building block according to the Skip Flag.
 *
 * @param flowsToExecute - List of ExecuteBuildingBlock object.
 * @param execution - BuildingBlockExecution object
 * @param currentBB - ExecuteBuildingBlock object
 */
@Override
public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB, BuildingBlockExecution execution) {
    String resourceKey = currentBB.getBuildingBlock().getKey();
    List<Resource> resources = execution.getVariable("resources");
    Resource resource = resources.stream().filter(r -> resourceKey.equals(r.getResourceId())).findFirst().orElseThrow(() -> new IllegalArgumentException("Resource not found for key:" + resourceKey));
    String scope = currentBB.getBuildingBlock().getBpmnScope();
    if ("SERVICE".equalsIgnoreCase(scope)) {
        Service service = catalogDbClient.getServiceByID(resource.getModelVersionId());
        currentSequenceSkipCheck(execution, service.getSkipPostInstConf());
    } else if ("VNF".equalsIgnoreCase(scope) && containsIgnoreCaseAction(currentBB, vnfActions)) {
        VnfResourceCustomization vrc = catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(resource.getModelCustomizationId());
        if (vrc != null) {
            logger.debug("getSkipPostInstConf value: " + vrc.getSkipPostInstConf());
            boolean skipConfigVNF = vrc.getSkipPostInstConf();
            currentSequenceSkipCheck(execution, skipConfigVNF);
        }
    } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("VFModule") && containsIgnoreCaseAction(currentBB, vFModuleAction)) {
        VfModuleCustomization vfc = catalogDbClient.getVfModuleCustomizationByModelCuztomizationUUID(resource.getModelCustomizationId());
        if (null != vfc) {
            logger.debug("getSkipPostInstConf value: " + vfc.getSkipPostInstConf().booleanValue());
            boolean skipVfModule = vfc.getSkipPostInstConf();
            currentSequenceSkipCheck(execution, skipVfModule);
        }
    } else if (currentBB.getBuildingBlock().getBpmnScope().equalsIgnoreCase("PNF") && containsIgnoreCaseAction(currentBB, pnfActions)) {
        PnfResourceCustomization pnfResourceCustomization = catalogDbClient.getPnfResourceCustomizationByModelCustomizationUUID(resource.getModelCustomizationId());
        if (null != pnfResourceCustomization) {
            logger.debug("getSkipPostInstConf value: " + pnfResourceCustomization.getSkipPostInstConf());
            boolean skipConfigPNF = pnfResourceCustomization.getSkipPostInstConf();
            currentSequenceSkipCheck(execution, skipConfigPNF);
        }
    }
}
Also used : PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) Resource(org.onap.so.bpmn.infrastructure.workflow.tasks.Resource) Service(org.onap.so.db.catalog.beans.Service) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization)

Example 5 with VnfResourceCustomization

use of org.onap.so.db.catalog.beans.VnfResourceCustomization in project so by onap.

the class MultiStageSkipListener method run.

@Override
public void run(List<ExecuteBuildingBlock> flowsToExecute, ExecuteBuildingBlock currentBB, BuildingBlockExecution execution) {
    String vfModuleId = currentBB.getResourceId();
    String vnfId = currentBB.getWorkflowResourceIds().getVnfId();
    org.onap.aai.domain.yang.VfModule vfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId);
    if (vfModule == null) {
        org.onap.aai.domain.yang.GenericVnf vnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
        if (vnf != null) {
            VnfResourceCustomization vnfCust = catalogDbClient.getVnfResourceCustomizationByModelCustomizationUUID(vnf.getModelCustomizationId());
            if (vnfCust != null && vnfCust.getMultiStageDesign() != null && vnfCust.getMultiStageDesign().equalsIgnoreCase("true")) {
                flowsToExecute.retainAll(Collections.singletonList(currentBB));
                execution.setVariable(G_MULTI_STAGE_DESIGN, Boolean.valueOf(vnfCust.getMultiStageDesign()));
            }
        }
    }
}
Also used : VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization)

Aggregations

VnfResourceCustomization (org.onap.so.db.catalog.beans.VnfResourceCustomization)43 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)17 Service (org.onap.so.db.catalog.beans.Service)15 VfModuleCustomization (org.onap.so.db.catalog.beans.VfModuleCustomization)13 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)11 VnfResource (org.onap.so.db.catalog.beans.VnfResource)10 VfModule (org.onap.so.db.catalog.beans.VfModule)7 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)7 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)6 PnfResourceCustomization (org.onap.so.db.catalog.beans.PnfResourceCustomization)6 Transactional (org.springframework.transaction.annotation.Transactional)6 List (java.util.List)5 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)5 VnfcInstanceGroupCustomization (org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 BuildingBlockExecution (org.onap.so.bpmn.common.BuildingBlockExecution)4 Resource (org.onap.so.bpmn.infrastructure.workflow.tasks.Resource)4 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)4 NetworkResourceCustomization (org.onap.so.db.catalog.beans.NetworkResourceCustomization)4