diff options
Diffstat (limited to 'adapters/mso-catalog-db-adapter')
17 files changed, 780 insertions, 4 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 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/catalogrest/QueryGroups.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryGroups.java new file mode 100644 index 0000000000..c15b0d9df1 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryGroups.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei 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.catalogrest; + +import org.onap.so.db.catalog.beans.InstanceGroup; +import org.onap.so.db.catalog.beans.VFCInstanceGroup; +import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@XmlRootElement(name = "groups") +public class QueryGroups extends CatalogQuery { + + private List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations; + private static final String TEMPLATE = "\n" + "\t{ \"modelInfo\" : {\n" + + "\t\t\"modelName\" : <MODEL_NAME>,\n" + "\t\t\"modelUuid\" : <MODEL_UUID>,\n" + + "\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n" + + "\t\t\"modelVersion\" : <MODEL_VERSION>\n" + "\t\t},\n" + "<_VNFCS_>\n" + "\t}"; + + public QueryGroups() { + super(); + vnfcInstanceGroupCustomizations = new ArrayList<>(); + + } + + public QueryGroups(List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations) { + this.vnfcInstanceGroupCustomizations = new ArrayList<>(); + if (vnfcInstanceGroupCustomizations != null) { + for (VnfcInstanceGroupCustomization g : vnfcInstanceGroupCustomizations) { + if (logger.isDebugEnabled()) { + logger.debug(g.toString()); + } + this.vnfcInstanceGroupCustomizations.add(g); + } + } + } + + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) + sb.append("{ "); + if (isArray) + sb.append("\"groups\": ["); + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + for (VnfcInstanceGroupCustomization o : vnfcInstanceGroupCustomizations) { + if (first) + sb.append("\n"); + first = false; + + boolean vnfcCustomizationNull = o.getVnfcCustomizations() == null; + InstanceGroup instanceGroup = o.getInstanceGroup(); + + if (instanceGroup != null) { + put(valueMap, "MODEL_NAME", instanceGroup.getModelName()); + put(valueMap, "MODEL_UUID", instanceGroup.getModelInvariantUUID()); + put(valueMap, "MODEL_INVARIANT_ID", instanceGroup.getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", instanceGroup.getModelUUID()); + } + + String subItem = new QueryVnfcs(vnfcCustomizationNull ? null : o.getVnfcCustomizations()).JSON2(true, true); + valueMap.put("_VNFCS_", subItem.replaceAll("(?m)^", "\t\t")); + sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); + sep = ",\n"; + } + if (!first) + sb.append("\n"); + if (isArray) + sb.append("]"); + if (!isEmbed && isArray) + sb.append("}"); + return sb.toString(); + } +} diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java index f786f25361..e5241a4e95 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceVnfs.java @@ -25,8 +25,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import javax.xml.bind.annotation.XmlRootElement; +import org.onap.so.db.catalog.beans.InstanceGroup; +import org.onap.so.db.catalog.beans.VFCInstanceGroup; import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +49,7 @@ public class QueryServiceVnfs extends CatalogQuery { + "\t\"nfFunction\" : <NF_FUNCTION>,\n" + "\t\"nfType\" : <NF_TYPE>,\n" + "\t\"nfRole\" : <NF_ROLE>,\n" + "\t\"nfNamingCode\" : <NF_NAMING_CODE>,\n" + "\t\"multiStageDesign\" : <MULTI_STEP_DESIGN>,\n" - + "\t\"resourceInput\" : <RESOURCE_INPUT>,\n" + "<_VFMODULES_>\n" + "\t}"; + + "\t\"resourceInput\" : <RESOURCE_INPUT>,\n" + "<_VFMODULES_>,\n" + "<_GROUPS_>\n" + "\t}"; public QueryServiceVnfs() { super(); @@ -120,6 +124,12 @@ public class QueryServiceVnfs extends CatalogQuery { String subitem = new QueryVfModule(vrNull ? null : o.getVfModuleCustomizations()).JSON2(true, true); valueMap.put("_VFMODULES_", subitem.replaceAll("(?m)^", "\t\t")); + List<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizations = + o.getVnfcInstanceGroupCustomizations(); + + String grpSubItem = new QueryGroups(vrNull ? null : vnfcInstanceGroupCustomizations).JSON2(true, true); + valueMap.put("_GROUPS_", grpSubItem.replaceAll("(?m)^", "\t\t")); + sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); sep = ",\n"; } diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java new file mode 100644 index 0000000000..0bf82fd8b7 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcs.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei 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.catalogrest; + +import org.onap.so.db.catalog.beans.VnfcCustomization; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@XmlRootElement(name = "vnfcs") +public class QueryVnfcs extends CatalogQuery { + private List<VnfcCustomization> vnfcCustomizations; + private static final String TEMPLATE = + "\t{\n" + "\t\t\"modelInfo\" : { \n" + "\t\t\t\"modelName\" : <MODEL_NAME>,\n" + + "\t\t\t\"modelUuid\" : <MODEL_UUID>,\n" + + "\t\t\t\"modelInvariantUuid\" : <MODEL_INVARIANT_ID>,\n" + + "\t\t\t\"modelVersion\" : <MODEL_VERSION>,\n" + + "\t\t\t\"modelCustomizationUuid\" : <MODEL_CUSTOMIZATION_UUID>\n" + "\t\t}" + "\t}"; + + public QueryVnfcs() { + super(); + vnfcCustomizations = new ArrayList(); + } + + public QueryVnfcs(List<VnfcCustomization> vnfcCustomizations) { + this.vnfcCustomizations = new ArrayList(); + if (vnfcCustomizations != null) { + for (VnfcCustomization vnfcCustomization : vnfcCustomizations) { + if (logger.isDebugEnabled()) { + logger.debug(vnfcCustomization.toString()); + } + this.vnfcCustomizations.add(vnfcCustomization); + } + } + } + + public List<VnfcCustomization> getVnfcCustomizations() { + return vnfcCustomizations; + } + + public void setVnfcCustomizations(List<VnfcCustomization> vnfcCustomizations) { + this.vnfcCustomizations = vnfcCustomizations; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + boolean first = true; + int i = 1; + for (VnfcCustomization o : vnfcCustomizations) { + sb.append(i).append("\t"); + if (!first) { + sb.append("\n"); + } + first = false; + sb.append(o); + } + return sb.toString(); + } + + @Override + public String JSON2(boolean isArray, boolean isEmbed) { + StringBuilder sb = new StringBuilder(); + if (!isEmbed && isArray) { + sb.append("{"); + } + + if (isArray) { + sb.append("\"vnfcs\": ["); + } + + Map<String, String> valueMap = new HashMap<>(); + String sep = ""; + boolean first = true; + + for (VnfcCustomization o : vnfcCustomizations) { + if (first) + sb.append("\n"); + first = false; + + put(valueMap, "MODEL_NAME", o.getModelName()); + put(valueMap, "MODEL_UUID", o.getModelUUID()); + put(valueMap, "MODEL_INVARIANT_ID", o.getModelInvariantUUID()); + put(valueMap, "MODEL_VERSION", o.getModelVersion()); + put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID()); + + sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap)); + sep = ",\n"; + } + if (!first) + sb.append("\n"); + if (isArray) + sb.append("]"); + if (!isEmbed && isArray) + sb.append("}"); + return sb.toString(); + } +} 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<Vnf> mapVnfs(org.onap.so.db.catalog.beans.Service service, int depth) { + List<Vnf> 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<VfModule> mapVfModules(VnfResourceCustomization vnfResourceCustomization, int depth) { + List<VfModule> 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<Service> queryServices(@QueryParam("modelName") String modelName, + @QueryParam("distributionStatus") String distributionStatus, @QueryParam("depth") int depth) { + List<Service> services = new ArrayList<>(); + List<org.onap.so.db.catalog.beans.Service> 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/application.yaml b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml index aa9317c920..b1528a0897 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml +++ b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml @@ -52,4 +52,4 @@ management: prometheus: enabled: true # Whether exporting of metrics to Prometheus is enabled. step: 1m # Step size (i.e. reporting frequency) to use. -
\ No newline at end of file + 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.11__AddVnfResourceOrder.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql index fabb005567..16e6ecf4bf 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.11__AddVnfResourceOrder.sql @@ -1,3 +1,7 @@ use catalogdb; + ALTER TABLE vnf_resource_customization -ADD VNFCINSTANCEGROUP_ORDER varchar(255);
\ No newline at end of file +ADD VNFCINSTANCEGROUP_ORDER varchar(255); + +ALTER TABLE vnfc_customization +ADD RESOURCE_INPUT varchar(2000);
\ No newline at end of file diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.12__Add_Relation_VnfcCustomization.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.12__Add_Relation_VnfcCustomization.sql new file mode 100644 index 0000000000..95a2c25eb8 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V5.12__Add_Relation_VnfcCustomization.sql @@ -0,0 +1,2 @@ +use catalogdb; +ALTER TABLE vnfc_customization ADD vnfc_instance_group_customization_id INTEGER 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 diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryGroupsTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryGroupsTest.java new file mode 100644 index 0000000000..00db6d5938 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryGroupsTest.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei 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.catalogrest; + +import org.assertj.core.api.Assertions; +import org.junit.Test; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.VFCInstanceGroup; +import org.onap.so.db.catalog.beans.VnfResource; +import org.onap.so.db.catalog.beans.VnfResourceCustomization; +import org.onap.so.db.catalog.beans.VnfcCustomization; +import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; +import org.onap.so.db.catalog.rest.beans.ServiceMacroHolder; +import org.onap.so.jsonpath.JsonPathUtil; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class QueryGroupsTest { + + @Test + public void convertToJson_successful() { + QueryGroups queryGroups = new QueryGroups(createList()); + String jsonResult = queryGroups.JSON2(true, false); + + Assertions.assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.groups[0].modelInfo.modelName")) + .contains("test"); + Assertions + .assertThat( + JsonPathUtil.getInstance().locateResult(jsonResult, "$.groups[0].vnfcs[0].modelInfo.modelName")) + .contains("test"); + } + + private List<VnfcInstanceGroupCustomization> createList() { + + VnfcCustomization vnfcCustomization = new VnfcCustomization(); + vnfcCustomization.setModelCustomizationUUID("test"); + vnfcCustomization.setModelVersion("test"); + vnfcCustomization.setModelInvariantUUID("test"); + vnfcCustomization.setModelName("test"); + + VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup(); + vfcInstanceGroup.setModelName("test"); + vfcInstanceGroup.setModelUUID("test"); + vfcInstanceGroup.setModelInvariantUUID("test"); + vfcInstanceGroup.setModelVersion("test"); + + VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = new VnfcInstanceGroupCustomization(); + vnfcInstanceGroupCustomization.setVnfcCustomizations(Arrays.asList(vnfcCustomization)); + vnfcInstanceGroupCustomization.setInstanceGroup(vfcInstanceGroup); + + + vfcInstanceGroup.setVnfcInstanceGroupCustomizations(Arrays.asList(vnfcInstanceGroupCustomization)); + return Arrays.asList(vnfcInstanceGroupCustomization); + } +} diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcsTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcsTest.java new file mode 100644 index 0000000000..1fd4f19e29 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/QueryVnfcsTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei 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.catalogrest; + +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; +import org.onap.so.db.catalog.beans.VnfcCustomization; +import org.onap.so.jsonpath.JsonPathUtil; +import java.util.ArrayList; +import java.util.List; + +public class QueryVnfcsTest { + + @Test + public void convertToJson_successful() { + QueryVnfcs queryVnfcs = new QueryVnfcs(createList()); + String jsonResult = queryVnfcs.JSON2(true, false); + System.out.println(jsonResult); + assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vnfcs[0].modelInfo.modelName")) + .contains("model1"); + assertThat(JsonPathUtil.getInstance().locateResult(jsonResult, "$.vnfcs[1].modelInfo.modelName")) + .contains("model2"); + + } + + private List<VnfcCustomization> createList() { + List<VnfcCustomization> customizations = new ArrayList(); + + VnfcCustomization c1 = new VnfcCustomization(); + c1.setModelName("model1"); + c1.setModelUUID("uuid1"); + c1.setModelInvariantUUID("inv1"); + c1.setModelVersion("v1"); + c1.setModelCustomizationUUID("cust1"); + + VnfcCustomization c2 = new VnfcCustomization(); + c2.setModelName("model2"); + c2.setModelUUID("uuid2"); + c2.setModelInvariantUUID("inv2"); + c2.setModelVersion("v2"); + c2.setModelCustomizationUUID("cust2"); + + customizations.add(c1); + customizations.add(c2); + return customizations; + } +} diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/ServiceMapperTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/ServiceMapperTest.java new file mode 100644 index 0000000000..b8161de6b2 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/adapters/catalogdb/catalogrest/ServiceMapperTest.java @@ -0,0 +1,134 @@ +package org.onap.so.adapters.catalogdb.catalogrest; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import org.junit.Test; +import org.onap.so.adapters.catalogdb.rest.ServiceMapper; +import org.onap.so.db.catalog.beans.HeatTemplate; +import org.onap.so.db.catalog.beans.HeatTemplateParam; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.rest.catalog.beans.Service; +import wiremock.com.fasterxml.jackson.core.JsonParseException; +import wiremock.com.fasterxml.jackson.databind.JsonMappingException; +import wiremock.com.fasterxml.jackson.databind.ObjectMapper; + +public class ServiceMapperTest { + + private ServiceMapper serviceMapper = new ServiceMapper(); + + @Test + public void service_map_test() throws JsonParseException, JsonMappingException, IOException { + Service actual = serviceMapper.mapService(getTestService(), 2); + assertThat(actual, sameBeanAs(getExpectedService())); + } + + private Service getExpectedService() throws JsonParseException, JsonMappingException, IOException { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(getJson("ExpectedService.json"), Service.class); + } + + + private org.onap.so.db.catalog.beans.Service getTestService() { + org.onap.so.db.catalog.beans.Service testService = new org.onap.so.db.catalog.beans.Service(); + testService.setCategory("category"); + testService.setDescription("description"); + testService.setDistrobutionStatus("distrobutionStatus"); + testService.setEnvironmentContext("environmentContext"); + testService.setModelInvariantUUID("modelInvariantUUID"); + testService.setModelName("modelName"); + testService.setModelUUID("modelUUID"); + testService.setModelVersion("modelVersion"); + testService.setServiceType("serviceType"); + testService.setServiceRole("serviceRole"); + testService.getVnfCustomizations().add(getTestVnfCustomization()); + return testService; + } + + private org.onap.so.db.catalog.beans.VnfResourceCustomization getTestVnfCustomization() { + org.onap.so.db.catalog.beans.VnfResourceCustomization test = + new org.onap.so.db.catalog.beans.VnfResourceCustomization(); + test.setId(1); + test.setAvailabilityZoneMaxCount(11); + test.setMaxInstances(3); + test.setMinInstances(1); + test.setModelCustomizationUUID("modelCustomizationUUID"); + test.setModelInstanceName("modelInstanceName"); + test.setMultiStageDesign("multiStageDesign"); + test.setNfFunction("nfFunction"); + test.setNfNamingCode("nfNamingCode"); + test.setNfRole("nfRole"); + test.setNfType("nfType"); + test.setService(new org.onap.so.db.catalog.beans.Service()); + test.setVnfResources(getTestVnfResource()); + test.setVfModuleCustomizations(getTestVfModuleCust()); + return test; + } + + private List<VfModuleCustomization> getTestVfModuleCust() { + List<VfModuleCustomization> test = new ArrayList<>(); + VfModuleCustomization testVfMod = new VfModuleCustomization(); + testVfMod.setAvailabilityZoneCount(10); + testVfMod.setInitialCount(1); + testVfMod.setLabel("label"); + testVfMod.setMaxInstances(3); + testVfMod.setMinInstances(1); + testVfMod.setModelCustomizationUUID("modelCustomizationUUID"); + org.onap.so.db.catalog.beans.VfModule vfModule = new org.onap.so.db.catalog.beans.VfModule(); + vfModule.setDescription("description"); + vfModule.setIsBase(false); + vfModule.setModelInvariantUUID("modelInvariantUUID"); + vfModule.setModelName("modelName"); + vfModule.setModelUUID("modelUUID"); + vfModule.setModelVersion("modelVersion"); + HeatTemplate moduleHeatTemplate = new HeatTemplate(); + moduleHeatTemplate.setArtifactChecksum("artifactChecksum"); + moduleHeatTemplate.setArtifactUuid("artifactUuid"); + List<HeatTemplate> childTemplates; + // moduleHeatTemplate.setChildTemplates(childTemplates); + moduleHeatTemplate.setDescription("description"); + Set<HeatTemplateParam> parameters = new HashSet<>(); + HeatTemplateParam heatParam = new HeatTemplateParam(); + heatParam.setHeatTemplateArtifactUuid("heatTemplateArtifactUuid"); + heatParam.setParamAlias("paramAlias"); + heatParam.setParamName("paramName"); + heatParam.setParamType("paramType"); + heatParam.setRequired(false); + parameters.add(heatParam); + moduleHeatTemplate.setParameters(parameters); + moduleHeatTemplate.setTemplateBody("templateBody"); + moduleHeatTemplate.setTemplateName("templateName"); + moduleHeatTemplate.setTimeoutMinutes(1000); + moduleHeatTemplate.setVersion("version"); + vfModule.setModuleHeatTemplate(moduleHeatTemplate); + testVfMod.setVfModule(vfModule); + test.add(testVfMod); + return test; + } + + private org.onap.so.db.catalog.beans.VnfResource getTestVnfResource() { + org.onap.so.db.catalog.beans.VnfResource test = new org.onap.so.db.catalog.beans.VnfResource(); + test.setCategory("category"); + test.setDescription("description"); + test.setModelInvariantUUID("modelInvariantUUID"); + test.setModelName("modelName"); + test.setModelUUID("modelUUID"); + test.setModelVersion("modelVersion"); + test.setAicVersionMax("cloudVersionMax"); + test.setAicVersionMin("cloudVersionMin"); + test.setOrchestrationMode("orchestrationMode"); + test.setSubCategory("subCategory"); + test.setToscaNodeType("toscaNodeType"); + return test; + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename))); + } +} diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index 51b44b0d3a..4127d07c5f 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java @@ -289,7 +289,6 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest { Assert.assertNotNull(vnfResource.getModelInvariantId()); Assert.assertNotNull(vnfResource.getModelVersion()); Assert.assertNotNull(vnfResource.getHeatTemplates()); - Assert.assertNotNull(vnfResource.getVnfResourceCustomizations()); Assert.assertEquals("vSAMP10a", vnfResource.getModelName()); } diff --git a/adapters/mso-catalog-db-adapter/src/test/resources/ExpectedService.json b/adapters/mso-catalog-db-adapter/src/test/resources/ExpectedService.json new file mode 100644 index 0000000000..cc5145f0e3 --- /dev/null +++ b/adapters/mso-catalog-db-adapter/src/test/resources/ExpectedService.json @@ -0,0 +1,52 @@ +{ + "modelName": "modelName", + "description": "description", + "modelVersionId": "modelUUID", + "modelInvariantId": "modelInvariantUUID", + "modelVersion": "modelVersion", + "serviceType": "serviceType", + "serviceRole": "serviceRole", + "environmentContext": "environmentContext", + "category": "category", + "distrobutionStatus": "distrobutionStatus", + "vnf": [ + { + "modelName": "modelName", + "modelVersionId": "modelUUID", + "modelInvariantId": "modelInvariantUUID", + "modelVersion": "modelVersion", + "modelCustomizationId": "modelCustomizationUUID", + "modelInstanceName": "modelInstanceName", + "minInstances": 1, + "maxInstances": 3, + "availabilityZoneMaxCount": 11, + "toscaNodeType": "toscaNodeType", + "nfFunction": "nfFunction", + "nfRole": "nfRole", + "nfNamingCode": "nfNamingCode", + "multiStageDesign": "multiStageDesign", + "orchestrationMode": "orchestrationMode", + "cloudVersionMin": "cloudVersionMin", + "cloudVersionMax": "cloudVersionMax", + "category": "category", + "subCategory": "subCategory", + "vfModule": [ + { + "modelVersionId": "modelUUID", + "modelInvariantId": "modelInvariantUUID", + "modelName": "modelName", + "modelVersion": "modelVersion", + "description": "description", + "isBase": false, + "modelCustomizationId": "modelCustomizationUUID", + "label": "label", + "minInstances": 1, + "maxInstances": 3, + "initialCount": "1", + "availabilityZoneCount": 10, + "isVolumeGroup": false + } + ] + } + ] +}
\ No newline at end of file |