import org.onap.so.db.catalog.beans.ServiceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.util.CollectionUtils;
import javax.xml.bind.annotation.XmlRootElement;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
@XmlRootElement(name = "serviceInfo")
this.serviceInfo = new ServiceInfo();
}
- public QueryServiceInfo(ServiceInfo serviceInfo) {
- this.serviceInfo = serviceInfo;
+ public QueryServiceInfo(List<ServiceInfo> serviceInfos) {
+ if (!CollectionUtils.isEmpty(serviceInfos)) {
+ this.serviceInfo = serviceInfos.get(0);
+ }
}
public ServiceInfo getServiceInfo() {
subitem = new QueryAllottedResourceCustomization(service.getAllottedCustomizations()).JSON2(true, true);
valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll(LINE_BEGINNING, "\t"));
- subitem = new QueryServiceInfo(serviceMacroHolder.getServiceInfo()).JSON2(true, true);
+ subitem = new QueryServiceInfo(service.getServiceInfos()).JSON2(true, true);
valueMap.put("_SERVICEINFO_", subitem.replaceAll(LINE_BEGINNING, "\t"));
subitem = new QueryServiceProxyCustomization(service.getServiceProxyCustomizations()).JSON2(true, true);
@Autowired
private InstanceGroupRepository instanceGroupRepository;
- @Autowired
- private ServiceInfoRepository serviceInfoRepository;
-
private static final String NO_MATCHING_PARAMETERS = "no matching parameters";
public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) {
respStatus = HttpStatus.SC_NOT_FOUND;
qryResp = new QueryServiceMacroHolder();
} else {
- ServiceInfo serviceInfo = serviceInfoRepository.findByService(ret.getService());
- ret.setServiceInfo(serviceInfo);
qryResp = new QueryServiceMacroHolder(ret);
logger.debug("serviceMacroHolder qryResp= {}", qryResp);
}
`ID` int (11) AUTO_INCREMENT,
`SERVICE_INPUT` varchar (5000),
`SERVICE_PROPERTIES` varchar (5000),
- PRIMARY KEY (`ID`)
+ `SERVICE_MODEL_UUID` varchar (200) NOT NULL,
+ PRIMARY KEY (`ID`),
+ CONSTRAINT `fk_service_info_service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `service_artifact`(
`CREATION_TIMESTAMP` DATETIME DEFAULT CURRENT_TIMESTAMP,
`SERVICE_MODEL_UUID` varchar (200) NOT NULL,
PRIMARY KEY (`ARTIFACT_UUID`),
- CONSTRAINT `fk_service_artifact_service_info1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE
+ CONSTRAINT `fk_service_artifact_service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
-
-CREATE TABLE IF NOT EXISTS `service_to_service_info` (
- `SERVICE_MODEL_UUID` varchar (200) NOT NULL,
- `SERVICE_INFO_ID` INT (11) NOT NULL,
- PRIMARY KEY (`SERVICE_MODEL_UUID`,`SERVICE_INFO_ID`),
- CONSTRAINT `fk_service_to_service_info__service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `fk_service_to_service_info__service_info1` FOREIGN KEY (`SERVICE_INFO_ID`) REFERENCES `service_info` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
-)
\ No newline at end of file
@Autowired
protected PnfCustomizationRepository pnfCustomizationRepository;
- @Autowired
- protected ServiceInfoRepository serviceInfoRepository;
-
@Autowired
protected WorkflowResource workflowResource;
createToscaCsar(toscaResourceStruct);
createService(toscaResourceStruct, vfResourceStruct);
Service service = toscaResourceStruct.getCatalogService();
- ServiceInfo serviceInfo = createServiceInfo(toscaResourceStruct, service);
+ createServiceInfo(toscaResourceStruct, service);
List<IEntityDetails> vfEntityList = getEntityDetails(toscaResourceStruct,
EntityQuery.newBuilder(SdcTypes.VF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
processServiceProxyAndConfiguration(toscaResourceStruct, service);
logger.info("Saving Service: {} ", service.getModelName());
- ServiceInfo serviceResult = serviceInfoRepository.save(serviceInfo);
- Service resultService = serviceResult.getService();
- correlateConfigCustomResources(resultService);
+ service = serviceRepo.save(service);
+ correlateConfigCustomResources(service);
workflowResource.processWorkflows(vfResourceStructure);
createToscaCsar(toscaResourceStruct);
createService(toscaResourceStruct, vfResourceStruct);
Service service = toscaResourceStruct.getCatalogService();
- ServiceInfo serviceInfo = createServiceInfo(toscaResourceStruct, service);
+ createServiceInfo(toscaResourceStruct, service);
createServiceArtifact(service, vfResourceStruct, artifactContent);
- serviceInfoRepository.save(serviceInfo);
+ serviceRepo.save(service);
}
private void createServiceArtifact(Service service, VfResourceStructure vfResourceStruct, String artifactContent) {
service.setServiceArtifactList(serviceArtifactList);
}
- private ServiceInfo createServiceInfo(ToscaResourceStructure toscaResourceStruct, Service service) {
+ private void createServiceInfo(ToscaResourceStructure toscaResourceStruct, Service service) {
+ List<ServiceInfo> serviceInfos = new ArrayList<>();
+
ServiceInfo serviceInfo = new ServiceInfo();
String serviceInput = getServiceInput(toscaResourceStruct);
serviceInfo.setServiceInput(serviceInput);
String serviceProperties = getServiceProperties(toscaResourceStruct);
serviceInfo.setServiceProperties(serviceProperties);
-
serviceInfo.setService(service);
- return serviceInfo;
+ serviceInfos.add(serviceInfo);
+
+ service.setServiceInfos(serviceInfos);
}
private String getServiceProperties(ToscaResourceStructure toscaResourceStruct) {
doReturn(resourceCustomizationUUID).when(metadata).getValue("vfModuleModelCustomizationUUID");
ServiceRepository serviceRepo = spy(ServiceRepository.class);
- ServiceInfoRepository serviceInfoRepo = spy(ServiceInfoRepository.class);
VnfResourceRepository vnfRepo = spy(VnfResourceRepository.class);
doReturn(null).when(vnfRepo).findResourceByModelUUID(uuid);
WorkflowResource workflowResource = spy(WorkflowResource.class);
ReflectionTestUtils.setField(toscaInstaller, "serviceRepo", serviceRepo);
- ReflectionTestUtils.setField(toscaInstaller, "serviceInfoRepository", serviceInfoRepo);
ReflectionTestUtils.setField(toscaInstaller, "vnfRepo", vnfRepo);
ReflectionTestUtils.setField(toscaInstaller, "vfModuleRepo", vfModuleRepo);
ReflectionTestUtils.setField(toscaInstaller, "instanceGroupRepo", instanceGroupRepo);
assertNotNull(service);
service.setModelVersion("1.0");
- ServiceInfo serviceInfo = new ServiceInfo();
- serviceInfo.setService(service);
doReturn(service).when(serviceRepo).save(service);
- doReturn(serviceInfo).when(serviceInfoRepo).save(any(ServiceInfo.class));
WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository =
spy(WatchdogComponentDistributionStatusRepository.class);
`ID` int (11) AUTO_INCREMENT,
`SERVICE_INPUT` varchar (5000),
`SERVICE_PROPERTIES` varchar (5000),
- PRIMARY KEY (`ID`)
+ `SERVICE_MODEL_UUID` varchar (200) NOT NULL,
+ PRIMARY KEY (`ID`),
+ CONSTRAINT `fk_service_info_service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS `service_artifact`(
CONSTRAINT `fk_service_artifact_service_info1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
-CREATE TABLE IF NOT EXISTS `service_to_service_info` (
- `SERVICE_MODEL_UUID` varchar (200) NOT NULL,
- `SERVICE_INFO_ID` INT (11) NOT NULL,
- PRIMARY KEY (`SERVICE_MODEL_UUID`,`SERVICE_INFO_ID`),
- CONSTRAINT `fk_service_to_service_info__service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE,
- CONSTRAINT `fk_service_to_service_info__service_info1` FOREIGN KEY (`SERVICE_INFO_ID`) REFERENCES `service_info` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
-)ENGINE=InnoDB DEFAULT CHARSET=latin1;
-
--------START Request DB SCHEMA --------
CREATE DATABASE requestdb;
USE requestdb;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "service")
private List<ServiceArtifact> serviceArtifactList;
+ @OneToMany(cascade = CascadeType.ALL, mappedBy = "service")
+ private List<ServiceInfo> serviceInfos;
+
@Column(name = "NAMING_POLICY")
private String namingPolicy;
this.serviceArtifactList = serviceArtifactList;
}
+ public List<ServiceInfo> getServiceInfos() {
+ if (serviceInfos == null) {
+ serviceInfos = new ArrayList<>();
+ }
+ return serviceInfos;
+ }
+
+ public void setServiceInfos(List<ServiceInfo> serviceInfos) {
+ this.serviceInfos = serviceInfos;
+ }
+
public String getWorkloadContext() {
return this.workloadContext;
}
@Column(name = "SERVICE_PROPERTIES")
private String serviceProperties;
- @OneToOne(cascade = CascadeType.ALL)
- @JoinTable(name = "service_to_service_info", joinColumns = @JoinColumn(name = "SERVICE_INFO_ID"),
- inverseJoinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID"))
+ @ManyToOne(cascade = CascadeType.ALL)
+ @JoinColumn(name = "SERVICE_MODEL_UUID")
private Service service;
public Integer getId() {
+++ /dev/null
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (c) 2019, CMCC Technologies Co., Ltd.
- * ================================================================================
- * 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.db.catalog.data.repository;
-
-import org.onap.so.db.catalog.beans.Service;
-import org.onap.so.db.catalog.beans.ServiceInfo;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.rest.core.annotation.RepositoryRestResource;
-
-@RepositoryRestResource(collectionResourceRel = "serviceInfo", path = "serviceInfo")
-public interface ServiceInfoRepository extends JpaRepository<ServiceInfo, Integer> {
-
- ServiceInfo findByService(Service service);
-
-}
private ArrayList<AllottedResourceCustomization> allottedResourceCustomizations;
private ArrayList<VnfResourceCustomization> vnfResourceCustomizations;
private ArrayList<ServiceProxyResourceCustomization> serviceProxyResourceCustomizations;
- private ServiceInfo serviceInfo;
public ServiceMacroHolder() {
this.allottedResourceCustomizations = new ArrayList<>();
this.vnfResourceCustomizations = new ArrayList<>();
this.serviceProxyResourceCustomizations = new ArrayList<>();
- this.serviceInfo = null;
}
public ServiceMacroHolder(Service service) {
this.service = service;
}
- public ServiceInfo getServiceInfo() {
- return serviceInfo;
- }
-
- public void setServiceInfo(ServiceInfo serviceInfo) {
- this.serviceInfo = serviceInfo;
- }
-
public void setVnfResources(ArrayList<VnfResource> vnfResources) {
this.vnfResources = vnfResources;
}
} else {
sb.append("service: null");
}
- if (this.serviceInfo != null) {
- sb.append("serviceInfo: " + this.serviceInfo.toString());
- } else {
- sb.append("serviceInfo: null");
- }
if (this.vnfResourceCustomizations != null && this.vnfResourceCustomizations.size() > 0) {
int i = 0;
sb.append("VnfResources: ");