2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.sdncsimulator.providers;
22 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.CREATED;
23 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.PENDINGCREATE;
24 import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE;
25 import static org.onap.so.sdncsimulator.utils.Constants.RESTCONF_CONFIG_END_POINT;
26 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_DATA_VNFS_VNF;
27 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION;
28 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION_CACHE;
29 import static org.onap.so.sdncsimulator.utils.Constants.VNF_DATA_VNF_TOPOLOGY;
30 import static org.onap.so.sdncsimulator.utils.Constants.YES;
31 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getString;
32 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getStringOrNull;
33 import static org.onap.so.sdncsimulator.utils.ObjectUtils.isValid;
34 import java.time.LocalDateTime;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Optional;
38 import javax.validation.Valid;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastActionEnumeration;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServiceData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfs;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServiceStatus;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure;
63 import org.onap.so.sdncsimulator.models.Output;
64 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67 import org.springframework.beans.factory.annotation.Autowired;
68 import org.springframework.cache.Cache;
69 import org.springframework.cache.CacheManager;
70 import org.springframework.http.HttpStatus;
71 import org.springframework.stereotype.Service;
74 * @author Waqas Ikram (waqas.ikram@est.tech)
78 public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider
79 implements ServiceOperationsCacheServiceProvider {
81 private static final String EMPTY_STRING = "";
82 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class);
85 public ServiceOperationsCacheServiceProviderimpl(final CacheManager cacheManager) {
90 public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
92 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
93 final String svcRequestId = getSvcRequestId(requestHeader);
95 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
96 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
97 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
99 if (isServiceOperationInformationNotExists(serviceInstanceId, input)) {
100 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
101 LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}",
104 final GenericResourceApiServicemodelinfrastructureService service =
105 getServiceItem(input, serviceInstanceId);
106 cache.put(serviceInstanceId, service);
108 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
110 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
111 .responseCode(serviceStatus.getResponseCode())
112 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
113 .serviceResponseInformation(new GenericResourceApiInstanceReference()
114 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)));
116 LOGGER.error("serviceInstanceId: {} already exists", serviceInstanceId);
117 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
118 .responseMessage("serviceInstanceId: " + serviceInstanceId + " already exists")
119 .svcRequestId(svcRequestId);
123 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
125 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
126 .responseMessage("Service instance not found").svcRequestId(svcRequestId);
131 public Output deleteServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
132 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
133 final String svcRequestId = getSvcRequestId(input.getSdncRequestHeader());
135 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
136 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
137 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
138 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
139 if (optional.isPresent()) {
140 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
141 LOGGER.info("Deleting GenericResourceApiServiceOperationInformation from cache using key: {}",
143 cache.evict(serviceInstanceId);
144 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.OK.toString())
145 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId).serviceResponseInformation(
146 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId));
149 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
153 LOGGER.error("Unable to remove service instance from cache due to invalid input: {}... ", input);
154 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
155 .responseMessage("Unable to remove service").svcRequestId(svcRequestId);
159 public Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService(
160 final String serviceInstanceId) {
161 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
163 final GenericResourceApiServicemodelinfrastructureService value =
164 cache.get(serviceInstanceId, GenericResourceApiServicemodelinfrastructureService.class);
166 LOGGER.info("Found {} in cahce for service instance id: {}", value, serviceInstanceId);
167 return Optional.of(value);
169 LOGGER.error("Unable to find GenericResourceApiServiceModelInfrastructure in cache for service instance id: {}",
171 return Optional.empty();
175 public Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
177 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
178 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
180 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
181 final String svcRequestId = getSvcRequestId(requestHeader);
183 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
184 && isValid(vnfInformation.getVnfId())) {
185 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
186 final String vnfId = vnfInformation.getVnfId();
187 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
188 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
189 if (optional.isPresent()) {
190 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
191 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
192 if (serviceData != null) {
193 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
194 final GenericResourceApiLastRpcActionEnumeration svcAction =
195 GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(requestHeader));
197 if (ifVnfNotExists(vnfId, svcAction, vnfsList)) {
198 vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input));
200 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
202 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
203 .responseCode(serviceStatus.getResponseCode())
204 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
205 .serviceResponseInformation(new GenericResourceApiInstanceReference()
206 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)))
207 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)
208 .objectPath(getObjectPath(serviceInstanceId, vnfId)));
210 LOGGER.error("vnfId: {} already exists with SVC Action: {}", vnfId, svcAction);
211 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
212 .responseMessage("vnfId: " + vnfId + " already exists").svcRequestId(svcRequestId);
216 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
221 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
223 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
224 .responseMessage("Unable to add vnf").svcRequestId(svcRequestId);
228 public Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
229 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
230 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
232 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
233 final String svcRequestId = getSvcRequestId(requestHeader);
235 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
236 && isValid(vnfInformation.getVnfId())) {
237 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
238 final String vnfId = vnfInformation.getVnfId();
239 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
240 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
241 if (optional.isPresent()) {
242 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
243 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
244 if (serviceData != null) {
245 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
246 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfInstanceOptional =
247 getExistingVnf(vnfId, vnfsList);
249 if (vnfInstanceOptional.isPresent()) {
250 vnfsList.removeIf(vnf -> {
251 final String existingVnfId = vnf.getVnfId();
252 if (existingVnfId != null && existingVnfId.equals(vnfId)) {
253 LOGGER.info("Remove vnf with id: {} ... ", existingVnfId);
259 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.OK.toString())
260 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId)
261 .serviceResponseInformation(
262 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId))
263 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId));
269 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
273 LOGGER.error("Unable to remove vnf instance from cache due to invalid input: {}... ", input);
274 return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
275 .responseMessage("Unable to remove vnf").svcRequestId(svcRequestId);
279 private String getSvcRequestId(final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader) {
280 return requestHeader != null ? requestHeader.getSvcRequestId() : null;
284 public void clearAll() {
285 clearCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
288 private String getObjectPath(final String serviceInstanceId, final String vnfId) {
289 return getObjectPath(serviceInstanceId) + SERVICE_DATA_VNFS_VNF + vnfId + VNF_DATA_VNF_TOPOLOGY;
292 private String getObjectPath(final String serviceInstanceId) {
293 return RESTCONF_CONFIG_END_POINT + serviceInstanceId;
297 private boolean ifVnfNotExists(final String vnfId, final GenericResourceApiLastRpcActionEnumeration svcAction,
298 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
299 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = getExistingVnf(vnfId, vnfsList);
300 if (optional.isPresent()) {
301 final GenericResourceApiServicedataServicedataVnfsVnf existingVnf = optional.get();
302 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = existingVnf.getVnfData();
304 if (vnfData != null && vnfData.getVnfLevelOperStatus() != null
305 && vnfData.getVnfLevelOperStatus().getLastRpcAction() != null) {
306 final GenericResourceApiLastRpcActionEnumeration existingVnflastRpcAction =
307 vnfData.getVnfLevelOperStatus().getLastRpcAction();
308 if (existingVnflastRpcAction.equals(svcAction)) {
309 LOGGER.error("Found vnf with id: {} and LastRpcAction: {} same as SvcAction: {}", vnfId,
310 existingVnflastRpcAction, svcAction);
313 LOGGER.warn("Will remove and replace existing vnf with id: {} as SvcAction is changed from {} to {}",
314 vnfId, existingVnflastRpcAction, svcAction);
315 vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId));
323 private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getExistingVnf(final String vnfId,
324 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
325 return vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst();
328 private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs(
329 final GenericResourceApiServicedataServiceData serviceData) {
330 GenericResourceApiServicedataServicedataVnfs vnfs = serviceData.getVnfs();
332 vnfs = new GenericResourceApiServicedataServicedataVnfs();
333 serviceData.setVnfs(vnfs);
336 List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = vnfs.getVnf();
337 if (vnfsList == null) {
338 vnfsList = new ArrayList<>();
339 vnfs.setVnf(vnfsList);
344 private GenericResourceApiServicedataServicedataVnfsVnf getGenericResourceApiServicedataVnf(
345 final String serviceInstanceId, final String vnfId, final GenericResourceApiVnfOperationInformation input) {
346 return new GenericResourceApiServicedataServicedataVnfsVnf().vnfId(vnfId).vnfData(getVnfData(input));
349 private GenericResourceApiServicedataServicedataVnfsVnfVnfData getVnfData(
350 final GenericResourceApiVnfOperationInformation input) {
352 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData =
353 new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
355 vnfData.vnfLevelOperStatus(
356 getServiceLevelOperStatus(PENDINGCREATE, input.getRequestInformation(), input.getSdncRequestHeader()));
357 vnfData.serviceInformation(input.getServiceInformation());
358 vnfData.sdncRequestHeader(input.getSdncRequestHeader());
359 vnfData.vnfInformation(input.getVnfInformation());
360 vnfData.requestInformation(input.getRequestInformation());
361 vnfData.vnfRequestInput(input.getVnfRequestInput());
363 vnfData.vnfTopology(getVnfTopology(input.getVnfInformation(), input.getVnfRequestInput()));
368 private GenericResourceApiVnftopologyVnfTopology getVnfTopology(
369 final GenericResourceApiVnfinformationVnfInformation vnfInformation,
370 final GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput) {
372 final GenericResourceApiVnftopologyVnfTopology apiVnftopologyVnfTopology =
373 new GenericResourceApiVnftopologyVnfTopology();
375 if (vnfInformation != null) {
376 apiVnftopologyVnfTopology.onapModelInformation(vnfInformation.getOnapModelInformation());
377 apiVnftopologyVnfTopology.vnfTopologyIdentifierStructure(getTopologyIdentifierStructure(vnfInformation));
379 if (vnfRequestInput != null) {
380 apiVnftopologyVnfTopology.tenant(vnfRequestInput.getTenant());
381 apiVnftopologyVnfTopology.aicClli(vnfRequestInput.getAicClli());
382 apiVnftopologyVnfTopology.aicCloudRegion(vnfRequestInput.getAicCloudRegion());
384 return apiVnftopologyVnfTopology;
387 private GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure getTopologyIdentifierStructure(
388 @Valid final GenericResourceApiVnfinformationVnfInformation vnfInformation) {
389 return new GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure()
390 .vnfId(vnfInformation.getVnfId()).vnfName(vnfInformation.getVnfName())
391 .vnfType(vnfInformation.getVnfType());
394 private GenericResourceApiServicemodelinfrastructureService getServiceItem(
395 final GenericResourceApiServiceOperationInformation input, final String serviceInstanceId) {
397 final GenericResourceApiServicedataServiceData apiServicedataServiceData =
398 new GenericResourceApiServicedataServiceData();
400 apiServicedataServiceData.requestInformation(input.getRequestInformation());
401 apiServicedataServiceData.serviceRequestInput(input.getServiceRequestInput());
402 apiServicedataServiceData.serviceInformation(input.getServiceInformation());
403 apiServicedataServiceData.serviceTopology(getServiceTopology(input));
404 apiServicedataServiceData.sdncRequestHeader(input.getSdncRequestHeader());
405 apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input));
407 final GenericResourceApiServicestatusServiceStatus serviceStatus =
408 getServiceStatus(getSvcAction(input.getSdncRequestHeader()),
409 getRequestAction(input.getRequestInformation()), HttpStatus.OK.toString());
411 return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData)
412 .serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId);
415 private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) {
416 return input != null ? getStringOrNull(input.getSvcAction()) : null;
419 private GenericResourceApiServicestatusServiceStatus getServiceStatus(final String rpcAction, final String action,
420 final String responseCode) {
421 return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES)
422 .rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction))
423 .rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString())
424 .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage(EMPTY_STRING).action(action);
427 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
428 final GenericResourceApiServiceOperationInformation input) {
429 return getServiceLevelOperStatus(CREATED, input.getRequestInformation(), input.getSdncRequestHeader());
432 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
433 final GenericResourceApiOrderStatusEnumeration statusEnumeration,
434 final GenericResourceApiRequestinformationRequestInformation requestInformation,
435 final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader) {
436 return new GenericResourceApiOperStatusData().orderStatus(statusEnumeration)
437 .lastAction(GenericResourceApiLastActionEnumeration.fromValue(getRequestAction(requestInformation)))
438 .lastRpcAction(GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(sdncRequestHeader)));
441 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) {
442 return getRequestAction(input, EMPTY_STRING);
445 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input,
446 final String defaultValue) {
447 return input != null ? getString(input.getRequestAction(), defaultValue) : defaultValue;
450 private GenericResourceApiServicetopologyServiceTopology getServiceTopology(
451 final GenericResourceApiServiceOperationInformation input) {
452 final GenericResourceApiOnapmodelinformationOnapModelInformation modelInformation =
453 input.getServiceInformation() != null ? input.getServiceInformation().getOnapModelInformation() : null;
454 return new GenericResourceApiServicetopologyServiceTopology().onapModelInformation(modelInformation)
455 .serviceTopologyIdentifier(getServiceTopologyIdentifier(input));
458 private GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier getServiceTopologyIdentifier(
459 final GenericResourceApiServiceOperationInformation input) {
460 final GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier identifier =
461 new GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier();
463 if (input.getServiceInformation() != null) {
464 final GenericResourceApiServiceinformationServiceInformation serviceInformation =
465 input.getServiceInformation();
466 identifier.globalCustomerId(serviceInformation.getGlobalCustomerId())
467 .serviceType(input.getServiceInformation().getSubscriptionServiceType())
468 .serviceInstanceId(input.getServiceInformation().getServiceInstanceId());;
471 if (input.getServiceRequestInput() != null) {
472 identifier.serviceInstanceName(input.getServiceRequestInput().getServiceInstanceName());
479 private boolean isServiceOperationInformationNotExists(final String serviceInstanceId,
480 final GenericResourceApiServiceOperationInformation input) {
481 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
482 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
483 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
485 if (optional.isPresent()) {
486 final GenericResourceApiServicemodelinfrastructureService existingService = optional.get();
487 final GenericResourceApiServicestatusServiceStatus serviceStatus = existingService.getServiceStatus();
488 if (serviceStatus != null) {
489 final GenericResourceApiRpcActionEnumeration rpcAction = serviceStatus.getRpcAction();
490 final String svcAction = getSvcAction(requestHeader);
491 if (rpcAction != null && rpcAction.toString().equals(svcAction)) {
492 LOGGER.error("Found Service with id: {} and RpcAction: {} same as SvcAction: {}",
493 serviceInstanceId, rpcAction, svcAction);
497 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
499 "Deleting existing GenericResourceApiServiceOperationInformation from cache using key: {} as SvcAction is changed from {} to {}",
500 serviceInstanceId, rpcAction, svcAction);
501 cache.evict(serviceInstanceId);