2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdnc.apps.ms.gra.controllers;
23 import java.util.ArrayList;
24 import java.util.Iterator;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Optional;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.validation.Valid;
32 import com.fasterxml.jackson.annotation.JsonInclude;
33 import com.fasterxml.jackson.core.JsonProcessingException;
34 import com.fasterxml.jackson.databind.ObjectMapper;
36 import org.onap.ccsdk.apps.services.RestApplicationException;
37 import org.onap.ccsdk.apps.services.RestException;
38 import org.onap.ccsdk.apps.services.RestProtocolException;
39 import org.onap.sdnc.apps.ms.gra.controllers.ServiceDataHelper.ServiceDataTransaction;
40 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResources;
41 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResourcesRepository;
42 import org.onap.sdnc.apps.ms.gra.data.ConfigNetworksRepository;
43 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurations;
44 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurationsRepository;
45 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
46 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
47 import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
48 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
49 import org.onap.sdnc.apps.ms.gra.data.ConfigVfModules;
50 import org.onap.sdnc.apps.ms.gra.data.ConfigVfModulesRepository;
51 import org.onap.sdnc.apps.ms.gra.data.ConfigVnfsRepository;
52 import org.onap.sdnc.apps.ms.gra.swagger.ConfigApi;
53 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource;
54 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData;
55 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiContrailroutetopologyContrailRouteTopology;
56 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
57 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiOperStatusData;
58 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration;
59 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData;
60 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology;
61 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadModelInformation;
62 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloaddataPreloadData;
63 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadmodelinformationPreloadList;
64 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation;
65 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServiceModelInfrastructure;
66 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServiceData;
67 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnf;
68 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
69 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule;
70 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicemodelinfrastructureService;
71 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicestatusServiceStatus;
72 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiServicetopologyServiceTopology;
73 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVfmoduletopologyVfModuleTopology;
74 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfNetworkData;
75 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfresourceassignmentsVnfResourceAssignments;
76 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks;
77 import org.onap.sdnc.apps.ms.gra.swagger.model.GenericResourceApiVnftopologyVnfTopology;
78 import org.slf4j.Logger;
79 import org.slf4j.LoggerFactory;
80 import org.springframework.beans.factory.annotation.Autowired;
81 import org.springframework.boot.autoconfigure.domain.EntityScan;
82 import org.springframework.context.annotation.ComponentScan;
83 import org.springframework.http.HttpStatus;
84 import org.springframework.http.ResponseEntity;
85 import org.springframework.stereotype.Controller;
88 @ComponentScan(basePackages = { "org.onap.sdnc.apps.ms.gra.*" })
89 @EntityScan("org.onap.sdnc.apps.ms.gra.springboot.*")
90 public class ConfigApiController implements ConfigApi {
91 private static final Logger log = LoggerFactory.getLogger(ConfigApiController.class);
93 private final ObjectMapper objectMapper;
95 private final HttpServletRequest request;
98 private ConfigPreloadDataRepository configPreloadDataRepository;
101 private ConfigServicesRepository configServicesRepository;
104 private ConfigNetworksRepository configNetworksRepository;
107 private ConfigVnfsRepository configVnfsRepository;
110 private ConfigVfModulesRepository configVfModulesRepository;
113 private ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
116 private ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
119 private ServiceDataHelper serviceDataHelper;
122 public ConfigApiController(ObjectMapper objectMapper, HttpServletRequest request) {
123 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
124 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
125 this.objectMapper = objectMapper;
126 this.request = request;
130 public Optional<ObjectMapper> getObjectMapper() {
131 return Optional.ofNullable(objectMapper);
135 public Optional<HttpServletRequest> getRequest() {
136 return Optional.ofNullable(request);
140 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationDelete() {
141 configPreloadDataRepository.deleteAll();
142 return (new ResponseEntity<>(HttpStatus.NO_CONTENT));
146 * Extracts port-mirror configuration data from CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS for a given, configuration-id
148 * Maps to /config/GENERIC-RESOURCE-API:port-mirror-configurations/port-mirror-configuration/{configuration-id}/
149 * @param configurationId the configuration ID for a port-mirror
150 * @return HttpStatus.OK (200) if the data is found.
151 * @throws RestException if the data does not exist.
153 public ResponseEntity<GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration>
154 configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet(
155 String configurationId) throws RestApplicationException {
156 GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration retval = null;
158 List<ConfigPortMirrorConfigurations> pmConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
160 if (pmConfigurations.isEmpty()) {
161 log.info("No configuration data found with id [{}]",configurationId);
162 throw new RestApplicationException("data-missing",
163 "Request could not be completed because the relevant data model content does not exist",
164 HttpStatus.NOT_FOUND.value());
166 ConfigPortMirrorConfigurations pmConfiguration = pmConfigurations.get(0);
167 retval = new GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration();
168 retval.setConfigurationId(configurationId);
169 retval.setConfigurationStatus(pmConfiguration.getPortMirrorConfigurationStatus());
171 retval.setConfigurationData(objectMapper.readValue(pmConfiguration.getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class));
172 } catch (JsonProcessingException e) {
173 log.error("Could not deserialize service data for service instance id {}", configurationId, e);
174 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
177 return new ResponseEntity<>(retval, HttpStatus.OK);
181 public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut(
182 String configurationId, @Valid GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration newConfiguration)
183 throws RestApplicationException {
185 boolean dataExists = false;
187 String newConfigurationId = newConfiguration.getConfigurationId();
189 ConfigPortMirrorConfigurations portMirrorConfiguration = null;
190 List<ConfigPortMirrorConfigurations> existingConfiguration = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
191 if ((existingConfiguration != null) && !existingConfiguration.isEmpty()) {
193 portMirrorConfiguration = existingConfiguration.get(0);
195 portMirrorConfiguration = new ConfigPortMirrorConfigurations();
196 portMirrorConfiguration.setConfigureationId(configurationId);
200 portMirrorConfiguration.setPmcData(objectMapper.writeValueAsString(newConfiguration.getConfigurationData()));
201 } catch (JsonProcessingException e) {
202 log.error("Could not serialize porr-mirror configuration data for {}", portMirrorConfiguration.getConfigureationId(), e);
203 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
206 portMirrorConfiguration.setPortMirrorConfigurationStatus(newConfiguration.getConfigurationStatus());
207 configPortMirrorConfigurationsRepository.save(portMirrorConfiguration);
210 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
212 return new ResponseEntity<>(HttpStatus.CREATED);
217 public ResponseEntity<GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology>
218 configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet(
219 String configurationId) throws RestApplicationException, RestProtocolException {
220 @Valid GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology portMirrorConfigurationTopology = null;
221 GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData portMirrorConfigurationData = null;
223 List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
224 if ((configPortMirrorConfigurations == null) || (configPortMirrorConfigurations.isEmpty())) {
225 log.info("No configuration data found with id [{}]", configurationId);
226 throw new RestApplicationException("data-missing",
227 "Request could not be completed because the relevant data model content does not exist",
228 HttpStatus.NOT_FOUND.value());
232 if ( configPortMirrorConfigurations.get(0).getPmcData().isEmpty()) {
233 throw new RestProtocolException("data-missing", "No configuration-data entry found", HttpStatus.NOT_FOUND.value());
235 portMirrorConfigurationData = objectMapper.readValue(configPortMirrorConfigurations.get(0).getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class);
236 portMirrorConfigurationTopology = portMirrorConfigurationData.getPortMirrorConfigurationTopology();
238 if (portMirrorConfigurationTopology == null) {
239 throw new RestProtocolException("data-missing", "No service-topology entry found", HttpStatus.NOT_FOUND.value());
241 return new ResponseEntity<>(portMirrorConfigurationTopology, HttpStatus.OK);
242 } catch (JsonProcessingException e) {
243 log.error("Could not parse service data", e);
244 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
250 public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete(String configurationId) {
251 configPortMirrorConfigurationsRepository.deleteByConfigurationId(configurationId);
252 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
256 * Extracts contrail-route-allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
258 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
259 * @param allottedResourceId the allotted-resource-id for a contrail-route
260 * @return HttpStatus.OK (200) if the data is found.
261 * @throws RestException if the data does not exist.
263 public ResponseEntity<GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource>
264 configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet(
265 String allottedResourceId) throws RestApplicationException {
266 GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource retval = null;
268 List<ConfigContrailRouteAllottedResources> allottedResources = configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
270 if (allottedResources.isEmpty()) {
271 log.info("No contrail-route-allotted-resource found with id [{}]", allottedResourceId);
272 throw new RestApplicationException("data-missing",
273 "Request could not be completed because the relevant data model content does not exist",
274 HttpStatus.NOT_FOUND.value());
277 ConfigContrailRouteAllottedResources allottedResource = allottedResources.get(0);
278 retval = new GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource();
279 retval.setAllottedResourceId(allottedResourceId);
280 retval.setAllottedResourceStatus(allottedResource.getAllottedResourceStatus());
282 retval.setAllottedResourceData(objectMapper.readValue(allottedResource.getArData(),
283 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class));
284 } catch (JsonProcessingException e) {
285 log.error("Could not deserialize service data for service instance id {}", allottedResourceId, e);
286 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
289 return new ResponseEntity<>(retval, HttpStatus.OK);
293 * PUT contrail-route-allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
295 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
296 * @param allottedResourceId the allotted-resource-id for a contrail-route
297 * @return HttpStatus.OK (200) if the data is found.
298 * @throws RestException if the data does not exist.
301 public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut(
302 String allottedResourceId, @Valid GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource newAllottedResource)
303 throws RestApplicationException {
305 boolean dataExists = false;
307 String newAllottedResourceId = newAllottedResource.getAllottedResourceId();
309 ConfigContrailRouteAllottedResources allottedResource = null;
310 List<ConfigContrailRouteAllottedResources> existingAllottedResource =
311 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
313 if ((existingAllottedResource != null) && !existingAllottedResource.isEmpty()) {
315 allottedResource = existingAllottedResource.get(0);
317 allottedResource = new ConfigContrailRouteAllottedResources();
318 allottedResource.setAllottedResourceId(allottedResourceId);
322 allottedResource.setArData(objectMapper.writeValueAsString(newAllottedResource.getAllottedResourceData()));
323 } catch (JsonProcessingException e) {
324 log.error("Could not serialize porr-mirror configuration data for {}", allottedResource.getAllottedResourceId(), e);
325 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
328 allottedResource.setAllottedResourceStatus(newAllottedResource.getAllottedResourceStatus());
329 configContrailRouteAllottedResourcesRepository.save(allottedResource);
332 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
334 return new ResponseEntity<>(HttpStatus.CREATED);
339 * Extracts contrail-route-topology data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
341 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}/allotted-resource-data/contrail-route-topology/
342 * @param allottedResourceId the allotted-resource-id for a contrail-route
343 * @return HttpStatus.OK (200) if the data is found.
344 * @throws RestException if the data does not exist.
347 public ResponseEntity<GenericResourceApiContrailroutetopologyContrailRouteTopology>
348 configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet(
349 String allottedResourceId) throws RestApplicationException, RestProtocolException {
350 @Valid GenericResourceApiContrailroutetopologyContrailRouteTopology contrailRouteTopology = null;
351 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData allottedResourceData = null;
353 List<ConfigContrailRouteAllottedResources> configContrailRouteAllottedResources =
354 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
356 if ((configContrailRouteAllottedResources == null) || (configContrailRouteAllottedResources.isEmpty())) {
357 log.info("No contrail-route-allotted-resoure data found with id [{}]", allottedResourceId);
358 throw new RestApplicationException("data-missing",
359 "Request could not be completed because the relevant data model content does not exist",
360 HttpStatus.NOT_FOUND.value());
364 if ( configContrailRouteAllottedResources.get(0).getArData().isEmpty()) {
365 throw new RestProtocolException("data-missing", "No allotted-resource-data entry found", HttpStatus.NOT_FOUND.value());
367 allottedResourceData = objectMapper.readValue(configContrailRouteAllottedResources.get(0).getArData(),
368 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class);
370 contrailRouteTopology = allottedResourceData.getContrailRouteTopology();
372 if (contrailRouteTopology == null) {
373 throw new RestProtocolException("data-missing", "No contrail-route-topology entry found", HttpStatus.NOT_FOUND.value());
375 return new ResponseEntity<>(contrailRouteTopology, HttpStatus.OK);
376 } catch (JsonProcessingException e) {
377 log.error("Could not parse port-mirror-configuration data", e);
378 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
384 * DELETE allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
386 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
387 * @param allottedResourceId the allotted-resource-id for a contrail-route
388 * @return HttpStatus.NO_CONTENT (204) if the data is found.
391 public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete(
392 String allottedResourceId) {
393 configContrailRouteAllottedResourcesRepository.deleteByAllottedResourceId(allottedResourceId);
394 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
399 public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet()
400 throws RestApplicationException {
401 GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation();
403 if (configPreloadDataRepository.count() == 0) {
404 throw new RestApplicationException("data-missing",
405 "Request could not be completed because the relevant data model content does not exist",
406 HttpStatus.NOT_FOUND.value());
409 for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
410 GenericResourceApiPreloadmodelinformationPreloadList preloadListItem = new GenericResourceApiPreloadmodelinformationPreloadList();
412 preloadListItem.setPreloadId(configPreloadData.getPreloadId());
413 preloadListItem.setPreloadType(configPreloadData.getPreloadType());
415 preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(),
416 GenericResourceApiPreloaddataPreloadData.class));
417 } catch (JsonProcessingException e) {
418 log.error("Could not convert preload data", e);
419 throw new RestApplicationException("data-conversion",
420 "Request could not be completed due to internal error", e,
421 HttpStatus.INTERNAL_SERVER_ERROR.value());
423 genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem);
426 return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK);
430 public ResponseEntity<GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPreloadNetworkTopologyInformationGet(
431 String preloadId, String preloadType) throws RestException {
432 GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation netTopoInfo = null;
434 if (configPreloadDataRepository.count() == 0) {
435 throw new RestApplicationException("data-missing",
436 "Request could not be completed because the relevant data model content does not exist",
437 HttpStatus.NOT_FOUND.value());
440 for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
443 GenericResourceApiPreloaddataPreloadData preloadDataItem = objectMapper
444 .readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class);
445 netTopoInfo = preloadDataItem.getPreloadNetworkTopologyInformation();
446 } catch (JsonProcessingException e) {
447 log.error("Could not convert preload data", e);
448 throw new RestApplicationException("data-conversion",
449 "Request could not be completed due to internal error", e,
450 HttpStatus.INTERNAL_SERVER_ERROR.value());
454 return new ResponseEntity<>(netTopoInfo, HttpStatus.OK);
459 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(
460 @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo)
461 throws RestApplicationException, RestProtocolException {
463 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
464 List<ConfigPreloadData> newPreloadData = new LinkedList<>();
466 if (preloadList != null) {
467 // Verification pass - if any items already exist, return an error
468 for (GenericResourceApiPreloadmodelinformationPreloadList curItem : preloadList) {
470 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
471 .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
472 if ((curPreloadData != null) && (!curPreloadData.isEmpty())) {
473 log.error("Preload data already exists for {}:{}", curItem.getPreloadId(),
474 curItem.getPreloadType());
475 throw new RestProtocolException("data-exists",
476 "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(),
477 HttpStatus.CONFLICT.value());
480 newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(),
481 objectMapper.writeValueAsString(curItem.getPreloadData())));
482 } catch (JsonProcessingException e) {
483 log.error("Cannot convert preload data");
484 throw new RestApplicationException("data-conversion",
485 "Request could not be completed due to internal error", e,
486 HttpStatus.INTERNAL_SERVER_ERROR.value());
493 for (ConfigPreloadData newDataItem : newPreloadData) {
494 log.info("Adding preload data for {}:{}", newDataItem.getPreloadId(), newDataItem.getPreloadType());
495 configPreloadDataRepository.save(newDataItem);
498 throw new RestProtocolException("data-missing", "No preload-list entries found to add",
499 HttpStatus.CONFLICT.value());
502 return new ResponseEntity<>(HttpStatus.CREATED);
506 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(
507 @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException {
509 boolean addedNew = false;
510 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
512 if (preloadList != null) {
513 Iterator<GenericResourceApiPreloadmodelinformationPreloadList> iter = preloadList.iterator();
514 while (iter.hasNext()) {
515 GenericResourceApiPreloadmodelinformationPreloadList curItem = iter.next();
516 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
517 .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
518 if ((curPreloadData == null) || curPreloadData.isEmpty()) {
523 configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(),
524 curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
525 } catch (JsonProcessingException e) {
526 log.error("Cannot convert preload data", e);
527 throw new RestApplicationException("data-conversion",
528 "Request could not be completed due to internal error", e,
529 HttpStatus.INTERNAL_SERVER_ERROR.value());
536 return new ResponseEntity<>(HttpStatus.CREATED);
538 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
544 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPost(
545 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException {
547 throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"",
548 HttpStatus.NOT_FOUND.value());
552 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeDelete(
553 String preloadId, String preloadType) {
554 configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
555 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
559 public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeGet(
560 String preloadId, String preloadType) throws RestApplicationException {
561 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
563 if (preloadData != null) {
564 if (!preloadData.isEmpty()) {
565 ConfigPreloadData preloadDataItem = preloadData.get(0);
566 GenericResourceApiPreloadmodelinformationPreloadList preloadDataList = new GenericResourceApiPreloadmodelinformationPreloadList();
567 preloadDataList.setPreloadId(preloadDataItem.getPreloadId());
568 preloadDataList.setPreloadType(preloadDataItem.getPreloadType());
570 preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(),
571 GenericResourceApiPreloaddataPreloadData.class));
572 } catch (JsonProcessingException e) {
573 log.error("Cannot convert preload data", e);
574 throw new RestApplicationException("data-conversion",
575 "Request could not be completed due to internal error", e,
576 HttpStatus.INTERNAL_SERVER_ERROR.value());
578 return new ResponseEntity<>(preloadDataList, HttpStatus.OK);
581 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
585 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePost(
586 String preloadId, String preloadType,
587 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
588 throws RestApplicationException, RestProtocolException {
589 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
592 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
593 log.error("Preload data already exists for {}:{}", preloadId, preloadType);
594 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
595 HttpStatus.CONFLICT.value());
599 log.info("Adding preload data for {}:{}", preloadId, preloadType);
600 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
601 objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
602 } catch (JsonProcessingException e) {
603 log.error("Cannot convert preload data", e);
604 throw new RestApplicationException("data-conversion",
605 "Request could not be completed due to internal error", e,
606 HttpStatus.INTERNAL_SERVER_ERROR.value());
609 return new ResponseEntity<>(HttpStatus.CREATED);
613 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePut(
614 String preloadId, String preloadType,
615 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
616 throws RestApplicationException, RestProtocolException {
617 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
619 boolean dataExists = false;
620 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
624 if ((preloadListItem.getPreloadId() == null) || (preloadListItem.getPreloadType() == null)
625 || (preloadListItem.getPreloadData() == null)) {
626 log.error("Invalid list item received: {}", preloadListItem);
627 throw new RestProtocolException("bad-attribute", "Invalid data received", HttpStatus.BAD_REQUEST.value());
632 log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType,
633 objectMapper.writeValueAsString(preloadListItem));
636 log.info("Adding preload data for {}:{}", preloadId, preloadType);
639 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
640 objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
641 } catch (JsonProcessingException e) {
642 log.error("Cannot convert preload data", e);
643 throw new RestApplicationException("data-conversion",
644 "Request could not be completed due to internal error", e,
645 HttpStatus.INTERNAL_SERVER_ERROR.value());
650 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
652 return new ResponseEntity<>(HttpStatus.CREATED);
657 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataDelete(
658 String preloadId, String preloadType) throws RestProtocolException {
659 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
662 if ((preloadData == null) || preloadData.isEmpty()) {
663 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
666 ConfigPreloadData preloadDataItem = preloadData.get(0);
668 if (preloadDataItem.getPreloadData() == null) {
669 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
671 preloadDataItem.setPreloadData(null);
672 configPreloadDataRepository.save(preloadDataItem);
674 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
678 public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataGet(
679 String preloadId, String preloadType) throws RestApplicationException, RestProtocolException {
680 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
683 if ((preloadData == null) || preloadData.isEmpty()) {
684 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
687 ConfigPreloadData preloadDataItem = preloadData.get(0);
689 if (preloadDataItem.getPreloadData() == null) {
690 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
693 return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(),
694 GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
695 } catch (JsonProcessingException e) {
696 log.error("Cannot convert preload data", e);
697 throw new RestApplicationException("data-conversion",
698 "Request could not be completed due to internal error", e,
699 HttpStatus.INTERNAL_SERVER_ERROR.value());
704 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPost(
705 String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
706 throws RestApplicationException, RestProtocolException {
709 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
711 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
712 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
715 if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
716 throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
717 HttpStatus.BAD_REQUEST.value());
720 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
722 if (preloadDataItem.getPreloadData() != null) {
723 log.error("Preload data already exists for {}:{} ", preloadId, preloadType);
724 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
725 HttpStatus.CONFLICT.value());
729 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
730 configPreloadDataRepository.save(preloadDataItem);
731 } catch (JsonProcessingException e) {
732 log.error("Cannot convert preload data", e);
733 throw new RestApplicationException("data-conversion",
734 "Request could not be completed due to internal error", e,
735 HttpStatus.INTERNAL_SERVER_ERROR.value());
738 return new ResponseEntity<>(HttpStatus.CREATED);
742 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPut(
743 String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
744 throws RestApplicationException, RestProtocolException {
745 boolean dataExists = false;
746 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
748 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
749 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
752 if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
753 throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
754 HttpStatus.BAD_REQUEST.value());
757 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
759 if (preloadDataItem.getPreloadData() != null) {
764 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
765 configPreloadDataRepository.save(preloadDataItem);
766 } catch (JsonProcessingException e) {
767 log.error("Cannot convert preload data", e);
768 throw new RestApplicationException("data-conversion",
769 "Request could not be completed due to internal error", e,
770 HttpStatus.INTERNAL_SERVER_ERROR.value());
774 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
776 return new ResponseEntity<>(HttpStatus.CREATED);
781 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesDelete() {
782 configVfModulesRepository.deleteAll();
783 configVnfsRepository.deleteAll();
784 configNetworksRepository.deleteAll();
785 configServicesRepository.deleteAll();
786 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
790 public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet()
791 throws RestApplicationException {
792 GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure();
794 if (configServicesRepository.count() == 0) {
795 throw new RestApplicationException("data-missing",
796 "Request could not be completed because the relevant data model content does not exist",
797 HttpStatus.NOT_FOUND.value());
800 for (ConfigServices service : configServicesRepository.findAll()) {
801 GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService();
802 String svcInstanceId = service.getSvcInstanceId();
804 serviceItem.setServiceInstanceId(svcInstanceId);
805 serviceItem.setServiceStatus(service.getServiceStatus());
807 // Construct service data from networks/vnfs/vfModules
808 GenericResourceApiServicedataServiceData serviceItemSvcData;
810 serviceItemSvcData = serviceDataHelper.getServiceData(service);
811 } catch (JsonProcessingException e) {
812 log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e);
813 throw new RestApplicationException("data-conversion",
814 "Request could not be completed due to internal error", e,
815 HttpStatus.INTERNAL_SERVER_ERROR.value());
819 if (serviceItemSvcData != null) {
820 serviceItem.setServiceData(serviceItemSvcData);
822 modelInfrastructure.addServiceItem(serviceItem);
825 return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK);
830 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(@Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure)
831 throws RestApplicationException, RestProtocolException {
833 ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
835 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
836 String svcInstanceId = serviceItem.getServiceInstanceId();
837 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
838 if ((existingService != null) && !existingService.isEmpty()) {
839 log.error("Service data already exists for {}", svcInstanceId);
840 throw new RestProtocolException("data-exists",
841 "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
843 ConfigServices service = new ConfigServices();
844 service.setSvcInstanceId(svcInstanceId);
845 service.setServiceStatus(serviceItem.getServiceStatus());
848 serviceDataHelper.saveService(service, serviceItem.getServiceData(), transaction);
849 } catch (JsonProcessingException e) {
850 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
851 throw new RestApplicationException("data-conversion",
852 "Request could not be completed due to internal error", e,
853 HttpStatus.INTERNAL_SERVER_ERROR.value());
858 transaction.commit();
860 return new ResponseEntity<>(HttpStatus.CREATED);
865 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(
866 @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException {
868 ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
869 boolean dataExists = false;
871 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
872 String svcInstanceId = serviceItem.getServiceInstanceId();
873 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
874 if ((existingService != null) && !existingService.isEmpty()) {
877 ConfigServices service = new ConfigServices();
878 service.setSvcInstanceId(svcInstanceId);
879 service.setServiceStatus(serviceItem.getServiceStatus());
881 serviceDataHelper.saveService(service, serviceItem.getServiceData(), transaction);
882 } catch (JsonProcessingException e) {
883 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
884 throw new RestApplicationException("data-conversion",
885 "Request could not be completed due to internal error", e,
886 HttpStatus.INTERNAL_SERVER_ERROR.value());
891 transaction.commit();
894 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
896 return new ResponseEntity<>(HttpStatus.CREATED);
902 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServicePost(
903 @Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException {
904 String svcInstanceId = servicesData.getServiceInstanceId();
906 ConfigServices configService = new ConfigServices(svcInstanceId, servicesData.getServiceStatus());
907 serviceDataHelper.saveService(configService, servicesData.getServiceData());
908 } catch (JsonProcessingException e) {
909 log.error("Cannot convert service data", e);
910 throw new RestApplicationException("data-conversion",
911 "Request could not be completed due to internal error", e,
912 HttpStatus.INTERNAL_SERVER_ERROR.value());
915 return new ResponseEntity<>(HttpStatus.OK);
919 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdDelete(
920 String serviceInstanceId) {
921 serviceDataHelper.deleteService(serviceInstanceId);
922 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
926 public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdGet(
927 String serviceInstanceId) throws RestApplicationException {
928 GenericResourceApiServicemodelinfrastructureService retval = null;
930 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
932 if (services.isEmpty()) {
933 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
935 ConfigServices service = services.get(0);
936 retval = new GenericResourceApiServicemodelinfrastructureService();
937 retval.setServiceInstanceId(serviceInstanceId);
938 retval.setServiceStatus(service.getServiceStatus());
940 retval.setServiceData(serviceDataHelper.getServiceData(service));
941 } catch (JsonProcessingException e) {
942 log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e);
943 throw new RestApplicationException("data-conversion",
944 "Request could not be completed due to internal error", e,
945 HttpStatus.INTERNAL_SERVER_ERROR.value());
950 return new ResponseEntity<>(retval, HttpStatus.OK);
955 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPost(String svcInstanceId,
956 @Valid GenericResourceApiServicemodelinfrastructureService newService)
957 throws RestApplicationException, RestProtocolException {
959 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
960 if ((existingService != null) && !existingService.isEmpty()) {
961 log.error("Service data already exists for {}", svcInstanceId);
962 throw new RestProtocolException("data-exists",
963 "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
965 ConfigServices service = new ConfigServices();
966 service.setSvcInstanceId(svcInstanceId);
967 service.setServiceStatus(newService.getServiceStatus());
969 serviceDataHelper.saveService(service, newService.getServiceData());
970 } catch (JsonProcessingException e) {
971 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
972 throw new RestApplicationException("data-conversion",
973 "Request could not be completed due to internal error", e,
974 HttpStatus.INTERNAL_SERVER_ERROR.value());
978 return new ResponseEntity<>(HttpStatus.CREATED);
982 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPut(String serviceInstanceId,
983 @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException {
985 boolean dataExists = false;
987 String svcInstanceId = newService.getServiceInstanceId();
989 ConfigServices service = null;
990 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
991 if ((existingService != null) && !existingService.isEmpty()) {
993 service = existingService.get(0);
995 service = new ConfigServices();
996 service.setSvcInstanceId(svcInstanceId);
999 service.setServiceStatus(newService.getServiceStatus());
1001 serviceDataHelper.saveService(service, newService.getServiceData());
1002 } catch (JsonProcessingException e) {
1003 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
1004 throw new RestApplicationException("data-conversion",
1005 "Request could not be completed due to internal error", e,
1006 HttpStatus.INTERNAL_SERVER_ERROR.value());
1011 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1013 return new ResponseEntity<>(HttpStatus.CREATED);
1018 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataDelete(
1019 String serviceInstanceId) throws RestProtocolException {
1020 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1022 if ((services == null) || (services.isEmpty())) {
1023 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1026 ConfigServices service = services.get(0);
1027 if (!serviceDataHelper.hasServiceData(service)) {
1028 throw new RestProtocolException("data-missing", "No service-data found", HttpStatus.NOT_FOUND.value());
1030 serviceDataHelper.clearServiceData(service);
1032 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1036 public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataGet(
1037 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1038 GenericResourceApiServicedataServiceData serviceData = null;
1040 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1041 if ((services == null) || (services.isEmpty())) {
1042 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1046 serviceData = serviceDataHelper.getServiceData(services.get(0));
1047 return new ResponseEntity<>(serviceData, HttpStatus.OK);
1048 } catch (JsonProcessingException e) {
1049 log.error("Could not parse service data", e);
1050 throw new RestApplicationException("data-conversion",
1051 "Request could not be completed due to internal error", e,
1052 HttpStatus.INTERNAL_SERVER_ERROR.value());
1058 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPost(
1059 String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1060 throws RestApplicationException, RestProtocolException {
1061 ConfigServices service;
1062 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1063 if ((services == null) || (services.isEmpty())) {
1064 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1067 if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1068 throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1069 HttpStatus.BAD_REQUEST.value());
1072 service = services.get(0);
1074 if (serviceDataHelper.hasServiceData(service)) {
1075 log.error("service-data already exists for svcInstanceId {}", serviceInstanceId);
1076 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1077 HttpStatus.CONFLICT.value());
1081 serviceDataHelper.saveService(service, serviceData);
1082 } catch (JsonProcessingException e) {
1083 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1084 throw new RestApplicationException("data-conversion",
1085 "Request could not be completed due to internal error", e,
1086 HttpStatus.INTERNAL_SERVER_ERROR.value());
1089 return new ResponseEntity<>(HttpStatus.CREATED);
1094 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPut(
1095 String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1096 throws RestApplicationException, RestProtocolException {
1097 ConfigServices service;
1098 boolean dataExists = false;
1100 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1101 if ((services == null) || (services.isEmpty())) {
1102 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1105 if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1106 throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1107 HttpStatus.BAD_REQUEST.value());
1110 service = services.get(0);
1112 dataExists = serviceDataHelper.hasServiceData(service);
1115 serviceDataHelper.saveService(service, serviceData);
1116 } catch (JsonProcessingException e) {
1117 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1118 throw new RestApplicationException("data-conversion",
1119 "Request could not be completed due to internal error", e,
1120 HttpStatus.INTERNAL_SERVER_ERROR.value());
1124 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1126 return new ResponseEntity<>(HttpStatus.CREATED);
1131 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusDelete(
1132 String serviceInstanceId) throws RestProtocolException {
1133 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1135 if ((services == null) || (services.isEmpty())) {
1136 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1139 ConfigServices service = services.get(0);
1140 if (service.getServiceStatus() == null) {
1141 throw new RestProtocolException("data-missing", "No service-status found", HttpStatus.NOT_FOUND.value());
1143 service.setServiceStatus(null);
1144 configServicesRepository.save(service);
1146 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1151 public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusGet(
1152 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1153 GenericResourceApiServicestatusServiceStatus serviceStatus = null;
1155 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1156 if ((services == null) || (services.isEmpty())) {
1157 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1160 serviceStatus = services.get(0).getServiceStatus();
1161 return new ResponseEntity<>(serviceStatus, HttpStatus.OK);
1165 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPost(
1166 String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1167 throws RestProtocolException {
1168 ConfigServices service;
1169 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1170 if ((services == null) || (services.isEmpty())) {
1171 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1174 if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1175 throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1176 HttpStatus.BAD_REQUEST.value());
1179 service = services.get(0);
1181 if (service.getServiceStatus() != null) {
1182 log.error("service-status already exists for svcInstanceId {}", serviceInstanceId);
1183 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1184 HttpStatus.CONFLICT.value());
1187 service.setServiceStatus(serviceStatus);
1188 configServicesRepository.save(service);
1190 return new ResponseEntity<>(HttpStatus.CREATED);
1195 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPut(
1196 String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1197 throws RestProtocolException {
1198 ConfigServices service;
1199 boolean dataExists = false;
1201 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1202 if ((services == null) || (services.isEmpty())) {
1203 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1206 if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1207 throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1208 HttpStatus.BAD_REQUEST.value());
1211 service = services.get(0);
1213 if (service.getServiceStatus() != null) {
1217 service.setServiceStatus(serviceStatus);
1218 configServicesRepository.save(service);
1221 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1223 return new ResponseEntity<>(HttpStatus.CREATED);
1228 * Deletes VNF data from the Config table specified Service Instance.
1231 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1233 * @param serviceInstanceId the Service Instance ID to perform the delete on
1234 * @param vnfId the VNF ID of the VNF to delete
1235 * @return HttpStatus.NO_CONTENT (204) on successful delete
1237 * HttpStatus.BAD_REQUEST (400) if unmarshalling Service Data from the
1238 * database fails, there is no VNF data for {@code vnfId}, or writing
1239 * Service Data back to the database fails.
1241 * HttpStatus.NOT_FOUND (404) if {@code serviceInstanceId} does not
1245 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete(
1246 String serviceInstanceId, String vnfId) throws RestException {
1247 log.info("DELETE | VNF Data for ({})", vnfId);
1249 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1250 ConfigServices data;
1251 if ((services == null) || (services.isEmpty())) {
1252 log.info("Could not find data for ({}).", serviceInstanceId);
1253 // Or throw the data not found error?
1254 throw new RestProtocolException("data-missing", "Service Instance ID not found.",
1255 HttpStatus.NOT_FOUND.value());
1257 data = services.get(0);
1260 if (!serviceDataHelper.hasServiceData(data)) {
1261 log.info("Could not find Service Data for ({}).", serviceInstanceId);
1262 throw new RestProtocolException("data-missing", "Service data not found.", HttpStatus.NOT_FOUND.value());
1265 if (serviceDataHelper.deleteVnf(serviceInstanceId, vnfId) > 0) {
1266 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1268 // Data was not found
1269 log.error("Did not find VNF ({}) in data.", vnfId);
1270 throw new RestProtocolException("data-missing", "VNF ID not found.", HttpStatus.NOT_FOUND.value());
1275 * Extracts VNF data from the Config table specified Service Instance.
1278 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1280 * @param serviceInstanceId the Service Instance ID to lookup data for
1281 * @param vnfId the VNF ID of the VNF to return
1282 * @return HttpStatus.OK (200) if the data is found.
1283 * @throws RestException if the data does not exist.
1286 public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnf> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet(
1287 String serviceInstanceId, String vnfId) throws RestException {
1288 log.info("GET | VNF Data for ({})", vnfId);
1290 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1291 if ((services == null) || (services.isEmpty())) {
1292 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1295 GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1297 vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1298 } catch (JsonProcessingException e) {
1299 log.error("Could not parse service data", e);
1300 throw new RestApplicationException("data-conversion",
1301 "Request could not be completed due to internal error", e,
1302 HttpStatus.INTERNAL_SERVER_ERROR.value());
1306 return new ResponseEntity<>(vnf, HttpStatus.OK);
1308 log.info("No information found for {}", vnfId);
1309 throw new RestApplicationException("data-missing",
1310 "Request could not be completed because the relevant data model content does not exist",
1311 HttpStatus.NOT_FOUND.value());
1316 * Creates or updates VNF data in the Config table for a specified Service
1317 * Instance. If it is a new Service Instance or a new VNF, creates all necessary
1318 * parent data containers, then performs the updates.
1320 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1321 * @param serviceInstanceId the Service Instance ID to perform the delete on
1322 * @param vnfId the VNF ID of the VNF to delete
1323 * @param genericResourceApiServicedataServicedataVnfsVnfBodyParam the playload
1324 * @return HttpStatus.CREATED (201) on successful create
1326 * HttpStatus.NO_CONTENT (204) on successful update
1328 * HttpStatus.BAD_REQUEST (400) if {@code vnfId} does not match what is specified in the
1329 * {@code genericResourceApiServicedataServicedataVnfsVnfBodyParam} , or if updating the database fails.
1330 * @throws RestException
1333 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut(
1334 String serviceInstanceId, String vnfId,
1335 GenericResourceApiServicedataServicedataVnfsVnf vnf)
1336 throws RestException {
1337 log.info("PUT | VNF Data for ({})", vnfId);
1338 if (!vnfId.equals(vnf.getVnfId())) {
1339 throw new RestProtocolException("bad-attribute", "vnf-id mismatch", HttpStatus.BAD_REQUEST.value());
1342 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1343 ConfigServices data;
1344 ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1345 if ((services == null) || (services.isEmpty())) {
1346 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1347 data = new ConfigServices();
1348 data.setSvcInstanceId(serviceInstanceId);
1349 transaction.save(data);
1351 data = services.get(0);
1355 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1356 if (serviceDataHelper.getVnf(serviceInstanceId, vnfId) == null) {
1357 responseStatus = HttpStatus.CREATED;
1359 serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1360 transaction.commit();
1361 return new ResponseEntity<>(responseStatus);
1362 } catch (JsonProcessingException e) {
1363 log.error("Error saving vnf", e);
1364 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1369 * Extracts VNF Topology data from the Config table specified Service Instance
1373 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/
1375 * @param serviceInstanceId the Service Instance ID to lookup data for
1376 * @param vnfId the VNF ID of the VNF to extract topology data from.
1377 * @return HttpStatus.OK (200) if the data is found.
1378 * @throws RestException if the data does not exist.
1381 public ResponseEntity<GenericResourceApiVnftopologyVnfTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet(
1382 String serviceInstanceId, String vnfId) throws RestException {
1383 log.info("GET | VNF Topology for ({})", vnfId);
1385 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1386 if ((services == null) || (services.isEmpty())) {
1387 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1390 GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1393 vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1394 } catch (JsonProcessingException e) {
1395 log.error("Could not parse service data", e);
1396 throw new RestApplicationException("data-conversion",
1397 "Request could not be completed due to internal error", e,
1398 HttpStatus.INTERNAL_SERVER_ERROR.value());
1401 // Drill down to find the data
1402 if (vnf != null && vnf.getVnfData() != null && vnf.getVnfData().getVnfTopology() != null) {
1403 return new ResponseEntity<>(vnf.getVnfData().getVnfTopology(), HttpStatus.OK);
1405 log.info("No information found for {}", vnfId);
1406 throw new RestApplicationException("data-missing",
1407 "Request could not be completed because the relevant data model content does not exist",
1408 HttpStatus.NOT_FOUND.value());
1413 * Creates or updates VNF Level Operation Status data in the Config table for a
1414 * specified Service Instance. If it is a new Service Instance or a new VNF,
1415 * creates all necessary parent data containers, then performs the updates.
1418 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-level-oper-status/
1420 * @param serviceInstanceId the Service Instance ID to
1421 * perform the delete on
1422 * @param vnfId the VNF ID of the VNF to
1424 * @param genericResourceApiOperStatusDataBodyParam the payload
1425 * @return HttpStatus.CREATED (201) on successful create.
1427 * HttpStatus.NO_CONTENT (204) on successful update.
1429 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1430 * @throws RestException
1433 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut(
1434 String serviceInstanceId, String vnfId,
1435 GenericResourceApiOperStatusData genericResourceApiOperStatusDataBodyParam) throws RestException {
1436 log.info("PUT | VNF Level Oper Status ({})", vnfId);
1437 ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1439 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1440 ConfigServices data;
1441 if ((services == null) || (services.isEmpty())) {
1442 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1443 data = new ConfigServices();
1444 data.setSvcInstanceId(serviceInstanceId);
1445 transaction.save(data);
1447 data = services.get(0);
1450 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1453 GenericResourceApiServicedataServicedataVnfsVnf vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1455 responseStatus = HttpStatus.CREATED;
1456 vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1457 vnf.setVnfId(vnfId);
1459 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.getVnfData();
1460 if (vnfData == null) {
1461 vnfData = new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
1463 vnfData.setVnfLevelOperStatus(genericResourceApiOperStatusDataBodyParam);
1464 vnf.setVnfData(vnfData);
1465 serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1466 transaction.commit();
1467 return new ResponseEntity<>(responseStatus);
1468 } catch (JsonProcessingException e) {
1469 log.error("Error saving vnf", e);
1470 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1475 * Creates or updates VNF Onap Model Information data in the Config table for a
1476 * specified Service Instance. If it is a new Service Instance or a new VNF,
1477 * creates all necessary parent data containers, then performs the updates.
1480 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/onap-model-information/
1482 * @param serviceInstanceId the
1499 * @param genericResourceApiOnapmodelinformationOnapModelInformationBodyParam the
1501 * @return HttpStatus.CREATED (201) on successful create.
1503 * HttpStatus.NO_CONTENT (204) on successful update.
1505 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1506 * @throws RestException
1509 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut(
1510 String serviceInstanceId, String vnfId,
1511 GenericResourceApiOnapmodelinformationOnapModelInformation genericResourceApiOnapmodelinformationOnapModelInformationBodyParam)
1512 throws RestException {
1513 log.info("PUT | VNF Topology Onap Model Information ({})", vnfId);
1514 ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1516 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1517 ConfigServices data;
1518 if ((services == null) || (services.isEmpty())) {
1519 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1520 data = new ConfigServices();
1521 data.setSvcInstanceId(serviceInstanceId);
1522 transaction.save(data);
1524 data = services.get(0);
1528 GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1529 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1532 vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1533 } catch(JsonProcessingException e) {
1535 log.error("Could not parse service data", e);
1536 throw new RestApplicationException("data-conversion",
1537 "Request could not be completed due to internal error", e,
1538 HttpStatus.INTERNAL_SERVER_ERROR.value());
1542 responseStatus = HttpStatus.CREATED;
1543 vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1544 vnf.setVnfId(vnfId);
1545 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1546 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1549 vnf.getVnfData().getVnfTopology()
1550 .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam);
1552 // Save the updated VNF (and service, if new)
1554 serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1555 transaction.commit();
1556 return new ResponseEntity<>(responseStatus);
1557 } catch (JsonProcessingException e) {
1558 log.error("Error mapping object to JSON", e);
1559 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1560 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1565 * Creates or updates VNF Network data in the Config table for a specified
1566 * Service Instance. If it is a new Service Instance or a new VNF, creates all
1567 * necessary parent data containers, then performs the updates.
1569 * 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/
1570 * @param serviceInstanceId the Service Instance ID to perform the delete on
1571 * @param vnfId the VNF ID of the VNF to delete
1572 * @param genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam the * payload
1573 * @return HttpStatus.CREATED (201) on successful create.
1575 * HttpStatus.NO_CONTENT (204) on successful update.
1577 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1578 * @throws RestException
1581 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut(
1582 String serviceInstanceId, String vnfId,
1583 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam)
1584 throws RestException {
1585 log.info("PUT | VNF Topology VNF Resource Assignments VNF Networks ({})", vnfId);
1587 ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1588 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1589 ConfigServices data;
1590 if ((services == null) || (services.isEmpty())) {
1591 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1592 data = new ConfigServices();
1593 data.setSvcInstanceId(serviceInstanceId);
1594 transaction.save(data);
1596 data = services.get(0);
1599 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1600 GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1603 vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1604 } catch(JsonProcessingException e) {
1606 log.error("Could not parse service data", e);
1607 throw new RestApplicationException("data-conversion",
1608 "Request could not be completed due to internal error", e,
1609 HttpStatus.INTERNAL_SERVER_ERROR.value());
1613 log.info("Creating VNF data for ({})", vnfId);
1614 vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1615 vnf.setVnfId(vnfId);
1616 responseStatus = HttpStatus.CREATED;
1618 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.getVnfData();
1619 if (vnfData == null) {
1620 vnfData = new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
1623 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfData.getVnfTopology();
1624 if (vnfTopology == null) {
1625 vnfTopology = new GenericResourceApiVnftopologyVnfTopology();
1628 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
1629 if (vnfResourceAssignments == null) {
1630 vnfResourceAssignments = new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments();
1632 vnfResourceAssignments.setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam);
1633 vnfTopology.setVnfResourceAssignments(vnfResourceAssignments);
1634 vnfData.setVnfTopology(vnfTopology);
1635 vnf.setVnfData(vnfData);
1637 // Map and save the new data
1639 serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1640 transaction.commit();
1641 return new ResponseEntity<>(responseStatus);
1642 } catch (JsonProcessingException e) {
1643 log.error("Error mapping object to JSON", e);
1644 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1645 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1650 * Creates or updates VNF Network Role data in the Config table for a specified
1651 * Service Instance. If it is a new Service Instance or a new VNF, creates all
1652 * necessary parent data containers, then performs the updates.
1655 * /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}/
1657 * @param serviceInstanceId the Service Instance ID to
1658 * perform the delete on
1659 * @param vnfId the VNF ID of the VNF to
1661 * @param genericResourceApiVnfNetworkDataBodyParam the payload
1662 * @return HttpStatus.CREATED (201) on successful create.
1664 * HttpStatus.NO_CONTENT (204) on successful update.
1666 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1667 * @throws RestException
1670 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut(
1671 String serviceInstanceId, String vnfId, String networkRole,
1672 GenericResourceApiVnfNetworkData genericResourceApiVnfNetworkDataBodyParam) throws RestException {
1673 log.info("PUT | VNF Network Network Role ({})", vnfId);
1674 if (!networkRole.equals(genericResourceApiVnfNetworkDataBodyParam.getNetworkRole())) {
1675 throw new RestProtocolException("bad-attribute", "network-role mismatch", HttpStatus.BAD_REQUEST.value());
1678 ServiceDataTransaction transaction = serviceDataHelper.createTransaction();
1680 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1681 ConfigServices data;
1682 if ((services == null) || (services.isEmpty())) {
1683 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1684 data = new ConfigServices();
1685 data.setSvcInstanceId(serviceInstanceId);
1686 transaction.save(data);
1688 data = services.get(0);
1691 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1692 GenericResourceApiServicedataServicedataVnfsVnf vnf = null;
1695 vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1696 } catch(JsonProcessingException e) {
1698 log.error("Could not parse service data", e);
1699 throw new RestApplicationException("data-conversion",
1700 "Request could not be completed due to internal error", e,
1701 HttpStatus.INTERNAL_SERVER_ERROR.value());
1705 log.info("Creating VNF data for ({})", vnfId);
1706 vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1707 vnf.setVnfId(vnfId);
1708 responseStatus = HttpStatus.CREATED;
1710 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.getVnfData();
1711 if (vnfData == null) {
1712 vnfData = new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
1715 GenericResourceApiVnftopologyVnfTopology vnfTopology = vnfData.getVnfTopology();
1716 if (vnfTopology == null) {
1717 vnfTopology = new GenericResourceApiVnftopologyVnfTopology();
1720 GenericResourceApiVnfresourceassignmentsVnfResourceAssignments vnfResourceAssignments = vnfTopology.getVnfResourceAssignments();
1721 if (vnfResourceAssignments == null) {
1722 vnfResourceAssignments = new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments();
1725 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworks = vnfResourceAssignments.getVnfNetworks();
1726 if (vnfNetworks == null) {
1727 vnfNetworks = new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks();
1728 vnfNetworks.setVnfNetwork(new ArrayList<>());
1732 if (vnfNetworks.getVnfNetwork().isEmpty()) {
1733 vnfNetworks.addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1735 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks vnfNetworksNew = new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks();
1736 vnfNetworksNew.setVnfNetwork(new ArrayList<>());
1737 vnfNetworks.getVnfNetwork().stream()
1738 .filter(targetNetwork -> !targetNetwork.getNetworkRole().equals(networkRole)).forEach(vnfNetworksNew::addVnfNetworkItem);
1740 vnfNetworksNew.addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1741 vnfNetworks = vnfNetworksNew;
1744 vnfResourceAssignments.setVnfNetworks(vnfNetworks);
1745 vnfTopology.setVnfResourceAssignments(vnfResourceAssignments);
1746 vnfData.setVnfTopology(vnfTopology);
1747 vnf.setVnfData(vnfData);
1749 serviceDataHelper.saveVnf(serviceInstanceId, vnf, transaction);
1750 transaction.commit();
1751 return new ResponseEntity<>(responseStatus);
1752 } catch (JsonProcessingException e) {
1753 log.error("Error mapping object to JSON", e);
1754 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1755 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1761 public ResponseEntity<GenericResourceApiServicetopologyServiceTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet(
1762 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1763 GenericResourceApiServicetopologyServiceTopology serviceTopology = null;
1764 GenericResourceApiServicedataServiceData serviceData = null;
1766 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1767 if ((services == null) || (services.isEmpty())) {
1768 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1771 ConfigServices service = services.get(0);
1774 if ( (service.getSvcData() == null) || service.getSvcData().isEmpty()) {
1775 throw new RestProtocolException("data-missing", "No service-data entry found",
1776 HttpStatus.NOT_FOUND.value());
1778 serviceData = serviceDataHelper.getServiceData(service);
1779 serviceTopology = serviceData.getServiceTopology();
1781 if (serviceTopology == null) {
1782 throw new RestProtocolException("data-missing", "No service-topology entry found",
1783 HttpStatus.NOT_FOUND.value());
1785 return new ResponseEntity<>(serviceTopology, HttpStatus.OK);
1786 } catch (JsonProcessingException e) {
1787 log.error("Could not parse service data", e);
1788 throw new RestApplicationException("data-conversion",
1789 "Request could not be completed due to internal error", e,
1790 HttpStatus.INTERNAL_SERVER_ERROR.value());
1796 * Extracts VF MODULE data from CONFIG_GRA_SERVICES for a given, service-instance-id, vnf-id, and vf-module-id
1798 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/
1799 * @param serviceInstanceId the Service Instance ID to lookup data for
1800 * @param vnfId the VNF ID of the VNF to return
1801 * @param vfModuleId the vf-moudle ID of a specific VNF to return
1802 * @return HttpStatus.OK (200) if the data is found.
1803 * @throws RestException if the data does not exist.
1806 public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule>
1807 configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet(
1808 String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
1810 log.info("GET | Vf Module Data for ({})", vfModuleId);
1813 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1814 if((services == null) || (services.isEmpty())) {
1815 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1818 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vfModule;
1820 vfModule = serviceDataHelper.getVfModule(serviceInstanceId, vnfId, vfModuleId);
1821 } catch (JsonProcessingException e) {
1822 log.error("Could not parse service data", e);
1823 throw new RestApplicationException("data-conversion",
1824 "Request could not be completed due to internal error", e,
1825 HttpStatus.INTERNAL_SERVER_ERROR.value());
1828 if(vfModule != null) {
1829 return new ResponseEntity<>(vfModule, HttpStatus.OK);
1831 log.info("No vf-module found for [{}]", vfModuleId);
1832 throw new RestApplicationException("data-missing",
1833 "Request could not be completed because the relevant data model content does not exist",
1834 HttpStatus.NOT_FOUND.value());
1839 * PUT VF MODULE data into CONFIG_GRA_SERVICES of a given, service-instance-id, vnf-id
1841 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/
1842 * @param serviceInstanceId the Service Instance ID
1843 * @param vnfId the VNF ID as the parent of the specified vf-module-id and child of the specified service-instance
1844 * @param vfModuleId the vf-moudle ID as a child of the specified VNF
1845 * @return HttpStatus.OK (200) if the data is found.
1846 * @throws RestException if the data does not exist.
1849 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut(
1850 String serviceInstanceId, String vnfId, String vfModuleId,
1851 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam)
1852 throws RestException {
1853 log.info("PUT | vf-module Data of ({}) for vnf ({}) in service({})", vfModuleId, vnfId, serviceInstanceId);
1855 if(! vfModuleId.equals(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam.getVfModuleId())) {
1856 throw new RestProtocolException("bad-attribute", "vf-module-id mismatch", HttpStatus.BAD_REQUEST.value());
1860 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1861 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1863 if((services == null) || (services.isEmpty())) {
1864 log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
1865 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1869 GenericResourceApiServicedataServicedataVnfsVnf vnf;
1871 vnf = serviceDataHelper.getVnf(serviceInstanceId, vnfId);
1872 } catch (JsonProcessingException e1) {
1873 log.error("Could not parse service data", e1);
1874 throw new RestApplicationException("data-conversion",
1875 "Request could not be completed due to internal error", e1,
1876 HttpStatus.INTERNAL_SERVER_ERROR.value());
1880 log.error("vnf-id ({}) not found in SDN.", vnfId);
1881 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1884 // See if this is the first vf module being added
1885 List<ConfigVfModules> configVfModules = configVfModulesRepository.findBySvcInstanceIdAndVnfId(serviceInstanceId, vnfId);
1887 if ((configVfModules == null) || configVfModules.isEmpty()) {
1888 responseStatus = HttpStatus.CREATED;
1893 serviceDataHelper.saveVfModule(serviceInstanceId, vnfId, genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam, null);
1894 return new ResponseEntity<>(responseStatus);
1895 } catch(JsonProcessingException e) {
1896 log.error("Error mapping object to JSON", e);
1897 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1898 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1903 * Extracts VF MODULE Topology data from the Config table specified Service
1904 * Instance and VNF ID.
1906 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/vf-module-data/vf-module-topology/
1907 * @param serviceInstanceId the Service Instance ID to lookup data for
1908 * @param vnfId the VNF ID of the VNF to extract topology data from.
1909 * @param vfModuleId the vf-module-idof the vf-module to extract topology data from.
1910 * @return HttpStatus.OK (200) if the data is found.
1911 * @throws RestException if the data does not exist.
1914 public ResponseEntity<GenericResourceApiVfmoduletopologyVfModuleTopology>
1915 configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet(
1916 String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
1917 log.info("GET | vf-module-topology for ({})", vfModuleId);
1919 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1920 if((services == null) || (services.isEmpty())) {
1921 throw new RestApplicationException("data-missing",
1922 "Request could not be completed because the relevant data model content does not exist",
1923 HttpStatus.NOT_FOUND.value());
1926 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vfModule;
1928 vfModule = serviceDataHelper.getVfModule(serviceInstanceId, vnfId, vfModuleId);
1929 } catch (JsonProcessingException e) {
1930 log.error("Could not parse service data", e);
1931 throw new RestApplicationException("data-conversion",
1932 "Request could not be completed due to internal error", e,
1933 HttpStatus.INTERNAL_SERVER_ERROR.value());
1935 if (vfModule != null
1936 && vfModule.getVfModuleData() != null
1937 && vfModule.getVfModuleData().getVfModuleTopology() != null) {
1938 return new ResponseEntity<>(vfModule.getVfModuleData().getVfModuleTopology(), HttpStatus.OK);
1940 log.info("No information found for {}", vfModuleId);
1941 throw new RestApplicationException("data-missing",
1942 "Request could not be completed because the relevant data model content does not exist",
1943 HttpStatus.NOT_FOUND.value());
1948 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete(
1949 String serviceInstanceId, String vnfId, String vfModuleId) throws RestProtocolException {
1951 log.info("DELETE | vf-module Data for ({})", vfModuleId);
1955 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1957 if((services == null) || (services.isEmpty())) {
1958 log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
1959 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1964 serviceDataHelper.deleteVfModule(serviceInstanceId, vnfId, vfModuleId);
1965 return new ResponseEntity<>(HttpStatus.OK);