diff options
Diffstat (limited to 'adapters/mso-catalog-db-adapter/src/main')
8 files changed, 254 insertions, 9 deletions
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 79aad1ad1a..b43447f5c4 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 @@ -25,6 +25,7 @@ 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.adapters.catalogdb.rest.VnfRestImpl; import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging; import org.springframework.context.annotation.Configuration; import io.swagger.jaxrs.config.BeanConfig; @@ -42,6 +43,7 @@ public class JerseyConfiguration extends ResourceConfig { register(SwaggerSerializers.class); register(JaxRsFilterLogging.class); register(ServiceRestImpl.class); + register(VnfRestImpl.class); BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.2"); beanConfig.setSchemes(new String[] {"https"}); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogEntityNotFoundException.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogEntityNotFoundException.java new file mode 100644 index 0000000000..f8a7ba6da4 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogEntityNotFoundException.java @@ -0,0 +1,14 @@ +package org.onap.so.adapters.catalogdb.rest; + +public class CatalogEntityNotFoundException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = -300157844846680791L; + + public CatalogEntityNotFoundException(String errorMessage) { + super(errorMessage); + } + +} diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogEntityNotFoundExceptionMapper.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogEntityNotFoundExceptionMapper.java new file mode 100644 index 0000000000..c42eaabea7 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogEntityNotFoundExceptionMapper.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 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 javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Provider +public class CatalogEntityNotFoundExceptionMapper implements ExceptionMapper<CatalogEntityNotFoundException> { + + private static final Logger logger = LoggerFactory.getLogger(CatalogEntityNotFoundExceptionMapper.class); + + @Override + public Response toResponse(CatalogEntityNotFoundException e) { + return Response.status(Response.Status.NOT_FOUND).entity(e).build(); + } +} 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 index dd18767762..e74663dbba 100644 --- 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 @@ -22,9 +22,11 @@ package org.onap.so.adapters.catalogdb.rest; import java.util.ArrayList; import java.util.List; +import org.onap.so.db.catalog.beans.CvnfcCustomization; 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.Cvnfc; import org.onap.so.rest.catalog.beans.Service; import org.onap.so.rest.catalog.beans.VfModule; import org.onap.so.rest.catalog.beans.Vnf; @@ -39,16 +41,23 @@ public class ServiceMapper { public Service mapService(org.onap.so.db.catalog.beans.Service service, int depth) { Service restService = new Service(); - restService.setCategory(service.getCategory()); + if (service.getCategory() != null) { + restService.setCategory(service.getCategory()); + } restService.setCreated(service.getCreated()); restService.setDescription(service.getDescription()); - restService.setDistrobutionStatus(service.getDistrobutionStatus()); + + if (service.getDistrobutionStatus() != null) { + 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()); + if (service.getServiceRole() != null) { + restService.setServiceRole(service.getServiceRole()); + } restService.setServiceType(service.getServiceType()); restService.setWorkloadContext(service.getWorkloadContext()); if (depth > 0) @@ -63,7 +72,7 @@ public class ServiceMapper { return vnfs; } - private Vnf mapVnf(org.onap.so.db.catalog.beans.VnfResourceCustomization vnfResourceCustomization, int depth) { + protected 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()); @@ -81,9 +90,12 @@ public class ServiceMapper { vnf.setNfFunction(vnfResourceCustomization.getNfFunction()); vnf.setNfNamingCode(vnfResourceCustomization.getNfNamingCode()); vnf.setNfRole(vnfResourceCustomization.getNfRole()); + vnf.setNfType(vnfResourceCustomization.getNfType()); + vnf.setNfDataValid(vnfResourceCustomization.getNfDataValid()); vnf.setOrchestrationMode(vnfResourceCustomization.getVnfResources().getOrchestrationMode()); vnf.setSubCategory(vnfResourceCustomization.getVnfResources().getSubCategory()); vnf.setToscaNodeType(vnfResourceCustomization.getVnfResources().getToscaNodeType()); + if (depth > 1) { vnf.setVfModule(mapVfModules(vnfResourceCustomization, depth)); } @@ -93,11 +105,11 @@ public class ServiceMapper { private List<VfModule> mapVfModules(VnfResourceCustomization vnfResourceCustomization, int depth) { List<VfModule> vfModules = new ArrayList<>(); vnfResourceCustomization.getVfModuleCustomizations().parallelStream() - .forEach(vfModule -> vfModules.add(mapVfModule(vfModule))); + .forEach(vfModule -> vfModules.add(mapVfModule(vfModule, depth))); return vfModules; } - private VfModule mapVfModule(VfModuleCustomization vfModuleCust) { + private VfModule mapVfModule(VfModuleCustomization vfModuleCust, int depth) { VfModule vfModule = new VfModule(); vfModule.setAvailabilityZoneCount(vfModuleCust.getAvailabilityZoneCount()); vfModule.setCreated(vfModuleCust.getCreated()); @@ -113,9 +125,34 @@ public class ServiceMapper { vfModule.setModelName(vfModuleCust.getVfModule().getModelName()); vfModule.setModelVersionId(vfModuleCust.getVfModule().getModelUUID()); vfModule.setModelVersion(vfModuleCust.getVfModule().getModelVersion()); + if (depth > 3) { + vfModule.setVnfc(mapCvnfcs(vfModuleCust)); + } return vfModule; } + private List<Cvnfc> mapCvnfcs(VfModuleCustomization vfModuleCustomization) { + List<Cvnfc> cvnfcs = new ArrayList<>(); + vfModuleCustomization.getCvnfcCustomization().parallelStream() + .forEach(cvnfcCust -> cvnfcs.add(mapCvnfcCus(cvnfcCust))); + return cvnfcs; + } + + private Cvnfc mapCvnfcCus(CvnfcCustomization cvnfcCust) { + Cvnfc cvnfc = new Cvnfc(); + cvnfc.setCreated(cvnfcCust.getCreated()); + cvnfc.setDescription(cvnfcCust.getDescription()); + cvnfc.setModelCustomizationId(cvnfcCust.getModelCustomizationUUID()); + cvnfc.setModelInstanceName(cvnfcCust.getModelInstanceName()); + cvnfc.setModelInvariantId(cvnfcCust.getModelInvariantUUID()); + cvnfc.setModelName(cvnfcCust.getModelName()); + cvnfc.setModelVersion(cvnfcCust.getModelVersion()); + cvnfc.setModelVersionId(cvnfcCust.getModelUUID()); + cvnfc.setNfcFunction(cvnfcCust.getNfcFunction()); + cvnfc.setNfcNamingCode(cvnfcCust.getNfcNamingCode()); + return cvnfc; + } + private boolean getIsVolumeGroup(VfModuleCustomization vfModuleCust) { boolean isVolumeGroup = false; HeatEnvironment envt = vfModuleCust.getVolumeHeatEnv(); 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 index 520de4d38c..6f556edfa1 100644 --- 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 @@ -38,7 +38,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -@Api(value = "/v1/services", tags = "model") +@Api(value = "/v1", tags = "model") @Path("/v1/services") @Component public class ServiceRestImpl { @@ -49,18 +49,21 @@ public class ServiceRestImpl { @Autowired private ServiceMapper serviceMapper; + @GET @Path("/{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); + if (service == null) { + new CatalogEntityNotFoundException("Unable to find Service " + modelUUID); + } return serviceMapper.mapService(service, depth); } @GET - @ApiOperation(value = "Find Service Models", response = Service.class, responseContainer = "List", - notes = "If no query parameters are sent an empty list will be returned") + @ApiOperation(value = "Find Service Models", response = Service.class, responseContainer = "List") @Produces({MediaType.APPLICATION_JSON}) @Transactional(readOnly = true) public List<Service> queryServices( @@ -74,6 +77,8 @@ public class ServiceRestImpl { serviceFromDB = serviceRepo.findByModelNameAndDistrobutionStatus(modelName, distributionStatus); } else if (!Strings.isNullOrEmpty(modelName)) { serviceFromDB = serviceRepo.findByModelName(modelName); + } else { + serviceFromDB = serviceRepo.findAll(); } serviceFromDB.stream().forEach(serviceDB -> services.add(serviceMapper.mapService(serviceDB, depth))); return services; diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfMapper.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfMapper.java new file mode 100644 index 0000000000..52a8ccb5a7 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfMapper.java @@ -0,0 +1,37 @@ +package org.onap.so.adapters.catalogdb.rest; + +import org.onap.so.db.catalog.beans.VnfResource; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.rest.catalog.beans.Vnf; +import org.springframework.stereotype.Component; +import com.google.common.base.Strings; + +@Component +public class VnfMapper { + + public VnfResourceCustomization mapVnf(VnfResourceCustomization vnfCust, Vnf vnf) { + + vnfCust.setAvailabilityZoneMaxCount(vnf.getAvailabilityZoneMaxCount()); + vnfCust.setMaxInstances(vnf.getMaxInstances()); + vnfCust.setMinInstances(vnf.getMinInstances()); + vnfCust.setModelCustomizationUUID(vnf.getModelCustomizationId()); + vnfCust.setModelInstanceName(vnf.getModelInstanceName()); + vnfCust.setMultiStageDesign(vnf.getMultiStageDesign()); + vnfCust.setNfDataValid(vnf.getNfDataValid()); + vnfCust.setNfFunction(Strings.nullToEmpty(vnf.getNfFunction())); + vnfCust.setNfNamingCode(Strings.nullToEmpty(vnf.getNfNamingCode())); + vnfCust.setNfRole(Strings.nullToEmpty(vnf.getNfRole())); + vnfCust.setNfType(Strings.nullToEmpty(vnf.getNfType())); + + VnfResource vnfRes = vnfCust.getVnfResources(); + vnfRes.setOrchestrationMode(Strings.nullToEmpty(vnfRes.getOrchestrationMode())); + vnfRes.setSubCategory(Strings.nullToEmpty(vnfRes.getSubCategory())); + vnfRes.setToscaNodeType(Strings.nullToEmpty(vnfRes.getToscaNodeType())); + vnfRes.setModelInvariantUUID(vnfRes.getModelInvariantId()); + vnfRes.setModelName(vnfRes.getModelName()); + vnfRes.setModelUUID(vnfRes.getModelUUID()); + vnfRes.setModelVersion(vnfRes.getModelVersion()); + return vnfCust; + } + +} diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfRestImpl.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfRestImpl.java new file mode 100644 index 0000000000..4353526872 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/VnfRestImpl.java @@ -0,0 +1,107 @@ +/*- + * ============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.List; +import java.util.stream.Collectors; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.data.repository.ServiceRepository; +import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository; +import org.onap.so.rest.catalog.beans.Vnf; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; + +@Api(value = "/v1/services/{modelUUID}/vnfs", tags = "model") +@Path("/v1/services/{modelUUID}/vnfs") +@Component +public class VnfRestImpl { + + @Autowired + private ServiceRepository serviceRepo; + + @Autowired + private ServiceMapper serviceMapper; + + @Autowired + private VnfMapper vnfMapper; + + @Autowired + private VnfCustomizationRepository vnfCustRepo; + + @GET + @ApiOperation(value = "Find a VNF model contained within a service", response = Vnf.class) + @Path("/{modelCustomizationUUID}") + @Produces({MediaType.APPLICATION_JSON}) + @Transactional(readOnly = true) + public Vnf findService(@PathParam("modelUUID") String serviceModelUUID, + @PathParam("modelCustomizationUUID") String modelCustomizationUUID, @QueryParam("depth") int depth) { + org.onap.so.db.catalog.beans.Service service = serviceRepo.findOneByModelUUID(serviceModelUUID); + if (service.getVnfCustomizations() == null || service.getVnfCustomizations().isEmpty()) { + throw new WebApplicationException("Vnf Not Found", 404); + } + List<VnfResourceCustomization> vnfCustom = service.getVnfCustomizations().stream() + .filter(vnfCust -> vnfCust.getModelCustomizationUUID().equals(modelCustomizationUUID)) + .collect(Collectors.toList()); + if (vnfCustom.isEmpty() || vnfCustom == null) { + return null; + } else if (vnfCustom.size() > 1) { + throw new RuntimeException( + "More than one Vnf model returned with model Customization UUID: " + modelCustomizationUUID); + } + return serviceMapper.mapVnf(vnfCustom.get(0), depth); + } + + @PUT + @ApiOperation(value = "Update a VNF model contained within a service", response = Vnf.class) + @Path("/{modelCustomizationUUID}") + @Produces({MediaType.APPLICATION_JSON}) + @Transactional + public Response findService(@PathParam("modelUUID") String serviceModelUUID, + @PathParam("modelCustomizationUUID") String modelCustomizationUUID, Vnf vnf) { + org.onap.so.db.catalog.beans.Service service = serviceRepo.findOneByModelUUID(serviceModelUUID); + List<VnfResourceCustomization> vnfCustom = service.getVnfCustomizations().stream() + .filter(vnfCust -> vnfCust.getModelCustomizationUUID().equals(modelCustomizationUUID)) + .collect(Collectors.toList()); + if (vnfCustom.isEmpty() || vnfCustom == null) { + throw new RuntimeException("No Vnf Found"); + } else if (vnfCustom.size() > 1) { + throw new RuntimeException( + "More than one Vnf model returned with model Customization UUID: " + modelCustomizationUUID); + } + VnfResourceCustomization vnfCust = vnfMapper.mapVnf(vnfCustom.get(0), vnf); + vnfCustRepo.save(vnfCust); + return Response.ok().build(); + } + +} + diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V6.2__AddNfValidData.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V6.2__AddNfValidData.sql new file mode 100644 index 0000000000..93dde1341e --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V6.2__AddNfValidData.sql @@ -0,0 +1,5 @@ +USE catalogdb; + +ALTER TABLE vnf_resource_customization +ADD IF NOT EXISTS NF_DATA_VALID tinyint(1) DEFAULT 0; + |