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 com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.JsonMappingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.onap.ccsdk.apps.services.RestApplicationException;
28 import org.onap.ccsdk.apps.services.RestException;
29 import org.onap.ccsdk.apps.services.RestProtocolError;
30 import org.onap.ccsdk.apps.services.RestProtocolException;
31 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
32 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
33 import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
34 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
35 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurations;
36 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurationsRepository;
37 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResources;
38 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResourcesRepository;
39 import org.onap.sdnc.apps.ms.gra.swagger.ConfigApi;
40 import org.onap.sdnc.apps.ms.gra.swagger.model.*;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.boot.autoconfigure.domain.EntityScan;
45 import org.springframework.context.annotation.ComponentScan;
46 import org.springframework.http.HttpStatus;
47 import org.springframework.http.ResponseEntity;
48 import org.springframework.stereotype.Controller;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.validation.Valid;
52 import java.util.ArrayList;
53 import java.util.Iterator;
54 import java.util.LinkedList;
55 import java.util.List;
56 import java.util.Optional;
57 import java.util.concurrent.atomic.AtomicBoolean;
58 import java.util.stream.Collectors;
59 import java.util.stream.Stream;
62 @ComponentScan(basePackages = { "org.onap.sdnc.apps.ms.gra.*" })
63 @EntityScan("org.onap.sdnc.apps.ms.gra.springboot.*")
64 public class ConfigApiController implements ConfigApi {
65 private static final Logger log = LoggerFactory.getLogger(ConfigApiController.class);
67 private final ObjectMapper objectMapper;
69 private final HttpServletRequest request;
72 private ConfigPreloadDataRepository configPreloadDataRepository;
75 private ConfigServicesRepository configServicesRepository;
78 private ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
81 private ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
85 public ConfigApiController(ObjectMapper objectMapper, HttpServletRequest request) {
86 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
87 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
88 this.objectMapper = objectMapper;
89 this.request = request;
93 public Optional<ObjectMapper> getObjectMapper() {
94 return Optional.ofNullable(objectMapper);
98 public Optional<HttpServletRequest> getRequest() {
99 return Optional.ofNullable(request);
103 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationDelete() {
104 configPreloadDataRepository.deleteAll();
105 return (new ResponseEntity<>(HttpStatus.NO_CONTENT));
109 * Extracts port-mirror configuration data from CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS for a given, configuration-id
111 * Maps to /config/GENERIC-RESOURCE-API:port-mirror-configurations/port-mirror-configuration/{configuration-id}/
112 * @param configurationId the configuration ID for a port-mirror
113 * @return HttpStatus.OK (200) if the data is found.
114 * @throws RestException if the data does not exist.
116 public ResponseEntity<GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration>
117 configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet(
118 String configurationId) throws RestApplicationException {
119 GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration retval = null;
121 List<ConfigPortMirrorConfigurations> pmConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
123 if (pmConfigurations.isEmpty()) {
124 log.info("No configuration data found with id [{}]",configurationId);
125 throw new RestApplicationException("data-missing",
126 "Request could not be completed because the relevant data model content does not exist",
127 HttpStatus.NOT_FOUND.value());
129 ConfigPortMirrorConfigurations pmConfiguration = pmConfigurations.get(0);
130 retval = new GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration();
131 retval.setConfigurationId(configurationId);
132 retval.setConfigurationStatus(pmConfiguration.getPortMirrorConfigurationStatus());
134 retval.setConfigurationData(objectMapper.readValue(pmConfiguration.getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class));
135 } catch (JsonProcessingException e) {
136 log.error("Could not deserialize service data for service instance id {}", configurationId, e);
137 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
140 return new ResponseEntity<>(retval, HttpStatus.OK);
144 public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut(
145 String configurationId, @Valid GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration newConfiguration)
146 throws RestApplicationException {
148 boolean dataExists = false;
150 String newConfigurationId = newConfiguration.getConfigurationId();
152 ConfigPortMirrorConfigurations portMirrorConfiguration = null;
153 List<ConfigPortMirrorConfigurations> existingConfiguration = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
154 if ((existingConfiguration != null) && !existingConfiguration.isEmpty()) {
156 portMirrorConfiguration = existingConfiguration.get(0);
158 portMirrorConfiguration = new ConfigPortMirrorConfigurations();
159 portMirrorConfiguration.setConfigureationId(configurationId);
163 portMirrorConfiguration.setPmcData(objectMapper.writeValueAsString(newConfiguration.getConfigurationData()));
164 } catch (JsonProcessingException e) {
165 log.error("Could not serialize porr-mirror configuration data for {}", portMirrorConfiguration.getConfigureationId(), e);
166 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
169 portMirrorConfiguration.setPortMirrorConfigurationStatus(newConfiguration.getConfigurationStatus());
170 configPortMirrorConfigurationsRepository.save(portMirrorConfiguration);
173 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
175 return new ResponseEntity<>(HttpStatus.CREATED);
180 public ResponseEntity<GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology>
181 configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet(
182 String configurationId) throws RestApplicationException, RestProtocolException {
183 @Valid GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology portMirrorConfigurationTopology = null;
184 GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData portMirrorConfigurationData = null;
186 List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
187 if ((configPortMirrorConfigurations == null) || (configPortMirrorConfigurations.isEmpty())) {
188 log.info("No configuration data found with id [{}]", configurationId);
189 throw new RestApplicationException("data-missing",
190 "Request could not be completed because the relevant data model content does not exist",
191 HttpStatus.NOT_FOUND.value());
195 if ( configPortMirrorConfigurations.get(0).getPmcData().isEmpty()) {
196 throw new RestProtocolException("data-missing", "No configuration-data entry found", HttpStatus.NOT_FOUND.value());
198 portMirrorConfigurationData = objectMapper.readValue(configPortMirrorConfigurations.get(0).getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class);
199 portMirrorConfigurationTopology = portMirrorConfigurationData.getPortMirrorConfigurationTopology();
201 if (portMirrorConfigurationTopology == null) {
202 throw new RestProtocolException("data-missing", "No service-topology entry found", HttpStatus.NOT_FOUND.value());
204 return new ResponseEntity<>(portMirrorConfigurationTopology, HttpStatus.OK);
205 } catch (JsonProcessingException e) {
206 log.error("Could not parse service data", e);
207 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
213 public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete(String configurationId) {
214 configPortMirrorConfigurationsRepository.deleteByConfigurationId(configurationId);
215 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
219 * Extracts contrail-route-allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
221 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
222 * @param allottedResourceId the allotted-resource-id for a contrail-route
223 * @return HttpStatus.OK (200) if the data is found.
224 * @throws RestException if the data does not exist.
226 public ResponseEntity<GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource>
227 configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet(
228 String allottedResourceId) throws RestApplicationException {
229 GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource retval = null;
231 List<ConfigContrailRouteAllottedResources> allottedResources = configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
233 if (allottedResources.isEmpty()) {
234 log.info("No contrail-route-allotted-resource found with id [{}]", allottedResourceId);
235 throw new RestApplicationException("data-missing",
236 "Request could not be completed because the relevant data model content does not exist",
237 HttpStatus.NOT_FOUND.value());
240 ConfigContrailRouteAllottedResources allottedResource = allottedResources.get(0);
241 retval = new GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource();
242 retval.setAllottedResourceId(allottedResourceId);
243 retval.setAllottedResourceStatus(allottedResource.getAllottedResourceStatus());
245 retval.setAllottedResourceData(objectMapper.readValue(allottedResource.getArData(),
246 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class));
247 } catch (JsonProcessingException e) {
248 log.error("Could not deserialize service data for service instance id {}", allottedResourceId, e);
249 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
252 return new ResponseEntity<>(retval, HttpStatus.OK);
256 * PUT 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.
264 public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut(
265 String allottedResourceId, @Valid GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource newAllottedResource)
266 throws RestApplicationException {
268 boolean dataExists = false;
270 String newAllottedResourceId = newAllottedResource.getAllottedResourceId();
272 ConfigContrailRouteAllottedResources allottedResource = null;
273 List<ConfigContrailRouteAllottedResources> existingAllottedResource =
274 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
276 if ((existingAllottedResource != null) && !existingAllottedResource.isEmpty()) {
278 allottedResource = existingAllottedResource.get(0);
280 allottedResource = new ConfigContrailRouteAllottedResources();
281 allottedResource.setAllottedResourceId(allottedResourceId);
285 allottedResource.setArData(objectMapper.writeValueAsString(newAllottedResource.getAllottedResourceData()));
286 } catch (JsonProcessingException e) {
287 log.error("Could not serialize porr-mirror configuration data for {}", allottedResource.getAllottedResourceId(), e);
288 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
291 allottedResource.setAllottedResourceStatus(newAllottedResource.getAllottedResourceStatus());
292 configContrailRouteAllottedResourcesRepository.save(allottedResource);
295 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
297 return new ResponseEntity<>(HttpStatus.CREATED);
302 * Extracts contrail-route-topology data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
304 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}/allotted-resource-data/contrail-route-topology/
305 * @param allottedResourceId the allotted-resource-id for a contrail-route
306 * @return HttpStatus.OK (200) if the data is found.
307 * @throws RestException if the data does not exist.
310 public ResponseEntity<GenericResourceApiContrailroutetopologyContrailRouteTopology>
311 configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet(
312 String allottedResourceId) throws RestApplicationException, RestProtocolException {
313 @Valid GenericResourceApiContrailroutetopologyContrailRouteTopology contrailRouteTopology = null;
314 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData allottedResourceData = null;
316 List<ConfigContrailRouteAllottedResources> configContrailRouteAllottedResources =
317 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
319 if ((configContrailRouteAllottedResources == null) || (configContrailRouteAllottedResources.isEmpty())) {
320 log.info("No contrail-route-allotted-resoure data found with id [{}]", allottedResourceId);
321 throw new RestApplicationException("data-missing",
322 "Request could not be completed because the relevant data model content does not exist",
323 HttpStatus.NOT_FOUND.value());
327 if ( configContrailRouteAllottedResources.get(0).getArData().isEmpty()) {
328 throw new RestProtocolException("data-missing", "No allotted-resource-data entry found", HttpStatus.NOT_FOUND.value());
330 allottedResourceData = objectMapper.readValue(configContrailRouteAllottedResources.get(0).getArData(),
331 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class);
333 contrailRouteTopology = allottedResourceData.getContrailRouteTopology();
335 if (contrailRouteTopology == null) {
336 throw new RestProtocolException("data-missing", "No contrail-route-topology entry found", HttpStatus.NOT_FOUND.value());
338 return new ResponseEntity<>(contrailRouteTopology, HttpStatus.OK);
339 } catch (JsonProcessingException e) {
340 log.error("Could not parse port-mirror-configuration data", e);
341 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
347 * DELETE allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
349 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
350 * @param allottedResourceId the allotted-resource-id for a contrail-route
351 * @return HttpStatus.NO_CONTENT (204) if the data is found.
354 public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete(
355 String allottedResourceId) {
356 configContrailRouteAllottedResourcesRepository.deleteByAllottedResourceId(allottedResourceId);
357 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
362 public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet()
363 throws RestApplicationException {
364 GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation();
366 if (configPreloadDataRepository.count() == 0) {
367 throw new RestApplicationException("data-missing",
368 "Request could not be completed because the relevant data model content does not exist",
369 HttpStatus.NOT_FOUND.value());
372 for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
373 GenericResourceApiPreloadmodelinformationPreloadList preloadListItem = new GenericResourceApiPreloadmodelinformationPreloadList();
375 preloadListItem.setPreloadId(configPreloadData.getPreloadId());
376 preloadListItem.setPreloadType(configPreloadData.getPreloadType());
378 preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(),
379 GenericResourceApiPreloaddataPreloadData.class));
380 } catch (JsonProcessingException e) {
381 log.error("Could not convert preload data", e);
382 throw new RestApplicationException("data-conversion",
383 "Request could not be completed due to internal error", e,
384 HttpStatus.INTERNAL_SERVER_ERROR.value());
386 genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem);
389 return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK);
393 public ResponseEntity<GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPreloadNetworkTopologyInformationGet(
394 String preloadId, String preloadType) throws RestException {
395 GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation netTopoInfo = null;
397 if (configPreloadDataRepository.count() == 0) {
398 throw new RestApplicationException("data-missing",
399 "Request could not be completed because the relevant data model content does not exist",
400 HttpStatus.NOT_FOUND.value());
403 for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
406 GenericResourceApiPreloaddataPreloadData preloadDataItem = objectMapper
407 .readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class);
408 netTopoInfo = preloadDataItem.getPreloadNetworkTopologyInformation();
409 } catch (JsonProcessingException e) {
410 log.error("Could not convert preload data", e);
411 throw new RestApplicationException("data-conversion",
412 "Request could not be completed due to internal error", e,
413 HttpStatus.INTERNAL_SERVER_ERROR.value());
417 return new ResponseEntity<>(netTopoInfo, HttpStatus.OK);
422 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(
423 @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo)
424 throws RestApplicationException, RestProtocolException {
426 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
427 List<ConfigPreloadData> newPreloadData = new LinkedList<>();
429 if (preloadList != null) {
430 // Verification pass - if any items already exist, return an error
431 for (GenericResourceApiPreloadmodelinformationPreloadList curItem : preloadList) {
433 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
434 .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
435 if ((curPreloadData != null) && (!curPreloadData.isEmpty())) {
436 log.error("Preload data already exists for {}:{}", curItem.getPreloadId(),
437 curItem.getPreloadType());
438 throw new RestProtocolException("data-exists",
439 "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(),
440 HttpStatus.CONFLICT.value());
443 newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(),
444 objectMapper.writeValueAsString(curItem.getPreloadData())));
445 } catch (JsonProcessingException e) {
446 log.error("Cannot convert preload data");
447 throw new RestApplicationException("data-conversion",
448 "Request could not be completed due to internal error", e,
449 HttpStatus.INTERNAL_SERVER_ERROR.value());
456 for (ConfigPreloadData newDataItem : newPreloadData) {
457 log.info("Adding preload data for {}:{}", newDataItem.getPreloadId(), newDataItem.getPreloadType());
458 configPreloadDataRepository.save(newDataItem);
461 throw new RestProtocolException("data-missing", "No preload-list entries found to add",
462 HttpStatus.CONFLICT.value());
465 return new ResponseEntity<>(HttpStatus.CREATED);
469 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(
470 @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException {
472 boolean addedNew = false;
473 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
475 if (preloadList != null) {
476 Iterator<GenericResourceApiPreloadmodelinformationPreloadList> iter = preloadList.iterator();
477 while (iter.hasNext()) {
478 GenericResourceApiPreloadmodelinformationPreloadList curItem = iter.next();
479 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
480 .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
481 if ((curPreloadData == null) || curPreloadData.isEmpty()) {
486 configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(),
487 curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
488 } catch (JsonProcessingException e) {
489 log.error("Cannot convert preload data", e);
490 throw new RestApplicationException("data-conversion",
491 "Request could not be completed due to internal error", e,
492 HttpStatus.INTERNAL_SERVER_ERROR.value());
499 return new ResponseEntity<>(HttpStatus.CREATED);
501 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
507 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPost(
508 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException {
510 throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"",
511 HttpStatus.NOT_FOUND.value());
515 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeDelete(
516 String preloadId, String preloadType) {
517 configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
518 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
522 public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeGet(
523 String preloadId, String preloadType) throws RestApplicationException {
524 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
526 if (preloadData != null) {
527 if (!preloadData.isEmpty()) {
528 ConfigPreloadData preloadDataItem = preloadData.get(0);
529 GenericResourceApiPreloadmodelinformationPreloadList preloadDataList = new GenericResourceApiPreloadmodelinformationPreloadList();
530 preloadDataList.setPreloadId(preloadDataItem.getPreloadId());
531 preloadDataList.setPreloadType(preloadDataItem.getPreloadType());
533 preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(),
534 GenericResourceApiPreloaddataPreloadData.class));
535 } catch (JsonProcessingException e) {
536 log.error("Cannot convert preload data", e);
537 throw new RestApplicationException("data-conversion",
538 "Request could not be completed due to internal error", e,
539 HttpStatus.INTERNAL_SERVER_ERROR.value());
541 return new ResponseEntity<>(preloadDataList, HttpStatus.OK);
544 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
548 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePost(
549 String preloadId, String preloadType,
550 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
551 throws RestApplicationException, RestProtocolException {
552 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
555 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
556 log.error("Preload data already exists for {}:{}", preloadId, preloadType);
557 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
558 HttpStatus.CONFLICT.value());
562 log.info("Adding preload data for {}:{}", preloadId, preloadType);
563 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
564 objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
565 } catch (JsonProcessingException e) {
566 log.error("Cannot convert preload data", e);
567 throw new RestApplicationException("data-conversion",
568 "Request could not be completed due to internal error", e,
569 HttpStatus.INTERNAL_SERVER_ERROR.value());
572 return new ResponseEntity<>(HttpStatus.CREATED);
576 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePut(
577 String preloadId, String preloadType,
578 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
579 throws RestApplicationException, RestProtocolException {
580 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
582 boolean dataExists = false;
583 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
587 if ((preloadListItem.getPreloadId() == null) || (preloadListItem.getPreloadType() == null)
588 || (preloadListItem.getPreloadData() == null)) {
589 log.error("Invalid list item received: {}", preloadListItem);
590 throw new RestProtocolException("bad-attribute", "Invalid data received", HttpStatus.BAD_REQUEST.value());
595 log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType,
596 objectMapper.writeValueAsString(preloadListItem));
599 log.info("Adding preload data for {}:{}", preloadId, preloadType);
602 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
603 objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
604 } catch (JsonProcessingException e) {
605 log.error("Cannot convert preload data", e);
606 throw new RestApplicationException("data-conversion",
607 "Request could not be completed due to internal error", e,
608 HttpStatus.INTERNAL_SERVER_ERROR.value());
613 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
615 return new ResponseEntity<>(HttpStatus.CREATED);
620 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataDelete(
621 String preloadId, String preloadType) throws RestProtocolException {
622 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
625 if ((preloadData == null) || preloadData.isEmpty()) {
626 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
629 ConfigPreloadData preloadDataItem = preloadData.get(0);
631 if (preloadDataItem.getPreloadData() == null) {
632 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
634 preloadDataItem.setPreloadData(null);
635 configPreloadDataRepository.save(preloadDataItem);
637 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
641 public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataGet(
642 String preloadId, String preloadType) throws RestApplicationException, RestProtocolException {
643 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
646 if ((preloadData == null) || preloadData.isEmpty()) {
647 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
650 ConfigPreloadData preloadDataItem = preloadData.get(0);
652 if (preloadDataItem.getPreloadData() == null) {
653 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
656 return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(),
657 GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
658 } catch (JsonProcessingException e) {
659 log.error("Cannot convert preload data", e);
660 throw new RestApplicationException("data-conversion",
661 "Request could not be completed due to internal error", e,
662 HttpStatus.INTERNAL_SERVER_ERROR.value());
667 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPost(
668 String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
669 throws RestApplicationException, RestProtocolException {
670 List<ConfigPreloadData> preloadDataEntries = configPreloadDataRepository
671 .findByPreloadIdAndPreloadType(preloadId, preloadType);
673 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
675 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
676 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
679 if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
680 throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
681 HttpStatus.BAD_REQUEST.value());
684 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
686 if (preloadDataItem.getPreloadData() != null) {
687 log.error("Preload data already exists for {}:{} ", preloadId, preloadType);
688 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
689 HttpStatus.CONFLICT.value());
693 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
694 configPreloadDataRepository.save(preloadDataItem);
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());
702 return new ResponseEntity<>(HttpStatus.CREATED);
706 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPut(
707 String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
708 throws RestApplicationException, RestProtocolException {
709 boolean dataExists = false;
710 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
712 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
713 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
716 if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
717 throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
718 HttpStatus.BAD_REQUEST.value());
721 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
723 if (preloadDataItem.getPreloadData() != null) {
728 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
729 configPreloadDataRepository.save(preloadDataItem);
730 } catch (JsonProcessingException e) {
731 log.error("Cannot convert preload data", e);
732 throw new RestApplicationException("data-conversion",
733 "Request could not be completed due to internal error", e,
734 HttpStatus.INTERNAL_SERVER_ERROR.value());
738 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
740 return new ResponseEntity<>(HttpStatus.CREATED);
745 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesDelete() {
746 configServicesRepository.deleteAll();
747 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
751 public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet()
752 throws RestApplicationException {
753 GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure();
755 if (configServicesRepository.count() == 0) {
756 throw new RestApplicationException("data-missing",
757 "Request could not be completed because the relevant data model content does not exist",
758 HttpStatus.NOT_FOUND.value());
761 for (ConfigServices service : configServicesRepository.findAll()) {
762 GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService();
763 serviceItem.setServiceInstanceId(service.getSvcInstanceId());
764 if (service.getSvcData() != null) {
766 serviceItem.setServiceData(objectMapper.readValue(service.getSvcData(),
767 GenericResourceApiServicedataServiceData.class));
768 } catch (JsonProcessingException e) {
769 log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e);
770 throw new RestApplicationException("data-conversion",
771 "Request could not be completed due to internal error", e,
772 HttpStatus.INTERNAL_SERVER_ERROR.value());
776 serviceItem.setServiceStatus(service.getServiceStatus());
777 modelInfrastructure.addServiceItem(serviceItem);
780 return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK);
785 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(
786 @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure)
787 throws RestApplicationException, RestProtocolException {
788 List<ConfigServices> newServices = new LinkedList<>();
790 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
791 String svcInstanceId = serviceItem.getServiceInstanceId();
792 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
793 if ((existingService != null) && !existingService.isEmpty()) {
794 log.error("Service data already exists for {}", svcInstanceId);
795 throw new RestProtocolException("data-exists",
796 "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
798 ConfigServices service = new ConfigServices();
799 service.setSvcInstanceId(svcInstanceId);
801 service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
802 } catch (JsonProcessingException e) {
803 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
804 throw new RestApplicationException("data-conversion",
805 "Request could not be completed due to internal error", e,
806 HttpStatus.INTERNAL_SERVER_ERROR.value());
809 service.setServiceStatus(serviceItem.getServiceStatus());
810 newServices.add(service);
813 for (ConfigServices service : newServices) {
814 configServicesRepository.save(service);
817 return new ResponseEntity<>(HttpStatus.CREATED);
822 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(
823 @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException {
825 List<ConfigServices> newServices = new LinkedList<>();
826 boolean dataExists = false;
828 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
829 String svcInstanceId = serviceItem.getServiceInstanceId();
830 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
831 if ((existingService != null) && !existingService.isEmpty()) {
834 ConfigServices service = new ConfigServices();
835 service.setSvcInstanceId(svcInstanceId);
837 service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
838 } catch (JsonProcessingException e) {
839 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
840 throw new RestApplicationException("data-conversion",
841 "Request could not be completed due to internal error", e,
842 HttpStatus.INTERNAL_SERVER_ERROR.value());
845 service.setServiceStatus(serviceItem.getServiceStatus());
846 newServices.add(service);
849 for (ConfigServices service : newServices) {
850 configServicesRepository.save(service);
854 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
856 return new ResponseEntity<>(HttpStatus.CREATED);
862 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServicePost(
863 @Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException {
864 String svcInstanceId = servicesData.getServiceInstanceId();
866 String svcData = objectMapper.writeValueAsString(servicesData.getServiceData());
867 ConfigServices configService = new ConfigServices(svcInstanceId, svcData, servicesData.getServiceStatus());
868 configServicesRepository.deleteBySvcInstanceId(svcInstanceId);
869 configServicesRepository.save(configService);
870 } catch (JsonProcessingException e) {
871 log.error("Cannot convert service data", e);
872 throw new RestApplicationException("data-conversion",
873 "Request could not be completed due to internal error", e,
874 HttpStatus.INTERNAL_SERVER_ERROR.value());
877 return new ResponseEntity<>(HttpStatus.OK);
881 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdDelete(
882 String serviceInstanceId) {
883 configServicesRepository.deleteBySvcInstanceId(serviceInstanceId);
884 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
888 public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdGet(
889 String serviceInstanceId) throws RestApplicationException {
890 GenericResourceApiServicemodelinfrastructureService retval = null;
892 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
894 if (services.isEmpty()) {
895 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
897 ConfigServices service = services.get(0);
898 retval = new GenericResourceApiServicemodelinfrastructureService();
899 retval.setServiceInstanceId(serviceInstanceId);
900 retval.setServiceStatus(service.getServiceStatus());
902 retval.setServiceData(
903 objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
904 } catch (JsonProcessingException e) {
905 log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e);
906 throw new RestApplicationException("data-conversion",
907 "Request could not be completed due to internal error", e,
908 HttpStatus.INTERNAL_SERVER_ERROR.value());
913 return new ResponseEntity<>(retval, HttpStatus.OK);
918 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPost(String svcInstanceId,
919 @Valid GenericResourceApiServicemodelinfrastructureService newService)
920 throws RestApplicationException, RestProtocolException {
922 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
923 if ((existingService != null) && !existingService.isEmpty()) {
924 log.error("Service data already exists for {}", svcInstanceId);
925 throw new RestProtocolException("data-exists",
926 "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
928 ConfigServices service = new ConfigServices();
929 service.setSvcInstanceId(svcInstanceId);
931 service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
932 } catch (JsonProcessingException e) {
933 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
934 throw new RestApplicationException("data-conversion",
935 "Request could not be completed due to internal error", e,
936 HttpStatus.INTERNAL_SERVER_ERROR.value());
939 service.setServiceStatus(newService.getServiceStatus());
940 configServicesRepository.save(service);
942 return new ResponseEntity<>(HttpStatus.CREATED);
946 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPut(String serviceInstanceId,
947 @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException {
949 boolean dataExists = false;
951 String svcInstanceId = newService.getServiceInstanceId();
953 ConfigServices service = null;
954 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
955 if ((existingService != null) && !existingService.isEmpty()) {
957 service = existingService.get(0);
959 service = new ConfigServices();
960 service.setSvcInstanceId(svcInstanceId);
964 service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
965 } catch (JsonProcessingException e) {
966 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
967 throw new RestApplicationException("data-conversion",
968 "Request could not be completed due to internal error", e,
969 HttpStatus.INTERNAL_SERVER_ERROR.value());
972 service.setServiceStatus(newService.getServiceStatus());
973 configServicesRepository.save(service);
976 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
978 return new ResponseEntity<>(HttpStatus.CREATED);
983 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataDelete(
984 String serviceInstanceId) throws RestProtocolException {
985 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
987 if ((services == null) || (services.isEmpty())) {
988 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
991 ConfigServices service = services.get(0);
992 if (service.getSvcData() == null) {
993 throw new RestProtocolException("data-missing", "No service-data found", HttpStatus.NOT_FOUND.value());
995 service.setSvcData(null);
996 configServicesRepository.save(service);
998 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1002 public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataGet(
1003 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1004 GenericResourceApiServicedataServiceData serviceData = null;
1006 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1007 if ((services == null) || (services.isEmpty())) {
1008 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1012 serviceData = objectMapper.readValue(services.get(0).getSvcData(),
1013 GenericResourceApiServicedataServiceData.class);
1014 return new ResponseEntity<>(serviceData, HttpStatus.OK);
1015 } catch (JsonProcessingException e) {
1016 log.error("Could not parse service data", e);
1017 throw new RestApplicationException("data-conversion",
1018 "Request could not be completed due to internal error", e,
1019 HttpStatus.INTERNAL_SERVER_ERROR.value());
1025 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPost(
1026 String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1027 throws RestApplicationException, RestProtocolException {
1028 ConfigServices service;
1029 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1030 if ((services == null) || (services.isEmpty())) {
1031 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1034 if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1035 throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1036 HttpStatus.BAD_REQUEST.value());
1039 service = services.get(0);
1041 if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)) {
1042 log.error("service-data already exists for svcInstanceId {}", serviceInstanceId);
1043 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1044 HttpStatus.CONFLICT.value());
1048 service.setSvcData(objectMapper.writeValueAsString(serviceData));
1049 configServicesRepository.save(service);
1050 } catch (JsonProcessingException e) {
1051 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1052 throw new RestApplicationException("data-conversion",
1053 "Request could not be completed due to internal error", e,
1054 HttpStatus.INTERNAL_SERVER_ERROR.value());
1057 return new ResponseEntity<>(HttpStatus.CREATED);
1062 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPut(
1063 String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1064 throws RestApplicationException, RestProtocolException {
1065 ConfigServices service;
1066 boolean dataExists = false;
1068 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1069 if ((services == null) || (services.isEmpty())) {
1070 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1073 if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1074 throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1075 HttpStatus.BAD_REQUEST.value());
1078 service = services.get(0);
1080 if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)) {
1085 service.setSvcData(objectMapper.writeValueAsString(serviceData));
1086 configServicesRepository.save(service);
1087 } catch (JsonProcessingException e) {
1088 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1089 throw new RestApplicationException("data-conversion",
1090 "Request could not be completed due to internal error", e,
1091 HttpStatus.INTERNAL_SERVER_ERROR.value());
1095 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1097 return new ResponseEntity<>(HttpStatus.CREATED);
1102 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusDelete(
1103 String serviceInstanceId) throws RestProtocolException {
1104 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1106 if ((services == null) || (services.isEmpty())) {
1107 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1110 ConfigServices service = services.get(0);
1111 if (service.getServiceStatus() == null) {
1112 throw new RestProtocolException("data-missing", "No service-status found", HttpStatus.NOT_FOUND.value());
1114 service.setServiceStatus(null);
1115 configServicesRepository.save(service);
1117 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1122 public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusGet(
1123 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1124 GenericResourceApiServicestatusServiceStatus serviceStatus = null;
1126 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1127 if ((services == null) || (services.isEmpty())) {
1128 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1131 serviceStatus = services.get(0).getServiceStatus();
1132 return new ResponseEntity<>(serviceStatus, HttpStatus.OK);
1136 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPost(
1137 String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1138 throws RestProtocolException {
1139 ConfigServices service;
1140 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1141 if ((services == null) || (services.isEmpty())) {
1142 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1145 if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1146 throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1147 HttpStatus.BAD_REQUEST.value());
1150 service = services.get(0);
1152 if (service.getServiceStatus() != null) {
1153 log.error("service-status already exists for svcInstanceId {}", serviceInstanceId);
1154 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1155 HttpStatus.CONFLICT.value());
1158 service.setServiceStatus(serviceStatus);
1159 configServicesRepository.save(service);
1161 return new ResponseEntity<>(HttpStatus.CREATED);
1166 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPut(
1167 String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1168 throws RestProtocolException {
1169 ConfigServices service;
1170 boolean dataExists = false;
1172 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1173 if ((services == null) || (services.isEmpty())) {
1174 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1177 if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1178 throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1179 HttpStatus.BAD_REQUEST.value());
1182 service = services.get(0);
1184 if (service.getServiceStatus() != null) {
1188 service.setServiceStatus(serviceStatus);
1189 configServicesRepository.save(service);
1192 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1194 return new ResponseEntity<>(HttpStatus.CREATED);
1199 * Deletes VNF data from the Config table specified Service Instance.
1202 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1204 * @param serviceInstanceId the Service Instance ID to perform the delete on
1205 * @param vnfId the VNF ID of the VNF to delete
1206 * @return HttpStatus.NO_CONTENT (204) on successful delete
1208 * HttpStatus.BAD_REQUEST (400) if unmarshalling Service Data from the
1209 * database fails, there is no VNF data for {@code vnfId}, or writing
1210 * Service Data back to the database fails.
1212 * HttpStatus.NOT_FOUND (404) if {@code serviceInstanceId} does not
1216 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete(
1217 String serviceInstanceId, String vnfId) throws RestException {
1218 log.info("DELETE | VNF Data for ({})", vnfId);
1221 * The logic may need to be moved inside of this check or this check may need to
1224 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1225 log.info("Something with header.");
1228 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1231 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1232 ConfigServices data;
1233 if ((services == null) || (services.isEmpty())) {
1234 log.info("Could not find data for ({}).", serviceInstanceId);
1235 // Or throw the data not found error?
1236 throw new RestProtocolException("data-missing", "Service Instance ID not found.",
1237 HttpStatus.NOT_FOUND.value());
1239 data = services.get(0);
1242 GenericResourceApiServicedataServiceData svcData;
1244 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1245 } catch (JsonProcessingException e) {
1246 // Or throw the data not found error?
1247 log.error("Could not map service data for ({})", serviceInstanceId);
1248 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1250 if (svcData == null) {
1251 // Or throw the data not found error?
1252 log.info("Could not find Service Data for ({}).", serviceInstanceId);
1253 throw new RestProtocolException("data-missing", "Service data not found.", HttpStatus.NOT_FOUND.value());
1256 GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs();
1258 // Or throw the data not found error?
1259 log.info("VNF List not found for ({}).", serviceInstanceId);
1260 throw new RestProtocolException("data-missing", "VNFs not found.", HttpStatus.NOT_FOUND.value());
1263 Stream<GenericResourceApiServicedataServicedataVnfsVnf> vnfStream = svcData.getVnfs().getVnf().stream();
1264 if (vnfStream.noneMatch(targetVnf -> targetVnf.getVnfId().equals(vnfId))) {
1265 // Data was not found
1266 log.error("Did not find VNF ({}) in data.", vnfId);
1267 throw new RestProtocolException("data-missing", "VNF ID not found.", HttpStatus.NOT_FOUND.value());
1269 // Recreate the stream per Sonar?
1270 vnfStream = svcData.getVnfs().getVnf().stream();
1271 svcData.getVnfs().setVnf(
1272 vnfStream.filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)).collect(Collectors.toList()));
1274 // Map and save the new data
1276 data.setSvcData(objectMapper.writeValueAsString(svcData));
1277 configServicesRepository.save(data);
1278 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1279 } catch (JsonProcessingException e) {
1280 log.error("Error mapping object to JSON", e);
1281 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1282 throw new RestProtocolException("internal-service-error", "Failed to save data.",
1283 HttpStatus.BAD_REQUEST.value());
1288 * Extracts VNF data from the Config table specified Service Instance.
1291 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1293 * @param serviceInstanceId the Service Instance ID to lookup data for
1294 * @param vnfId the VNF ID of the VNF to return
1295 * @return HttpStatus.OK (200) if the data is found.
1296 * @throws RestException if the data does not exist.
1299 public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnf> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet(
1300 String serviceInstanceId, String vnfId) throws RestException {
1301 log.info("GET | VNF Data for ({})", vnfId);
1302 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1303 if (getAcceptHeader().get().contains("application/json")) {
1307 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1309 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1310 if ((services == null) || (services.isEmpty())) {
1311 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1314 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(services.get(0), vnfId);
1315 if (vnf.isPresent()) {
1316 return new ResponseEntity<>(vnf.get(), HttpStatus.OK);
1318 log.info("No information found for {}", vnfId);
1319 throw new RestApplicationException("data-missing",
1320 "Request could not be completed because the relevant data model content does not exist",
1321 HttpStatus.NOT_FOUND.value());
1326 * Extracts a vf-module object from the database,
1327 * @param configServices A Config Services option created from a Service
1329 * @param vnfId the target VNF ID
1330 * @param vfModuleId the target vf-module ID
1331 * @return An empty Optional if the Service Data does not exist, an empty
1332 * Optional if the VNF is not found, or an optional containing the
1335 private Optional<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule> getVfModuleObject (
1336 ConfigServices configServices, String vnfId, String vfModuleId) {
1337 // Map the Marshall the JSON String into a Java Object
1338 log.info("Getting vf-module Data for ({})", vfModuleId);
1340 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(configServices, vnfId);
1341 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.get().getVnfData();
1343 return vnfData.getVfModules().getVfModule()
1345 .filter(vf -> vf.getVfModuleId().equals(vfModuleId))
1350 * Creates or updates VNF data in the Config table for a specified Service
1351 * Instance. If it is a new Service Instance or a new VNF, creates all necessary
1352 * parent data containers, then performs the updates.
1354 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1355 * @param serviceInstanceId the Service Instance ID to perform the delete on
1356 * @param vnfId the VNF ID of the VNF to delete
1357 * @param genericResourceApiServicedataServicedataVnfsVnfBodyParam the playload
1358 * @return HttpStatus.CREATED (201) on successful create
1360 * HttpStatus.NO_CONTENT (204) on successful update
1362 * HttpStatus.BAD_REQUEST (400) if {@code vnfId} does not match what is specified in the
1363 * {@code genericResourceApiServicedataServicedataVnfsVnfBodyParam} , or if updating the database fails.
1364 * @throws RestException
1367 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut(
1368 String serviceInstanceId, String vnfId,
1369 GenericResourceApiServicedataServicedataVnfsVnf genericResourceApiServicedataServicedataVnfsVnfBodyParam)
1370 throws RestException {
1371 log.info("PUT | VNF Data for ({})", vnfId);
1372 if (!vnfId.equals(genericResourceApiServicedataServicedataVnfsVnfBodyParam.getVnfId())) {
1373 throw new RestProtocolException("bad-attribute", "vnf-id mismatch", HttpStatus.BAD_REQUEST.value());
1375 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1376 log.info("Something with header");
1379 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1382 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1383 ConfigServices data;
1384 if ((services == null) || (services.isEmpty())) {
1385 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1386 data = new ConfigServices();
1387 data.setSvcInstanceId(serviceInstanceId);
1389 data = services.get(0);
1392 GenericResourceApiServicedataServiceData svcData = null;
1394 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1395 } catch (JsonProcessingException e) {
1396 log.error("Could not map service data for ({})", serviceInstanceId);
1398 if (svcData == null) {
1399 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1400 svcData = new GenericResourceApiServicedataServiceData();
1402 if (svcData.getVnfs() == null) {
1403 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1404 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1405 svcData.getVnfs().setVnf(new ArrayList<>());
1408 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1409 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1410 if (svcData.getVnfs().getVnf().isEmpty()) {
1411 log.info("Creating VNF data for ({})", vnfId);
1412 vnflist.addVnfItem(genericResourceApiServicedataServicedataVnfsVnfBodyParam);
1413 responseStatus = HttpStatus.CREATED;
1415 log.info("Updating VNF data for ({})", vnfId);
1416 // Filter out all of the other vnf objects into a new VNF List
1417 // Replace if a delete method exists
1418 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1419 .forEach(vnflist::addVnfItem);
1420 vnflist.addVnfItem(genericResourceApiServicedataServicedataVnfsVnfBodyParam);
1422 svcData.setVnfs(vnflist);
1423 // Map and save the new data
1425 data.setSvcData(objectMapper.writeValueAsString(svcData));
1426 configServicesRepository.save(data);
1427 return new ResponseEntity<>(responseStatus);
1428 } catch (JsonProcessingException e) {
1429 log.error("Error mapping object to JSON", e);
1430 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1431 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1436 * Extracts VNF Topology data from the Config table specified Service Instance
1440 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/
1442 * @param serviceInstanceId the Service Instance ID to lookup data for
1443 * @param vnfId the VNF ID of the VNF to extract topology data from.
1444 * @return HttpStatus.OK (200) if the data is found.
1445 * @throws RestException if the data does not exist.
1448 public ResponseEntity<GenericResourceApiVnftopologyVnfTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet(
1449 String serviceInstanceId, String vnfId) throws RestException {
1450 log.info("GET | VNF Topology for ({})", vnfId);
1451 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1452 if (getAcceptHeader().get().contains("application/json")) {
1457 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1459 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1460 if ((services == null) || (services.isEmpty())) {
1461 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1464 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(services.get(0), vnfId);
1465 // Drill down to find the data
1466 if (vnf.isPresent() && vnf.get().getVnfData() != null && vnf.get().getVnfData().getVnfTopology() != null) {
1467 return new ResponseEntity<>(vnf.get().getVnfData().getVnfTopology(), HttpStatus.OK);
1469 log.info("No information found for {}", vnfId);
1470 throw new RestApplicationException("data-missing",
1471 "Request could not be completed because the relevant data model content does not exist",
1472 HttpStatus.NOT_FOUND.value());
1477 * Creates or updates VNF Level Operation Status data in the Config table for a
1478 * specified Service Instance. If it is a new Service Instance or a new VNF,
1479 * creates all necessary parent data containers, then performs the updates.
1482 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-level-oper-status/
1484 * @param serviceInstanceId the Service Instance ID to
1485 * perform the delete on
1486 * @param vnfId the VNF ID of the VNF to
1488 * @param genericResourceApiOperStatusDataBodyParam the payload
1489 * @return HttpStatus.CREATED (201) on successful create.
1491 * HttpStatus.NO_CONTENT (204) on successful update.
1493 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1494 * @throws RestException
1497 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut(
1498 String serviceInstanceId, String vnfId,
1499 GenericResourceApiOperStatusData genericResourceApiOperStatusDataBodyParam) throws RestException {
1500 log.info("PUT | VNF Level Oper Status ({})", vnfId);
1501 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1504 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1507 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1508 ConfigServices data;
1509 if ((services == null) || (services.isEmpty())) {
1510 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1511 data = new ConfigServices();
1512 data.setSvcInstanceId(serviceInstanceId);
1514 data = services.get(0);
1517 GenericResourceApiServicedataServiceData svcData = null;
1519 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1520 } catch (JsonProcessingException e) {
1521 log.error("Could not map service data for ({})", serviceInstanceId);
1523 if (svcData == null) {
1524 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1525 svcData = new GenericResourceApiServicedataServiceData();
1527 if (svcData.getVnfs() == null) {
1528 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1529 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1530 svcData.getVnfs().setVnf(new ArrayList<>());
1533 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1534 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1535 if (svcData.getVnfs().getVnf().isEmpty()) {
1536 log.info("Creating VNF data for ({})", vnfId);
1537 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1538 vnf.setVnfId(vnfId);
1539 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1540 vnf.getVnfData().setVnfLevelOperStatus(genericResourceApiOperStatusDataBodyParam);
1541 vnflist.addVnfItem(vnf);
1542 responseStatus = HttpStatus.CREATED;
1544 log.info("Updating VNF data for ({})", vnfId);
1545 // Filter out all of the other vnf objects into a new VNF List
1546 // Replace if a delete method exists
1547 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1548 .forEach(vnflist::addVnfItem);
1549 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1550 // If the vnf exists, set it up with new data
1551 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1552 if (vnfOptional.isPresent()) {
1553 vnf = vnfOptional.get();
1555 if (vnf.getVnfData() == null) {
1556 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1557 responseStatus = HttpStatus.CREATED;
1560 vnf.getVnfData().setVnfLevelOperStatus(genericResourceApiOperStatusDataBodyParam);
1561 vnflist.addVnfItem(vnf);
1564 svcData.setVnfs(vnflist);
1565 // Map and save the new data
1567 data.setSvcData(objectMapper.writeValueAsString(svcData));
1568 configServicesRepository.save(data);
1569 return new ResponseEntity<>(responseStatus);
1570 } catch (JsonProcessingException e) {
1571 log.error("Error mapping object to JSON", e);
1572 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1573 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1578 * Creates or updates VNF Onap Model Information data in the Config table for a
1579 * specified Service Instance. If it is a new Service Instance or a new VNF,
1580 * creates all necessary parent data containers, then performs the updates.
1583 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/onap-model-information/
1585 * @param serviceInstanceId the
1602 * @param genericResourceApiOnapmodelinformationOnapModelInformationBodyParam the
1604 * @return HttpStatus.CREATED (201) on successful create.
1606 * HttpStatus.NO_CONTENT (204) on successful update.
1608 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1609 * @throws RestException
1612 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut(
1613 String serviceInstanceId, String vnfId,
1614 GenericResourceApiOnapmodelinformationOnapModelInformation genericResourceApiOnapmodelinformationOnapModelInformationBodyParam)
1615 throws RestException {
1616 log.info("PUT | VNF Topology Onap Model Information ({})", vnfId);
1617 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1620 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1623 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1624 ConfigServices data;
1625 if ((services == null) || (services.isEmpty())) {
1626 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1627 data = new ConfigServices();
1628 data.setSvcInstanceId(serviceInstanceId);
1630 data = services.get(0);
1633 GenericResourceApiServicedataServiceData svcData = null;
1635 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1636 } catch (JsonProcessingException e) {
1637 log.error("Could not map service data for ({})", serviceInstanceId);
1639 if (svcData == null) {
1640 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1641 svcData = new GenericResourceApiServicedataServiceData();
1643 if (svcData.getVnfs() == null) {
1644 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1645 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1646 svcData.getVnfs().setVnf(new ArrayList<>());
1649 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1650 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1651 if (svcData.getVnfs().getVnf().isEmpty()) {
1652 log.info("Creating VNF data for ({})", vnfId);
1653 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1654 vnf.setVnfId(vnfId);
1655 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1656 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1657 vnf.getVnfData().getVnfTopology()
1658 .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam);
1659 vnflist.addVnfItem(vnf);
1660 responseStatus = HttpStatus.CREATED;
1662 log.info("Updating VNF data for ({})", vnfId);
1663 // Filter out all of the other vnf objects into a new VNF List
1664 // Replace if a delete method exists
1665 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1666 .forEach(vnflist::addVnfItem);
1667 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1668 // If the vnf exists, set it up with new data
1669 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1670 if (vnfOptional.isPresent()) {
1671 vnf = vnfOptional.get();
1673 if (vnf.getVnfData() == null) {
1674 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1676 if (vnf.getVnfData().getVnfTopology() == null) {
1677 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1678 responseStatus = HttpStatus.CREATED;
1681 vnf.getVnfData().getVnfTopology()
1682 .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam);
1683 vnflist.addVnfItem(vnf);
1686 svcData.setVnfs(vnflist);
1687 // Map and save the new data
1689 data.setSvcData(objectMapper.writeValueAsString(svcData));
1690 configServicesRepository.save(data);
1691 return new ResponseEntity<>(responseStatus);
1692 } catch (JsonProcessingException e) {
1693 log.error("Error mapping object to JSON", e);
1694 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1695 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1700 * Creates or updates VNF Network data in the Config table for a specified
1701 * Service Instance. If it is a new Service Instance or a new VNF, creates all
1702 * necessary parent data containers, then performs the updates.
1704 * 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/
1705 * @param serviceInstanceId the Service Instance ID to perform the delete on
1706 * @param vnfId the VNF ID of the VNF to delete
1707 * @param genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam the * payload
1708 * @return HttpStatus.CREATED (201) on successful create.
1710 * HttpStatus.NO_CONTENT (204) on successful update.
1712 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1713 * @throws RestException
1716 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut(
1717 String serviceInstanceId, String vnfId,
1718 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam)
1719 throws RestException {
1720 log.info("PUT | VNF Topology VNF Resource Assignments VNF Networks ({})", vnfId);
1721 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1724 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1727 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1728 ConfigServices data;
1729 if ((services == null) || (services.isEmpty())) {
1730 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1731 data = new ConfigServices();
1732 data.setSvcInstanceId(serviceInstanceId);
1734 data = services.get(0);
1737 GenericResourceApiServicedataServiceData svcData = null;
1739 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1740 } catch (JsonProcessingException e) {
1741 log.error("Could not map service data for ({})", serviceInstanceId);
1743 if (svcData == null) {
1744 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1745 svcData = new GenericResourceApiServicedataServiceData();
1747 if (svcData.getVnfs() == null) {
1748 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1749 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1750 svcData.getVnfs().setVnf(new ArrayList<>());
1753 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1754 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1755 if (svcData.getVnfs().getVnf().isEmpty()) {
1756 log.info("Creating VNF data for ({})", vnfId);
1757 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1758 vnf.setVnfId(vnfId);
1759 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1760 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1761 vnf.getVnfData().getVnfTopology()
1762 .setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1763 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1764 .setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam);
1765 vnflist.addVnfItem(vnf);
1766 responseStatus = HttpStatus.CREATED;
1768 log.info("Updating VNF data for ({})", vnfId);
1769 // Filter out all of the other vnf objects into a new VNF List
1770 // Replace if a delete method exists
1771 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1772 .forEach(vnflist::addVnfItem);
1773 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1774 // If the vnf exists, set it up with new data
1775 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1776 if (vnfOptional.isPresent()) {
1777 vnf = vnfOptional.get();
1779 if (vnf.getVnfData() == null) {
1780 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1782 if (vnf.getVnfData().getVnfTopology() == null) {
1783 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1785 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) {
1786 vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(
1787 new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1788 responseStatus = HttpStatus.CREATED;
1791 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1792 .setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam);
1793 vnflist.addVnfItem(vnf);
1796 svcData.setVnfs(vnflist);
1797 // Map and save the new data
1799 data.setSvcData(objectMapper.writeValueAsString(svcData));
1800 configServicesRepository.save(data);
1801 return new ResponseEntity<>(responseStatus);
1802 } catch (JsonProcessingException e) {
1803 log.error("Error mapping object to JSON", e);
1804 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1805 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1810 * Creates or updates VNF Network Role data in the Config table for a specified
1811 * Service Instance. If it is a new Service Instance or a new VNF, creates all
1812 * necessary parent data containers, then performs the updates.
1815 * /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}/
1817 * @param serviceInstanceId the Service Instance ID to
1818 * perform the delete on
1819 * @param vnfId the VNF ID of the VNF to
1821 * @param genericResourceApiVnfNetworkDataBodyParam the payload
1822 * @return HttpStatus.CREATED (201) on successful create.
1824 * HttpStatus.NO_CONTENT (204) on successful update.
1826 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1827 * @throws RestException
1830 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut(
1831 String serviceInstanceId, String vnfId, String networkRole,
1832 GenericResourceApiVnfNetworkData genericResourceApiVnfNetworkDataBodyParam) throws RestException {
1833 log.info("PUT | VNF Network Network Role ({})", vnfId);
1834 if (!networkRole.equals(genericResourceApiVnfNetworkDataBodyParam.getNetworkRole())) {
1835 throw new RestProtocolException("bad-attribute", "network-role mismatch", HttpStatus.BAD_REQUEST.value());
1837 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1840 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1843 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1844 ConfigServices data;
1845 if ((services == null) || (services.isEmpty())) {
1846 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1847 data = new ConfigServices();
1848 data.setSvcInstanceId(serviceInstanceId);
1850 data = services.get(0);
1853 GenericResourceApiServicedataServiceData svcData = null;
1855 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1856 } catch (JsonProcessingException e) {
1857 log.error("Could not map service data for ({})", serviceInstanceId);
1859 if (svcData == null) {
1860 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1861 svcData = new GenericResourceApiServicedataServiceData();
1863 if (svcData.getVnfs() == null) {
1864 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1865 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1866 svcData.getVnfs().setVnf(new ArrayList<>());
1869 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1870 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1871 if (svcData.getVnfs().getVnf().isEmpty()) {
1872 log.info("Creating VNF data for ({})", vnfId);
1873 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1874 vnf.setVnfId(vnfId);
1875 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1876 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1877 vnf.getVnfData().getVnfTopology()
1878 .setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1879 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1880 .setVnfNetworks(new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks());
1881 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks()
1882 .setVnfNetwork(new ArrayList<>());
1883 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks()
1884 .addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1885 vnflist.addVnfItem(vnf);
1886 responseStatus = HttpStatus.CREATED;
1888 log.info("Updating VNF data for ({})", vnfId);
1889 // Filter out all of the other vnf objects into a new VNF List
1890 // Replace if a delete method exists
1891 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1892 .forEach(vnflist::addVnfItem);
1893 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1894 // If the vnf exists, set it up with new data
1895 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1896 if (vnfOptional.isPresent()) {
1897 vnf = vnfOptional.get();
1899 if (vnf.getVnfData() == null) {
1900 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1902 if (vnf.getVnfData().getVnfTopology() == null) {
1903 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1905 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) {
1906 vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(
1907 new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1909 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks() == null) {
1910 log.info("Creating new VnfNetworks");
1911 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(
1912 new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks());
1915 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks networkList = new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks();
1916 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().getVnfNetwork()
1918 log.info("First entry into network info.");
1919 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks()
1920 .addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1921 responseStatus = HttpStatus.CREATED;
1923 log.info("Found networks. Filtering.");
1924 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().getVnfNetwork().stream()
1925 .filter(targetNetwork -> !targetNetwork.getNetworkRole().equals(networkRole))
1926 .forEach(networkList::addVnfNetworkItem);
1927 networkList.addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1929 if (networkList.getVnfNetwork().size() != vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1930 .getVnfNetworks().getVnfNetwork().size()) {
1931 log.info("Added a new Item");
1932 responseStatus = HttpStatus.CREATED;
1934 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(networkList);
1937 vnflist.addVnfItem(vnf);
1940 svcData.setVnfs(vnflist);
1941 // Map and save the new data
1943 data.setSvcData(objectMapper.writeValueAsString(svcData));
1944 configServicesRepository.save(data);
1945 return new ResponseEntity<>(responseStatus);
1946 } catch (JsonProcessingException e) {
1947 log.error("Error mapping object to JSON", e);
1948 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1949 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1954 * Extracts a VNF object from the database,
1956 * @param configServices A Config Services option created from a Service
1958 * @param vnfId the target VNF ID
1959 * @return An empty Optional if the Service Data does not exist, an empty
1960 * Optional if the VNF is not found, or an optional containing the found
1963 private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getVnfObject(ConfigServices configServices,
1965 // Map the Marshall the JSON String into a Java Object
1966 log.info("Getting VNF Data for ({})", vnfId);
1967 GenericResourceApiServicedataServiceData svcData;
1969 svcData = objectMapper.readValue(configServices.getSvcData(),
1970 GenericResourceApiServicedataServiceData.class);
1971 } catch (JsonProcessingException e) {
1972 log.error("Error", e);
1973 return Optional.empty();
1977 * Get a stream of the VNF Objects and return the target if it's found, assuming
1978 * that each VNF ID is unique within a Service Instance Object
1980 return svcData.getVnfs().getVnf().stream().filter(targetVnf -> targetVnf.getVnfId().equals(vnfId)).findFirst();
1984 public ResponseEntity<GenericResourceApiServicetopologyServiceTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet(
1985 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1986 GenericResourceApiServicetopologyServiceTopology serviceTopology = null;
1987 GenericResourceApiServicedataServiceData serviceData = null;
1989 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1990 if ((services == null) || (services.isEmpty())) {
1991 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1995 if (services.get(0).getSvcData().isEmpty()) {
1996 throw new RestProtocolException("data-missing", "No service-data entry found",
1997 HttpStatus.NOT_FOUND.value());
1999 serviceData = objectMapper.readValue(services.get(0).getSvcData(),
2000 GenericResourceApiServicedataServiceData.class);
2001 serviceTopology = serviceData.getServiceTopology();
2003 if (serviceTopology == null) {
2004 throw new RestProtocolException("data-missing", "No service-topology entry found",
2005 HttpStatus.NOT_FOUND.value());
2007 return new ResponseEntity<>(serviceTopology, HttpStatus.OK);
2008 } catch (JsonProcessingException e) {
2009 log.error("Could not parse service data", e);
2010 throw new RestApplicationException("data-conversion",
2011 "Request could not be completed due to internal error", e,
2012 HttpStatus.INTERNAL_SERVER_ERROR.value());
2018 * Extracts VF MODULE data from CONFIG_GRA_SERVICES for a given, service-instance-id, vnf-id, and vf-module-id
2020 * 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}/
2021 * @param serviceInstanceId the Service Instance ID to lookup data for
2022 * @param vnfId the VNF ID of the VNF to return
2023 * @param vfModuleId the vf-moudle ID of a specific VNF to return
2024 * @return HttpStatus.OK (200) if the data is found.
2025 * @throws RestException if the data does not exist.
2028 public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule>
2029 configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet(
2030 String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
2032 log.info("GET | Vf Module Data for ({})", vfModuleId);
2034 if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2035 if(getAcceptHeader().get().contains("application/json")) {
2038 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2040 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2041 if((services == null) || (services.isEmpty())) {
2042 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
2045 Optional<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule> vfModule =
2046 getVfModuleObject(services.get(0), vnfId, vfModuleId);
2047 if(vfModule.isPresent()) {
2048 return new ResponseEntity<>(vfModule.get(), HttpStatus.OK);
2050 log.info("No vf-module found for [{}]", vfModuleId);
2051 throw new RestApplicationException("data-missing",
2052 "Request could not be completed because the relevant data model content does not exist",
2053 HttpStatus.NOT_FOUND.value());
2058 * PUT VF MODULE data into CONFIG_GRA_SERVICES of a given, service-instance-id, vnf-id
2060 * 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}/
2061 * @param serviceInstanceId the Service Instance ID
2062 * @param vnfId the VNF ID as the parent of the specified vf-module-id and child of the specified service-instance
2063 * @param vfModuleId the vf-moudle ID as a child of the specified VNF
2064 * @return HttpStatus.OK (200) if the data is found.
2065 * @throws RestException if the data does not exist.
2068 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut(
2069 String serviceInstanceId, String vnfId, String vfModuleId,
2070 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam)
2071 throws RestException {
2072 log.info("PUT | vf-module Data of ({}) for vnf ({}) in service({})", vfModuleId, vnfId, serviceInstanceId);
2074 if(! vfModuleId.equals(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam.getVfModuleId())) {
2075 throw new RestProtocolException("bad-attribute", "vf-module-id mismatch", HttpStatus.BAD_REQUEST.value());
2077 if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2078 log.info("Something with header");
2080 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2083 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
2084 ConfigServices service;
2085 GenericResourceApiServicedataServiceData svcData;
2086 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2088 if((services == null) || (services.isEmpty())) {
2089 log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
2090 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2092 service = services.get(0);
2096 svcData = objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class);
2097 } catch(JsonProcessingException e) {
2098 log.error("Error", e);
2099 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2102 GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs();
2103 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf =
2106 .filter(targetVnf -> targetVnf.getVnfId().equals(vnfId))
2109 if(! vnf.isPresent()) {
2110 log.error("vnf-id ({}) not found in SDN.", vnfId);
2111 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2114 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.get().getVnfData();
2115 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules existingVfModules = vnfData.getVfModules();
2116 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules newVfModules = new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules();
2118 if (existingVfModules == null || existingVfModules.getVfModule().isEmpty()) {
2119 log.info("No existing vf-module found. Creating the first vf-module for vnf [{}]", vnfId);
2120 newVfModules.addVfModuleItem(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam);
2121 responseStatus = HttpStatus.CREATED;
2124 ArrayList<String> vfModuleIds = new ArrayList<>();
2125 for (GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vf : existingVfModules.getVfModule()) {
2126 vfModuleIds.add(vf.getVfModuleId());
2128 log.info("[{}] vf-module(s) {} found in vnf [{}]", existingVfModules.getVfModule().size(), vfModuleIds, vnfId);
2129 if (!vfModuleIds.isEmpty() && vfModuleIds.contains(vfModuleId)) {
2130 log.info("Overwriting vf-module [{}] in vnf [{}]", vfModuleId, vnfId);
2132 log.info("Adding vf-module [{}] to vnf [{}]", vfModuleId, vnfId);
2134 existingVfModules.getVfModule()
2136 .filter(vf -> ! vf.getVfModuleId().equals(vfModuleId))
2137 .forEach(newVfModules::addVfModuleItem);
2138 newVfModules.addVfModuleItem(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam);
2139 responseStatus = HttpStatus.OK;
2141 vnfData.setVfModules(newVfModules);
2142 // Map and save the new data
2144 service.setSvcData(objectMapper.writeValueAsString(svcData));
2145 configServicesRepository.save(service);
2146 return new ResponseEntity<>(responseStatus);
2147 } catch(JsonProcessingException e) {
2148 log.error("Error mapping object to JSON", e);
2149 // Should probably be a 500 INTERNAL_SERVICE_ERROR
2150 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2155 * Extracts VF MODULE Topology data from the Config table specified Service
2156 * Instance and VNF ID.
2158 * 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/
2159 * @param serviceInstanceId the Service Instance ID to lookup data for
2160 * @param vnfId the VNF ID of the VNF to extract topology data from.
2161 * @param vfModuleId the vf-module-idof the vf-module to extract topology data from.
2162 * @return HttpStatus.OK (200) if the data is found.
2163 * @throws RestException if the data does not exist.
2166 public ResponseEntity<GenericResourceApiVfmoduletopologyVfModuleTopology>
2167 configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet(
2168 String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
2169 log.info("GET | vf-module-topology for ({})", vfModuleId);
2170 if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2171 if (getAcceptHeader().get().contains("application/json")) {
2172 log.info("Something with header");
2175 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2177 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2178 if((services == null) || (services.isEmpty())) {
2179 throw new RestApplicationException("data-missing",
2180 "Request could not be completed because the relevant data model content does not exist",
2181 HttpStatus.NOT_FOUND.value());
2184 Optional<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule> vfModule =
2185 getVfModuleObject(services.get(0), vnfId, vfModuleId);
2186 if(vfModule.isPresent()
2187 && vfModule.get().getVfModuleData() != null
2188 && vfModule.get().getVfModuleData().getVfModuleTopology() != null) {
2189 return new ResponseEntity<>(vfModule.get().getVfModuleData().getVfModuleTopology(), HttpStatus.OK);
2191 log.info("No information found for {}", vfModuleId);
2192 throw new RestApplicationException("data-missing",
2193 "Request could not be completed because the relevant data model content does not exist",
2194 HttpStatus.NOT_FOUND.value());
2199 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete(
2200 String serviceInstanceId, String vnfId, String vfModuleId) throws RestProtocolException {
2202 log.info("DELETE | vf-module Data for ({})", vfModuleId);
2204 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2205 log.info("Something with header.");
2207 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2210 ConfigServices service;
2211 GenericResourceApiServicedataServiceData svcData;
2212 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2214 if((services == null) || (services.isEmpty())) {
2215 log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
2216 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2218 service = services.get(0);
2222 svcData = objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class);
2223 } catch(JsonProcessingException e) {
2224 log.error("Error", e);
2225 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2228 GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs();
2229 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf =
2232 .filter(targetVnf -> targetVnf.getVnfId().equals(vnfId))
2235 if(! vnf.isPresent()) {
2236 log.error("vnf-id ({}) not found in SDN.", vnfId);
2237 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2240 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.get().getVnfData();
2241 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules existingVfModules = vnfData.getVfModules();
2242 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules newVfModules = new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules();
2244 if (existingVfModules == null || existingVfModules.getVfModule().isEmpty()) {
2245 log.info("No existing vf-module found. Creating the first vf-module for vnf [{}]", vnfId);
2246 return new ResponseEntity<>(HttpStatus.OK);
2249 ArrayList<String> vfModuleIds = new ArrayList<>();
2250 for (GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vf : existingVfModules.getVfModule()) {
2251 vfModuleIds.add(vf.getVfModuleId());
2253 log.info("[{}] vf-module(s) {} found in vnf [{}]", existingVfModules.getVfModule().size(), vfModuleIds, vnfId);
2254 if (!vfModuleIds.isEmpty() && vfModuleIds.contains(vfModuleId)) {
2255 log.info("Deleting vf-module [{}] from vnf [{}]", vfModuleId, vnfId);
2257 log.info("vf-module [{}] not found in vnf [{}]", vfModuleId, vnfId);
2258 return new ResponseEntity<>(HttpStatus.OK);
2260 existingVfModules.getVfModule()
2262 .filter(vf -> ! vf.getVfModuleId().equals(vfModuleId))
2263 .forEach(newVfModules::addVfModuleItem);
2264 vnfData.setVfModules(newVfModules);
2265 log.info("vf-module [{}] deleted from vnf [{}]", vfModuleId, vnfId);
2267 // Map and save the new data
2269 service.setSvcData(objectMapper.writeValueAsString(svcData));
2270 configServicesRepository.save(service);
2271 return new ResponseEntity<>(HttpStatus.OK);
2272 } catch(JsonProcessingException e) {
2273 log.error("Error mapping object to JSON", e);
2274 // Should probably be a 500 INTERNAL_SERVICE_ERROR
2275 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);