Search in sources :

Example 1 with NetworkResource

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

the class ToscaResourceInstaller method createNetworkResource.

protected NetworkResource createNetworkResource(IEntityDetails vlEntity, ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin) {
    NetworkResource networkResource = new NetworkResource();
    String providerNetwork = getLeafPropertyValue(vlEntity, SdcPropertyNames.PROPERTY_NAME_PROVIDERNETWORK_ISPROVIDERNETWORK);
    if ("true".equalsIgnoreCase(providerNetwork)) {
        networkResource.setNeutronNetworkType(PROVIDER);
    } else {
        networkResource.setNeutronNetworkType(BASIC);
    }
    networkResource.setModelName(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
    networkResource.setModelInvariantUUID(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
    networkResource.setModelUUID(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
    networkResource.setModelVersion(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
    networkResource.setAicVersionMax(aicMax);
    networkResource.setAicVersionMin(aicMin);
    networkResource.setToscaNodeType(vlEntity.getToscaType());
    networkResource.setDescription(testNull(vlEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
    networkResource.setOrchestrationMode(HEAT);
    networkResource.setHeatTemplate(heatTemplate);
    return networkResource;
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource)

Example 2 with NetworkResource

use of org.onap.so.db.catalog.beans.NetworkResource 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 3 with NetworkResource

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

the class ToscaResourceInstaller method createNetwork.

protected NetworkResourceCustomization createNetwork(IEntityDetails networkEntity, ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin, Service service) {
    NetworkResourceCustomization networkResourceCustomization = networkCustomizationRepo.findOneByModelCustomizationUUID(networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
    boolean networkUUIDsMatch = true;
    // If not we'll update the Customization record with latest from the distribution
    if (networkResourceCustomization != null) {
        String existingNetworkModelUUID = networkResourceCustomization.getNetworkResource().getModelUUID();
        String latestNetworkModelUUID = networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
        if (!existingNetworkModelUUID.equals(latestNetworkModelUUID)) {
            networkUUIDsMatch = false;
        }
    }
    if (networkResourceCustomization != null && !networkUUIDsMatch) {
        NetworkResource networkResource = createNetworkResource(networkEntity, toscaResourceStructure, heatTemplate, aicMax, aicMin);
        networkResourceCustomization.setNetworkResource(networkResource);
        networkCustomizationRepo.saveAndFlush(networkResourceCustomization);
    } else if (networkResourceCustomization == null) {
        networkResourceCustomization = createNetworkResourceCustomization(networkEntity, toscaResourceStructure);
        NetworkResource networkResource = findExistingNetworkResource(service, networkEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
        if (networkResource == null)
            networkResource = createNetworkResource(networkEntity, toscaResourceStructure, heatTemplate, aicMax, aicMin);
        networkResource.addNetworkResourceCustomization(networkResourceCustomization);
        networkResourceCustomization.setNetworkResource(networkResource);
    }
    return networkResourceCustomization;
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) CollectionNetworkResourceCustomization(org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization)

Example 4 with NetworkResource

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

the class RequestHandlerUtils method getNetworkUri.

private RecipeLookupResult getNetworkUri(ServiceInstancesRequest sir, Actions action) throws ValidationException {
    String defaultNetworkType = getDefaultModel(sir);
    ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
    String modelName = modelInfo.getModelName();
    Recipe recipe = null;
    if (modelInfo.getModelCustomizationId() != null) {
        NetworkResourceCustomization networkResourceCustomization = catalogDbClient.getNetworkResourceCustomizationByModelCustomizationUUID(modelInfo.getModelCustomizationId());
        if (networkResourceCustomization != null) {
            NetworkResource networkResource = networkResourceCustomization.getNetworkResource();
            if (networkResource != null) {
                if (modelInfo.getModelVersionId() == null) {
                    modelInfo.setModelVersionId(networkResource.getModelUUID());
                }
                recipe = catalogDbClient.getFirstNetworkRecipeByModelNameAndAction(networkResource.getModelName(), action.toString());
            } else {
                throw new ValidationException("no catalog entry found");
            }
        } else if (action != Action.deleteInstance) {
            throw new ValidationException("modelCustomizationId for networkResourceCustomization lookup", true);
        }
    } else {
        // ok for version < 3 and action delete
        if (modelName != null) {
            recipe = catalogDbClient.getFirstNetworkRecipeByModelNameAndAction(modelName, action.toString());
        }
    }
    if (recipe == null) {
        recipe = catalogDbClient.getFirstNetworkRecipeByModelNameAndAction(defaultNetworkType, action.toString());
    }
    return recipe != null ? new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout()) : null;
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) ValidationException(org.onap.so.exceptions.ValidationException) VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) Recipe(org.onap.so.db.catalog.beans.Recipe) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization)

Example 5 with NetworkResource

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

the class MsoHeatUtils method getNetworkHeatTimeoutValue.

public int getNetworkHeatTimeoutValue(String modelCustomizationUuid, String networkType) {
    int timeoutMinutes = DEFAULT_POLLING_TIMEOUT;
    try {
        NetworkResource networkResource = null;
        if (isBlank(modelCustomizationUuid)) {
            if (isNotBlank(networkType)) {
                networkResource = catalogClient.getNetworkResourceByModelName(networkType);
            }
        } else {
            NetworkResourceCustomization nrc = catalogClient.getNetworkResourceCustomizationByModelCustomizationUUID(modelCustomizationUuid);
            if (nrc != null) {
                networkResource = nrc.getNetworkResource();
            }
        }
        if (networkResource != null) {
            networkResource.getHeatTemplate().getTimeoutMinutes();
            HeatTemplate heat = networkResource.getHeatTemplate();
            if (heat != null && heat.getTimeoutMinutes() != null) {
                if (heat.getTimeoutMinutes() < DEFAULT_POLLING_TIMEOUT) {
                    timeoutMinutes = heat.getTimeoutMinutes();
                }
            }
        } else {
            logger.debug("Unable to find Network Resource with model customization uuid {} or network type {}. Using default timeout {}", modelCustomizationUuid, networkType, timeoutMinutes);
        }
    } catch (Exception e) {
        logger.warn("Exception occured while getting heat timeout value. Using default timeout {}", timeoutMinutes, e);
    }
    return timeoutMinutes;
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) HeatTemplate(org.onap.so.db.catalog.beans.HeatTemplate) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) VduException(org.onap.so.adapters.vdu.VduException) OpenStackConnectException(com.woorea.openstack.base.client.OpenStackConnectException) OpenStackResponseException(com.woorea.openstack.base.client.OpenStackResponseException) MsoException(org.onap.so.openstack.exceptions.MsoException) MsoOpenstackException(org.onap.so.openstack.exceptions.MsoOpenstackException) IOException(java.io.IOException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Aggregations

NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)14 NetworkResourceCustomization (org.onap.so.db.catalog.beans.NetworkResourceCustomization)8 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 NetworkException (org.onap.so.adapters.network.exceptions.NetworkException)3 CollectionNetworkResourceCustomization (org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization)3 Service (org.onap.so.db.catalog.beans.Service)3 MsoException (org.onap.so.openstack.exceptions.MsoException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)2 AllottedResource (org.onap.so.db.catalog.beans.AllottedResource)2 TempNetworkHeatTemplateLookup (org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup)2 NetworkType (org.onap.so.openstack.utils.MsoNeutronUtils.NetworkType)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)1 WireMock.urlPathEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo)1