2 * Copyright © 2024 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.servicehandler.impl;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Optional;
12 import org.opendaylight.transportpce.common.OperationResult;
13 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
14 import org.opendaylight.transportpce.servicehandler.ServiceInput;
15 import org.opendaylight.transportpce.servicehandler.impl.ServicehandlerImpl.LogMessages;
16 import org.opendaylight.transportpce.servicehandler.listeners.NetworkListener;
17 import org.opendaylight.transportpce.servicehandler.listeners.PceListener;
18 import org.opendaylight.transportpce.servicehandler.listeners.RendererListener;
19 import org.opendaylight.transportpce.servicehandler.service.RendererServiceWrapper;
20 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
21 import org.opendaylight.transportpce.servicehandler.validation.ServiceCreateValidation;
22 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.RpcActions;
23 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes;
24 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
25 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigure;
26 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureInput;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureOutput;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 public class ServiceReconfigureImpl implements ServiceReconfigure {
35 private static final Logger LOG = LoggerFactory.getLogger(ServiceReconfigureImpl.class);
36 private static final String SERVICE_RECONFIGURE_MSG = "serviceReconfigure: {}";
38 private ServiceDataStoreOperations serviceDataStoreOperations;
39 private PceListener pceListener;
40 private RendererListener rendererListener;
41 private NetworkListener networkListener;
42 private RendererServiceWrapper rendererServiceWrapper;
44 public ServiceReconfigureImpl(final ServiceDataStoreOperations serviceDataStoreOperations,
45 final PceListener pceListener, RendererListener rendererListener, NetworkListener networkListener,
46 RendererServiceWrapper rendererServiceWrapper) {
47 this.serviceDataStoreOperations = serviceDataStoreOperations;
48 this.pceListener = pceListener;
49 this.rendererListener = rendererListener;
50 this.networkListener = networkListener;
51 this.rendererServiceWrapper = rendererServiceWrapper;
56 public ListenableFuture<RpcResult<ServiceReconfigureOutput>> invoke(ServiceReconfigureInput input) {
57 String serviceName = input.getServiceName();
58 LOG.info("RPC serviceReconfigure received for {}", serviceName);
59 Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
60 if (servicesObject.isEmpty()) {
61 LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.serviceNotInDS(serviceName));
62 return ModelMappingUtils.createCreateServiceReply(
64 LogMessages.serviceNotInDS(serviceName));
66 LOG.debug("Service '{}' found in datastore", serviceName);
67 OperationResult validationResult = ServiceCreateValidation
68 .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure);
69 if (!validationResult.isSuccess()) {
70 LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.ABORT_VALID_FAILED);
71 return ModelMappingUtils.createCreateServiceReply(
73 validationResult.getResultMessage());
75 this.pceListener.setInput(new ServiceInput(input));
76 this.pceListener.setServiceReconfigure(true);
77 this.pceListener.setserviceDataStoreOperations(this.serviceDataStoreOperations);
78 this.rendererListener.setserviceDataStoreOperations(serviceDataStoreOperations);
79 this.rendererListener.setServiceInput(new ServiceInput(input));
80 this.networkListener.setserviceDataStoreOperations(serviceDataStoreOperations);
81 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
82 .ServiceDeleteInput serviceDeleteInput =
83 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
84 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
85 .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
86 ServiceNotificationTypes.ServiceDeleteResult, null);
88 LOG.error(SERVICE_RECONFIGURE_MSG, LogMessages.RENDERER_DELETE_FAILED);
89 return ModelMappingUtils.createCreateServiceReply(
91 LogMessages.RENDERER_DELETE_FAILED);
92 //TODO check if RpcStatus.Successful is really expected here
94 LOG.info("RPC serviceReconfigure in progress...");
95 ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
96 return ModelMappingUtils.createCreateServiceReply(
98 common.getResponseMessage());