diff options
5 files changed, 1028 insertions, 319 deletions
diff --git a/ms/generic-resource-api/src/main/dc/docker-compose.yaml b/ms/generic-resource-api/src/main/dc/docker-compose.yaml index 8063d08..fc70f43 100755 --- a/ms/generic-resource-api/src/main/dc/docker-compose.yaml +++ b/ms/generic-resource-api/src/main/dc/docker-compose.yaml @@ -25,7 +25,7 @@ services: - db container_name: gra_controller ports: - - "8080:8080" + - "8181:8080" - "8443:8443" links: - db:dbhost diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java index 581f0c7..a8aeb99 100644 --- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java +++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java @@ -22,6 +22,7 @@ package org.onap.sdnc.apps.ms.gra.controllers; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.onap.ccsdk.apps.services.RestApplicationException; import org.onap.ccsdk.apps.services.RestException; @@ -54,7 +55,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; @Controller -@ComponentScan(basePackages = {"org.onap.sdnc.apps.ms.gra.*"}) +@ComponentScan(basePackages = { "org.onap.sdnc.apps.ms.gra.*" }) @EntityScan("org.onap.sdnc.apps.ms.gra.springboot.*") public class ConfigApiController implements ConfigApi { private static final Logger log = LoggerFactory.getLogger(ConfigApiController.class); @@ -94,11 +95,14 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet() throws RestApplicationException { + public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet() + throws RestApplicationException { GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation(); if (configPreloadDataRepository.count() == 0) { - throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value()); + throw new RestApplicationException("data-missing", + "Request could not be completed because the relevant data model content does not exist", + HttpStatus.NOT_FOUND.value()); } for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) { @@ -107,20 +111,53 @@ public class ConfigApiController implements ConfigApi { preloadListItem.setPreloadId(configPreloadData.getPreloadId()); preloadListItem.setPreloadType(configPreloadData.getPreloadType()); try { - preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class)); + preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(), + GenericResourceApiPreloaddataPreloadData.class)); } catch (JsonProcessingException e) { log.error("Could not convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem); } - return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(@Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException, RestProtocolException { + public ResponseEntity<GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPreloadNetworkTopologyInformationGet( + String preloadId, String preloadType) throws RestException { + GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation netTopoInfo = null; + + if (configPreloadDataRepository.count() == 0) { + throw new RestApplicationException("data-missing", + "Request could not be completed because the relevant data model content does not exist", + HttpStatus.NOT_FOUND.value()); + } + + for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) { + + try { + GenericResourceApiPreloaddataPreloadData preloadDataItem = objectMapper + .readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class); + netTopoInfo = preloadDataItem.getPreloadNetworkTopologyInformation(); + } catch (JsonProcessingException e) { + log.error("Could not convert preload data", e); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); + } + } + + return new ResponseEntity<>(netTopoInfo, HttpStatus.OK); + } + + + @Override + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost( + @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) + throws RestApplicationException, RestProtocolException { List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList(); List<ConfigPreloadData> newPreloadData = new LinkedList<>(); @@ -129,16 +166,23 @@ public class ConfigApiController implements ConfigApi { // Verification pass - if any items already exist, return an error for (GenericResourceApiPreloadmodelinformationPreloadList curItem : preloadList) { - List<ConfigPreloadData> curPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType()); + List<ConfigPreloadData> curPreloadData = configPreloadDataRepository + .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType()); if ((curPreloadData != null) && (!curPreloadData.isEmpty())) { - log.error("Preload data already exists for {}:{}", curItem.getPreloadId(), curItem.getPreloadType()); - throw new RestProtocolException("data-exists", "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(), HttpStatus.CONFLICT.value()); + log.error("Preload data already exists for {}:{}", curItem.getPreloadId(), + curItem.getPreloadType()); + throw new RestProtocolException("data-exists", + "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(), + HttpStatus.CONFLICT.value()); } else { try { - newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData()))); + newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(), + objectMapper.writeValueAsString(curItem.getPreloadData()))); } catch (JsonProcessingException e) { log.error("Cannot convert preload data"); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } } @@ -150,14 +194,16 @@ public class ConfigApiController implements ConfigApi { configPreloadDataRepository.save(newDataItem); } } else { - throw new RestProtocolException("data-missing", "No preload-list entries found to add", HttpStatus.CONFLICT.value()); + throw new RestProtocolException("data-missing", "No preload-list entries found to add", + HttpStatus.CONFLICT.value()); } return new ResponseEntity<>(HttpStatus.CREATED); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(@Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException { + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut( + @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException { boolean addedNew = false; List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList(); @@ -166,16 +212,20 @@ public class ConfigApiController implements ConfigApi { Iterator<GenericResourceApiPreloadmodelinformationPreloadList> iter = preloadList.iterator(); while (iter.hasNext()) { GenericResourceApiPreloadmodelinformationPreloadList curItem = iter.next(); - List<ConfigPreloadData> curPreloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType()); + List<ConfigPreloadData> curPreloadData = configPreloadDataRepository + .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType()); if ((curPreloadData == null) || curPreloadData.isEmpty()) { addedNew = true; } try { - configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData()))); + configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(), + curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData()))); } catch (JsonProcessingException e) { log.error("Cannot convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } } @@ -190,21 +240,25 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPost(@Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPost( + @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException { - throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"", HttpStatus.NOT_FOUND.value()); + throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"", + HttpStatus.NOT_FOUND.value()); } - @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeDelete(String preloadId, String preloadType) { + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeDelete( + String preloadId, String preloadType) { configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @Override - public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeGet(String preloadId, String preloadType) throws RestApplicationException { - List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); + public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeGet( + String preloadId, String preloadType) throws RestApplicationException { + List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, + preloadType); if (preloadData != null) { if (!preloadData.isEmpty()) { ConfigPreloadData preloadDataItem = preloadData.get(0); @@ -212,10 +266,13 @@ public class ConfigApiController implements ConfigApi { preloadDataList.setPreloadId(preloadDataItem.getPreloadId()); preloadDataList.setPreloadType(preloadDataItem.getPreloadType()); try { - preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class)); + preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(), + GenericResourceApiPreloaddataPreloadData.class)); } catch (JsonProcessingException e) { log.error("Cannot convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } return new ResponseEntity<>(preloadDataList, HttpStatus.OK); } @@ -224,52 +281,67 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePost(String preloadId, String preloadType, @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestApplicationException, RestProtocolException { - List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePost( + String preloadId, String preloadType, + @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) + throws RestApplicationException, RestProtocolException { + List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, + preloadType); if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) { log.error("Preload data already exists for {}:{}", preloadId, preloadType); - throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, HttpStatus.CONFLICT.value()); + throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, + HttpStatus.CONFLICT.value()); } try { log.info("Adding preload data for {}:{}", preloadId, preloadType); - configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem.getPreloadData()))); + configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, + objectMapper.writeValueAsString(preloadListItem.getPreloadData()))); } catch (JsonProcessingException e) { log.error("Cannot convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } return new ResponseEntity<>(HttpStatus.CREATED); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePut(String preloadId, String preloadType, @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestApplicationException, RestProtocolException { - List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePut( + String preloadId, String preloadType, + @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) + throws RestApplicationException, RestProtocolException { + List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, + preloadType); boolean dataExists = false; if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) { dataExists = true; } - if ((preloadListItem.getPreloadId() == null) || - (preloadListItem.getPreloadType() == null) || - (preloadListItem.getPreloadData() == null)) { + if ((preloadListItem.getPreloadId() == null) || (preloadListItem.getPreloadType() == null) + || (preloadListItem.getPreloadData() == null)) { log.error("Invalid list item received: {}", preloadListItem); throw new RestProtocolException("bad-attribute", "Invalid data received", HttpStatus.BAD_REQUEST.value()); } try { if (dataExists) { - log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem)); + log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType, + objectMapper.writeValueAsString(preloadListItem)); } else { log.info("Adding preload data for {}:{}", preloadId, preloadType); } - configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, objectMapper.writeValueAsString(preloadListItem.getPreloadData()))); + configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType, + objectMapper.writeValueAsString(preloadListItem.getPreloadData()))); } catch (JsonProcessingException e) { log.error("Cannot convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } @@ -280,10 +352,11 @@ public class ConfigApiController implements ConfigApi { } } - @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataDelete(String preloadId, String preloadType) throws RestProtocolException { - List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataDelete( + String preloadId, String preloadType) throws RestProtocolException { + List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, + preloadType); if ((preloadData == null) || preloadData.isEmpty()) { throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value()); @@ -297,14 +370,14 @@ public class ConfigApiController implements ConfigApi { preloadDataItem.setPreloadData(null); configPreloadDataRepository.save(preloadDataItem); - return new ResponseEntity<>(HttpStatus.NO_CONTENT); } - @Override - public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataGet(String preloadId, String preloadType) throws RestApplicationException, RestProtocolException { - List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); + public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataGet( + String preloadId, String preloadType) throws RestApplicationException, RestProtocolException { + List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, + preloadType); if ((preloadData == null) || preloadData.isEmpty()) { throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value()); @@ -316,32 +389,40 @@ public class ConfigApiController implements ConfigApi { throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value()); } try { - return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK); + return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(), + GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK); } catch (JsonProcessingException e) { log.error("Cannot convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPost(String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) throws RestApplicationException, RestProtocolException { - List<ConfigPreloadData> preloadDataEntries = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); - - List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPost( + String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) + throws RestApplicationException, RestProtocolException { + List<ConfigPreloadData> preloadDataEntries = configPreloadDataRepository + .findByPreloadIdAndPreloadType(preloadId, preloadType); + + List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, + preloadType); if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) { throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value()); } - if ((preloadData == null) || - (preloadData.getPreloadNetworkTopologyInformation() == null)) { - throw new RestProtocolException("bad-attribute", "Invalid preloadData received", HttpStatus.BAD_REQUEST.value()); + if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) { + throw new RestProtocolException("bad-attribute", "Invalid preloadData received", + HttpStatus.BAD_REQUEST.value()); } ConfigPreloadData preloadDataItem = preloadDataItems.get(0); if (preloadDataItem.getPreloadData() != null) { log.error("Preload data already exists for {}:{} ", preloadId, preloadType); - throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, HttpStatus.CONFLICT.value()); + throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType, + HttpStatus.CONFLICT.value()); } try { @@ -349,23 +430,28 @@ public class ConfigApiController implements ConfigApi { configPreloadDataRepository.save(preloadDataItem); } catch (JsonProcessingException e) { log.error("Cannot convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } return new ResponseEntity<>(HttpStatus.CREATED); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPut(String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) throws RestApplicationException, RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPut( + String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData) + throws RestApplicationException, RestProtocolException { boolean dataExists = false; - List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, preloadType); + List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId, + preloadType); if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) { throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value()); } - if ((preloadData == null) || - (preloadData.getPreloadNetworkTopologyInformation() == null)) { - throw new RestProtocolException("bad-attribute", "Invalid preloadData received", HttpStatus.BAD_REQUEST.value()); + if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) { + throw new RestProtocolException("bad-attribute", "Invalid preloadData received", + HttpStatus.BAD_REQUEST.value()); } ConfigPreloadData preloadDataItem = preloadDataItems.get(0); @@ -379,7 +465,9 @@ public class ConfigApiController implements ConfigApi { configPreloadDataRepository.save(preloadDataItem); } catch (JsonProcessingException e) { log.error("Cannot convert preload data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } if (dataExists) { @@ -396,36 +484,43 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet() throws RestApplicationException { + public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet() + throws RestApplicationException { GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure(); - if (configServicesRepository.count() == 0) { - throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value()); + if (configServicesRepository.count() == 0) { + throw new RestApplicationException("data-missing", + "Request could not be completed because the relevant data model content does not exist", + HttpStatus.NOT_FOUND.value()); } for (ConfigServices service : configServicesRepository.findAll()) { GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService(); serviceItem.setServiceInstanceId(service.getSvcInstanceId()); if (service.getSvcData() != null) { - try { - serviceItem.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class)); - } catch (JsonProcessingException e) { - log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + try { + serviceItem.setServiceData(objectMapper.readValue(service.getSvcData(), + GenericResourceApiServicedataServiceData.class)); + } catch (JsonProcessingException e) { + log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); + } } - } serviceItem.setServiceStatus(service.getServiceStatus()); modelInfrastructure.addServiceItem(serviceItem); } - return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException, RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost( + @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) + throws RestApplicationException, RestProtocolException { List<ConfigServices> newServices = new LinkedList<>(); for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) { @@ -433,7 +528,8 @@ public class ConfigApiController implements ConfigApi { List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId); if ((existingService != null) && !existingService.isEmpty()) { log.error("Service data already exists for {}", svcInstanceId); - throw new RestProtocolException("data-exists", "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value()); + throw new RestProtocolException("data-exists", + "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value()); } ConfigServices service = new ConfigServices(); service.setSvcInstanceId(svcInstanceId); @@ -441,7 +537,9 @@ public class ConfigApiController implements ConfigApi { service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData())); } catch (JsonProcessingException e) { log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } service.setServiceStatus(serviceItem.getServiceStatus()); @@ -457,7 +555,8 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut( + @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException { List<ConfigServices> newServices = new LinkedList<>(); boolean dataExists = false; @@ -474,7 +573,9 @@ public class ConfigApiController implements ConfigApi { service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData())); } catch (JsonProcessingException e) { log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } service.setServiceStatus(serviceItem.getServiceStatus()); @@ -494,7 +595,8 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServicePost(@Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServicePost( + @Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException { String svcInstanceId = servicesData.getServiceInstanceId(); try { String svcData = objectMapper.writeValueAsString(servicesData.getServiceData()); @@ -503,20 +605,24 @@ public class ConfigApiController implements ConfigApi { configServicesRepository.save(configService); } catch (JsonProcessingException e) { log.error("Cannot convert service data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } return new ResponseEntity<>(HttpStatus.OK); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdDelete(String serviceInstanceId) { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdDelete( + String serviceInstanceId) { configServicesRepository.deleteBySvcInstanceId(serviceInstanceId); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @Override - public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdGet(String serviceInstanceId) throws RestApplicationException { + public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdGet( + String serviceInstanceId) throws RestApplicationException { GenericResourceApiServicemodelinfrastructureService retval = null; List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); @@ -529,26 +635,31 @@ public class ConfigApiController implements ConfigApi { retval.setServiceInstanceId(serviceInstanceId); retval.setServiceStatus(service.getServiceStatus()); try { - retval.setServiceData(objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class)); + retval.setServiceData( + objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class)); } catch (JsonProcessingException e) { log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } } - return new ResponseEntity<>(retval, HttpStatus.OK); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPost(String svcInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException, RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPost(String svcInstanceId, + @Valid GenericResourceApiServicemodelinfrastructureService newService) + throws RestApplicationException, RestProtocolException { List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId); if ((existingService != null) && !existingService.isEmpty()) { log.error("Service data already exists for {}", svcInstanceId); - throw new RestProtocolException("data-exists", "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value()); + throw new RestProtocolException("data-exists", + "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value()); } ConfigServices service = new ConfigServices(); service.setSvcInstanceId(svcInstanceId); @@ -556,7 +667,9 @@ public class ConfigApiController implements ConfigApi { service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData())); } catch (JsonProcessingException e) { log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } service.setServiceStatus(newService.getServiceStatus()); @@ -566,7 +679,8 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPut(String serviceInstanceId, @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPut(String serviceInstanceId, + @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException { boolean dataExists = false; @@ -586,7 +700,9 @@ public class ConfigApiController implements ConfigApi { service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData())); } catch (JsonProcessingException e) { log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } service.setServiceStatus(newService.getServiceStatus()); @@ -599,9 +715,9 @@ public class ConfigApiController implements ConfigApi { } } - @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataDelete(String serviceInstanceId) throws RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataDelete( + String serviceInstanceId) throws RestProtocolException { List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); if ((services == null) || (services.isEmpty())) { @@ -619,7 +735,8 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException { + public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataGet( + String serviceInstanceId) throws RestApplicationException, RestProtocolException { GenericResourceApiServicedataServiceData serviceData = null; List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); @@ -628,51 +745,59 @@ public class ConfigApiController implements ConfigApi { } try { - serviceData = objectMapper.readValue(services.get(0).getSvcData(), GenericResourceApiServicedataServiceData.class); + serviceData = objectMapper.readValue(services.get(0).getSvcData(), + GenericResourceApiServicedataServiceData.class); return new ResponseEntity<>(serviceData, HttpStatus.OK); } catch (JsonProcessingException e) { log.error("Could not parse service data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPost(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) throws RestApplicationException, RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPost( + String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) + throws RestApplicationException, RestProtocolException { ConfigServices service; List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); if ((services == null) || (services.isEmpty())) { throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); } - if ((serviceData == null) || - (serviceData.getServiceInformation() == null)) { - throw new RestProtocolException("bad-attribute", "Invalid service-data received", HttpStatus.BAD_REQUEST.value()); + if ((serviceData == null) || (serviceData.getServiceInformation() == null)) { + throw new RestProtocolException("bad-attribute", "Invalid service-data received", + HttpStatus.BAD_REQUEST.value()); } service = services.get(0); - if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)){ + if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)) { log.error("service-data already exists for svcInstanceId {}", serviceInstanceId); - throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, HttpStatus.CONFLICT.value()); + throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, + HttpStatus.CONFLICT.value()); } - try { service.setSvcData(objectMapper.writeValueAsString(serviceData)); configServicesRepository.save(service); } catch (JsonProcessingException e) { log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } - return new ResponseEntity<>(HttpStatus.CREATED); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPut(String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) throws RestApplicationException, RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPut( + String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData) + throws RestApplicationException, RestProtocolException { ConfigServices service; boolean dataExists = false; @@ -681,9 +806,9 @@ public class ConfigApiController implements ConfigApi { throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); } - if ((serviceData == null) || - (serviceData.getServiceInformation() == null)) { - throw new RestProtocolException("bad-attribute", "Invalid service-data received", HttpStatus.BAD_REQUEST.value()); + if ((serviceData == null) || (serviceData.getServiceInformation() == null)) { + throw new RestProtocolException("bad-attribute", "Invalid service-data received", + HttpStatus.BAD_REQUEST.value()); } service = services.get(0); @@ -697,7 +822,9 @@ public class ConfigApiController implements ConfigApi { configServicesRepository.save(service); } catch (JsonProcessingException e) { log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } if (dataExists) { @@ -708,7 +835,8 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusDelete(String serviceInstanceId) throws RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusDelete( + String serviceInstanceId) throws RestProtocolException { List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); if ((services == null) || (services.isEmpty())) { @@ -727,7 +855,8 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException { + public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusGet( + String serviceInstanceId) throws RestApplicationException, RestProtocolException { GenericResourceApiServicestatusServiceStatus serviceStatus = null; List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); @@ -740,36 +869,39 @@ public class ConfigApiController implements ConfigApi { } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPost(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) throws RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPost( + String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) + throws RestProtocolException { ConfigServices service; List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); if ((services == null) || (services.isEmpty())) { throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); } - if ((serviceStatus == null) || - (serviceStatus.getAction() == null)) { - throw new RestProtocolException("bad-attribute", "Invalid service-status received", HttpStatus.BAD_REQUEST.value()); + if ((serviceStatus == null) || (serviceStatus.getAction() == null)) { + throw new RestProtocolException("bad-attribute", "Invalid service-status received", + HttpStatus.BAD_REQUEST.value()); } service = services.get(0); if (service.getServiceStatus() != null) { log.error("service-status already exists for svcInstanceId {}", serviceInstanceId); - throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, HttpStatus.CONFLICT.value()); + throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId, + HttpStatus.CONFLICT.value()); } - service.setServiceStatus(serviceStatus); configServicesRepository.save(service); - return new ResponseEntity<>(HttpStatus.CREATED); } @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPut(String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) throws RestProtocolException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPut( + String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus) + throws RestProtocolException { ConfigServices service; boolean dataExists = false; @@ -778,9 +910,9 @@ public class ConfigApiController implements ConfigApi { throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); } - if ((serviceStatus == null) || - (serviceStatus.getAction() == null)) { - throw new RestProtocolException("bad-attribute", "Invalid service-status received", HttpStatus.BAD_REQUEST.value()); + if ((serviceStatus == null) || (serviceStatus.getAction() == null)) { + throw new RestProtocolException("bad-attribute", "Invalid service-status received", + HttpStatus.BAD_REQUEST.value()); } service = services.get(0); @@ -789,7 +921,6 @@ public class ConfigApiController implements ConfigApi { dataExists = true; } - service.setServiceStatus(serviceStatus); configServicesRepository.save(service); @@ -803,37 +934,43 @@ public class ConfigApiController implements ConfigApi { /** * Deletes VNF data from the Config table specified Service Instance. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/ + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/ + * * @param serviceInstanceId the Service Instance ID to perform the delete on - * @param vnfId the VNF ID of the VNF to delete + * @param vnfId the VNF ID of the VNF to delete * @return HttpStatus.NO_CONTENT (204) on successful delete * <p> - * HttpStatus.BAD_REQUEST (400) if unmarshalling Service Data from - * the database fails, there is no VNF data for {@code vnfId}, or - * writing Service Data back to the database fails. + * HttpStatus.BAD_REQUEST (400) if unmarshalling Service Data from the + * database fails, there is no VNF data for {@code vnfId}, or writing + * Service Data back to the database fails. * <p> - * HttpStatus.NOT_FOUND (404) if {@code serviceInstanceId} does - * not exist. + * HttpStatus.NOT_FOUND (404) if {@code serviceInstanceId} does not + * exist. */ @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete(String serviceInstanceId, String vnfId) throws RestException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete( + String serviceInstanceId, String vnfId) throws RestException { log.info("DELETE | VNF Data for ({})", vnfId); - /* The logic may need to be moved inside of this check or this check - * may need to be removed. + /* + * The logic may need to be moved inside of this check or this check may need to + * be removed. */ - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { log.info("Something with header."); } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); ConfigServices data; - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { log.info("Could not find data for ({}).", serviceInstanceId); // Or throw the data not found error? - throw new RestProtocolException("data-missing", "Service Instance ID not found.", HttpStatus.NOT_FOUND.value()); + throw new RestProtocolException("data-missing", "Service Instance ID not found.", + HttpStatus.NOT_FOUND.value()); } else { data = services.get(0); } @@ -841,112 +978,131 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServiceData svcData; try { svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { // Or throw the data not found error? log.error("Could not map service data for ({})", serviceInstanceId); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } - if(svcData == null) { + if (svcData == null) { // Or throw the data not found error? log.info("Could not find Service Data for ({}).", serviceInstanceId); throw new RestProtocolException("data-missing", "Service data not found.", HttpStatus.NOT_FOUND.value()); } GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs(); - if(vnfs == null) { + if (vnfs == null) { // Or throw the data not found error? log.info("VNF List not found for ({}).", serviceInstanceId); throw new RestProtocolException("data-missing", "VNFs not found.", HttpStatus.NOT_FOUND.value()); } Stream<GenericResourceApiServicedataServicedataVnfsVnf> vnfStream = svcData.getVnfs().getVnf().stream(); - if(vnfStream.noneMatch(targetVnf -> targetVnf.getVnfId().equals(vnfId))) { + if (vnfStream.noneMatch(targetVnf -> targetVnf.getVnfId().equals(vnfId))) { // Data was not found log.error("Did not find VNF ({}) in data.", vnfId); throw new RestProtocolException("data-missing", "VNF ID not found.", HttpStatus.NOT_FOUND.value()); } // Recreate the stream per Sonar? vnfStream = svcData.getVnfs().getVnf().stream(); - svcData.getVnfs().setVnf(vnfStream.filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)).collect(Collectors.toList())); + svcData.getVnfs().setVnf( + vnfStream.filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)).collect(Collectors.toList())); // Map and save the new data try { data.setSvcData(objectMapper.writeValueAsString(svcData)); configServicesRepository.save(data); return new ResponseEntity<>(HttpStatus.NO_CONTENT); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Error mapping object to JSON", e); // Should probably be a 500 INTERNAL_SERVICE_ERROR - throw new RestProtocolException("internal-service-error", "Failed to save data.", HttpStatus.BAD_REQUEST.value()); + throw new RestProtocolException("internal-service-error", "Failed to save data.", + HttpStatus.BAD_REQUEST.value()); } } /** * Extracts VNF data from the Config table specified Service Instance. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/ + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/ + * * @param serviceInstanceId the Service Instance ID to lookup data for - * @param vnfId the VNF ID of the VNF to return + * @param vnfId the VNF ID of the VNF to return * @return HttpStatus.OK (200) if the data is found. * @throws RestException if the data does not exist. */ @Override - public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnf> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet(String serviceInstanceId, String vnfId) throws RestException { + public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnf> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet( + String serviceInstanceId, String vnfId) throws RestException { log.info("GET | VNF Data for ({})", vnfId); - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { - if(getAcceptHeader().get().contains("application/json")) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getAcceptHeader().get().contains("application/json")) { } } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); } Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(services.get(0), vnfId); - if(vnf.isPresent()) { + if (vnf.isPresent()) { return new ResponseEntity<>(vnf.get(), HttpStatus.OK); } else { log.info("No information found for {}", vnfId); - throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value()); + throw new RestApplicationException("data-missing", + "Request could not be completed because the relevant data model content does not exist", + HttpStatus.NOT_FOUND.value()); } } /** * Creates or updates VNF data in the Config table for a specified Service - * Instance. If it is a new Service Instance or a new VNF, creates all - * necessary parent data containers, then performs the updates. + * Instance. If it is a new Service Instance or a new VNF, creates all necessary + * parent data containers, then performs the updates. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/ - * @param serviceInstanceId the Service Instance ID to perform the delete on - * @param vnfId the VNF ID of the VNF to delete + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/ + * + * @param serviceInstanceId the Service + * Instance ID + * to perform + * the delete on + * @param vnfId the VNF ID of + * the VNF to + * delete * @param genericResourceApiServicedataServicedataVnfsVnfBodyParam the playload * @return HttpStatus.CREATED (201) on successful create * <p> * HttpStatus.NO_CONTENT (204) on successful update * <p> - * HttpStatus.BAD_REQUEST (400) if {@code vnfId} does not match - * what is specified in the - * {@code genericResourceApiServicedataServicedataVnfsVnfBodyParam} - * , or if updating the database fails. + * HttpStatus.BAD_REQUEST (400) if {@code vnfId} does not match what is + * specified in the + * {@code genericResourceApiServicedataServicedataVnfsVnfBodyParam} , or + * if updating the database fails. * @throws RestException */ @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut(String serviceInstanceId, String vnfId, GenericResourceApiServicedataServicedataVnfsVnf genericResourceApiServicedataServicedataVnfsVnfBodyParam) throws RestException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut( + String serviceInstanceId, String vnfId, + GenericResourceApiServicedataServicedataVnfsVnf genericResourceApiServicedataServicedataVnfsVnfBodyParam) + throws RestException { log.info("PUT | VNF Data for ({})", vnfId); - if(!vnfId.equals(genericResourceApiServicedataServicedataVnfsVnfBodyParam.getVnfId())) { + if (!vnfId.equals(genericResourceApiServicedataServicedataVnfsVnfBodyParam.getVnfId())) { throw new RestProtocolException("bad-attribute", "vnf-id mismatch", HttpStatus.BAD_REQUEST.value()); } - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { log.info("Something with header"); } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); ConfigServices data; - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId); data = new ConfigServices(); data.setSvcInstanceId(serviceInstanceId); @@ -957,14 +1113,14 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServiceData svcData = null; try { svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Could not map service data for ({})", serviceInstanceId); } - if(svcData == null) { + if (svcData == null) { log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId); svcData = new GenericResourceApiServicedataServiceData(); } - if(svcData.getVnfs() == null) { + if (svcData.getVnfs() == null) { log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId); svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs()); svcData.getVnfs().setVnf(new ArrayList<>()); @@ -972,7 +1128,7 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs(); HttpStatus responseStatus = HttpStatus.NO_CONTENT; - if(svcData.getVnfs().getVnf().isEmpty()) { + if (svcData.getVnfs().getVnf().isEmpty()) { log.info("Creating VNF data for ({})", vnfId); vnflist.addVnfItem(genericResourceApiServicedataServicedataVnfsVnfBodyParam); responseStatus = HttpStatus.CREATED; @@ -980,10 +1136,7 @@ public class ConfigApiController implements ConfigApi { log.info("Updating VNF data for ({})", vnfId); // Filter out all of the other vnf objects into a new VNF List // Replace if a delete method exists - svcData.getVnfs() - .getVnf() - .stream() - .filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) + svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) .forEach(vnflist::addVnfItem); vnflist.addVnfItem(genericResourceApiServicedataServicedataVnfsVnfBodyParam); } @@ -993,7 +1146,7 @@ public class ConfigApiController implements ConfigApi { data.setSvcData(objectMapper.writeValueAsString(svcData)); configServicesRepository.save(data); return new ResponseEntity<>(responseStatus); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Error mapping object to JSON", e); // Should probably be a 500 INTERNAL_SERVICE_ERROR return new ResponseEntity<>(HttpStatus.BAD_REQUEST); @@ -1001,51 +1154,58 @@ public class ConfigApiController implements ConfigApi { } /** - * Extracts VNF Topology data from the Config table specified Service - * Instance and VNF ID. + * Extracts VNF Topology data from the Config table specified Service Instance + * and VNF ID. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/ + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/ + * * @param serviceInstanceId the Service Instance ID to lookup data for - * @param vnfId the VNF ID of the VNF to extract topology data from. + * @param vnfId the VNF ID of the VNF to extract topology data from. * @return HttpStatus.OK (200) if the data is found. * @throws RestException if the data does not exist. */ @Override - public ResponseEntity<GenericResourceApiVnftopologyVnfTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet(String serviceInstanceId, String vnfId) throws RestException { + public ResponseEntity<GenericResourceApiVnftopologyVnfTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet( + String serviceInstanceId, String vnfId) throws RestException { log.info("GET | VNF Topology for ({})", vnfId); - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { if (getAcceptHeader().get().contains("application/json")) { } } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); } Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(services.get(0), vnfId); // Drill down to find the data - if(vnf.isPresent() - && vnf.get().getVnfData() != null - && vnf.get().getVnfData().getVnfTopology() != null) { + if (vnf.isPresent() && vnf.get().getVnfData() != null && vnf.get().getVnfData().getVnfTopology() != null) { return new ResponseEntity<>(vnf.get().getVnfData().getVnfTopology(), HttpStatus.OK); } else { log.info("No information found for {}", vnfId); - throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value()); + throw new RestApplicationException("data-missing", + "Request could not be completed because the relevant data model content does not exist", + HttpStatus.NOT_FOUND.value()); } } /** - * Creates or updates VNF Level Operation Status data in the Config table - * for a specified Service Instance. If it is a new Service Instance or a - * new VNF, creates all necessary parent data containers, then performs the - * updates. + * Creates or updates VNF Level Operation Status data in the Config table for a + * specified Service Instance. If it is a new Service Instance or a new VNF, + * creates all necessary parent data containers, then performs the updates. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-level-oper-status/ - * @param serviceInstanceId the Service Instance ID to perform the delete on - * @param vnfId the VNF ID of the VNF to delete + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-level-oper-status/ + * + * @param serviceInstanceId the Service Instance ID to + * perform the delete on + * @param vnfId the VNF ID of the VNF to + * delete * @param genericResourceApiOperStatusDataBodyParam the payload * @return HttpStatus.CREATED (201) on successful create. * <p> @@ -1055,16 +1215,19 @@ public class ConfigApiController implements ConfigApi { * @throws RestException */ @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut(String serviceInstanceId, String vnfId, GenericResourceApiOperStatusData genericResourceApiOperStatusDataBodyParam) throws RestException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut( + String serviceInstanceId, String vnfId, + GenericResourceApiOperStatusData genericResourceApiOperStatusDataBodyParam) throws RestException { log.info("PUT | VNF Level Oper Status ({})", vnfId); - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); ConfigServices data; - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId); data = new ConfigServices(); data.setSvcInstanceId(serviceInstanceId); @@ -1075,14 +1238,14 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServiceData svcData = null; try { svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Could not map service data for ({})", serviceInstanceId); } - if(svcData == null) { + if (svcData == null) { log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId); svcData = new GenericResourceApiServicedataServiceData(); } - if(svcData.getVnfs() == null) { + if (svcData.getVnfs() == null) { log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId); svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs()); svcData.getVnfs().setVnf(new ArrayList<>()); @@ -1090,7 +1253,7 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs(); HttpStatus responseStatus = HttpStatus.NO_CONTENT; - if(svcData.getVnfs().getVnf().isEmpty()) { + if (svcData.getVnfs().getVnf().isEmpty()) { log.info("Creating VNF data for ({})", vnfId); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); vnf.setVnfId(vnfId); @@ -1102,18 +1265,15 @@ public class ConfigApiController implements ConfigApi { log.info("Updating VNF data for ({})", vnfId); // Filter out all of the other vnf objects into a new VNF List // Replace if a delete method exists - svcData.getVnfs() - .getVnf() - .stream() - .filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) + svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) .forEach(vnflist::addVnfItem); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); // If the vnf exists, set it up with new data Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId); - if(vnfOptional.isPresent()) { + if (vnfOptional.isPresent()) { vnf = vnfOptional.get(); } - if(vnf.getVnfData() == null) { + if (vnf.getVnfData() == null) { vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData()); responseStatus = HttpStatus.CREATED; } @@ -1128,7 +1288,7 @@ public class ConfigApiController implements ConfigApi { data.setSvcData(objectMapper.writeValueAsString(svcData)); configServicesRepository.save(data); return new ResponseEntity<>(responseStatus); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Error mapping object to JSON", e); // Should probably be a 500 INTERNAL_SERVICE_ERROR return new ResponseEntity<>(HttpStatus.BAD_REQUEST); @@ -1136,15 +1296,32 @@ public class ConfigApiController implements ConfigApi { } /** - * Creates or updates VNF Onap Model Information data in the Config table - * for a specified Service Instance. If it is a new Service Instance or a - * new VNF, creates all necessary parent data containers, then performs the - * updates. + * Creates or updates VNF Onap Model Information data in the Config table for a + * specified Service Instance. If it is a new Service Instance or a new VNF, + * creates all necessary parent data containers, then performs the updates. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/onap-model-information/ - * @param serviceInstanceId the Service Instance ID to perform the delete on - * @param vnfId the VNF ID of the VNF to delete - * @param genericResourceApiOnapmodelinformationOnapModelInformationBodyParam the payload + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/onap-model-information/ + * + * @param serviceInstanceId the + * Service + * Instance + * ID + * to + * perform + * the + * delete + * on + * @param vnfId the + * VNF + * ID + * of + * the + * VNF + * to + * delete + * @param genericResourceApiOnapmodelinformationOnapModelInformationBodyParam the + * payload * @return HttpStatus.CREATED (201) on successful create. * <p> * HttpStatus.NO_CONTENT (204) on successful update. @@ -1153,16 +1330,20 @@ public class ConfigApiController implements ConfigApi { * @throws RestException */ @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut(String serviceInstanceId, String vnfId, GenericResourceApiOnapmodelinformationOnapModelInformation genericResourceApiOnapmodelinformationOnapModelInformationBodyParam) throws RestException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut( + String serviceInstanceId, String vnfId, + GenericResourceApiOnapmodelinformationOnapModelInformation genericResourceApiOnapmodelinformationOnapModelInformationBodyParam) + throws RestException { log.info("PUT | VNF Topology Onap Model Information ({})", vnfId); - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); ConfigServices data; - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId); data = new ConfigServices(); data.setSvcInstanceId(serviceInstanceId); @@ -1173,14 +1354,14 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServiceData svcData = null; try { svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Could not map service data for ({})", serviceInstanceId); } - if(svcData == null) { + if (svcData == null) { log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId); svcData = new GenericResourceApiServicedataServiceData(); } - if(svcData.getVnfs() == null) { + if (svcData.getVnfs() == null) { log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId); svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs()); svcData.getVnfs().setVnf(new ArrayList<>()); @@ -1188,39 +1369,38 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs(); HttpStatus responseStatus = HttpStatus.NO_CONTENT; - if(svcData.getVnfs().getVnf().isEmpty()) { + if (svcData.getVnfs().getVnf().isEmpty()) { log.info("Creating VNF data for ({})", vnfId); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); vnf.setVnfId(vnfId); vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData()); vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology()); - vnf.getVnfData().getVnfTopology().setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam); + vnf.getVnfData().getVnfTopology() + .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam); vnflist.addVnfItem(vnf); responseStatus = HttpStatus.CREATED; } else { log.info("Updating VNF data for ({})", vnfId); // Filter out all of the other vnf objects into a new VNF List // Replace if a delete method exists - svcData.getVnfs() - .getVnf() - .stream() - .filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) + svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) .forEach(vnflist::addVnfItem); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); // If the vnf exists, set it up with new data Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId); - if(vnfOptional.isPresent()) { + if (vnfOptional.isPresent()) { vnf = vnfOptional.get(); } - if(vnf.getVnfData() == null) { + if (vnf.getVnfData() == null) { vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData()); } - if(vnf.getVnfData().getVnfTopology() == null) { + if (vnf.getVnfData().getVnfTopology() == null) { vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology()); responseStatus = HttpStatus.CREATED; } - vnf.getVnfData().getVnfTopology().setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam); + vnf.getVnfData().getVnfTopology() + .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam); vnflist.addVnfItem(vnf); } @@ -1230,7 +1410,7 @@ public class ConfigApiController implements ConfigApi { data.setSvcData(objectMapper.writeValueAsString(svcData)); configServicesRepository.save(data); return new ResponseEntity<>(responseStatus); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Error mapping object to JSON", e); // Should probably be a 500 INTERNAL_SERVICE_ERROR return new ResponseEntity<>(HttpStatus.BAD_REQUEST); @@ -1239,13 +1419,31 @@ public class ConfigApiController implements ConfigApi { /** * Creates or updates VNF Network data in the Config table for a specified - * Service Instance. If it is a new Service Instance or a new VNF, creates - * all necessary parent data containers, then performs the updates. + * Service Instance. If it is a new Service Instance or a new VNF, creates all + * necessary parent data containers, then performs the updates. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/ - * @param serviceInstanceId the Service Instance ID to perform the delete on - * @param vnfId the VNF ID of the VNF to delete - * @param genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam the payload + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/ + * + * @param serviceInstanceId the + * Service + * Instance + * ID + * to + * perform + * the + * delete + * on + * @param vnfId the + * VNF + * ID + * of + * the + * VNF + * to + * delete + * @param genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam the + * payload * @return HttpStatus.CREATED (201) on successful create. * <p> * HttpStatus.NO_CONTENT (204) on successful update. @@ -1254,16 +1452,20 @@ public class ConfigApiController implements ConfigApi { * @throws RestException */ @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut(String serviceInstanceId, String vnfId, GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam) throws RestException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut( + String serviceInstanceId, String vnfId, + GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam) + throws RestException { log.info("PUT | VNF Topology VNF Resource Assignments VNF Networks ({})", vnfId); - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); ConfigServices data; - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId); data = new ConfigServices(); data.setSvcInstanceId(serviceInstanceId); @@ -1274,14 +1476,14 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServiceData svcData = null; try { svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Could not map service data for ({})", serviceInstanceId); } - if(svcData == null) { + if (svcData == null) { log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId); svcData = new GenericResourceApiServicedataServiceData(); } - if(svcData.getVnfs() == null) { + if (svcData.getVnfs() == null) { log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId); svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs()); svcData.getVnfs().setVnf(new ArrayList<>()); @@ -1289,43 +1491,44 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs(); HttpStatus responseStatus = HttpStatus.NO_CONTENT; - if(svcData.getVnfs().getVnf().isEmpty()) { + if (svcData.getVnfs().getVnf().isEmpty()) { log.info("Creating VNF data for ({})", vnfId); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); vnf.setVnfId(vnfId); vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData()); vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology()); - vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); - vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam); + vnf.getVnfData().getVnfTopology() + .setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); + vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() + .setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam); vnflist.addVnfItem(vnf); responseStatus = HttpStatus.CREATED; } else { log.info("Updating VNF data for ({})", vnfId); // Filter out all of the other vnf objects into a new VNF List // Replace if a delete method exists - svcData.getVnfs() - .getVnf() - .stream() - .filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) + svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) .forEach(vnflist::addVnfItem); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); // If the vnf exists, set it up with new data Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId); - if(vnfOptional.isPresent()) { + if (vnfOptional.isPresent()) { vnf = vnfOptional.get(); } - if(vnf.getVnfData() == null) { + if (vnf.getVnfData() == null) { vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData()); } - if(vnf.getVnfData().getVnfTopology() == null) { + if (vnf.getVnfData().getVnfTopology() == null) { vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology()); } - if(vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) { - vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); + if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) { + vnf.getVnfData().getVnfTopology().setVnfResourceAssignments( + new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); responseStatus = HttpStatus.CREATED; } - vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam); + vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() + .setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam); vnflist.addVnfItem(vnf); } @@ -1335,7 +1538,7 @@ public class ConfigApiController implements ConfigApi { data.setSvcData(objectMapper.writeValueAsString(svcData)); configServicesRepository.save(data); return new ResponseEntity<>(responseStatus); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Error mapping object to JSON", e); // Should probably be a 500 INTERNAL_SERVICE_ERROR return new ResponseEntity<>(HttpStatus.BAD_REQUEST); @@ -1343,14 +1546,17 @@ public class ConfigApiController implements ConfigApi { } /** - * Creates or updates VNF Network Role data in the Config table for a - * specified Service Instance. If it is a new Service Instance or a new - * VNF, creates all necessary parent data containers, then performs the - * updates. + * Creates or updates VNF Network Role data in the Config table for a specified + * Service Instance. If it is a new Service Instance or a new VNF, creates all + * necessary parent data containers, then performs the updates. * <p> - * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/vnf-network/{network-role}/ - * @param serviceInstanceId the Service Instance ID to perform the delete on - * @param vnfId the VNF ID of the VNF to delete + * Maps to + * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/vnf-network/{network-role}/ + * + * @param serviceInstanceId the Service Instance ID to + * perform the delete on + * @param vnfId the VNF ID of the VNF to + * delete * @param genericResourceApiVnfNetworkDataBodyParam the payload * @return HttpStatus.CREATED (201) on successful create. * <p> @@ -1360,19 +1566,22 @@ public class ConfigApiController implements ConfigApi { * @throws RestException */ @Override - public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut(String serviceInstanceId, String vnfId, String networkRole, GenericResourceApiVnfNetworkData genericResourceApiVnfNetworkDataBodyParam) throws RestException { + public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut( + String serviceInstanceId, String vnfId, String networkRole, + GenericResourceApiVnfNetworkData genericResourceApiVnfNetworkDataBodyParam) throws RestException { log.info("PUT | VNF Network Network Role ({})", vnfId); - if(!networkRole.equals(genericResourceApiVnfNetworkDataBodyParam.getNetworkRole())) { + if (!networkRole.equals(genericResourceApiVnfNetworkDataBodyParam.getNetworkRole())) { throw new RestProtocolException("bad-attribute", "network-role mismatch", HttpStatus.BAD_REQUEST.value()); } - if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { + if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) { } else { - log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); + log.warn( + "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated"); } List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); ConfigServices data; - if((services == null) || (services.isEmpty())) { + if ((services == null) || (services.isEmpty())) { log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId); data = new ConfigServices(); data.setSvcInstanceId(serviceInstanceId); @@ -1383,14 +1592,14 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServiceData svcData = null; try { svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Could not map service data for ({})", serviceInstanceId); } - if(svcData == null) { + if (svcData == null) { log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId); svcData = new GenericResourceApiServicedataServiceData(); } - if(svcData.getVnfs() == null) { + if (svcData.getVnfs() == null) { log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId); svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs()); svcData.getVnfs().setVnf(new ArrayList<>()); @@ -1398,51 +1607,56 @@ public class ConfigApiController implements ConfigApi { GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs(); HttpStatus responseStatus = HttpStatus.NO_CONTENT; - if(svcData.getVnfs().getVnf().isEmpty()) { + if (svcData.getVnfs().getVnf().isEmpty()) { log.info("Creating VNF data for ({})", vnfId); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); vnf.setVnfId(vnfId); vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData()); vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology()); - vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); - vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks()); - vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().setVnfNetwork(new ArrayList<>()); - vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam); + vnf.getVnfData().getVnfTopology() + .setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); + vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() + .setVnfNetworks(new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks()); + vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks() + .setVnfNetwork(new ArrayList<>()); + vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks() + .addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam); vnflist.addVnfItem(vnf); responseStatus = HttpStatus.CREATED; } else { log.info("Updating VNF data for ({})", vnfId); // Filter out all of the other vnf objects into a new VNF List // Replace if a delete method exists - svcData.getVnfs() - .getVnf() - .stream() - .filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) + svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)) .forEach(vnflist::addVnfItem); GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf(); // If the vnf exists, set it up with new data Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId); - if(vnfOptional.isPresent()) { + if (vnfOptional.isPresent()) { vnf = vnfOptional.get(); } - if(vnf.getVnfData() == null) { + if (vnf.getVnfData() == null) { vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData()); } - if(vnf.getVnfData().getVnfTopology() == null) { + if (vnf.getVnfData().getVnfTopology() == null) { vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology()); } - if(vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) { - vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); + if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) { + vnf.getVnfData().getVnfTopology().setVnfResourceAssignments( + new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments()); } - if(vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks() == null) { + if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks() == null) { log.info("Creating new VnfNetworks"); - vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks()); + vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks( + new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks()); } GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks networkList = new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks(); - if(vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().getVnfNetwork().isEmpty()) { + if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().getVnfNetwork() + .isEmpty()) { log.info("First entry into network info."); - vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam); + vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks() + .addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam); responseStatus = HttpStatus.CREATED; } else { log.info("Found networks. Filtering."); @@ -1451,7 +1665,8 @@ public class ConfigApiController implements ConfigApi { .forEach(networkList::addVnfNetworkItem); networkList.addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam); - if(networkList.getVnfNetwork().size() != vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().getVnfNetwork().size()) { + if (networkList.getVnfNetwork().size() != vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() + .getVnfNetworks().getVnfNetwork().size()) { log.info("Added a new Item"); responseStatus = HttpStatus.CREATED; } @@ -1467,7 +1682,7 @@ public class ConfigApiController implements ConfigApi { data.setSvcData(objectMapper.writeValueAsString(svcData)); configServicesRepository.save(data); return new ResponseEntity<>(responseStatus); - } catch(JsonProcessingException e) { + } catch (JsonProcessingException e) { log.error("Error mapping object to JSON", e); // Should probably be a 500 INTERNAL_SERVICE_ERROR return new ResponseEntity<>(HttpStatus.BAD_REQUEST); @@ -1476,59 +1691,67 @@ public class ConfigApiController implements ConfigApi { /** * Extracts a VNF object from the database, + * * @param configServices A Config Services option created from a Service * Instance ID - * @param vnfId the target VNF ID + * @param vnfId the target VNF ID * @return An empty Optional if the Service Data does not exist, an empty - * Optional if the VNF is not found, or an optional containing the - * found VNF. + * Optional if the VNF is not found, or an optional containing the found + * VNF. */ - private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getVnfObject(ConfigServices configServices, String vnfId) { + private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getVnfObject(ConfigServices configServices, + String vnfId) { // Map the Marshall the JSON String into a Java Object log.info("Getting VNF Data for ({})", vnfId); GenericResourceApiServicedataServiceData svcData; try { - svcData = objectMapper.readValue(configServices.getSvcData(), GenericResourceApiServicedataServiceData.class); - } catch(JsonProcessingException e) { + svcData = objectMapper.readValue(configServices.getSvcData(), + GenericResourceApiServicedataServiceData.class); + } catch (JsonProcessingException e) { log.error("Error", e); return Optional.empty(); } - /*Get a stream of the VNF Objects and return the target if it's found, - * assuming that each VNF ID is unique within a Service Instance Object + /* + * Get a stream of the VNF Objects and return the target if it's found, assuming + * that each VNF ID is unique within a Service Instance Object */ - return svcData.getVnfs().getVnf() - .stream() - .filter(targetVnf -> targetVnf.getVnfId().equals(vnfId)) - .findFirst(); + return svcData.getVnfs().getVnf().stream().filter(targetVnf -> targetVnf.getVnfId().equals(vnfId)).findFirst(); } @Override - public ResponseEntity<GenericResourceApiServicetopologyServiceTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException { + public ResponseEntity<GenericResourceApiServicetopologyServiceTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet( + String serviceInstanceId) throws RestApplicationException, RestProtocolException { GenericResourceApiServicetopologyServiceTopology serviceTopology = null; GenericResourceApiServicedataServiceData serviceData = null; - + List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); if ((services == null) || (services.isEmpty())) { throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); } try { - if ( services.get(0).getSvcData().isEmpty()) { - throw new RestProtocolException("data-missing", "No service-data entry found", HttpStatus.NOT_FOUND.value()); + if (services.get(0).getSvcData().isEmpty()) { + throw new RestProtocolException("data-missing", "No service-data entry found", + HttpStatus.NOT_FOUND.value()); } else { - serviceData = objectMapper.readValue(services.get(0).getSvcData(), GenericResourceApiServicedataServiceData.class); + serviceData = objectMapper.readValue(services.get(0).getSvcData(), + GenericResourceApiServicedataServiceData.class); serviceTopology = serviceData.getServiceTopology(); } if (serviceTopology == null) { - throw new RestProtocolException("data-missing", "No service-topology entry found", HttpStatus.NOT_FOUND.value()); + throw new RestProtocolException("data-missing", "No service-topology entry found", + HttpStatus.NOT_FOUND.value()); } return new ResponseEntity<>(serviceTopology, HttpStatus.OK); } catch (JsonProcessingException e) { log.error("Could not parse service data", e); - throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + throw new RestApplicationException("data-conversion", + "Request could not be completed due to internal error", e, + HttpStatus.INTERNAL_SERVER_ERROR.value()); } } + } diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java index ac9a8b1..6a4e561 100644 --- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java +++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiController.java @@ -484,8 +484,12 @@ public class OperationsApiController implements OperationsApi { // Add config tree data to SvcLogicContext List<ConfigServices> configServices = configServicesRepository.findBySvcInstanceId(svcInstanceId); ConfigServices configService = null; + String svcData = null; if (configServices != null && !configServices.isEmpty()) { configService = configServices.get(0); + svcData = configService.getSvcData(); + } + if (svcData != null) { ctxIn.mergeJson("service-data", configService.getSvcData()); } else { log.debug("exiting {} because the service-instance does not have any service data in SDN", svcOperation); diff --git a/ms/generic-resource-api/src/main/resources/startGra.sh b/ms/generic-resource-api/src/main/resources/startGra.sh index cdf1566..c35d63f 100644 --- a/ms/generic-resource-api/src/main/resources/startGra.sh +++ b/ms/generic-resource-api/src/main/resources/startGra.sh @@ -56,13 +56,13 @@ echo -e "\nDatabase ready" # Initialize schema if [ -f ${SDNC_CONFIG_DIR}/schema-mysql.sql ] then - mysql -h ${MYSQL_DB_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWD} ${MYSQL_DATABASE} < ${SDNC_CONFIG_DIR}/schema-mysql.sql + mysql -h ${MYSQL_DB_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < ${SDNC_CONFIG_DIR}/schema-mysql.sql fi # Load data if [ -f ${SDNC_CONFIG_DIR}/data-mysql.sql ] then - mysql -h ${MYSQL_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < ${SDNC_CONFIG_DIR}/data-mysql.sql + mysql -h ${MYSQL_DB_HOST} -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} < ${SDNC_CONFIG_DIR}/data-mysql.sql fi if [ ! -f ${SDNC_CERT_DIR}/${TRUSTSTORE} ]; then diff --git a/ms/generic-resource-api/src/test/resources/GR_API.http b/ms/generic-resource-api/src/test/resources/GR_API.http new file mode 100644 index 0000000..8fb20d6 --- /dev/null +++ b/ms/generic-resource-api/src/test/resources/GR_API.http @@ -0,0 +1,482 @@ +### preload data (network)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:preload-network-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "preload-network-topology-information": {
+ "host-routes": [
+ {
+ "next-hop": "10.1.12.1",
+ "route-prefix": "12"
+ }
+ ],
+ "is-external-network": true,
+ "is-provider-network": true,
+ "is-shared-network": true,
+ "network-policy": [
+ {
+ "network-policy-fqdn": "policy-sdnc.onap.org",
+ "network-policy-id": "123"
+ }
+ ],
+ "network-topology-identifier-structure": {
+ "eipam-v4-address-plan": "plan9",
+ "eipam-v6-address-plan": "plan9v6",
+ "is-trunked": true,
+ "network-id": "vUSP-23804-T-01-wnv1a_int_csdb_net_1",
+ "network-instance-group-id": "abc123",
+ "network-name": "syfy",
+ "network-role": "secret",
+ "network-technology": "soupcan",
+ "network-type": "fake",
+ "related-networks": {
+ "related-network": [
+ {
+ "network-id": "skynet",
+ "network-role": "master",
+ "vlan-tags": {
+ "is-private": true,
+ "lower-tag-id": 0,
+ "upper-tag-id": 0,
+ "vlan-interface": "le0"
+ }
+ }
+ ]
+ },
+ "segmentation-id": "seg1"
+ },
+ "physical-network-name": "skynet",
+ "route-table-reference": [
+ {
+ "route-table-reference-fqdn": "sky.net",
+ "route-table-reference-id": "ref1"
+ }
+ ],
+ "subnets": [
+ {
+ "addr-from-start": "Y",
+ "cidr-mask": "255.255.0.0",
+ "dhcp-enabled": "Y",
+ "dhcp-end-address": "10.1.2.254",
+ "dhcp-start-address": "10.1.2.1",
+ "gateway-address": "10.1.2.255",
+ "ip-version": "ipv4",
+ "start-address": "10.1.2.1",
+ "subnet-name": "subnet1",
+ "subnet-role": "puppies",
+ "subnet-sequence": 0
+ }
+ ],
+ "vpn-bindings": [
+ {
+ "aic-zone": "zone1",
+ "global-route-target": "string",
+ "route-target-role": "string",
+ "vpn-binding-id": "string",
+ "vpn-name": "string"
+ }
+ ]
+ },
+ "request-information": {
+ "notification-url": "http://dev.null.com",
+ "order-number": "123456",
+ "order-version": "2010.06",
+ "request-action": "CreateNetworkInstance",
+ "request-id": "REQ123456",
+ "source": "curl"
+ },
+ "sdnc-request-header": {
+ "svc-action": "reserve",
+ "svc-notification-url": "http://dev.null.com",
+ "svc-request-id": "SVCREQ123456"
+ }
+ }
+}
+
+### service-topology (assign)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:service-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "request-information": {
+ "notification-url": "http://dev.null",
+ "order-number": "123",
+ "order-version": "version1",
+ "request-action": "CreateServiceInstance",
+ "request-id": "{{$guid}}",
+ "source": "simulator"
+ },
+ "sdnc-request-header": {
+ "svc-action": "assign",
+ "svc-notification-url": "http://dev.null",
+ "svc-request-id": "svc-{{$guid}}"
+ },
+ "service-information": {
+ "global-customer-id": "{{$guid}}",
+ "onap-model-information": {
+ "model-customization-uuid": "12341234",
+ "model-invariant-uuid": "12341234",
+ "model-name": "vBNG_0202",
+ "model-uuid": "00e50cbd-ef0f-4b28-821e-f2b583752dd3",
+ "model-version": "1920"
+ },
+ "service-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "subscriber-name": "test",
+ "subscription-service-type": "test"
+ },
+ "service-request-input": {
+ "service-instance-name": "zrdm61asmsf01_svc"
+ }
+ }
+ }
+
+
+### service-topology (changeassign)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:service-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "request-information": {
+ "notification-url": "http://dev.null",
+ "order-number": "123",
+ "order-version": "version1",
+ "request-action": "CreateServiceInstance",
+ "request-id": "{{$guid}}",
+ "source": "simulator"
+ },
+ "sdnc-request-header": {
+ "svc-action": "changeassign",
+ "svc-notification-url": "http://dev.null",
+ "svc-request-id": "svc-{{$guid}}"
+ },
+ "service-information": {
+ "global-customer-id": "{{$guid}}",
+ "onap-model-information": {
+ "model-customization-uuid": "12341234",
+ "model-invariant-uuid": "12341234",
+ "model-name": "vcpesvc_vbng_0412a",
+ "model-uuid": "12eb33fa-b221-4d87-939c-d808b5799a7c",
+ "model-version": "1933"
+ },
+ "service-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "subscriber-name": "test",
+ "subscription-service-type": "test"
+ },
+ "service-request-input": {
+ "service-instance-name": "zrdm61asmsf01_svc"
+ }
+ }
+ }
+
+### service-topology (deactivate)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:service-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "request-information": {
+ "notification-url": "http://dev.null",
+ "order-number": "123",
+ "order-version": "version1",
+ "request-action": "DeleteServiceInstance",
+ "request-id": "{{$guid}}",
+ "source": "simulator"
+ },
+ "sdnc-request-header": {
+ "svc-action": "deactivate",
+ "svc-notification-url": "http://dev.null",
+ "svc-request-id": "svc-{{$guid}}"
+ },
+ "service-information": {
+ "global-customer-id": "{{$guid}}",
+ "onap-model-information": {
+ "model-customization-uuid": "12341234",
+ "model-invariant-uuid": "12341234",
+ "model-name": "vcpesvc_vbng_0412a",
+ "model-uuid": "12eb33fa-b221-4d87-939c-d808b5799a7c",
+ "model-version": "1933"
+ },
+ "service-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "subscriber-name": "test",
+ "subscription-service-type": "test"
+ },
+ "service-request-input": {
+ "service-instance-name": "zrdm61asmsf01_svc"
+ }
+ }
+ }
+
+### service-topology (delete)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:service-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "request-information": {
+ "notification-url": "http://dev.null",
+ "order-number": "123",
+ "order-version": "version1",
+ "request-action": "DeleteServiceInstance",
+ "request-id": "{{$guid}}",
+ "source": "simulator"
+ },
+ "sdnc-request-header": {
+ "svc-action": "delete",
+ "svc-notification-url": "http://dev.null",
+ "svc-request-id": "svc-{{$guid}}"
+ },
+ "service-information": {
+ "global-customer-id": "{{$guid}}",
+ "onap-model-information": {
+ "model-customization-uuid": "12341234",
+ "model-invariant-uuid": "12341234",
+ "model-name": "vcpesvc_vbng_0412a",
+ "model-uuid": "12eb33fa-b221-4d87-939c-d808b5799a7c",
+ "model-version": "1933"
+ },
+ "service-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca",
+ "subscriber-name": "test",
+ "subscription-service-type": "test"
+ },
+ "service-request-input": {
+ "service-instance-name": "zrdm61asmsf01_svc"
+ }
+ }
+ }
+
+
+### network-topology (assign)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "network-information": {
+ "onap-model-information": {
+ "model-name": "VcpesvcVbng0412a.bng_mux",
+ "model-version": "1.0",
+ "model-customization-uuid": "b0cf3385-a390-488c-b6a0-d879fb4a4825",
+ "model-uuid": "9b7c1cbe-ddcd-458c-8792-d76391419b72",
+ "model-invariant-uuid": "206d5e6c-4cba-4c14-b942-5d946c881869"
+ },
+ "network-id": "2e723205-7f96-49a9-bd60-24168fbd9f07"
+ },
+ "network-request-input": {
+ "aic-cloud-region": "wnv1a",
+ "cloud-owner": "att-nc",
+ "tenant": "1795554216e946af8a3c788f195eb813",
+ "network-name": "vUSP-23804-T-01-wnv1a_int_csdb_net_1"
+ },
+ "request-information": {
+ "request-action": "CreateNetworkInstance",
+ "source": "simulator",
+ "request-id": "{{$guid}}"
+ },
+ "sdnc-request-header": {
+ "svc-request-id": "svc-{{$guid}}",
+ "svc-action": "assign"
+ },
+ "service-information": {
+ "onap-model-information": {
+ "model-name": "vcpesvc_vbng_0412a",
+ "model-version": "3.0",
+ "model-uuid": "12eb33fa-b221-4d87-939c-d808b5799a7c",
+ "model-invariant-uuid": "ead151e2-e18a-44fc-b6ac-3ae3d819dcd6"
+ },
+ "subscription-service-type": "VIRTUAL USP",
+ "service-id": "svc-{{$guid}}",
+ "global-customer-id": "{{$guid}}",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca"
+ }
+ }
+}
+
+
+### network-topology (activate)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "network-information": {
+ "onap-model-information": {
+ "model-name": "VcpesvcVbng0412a.bng_mux",
+ "model-version": "1.0",
+ "model-customization-uuid": "b0cf3385-a390-488c-b6a0-d879fb4a4825",
+ "model-uuid": "9b7c1cbe-ddcd-458c-8792-d76391419b72",
+ "model-invariant-uuid": "206d5e6c-4cba-4c14-b942-5d946c881869"
+ },
+ "network-technology": "",
+ "network-id": "2e723205-7f96-49a9-bd60-24168fbd9f07",
+ "network-type": ""
+ },
+ "network-request-input": {
+ "aic-cloud-region": "wnv1a",
+ "cloud-owner": "att-nc",
+ "tenant": "1795554216e946af8a3c788f195eb813",
+ "network-name": "vUSP-23804-T-01-wnv1a_int_ccfx_net_1"
+ },
+ "request-information": {
+ "request-action": "CreateNetworkInstance",
+ "source": "simulator",
+ "request-id": "{{$guid}}"
+ },
+ "sdnc-request-header": {
+ "svc-request-id": "svc-{{$guid}}",
+ "svc-action": "activate"
+ },
+ "service-information": {
+ "onap-model-information": {
+ "model-name": "vcpesvc_vbng_0412a",
+ "model-version": "3.0",
+ "model-uuid": "12eb33fa-b221-4d87-939c-d808b5799a7c",
+ "model-invariant-uuid": "ead151e2-e18a-44fc-b6ac-3ae3d819dcd6"
+ },
+ "subscription-service-type": "VIRTUAL USP",
+ "service-id": "svc-{{$guid}}",
+ "global-customer-id": "{{$guid}}",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca"
+ }
+ }
+}
+
+### network-topology (deactivate)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "network-information": {
+ "onap-model-information": {
+ "model-name": "VcpesvcVbng0412a.bng_mux",
+ "model-version": "1.0",
+ "model-customization-uuid": "b0cf3385-a390-488c-b6a0-d879fb4a4825",
+ "model-uuid": "9b7c1cbe-ddcd-458c-8792-d76391419b72",
+ "model-invariant-uuid": "206d5e6c-4cba-4c14-b942-5d946c881869"
+ },
+ "network-technology": "",
+ "network-id": "2e723205-7f96-49a9-bd60-24168fbd9f07",
+ "network-type": ""
+ },
+ "network-request-input": {
+ "aic-cloud-region": "wnv1a",
+ "cloud-owner": "att-nc",
+ "tenant": "1795554216e946af8a3c788f195eb813",
+ "network-name": "vUSP-23804-T-01-wnv1a_int_ccfx_net_1"
+ },
+ "request-information": {
+ "request-action": "DeleteNetworkInstance",
+ "source": "simulator",
+ "request-id": "{{$guid}}"
+ },
+ "sdnc-request-header": {
+ "svc-request-id": "svc-{{$guid}}",
+ "svc-action": "deactivate"
+ },
+ "service-information": {
+ "onap-model-information": {
+ "model-name": "vcpesvc_vbng_0412a",
+ "model-version": "3.0",
+ "model-uuid": "12eb33fa-b221-4d87-939c-d808b5799a7c",
+ "model-invariant-uuid": "ead151e2-e18a-44fc-b6ac-3ae3d819dcd6"
+ },
+ "subscription-service-type": "VIRTUAL USP",
+ "service-id": "svc-{{$guid}}",
+ "global-customer-id": "{{$guid}}",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca"
+ }
+ }
+}
+
+### network-topology (unassign)
+POST {{hostname}}/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{
+ "input": {
+ "network-information": {
+ "onap-model-information": {
+ "model-name": "VcpesvcVbng0412a.bng_mux",
+ "model-version": "1.0",
+ "model-customization-uuid": "b0cf3385-a390-488c-b6a0-d879fb4a4825",
+ "model-uuid": "9b7c1cbe-ddcd-458c-8792-d76391419b72",
+ "model-invariant-uuid": "206d5e6c-4cba-4c14-b942-5d946c881869"
+ },
+ "network-technology": "",
+ "network-id": "2e723205-7f96-49a9-bd60-24168fbd9f07",
+ "network-type": ""
+ },
+ "network-request-input": {
+ "aic-cloud-region": "wnv1a",
+ "cloud-owner": "att-nc",
+ "tenant": "1795554216e946af8a3c788f195eb813",
+ "network-name": "vUSP-23804-T-01-wnv1a_int_ccfx_net_1"
+ },
+ "request-information": {
+ "request-action": "DeleteNetworkInstance",
+ "source": "simulator",
+ "request-id": "{{$guid}}"
+ },
+ "sdnc-request-header": {
+ "svc-request-id": "svc-{{$guid}}",
+ "svc-action": "unassign"
+ },
+ "service-information": {
+ "onap-model-information": {
+ "model-name": "vcpesvc_vbng_0412a",
+ "model-version": "3.0",
+ "model-uuid": "12eb33fa-b221-4d87-939c-d808b5799a7c",
+ "model-invariant-uuid": "ead151e2-e18a-44fc-b6ac-3ae3d819dcd6"
+ },
+ "subscription-service-type": "VIRTUAL USP",
+ "service-id": "svc-{{$guid}}",
+ "global-customer-id": "{{$guid}}",
+ "service-instance-id": "5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca"
+ }
+ }
+}
+
+### Healthcheck
+POST {{hostname}}/restconf/operations/SLI-API:healthcheck/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+{ input: {}}
+
+### get service instance / topology
+GET {{hostname}}/restconf/config/GENERIC-RESOURCE-API:services/service/5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca/service-data/service-topology/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
+
+### top level get
+GET {{hostname}}/restconf/config/GENERIC-RESOURCE-API:services/service/5c4f2d89-57a3-47e9-b49b-d3c63eb0b3ca/
+Authorization: Basic {{token}}
+Content-Type: application/json
+Accept: application/json
\ No newline at end of file |