From acb8997a69725a39270a6527b33995f51c1e4586 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Tue, 30 Apr 2019 21:00:08 -0400 Subject: Add Model Version Query Fix the sql migration version numbering to be proper Fix marking test as private, mark public Clean up public declarations to private Fix schema.sql to have new column for unit test Revert POM Change, add License, clean up comments Fix bad spelling of method name issue Update catalog db to support new rest endpoint Update local query service and mappers Localstaging of potential catalog db changes Update logic to write overall distro status Change-Id: I84d53b972ede3176c5af32d13444583a36606efa Issue-ID: SO-1820 Signed-off-by: Benjamin, Max (mb388a) --- .../so/adapters/catalogdb/JerseyConfiguration.java | 2 + .../catalogdb/rest/CatalogDbAdapterRest.java | 1 + .../so/adapters/catalogdb/rest/ServiceMapper.java | 128 +++++++++++++++++++++ .../adapters/catalogdb/rest/ServiceRestImpl.java | 76 ++++++++++++ .../db/manual/Migrate_Distrobution_Status.sql | 11 ++ .../V5.6.6__Add_Column_For_Distrobution_Status.sql | 1 + 6 files changed, 219 insertions(+) create mode 100644 adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceMapper.java create mode 100644 adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java create mode 100644 adapters/mso-catalog-db-adapter/src/main/resources/db/manual/Migrate_Distrobution_Status.sql create mode 100644 adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.6.6__Add_Column_For_Distrobution_Status.sql (limited to 'adapters/mso-catalog-db-adapter/src/main') diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java index db73d4afec..0e526e59fb 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/JerseyConfiguration.java @@ -24,6 +24,7 @@ import javax.annotation.PostConstruct; import javax.ws.rs.ApplicationPath; import org.glassfish.jersey.server.ResourceConfig; import org.onap.so.adapters.catalogdb.rest.CatalogDbAdapterRest; +import org.onap.so.adapters.catalogdb.rest.ServiceRestImpl; import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging; import org.springframework.context.annotation.Configuration; import io.swagger.jaxrs.config.BeanConfig; @@ -40,6 +41,7 @@ public class JerseyConfiguration extends ResourceConfig { register(ApiListingResource.class); register(SwaggerSerializers.class); register(JaxRsFilterLogging.class); + register(ServiceRestImpl.class); BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.2"); beanConfig.setSchemes(new String[] {"http"}); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java index 6cc53e6ec9..589f119337 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java @@ -279,6 +279,7 @@ public class CatalogDbAdapterRest { @QueryParam("serviceModelUuid") String modelUUID, @QueryParam("serviceModelInvariantUuid") String modelInvariantUUID, @QueryParam("serviceModelVersion") String modelVersion) { + QueryServiceMacroHolder qryResp; int respStatus = HttpStatus.SC_OK; String uuid = ""; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceMapper.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceMapper.java new file mode 100644 index 0000000000..dd18767762 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceMapper.java @@ -0,0 +1,128 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.catalogdb.rest; + +import java.util.ArrayList; +import java.util.List; +import org.onap.so.db.catalog.beans.HeatEnvironment; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.rest.catalog.beans.Service; +import org.onap.so.rest.catalog.beans.VfModule; +import org.onap.so.rest.catalog.beans.Vnf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + + +@Component +public class ServiceMapper { + private static final Logger logger = LoggerFactory.getLogger(ServiceMapper.class); + + public Service mapService(org.onap.so.db.catalog.beans.Service service, int depth) { + Service restService = new Service(); + restService.setCategory(service.getCategory()); + restService.setCreated(service.getCreated()); + restService.setDescription(service.getDescription()); + restService.setDistrobutionStatus(service.getDistrobutionStatus()); + restService.setEnvironmentContext(service.getEnvironmentContext()); + restService.setModelInvariantId(service.getModelInvariantUUID()); + restService.setModelName(service.getModelName()); + restService.setModelVersionId(service.getModelUUID()); + restService.setModelVersion(service.getModelVersion()); + restService.setServiceRole(service.getServiceRole()); + restService.setServiceType(service.getServiceType()); + restService.setWorkloadContext(service.getWorkloadContext()); + if (depth > 0) + restService.setVnf(mapVnfs(service, depth)); + return restService; + } + + private List mapVnfs(org.onap.so.db.catalog.beans.Service service, int depth) { + List vnfs = new ArrayList<>(); + logger.info("Vnf Count : {}", service.getVnfCustomizations().size()); + service.getVnfCustomizations().parallelStream().forEach(vnf -> vnfs.add(mapVnf(vnf, depth))); + return vnfs; + } + + private Vnf mapVnf(org.onap.so.db.catalog.beans.VnfResourceCustomization vnfResourceCustomization, int depth) { + Vnf vnf = new Vnf(); + vnf.setAvailabilityZoneMaxCount(vnfResourceCustomization.getAvailabilityZoneMaxCount()); + vnf.setCategory(vnfResourceCustomization.getVnfResources().getCategory()); + vnf.setCloudVersionMax(vnfResourceCustomization.getVnfResources().getAicVersionMax()); + vnf.setCloudVersionMin(vnfResourceCustomization.getVnfResources().getAicVersionMin()); + vnf.setMaxInstances(vnfResourceCustomization.getMaxInstances()); + vnf.setMinInstances(vnfResourceCustomization.getMinInstances()); + vnf.setModelCustomizationId(vnfResourceCustomization.getModelCustomizationUUID()); + vnf.setModelInstanceName(vnfResourceCustomization.getModelInstanceName()); + vnf.setModelInvariantId(vnfResourceCustomization.getVnfResources().getModelInvariantId()); + vnf.setModelName(vnfResourceCustomization.getVnfResources().getModelName()); + vnf.setModelVersionId(vnfResourceCustomization.getVnfResources().getModelUUID()); + vnf.setModelVersion(vnfResourceCustomization.getVnfResources().getModelVersion()); + vnf.setMultiStageDesign(vnfResourceCustomization.getMultiStageDesign()); + vnf.setNfFunction(vnfResourceCustomization.getNfFunction()); + vnf.setNfNamingCode(vnfResourceCustomization.getNfNamingCode()); + vnf.setNfRole(vnfResourceCustomization.getNfRole()); + vnf.setOrchestrationMode(vnfResourceCustomization.getVnfResources().getOrchestrationMode()); + vnf.setSubCategory(vnfResourceCustomization.getVnfResources().getSubCategory()); + vnf.setToscaNodeType(vnfResourceCustomization.getVnfResources().getToscaNodeType()); + if (depth > 1) { + vnf.setVfModule(mapVfModules(vnfResourceCustomization, depth)); + } + return vnf; + } + + private List mapVfModules(VnfResourceCustomization vnfResourceCustomization, int depth) { + List vfModules = new ArrayList<>(); + vnfResourceCustomization.getVfModuleCustomizations().parallelStream() + .forEach(vfModule -> vfModules.add(mapVfModule(vfModule))); + return vfModules; + } + + private VfModule mapVfModule(VfModuleCustomization vfModuleCust) { + VfModule vfModule = new VfModule(); + vfModule.setAvailabilityZoneCount(vfModuleCust.getAvailabilityZoneCount()); + vfModule.setCreated(vfModuleCust.getCreated()); + vfModule.setDescription(vfModuleCust.getVfModule().getDescription()); + vfModule.setInitialCount(vfModuleCust.getInitialCount()); + vfModule.setIsBase(vfModuleCust.getVfModule().getIsBase()); + vfModule.setIsVolumeGroup(getIsVolumeGroup(vfModuleCust)); + vfModule.setMaxInstances(vfModuleCust.getMaxInstances()); + vfModule.setMinInstances(vfModuleCust.getMinInstances()); + vfModule.setLabel(vfModuleCust.getLabel()); + vfModule.setModelCustomizationId(vfModuleCust.getModelCustomizationUUID()); + vfModule.setModelInvariantId(vfModuleCust.getVfModule().getModelInvariantUUID()); + vfModule.setModelName(vfModuleCust.getVfModule().getModelName()); + vfModule.setModelVersionId(vfModuleCust.getVfModule().getModelUUID()); + vfModule.setModelVersion(vfModuleCust.getVfModule().getModelVersion()); + return vfModule; + } + + private boolean getIsVolumeGroup(VfModuleCustomization vfModuleCust) { + boolean isVolumeGroup = false; + HeatEnvironment envt = vfModuleCust.getVolumeHeatEnv(); + if (envt != null) { + isVolumeGroup = true; + } + return isVolumeGroup; + } + +} diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java new file mode 100644 index 0000000000..1ca8998396 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/ServiceRestImpl.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.catalogdb.rest; + +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.onap.so.db.catalog.data.repository.ServiceRepository; +import org.onap.so.rest.catalog.beans.Service; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import com.google.common.base.Strings; +import io.swagger.annotations.ApiOperation; + +@Path("/v1/") +@Component +public class ServiceRestImpl { + + @Autowired + private ServiceRepository serviceRepo; + + @Autowired + private ServiceMapper serviceMapper; + + @GET + @Path("/services/{modelUUID}") + @Produces({MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public Service findService(@PathParam("modelUUID") String modelUUID, @QueryParam("depth") int depth) { + org.onap.so.db.catalog.beans.Service service = serviceRepo.findOneByModelUUID(modelUUID); + return serviceMapper.mapService(service, depth); + } + + @GET + @Path("/services") + @ApiOperation(value = "Find Service Models", response = Service.class, responseContainer = "List") + @Produces({MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public List queryServices(@QueryParam("modelName") String modelName, + @QueryParam("distributionStatus") String distributionStatus, @QueryParam("depth") int depth) { + List services = new ArrayList<>(); + List serviceFromDB = new ArrayList<>(); + if (!Strings.isNullOrEmpty(modelName) && !Strings.isNullOrEmpty(distributionStatus)) { + serviceFromDB = serviceRepo.findByModelNameAndDistrobutionStatus(modelName, distributionStatus); + } else if (!Strings.isNullOrEmpty(modelName)) { + serviceFromDB = serviceRepo.findByModelName(modelName); + } + serviceFromDB.stream().forEach(serviceDB -> services.add(serviceMapper.mapService(serviceDB, depth))); + return services; + } +} diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/manual/Migrate_Distrobution_Status.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/manual/Migrate_Distrobution_Status.sql new file mode 100644 index 0000000000..4a9c2cce9f --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/manual/Migrate_Distrobution_Status.sql @@ -0,0 +1,11 @@ + +UPDATE catalogdb.service serv SET OVERALL_DISTRIBUTION_STATUS =( +SELECT wds.DISTRIBUTION_ID_STATUS +FROM requestdb.watchdog_distributionid_status wds +INNER JOIN requestdb.watchdog_service_mod_ver_id_lookup wdlook +ON wds.DISTRIBUTION_ID = wdlook.DISTRIBUTION_ID +WHERE wdlook.SERVICE_MODEL_VERSION_ID = serv.MODEL_UUID +ORDER BY wdlook.MODIFY_TIME DESC LIMIT 1); + +UPDATE catalogdb.service SET OVERALL_DISTRIBUTION_STATUS = 'DISTRIBUTION_COMPLETE_OK' +WHERE service.OVERALL_DISTRIBUTION_STATUS = NULL; \ No newline at end of file diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.6.6__Add_Column_For_Distrobution_Status.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.6.6__Add_Column_For_Distrobution_Status.sql new file mode 100644 index 0000000000..ae416ffbfe --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.6.6__Add_Column_For_Distrobution_Status.sql @@ -0,0 +1 @@ +ALTER TABLE catalogdb.service ADD COLUMN IF NOT EXISTS OVERALL_DISTRIBUTION_STATUS varchar(45); \ No newline at end of file -- cgit 1.2.3-korg