Add pce-constraint-mode enum in pce yang model
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / impl / ServicehandlerImpl.java
1 /*
2  * Copyright © 2017 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.servicehandler.impl;
9
10 import com.google.common.collect.ImmutableClassToInstanceMap;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.time.OffsetDateTime;
13 import java.time.ZoneOffset;
14 import java.time.format.DateTimeFormatter;
15 import java.util.Map;
16 import java.util.Optional;
17 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
18 import org.opendaylight.mdsal.binding.api.RpcProviderService;
19 import org.opendaylight.transportpce.common.OperationResult;
20 import org.opendaylight.transportpce.common.ResponseCodes;
21 import org.opendaylight.transportpce.pce.service.PathComputationService;
22 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
23 import org.opendaylight.transportpce.servicehandler.CatalogInput;
24 import org.opendaylight.transportpce.servicehandler.DowngradeConstraints;
25 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
26 import org.opendaylight.transportpce.servicehandler.ServiceInput;
27 import org.opendaylight.transportpce.servicehandler.catalog.CatalogDataStoreOperations;
28 import org.opendaylight.transportpce.servicehandler.catalog.CatalogMapper;
29 import org.opendaylight.transportpce.servicehandler.listeners.NetworkListener;
30 import org.opendaylight.transportpce.servicehandler.listeners.PceListener;
31 import org.opendaylight.transportpce.servicehandler.listeners.RendererListener;
32 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
33 import org.opendaylight.transportpce.servicehandler.service.RendererServiceWrapper;
34 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
35 import org.opendaylight.transportpce.servicehandler.validation.CatalogValidation;
36 import org.opendaylight.transportpce.servicehandler.validation.ServiceCreateValidation;
37 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
38 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PathComputationRequestOutput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.PathComputationRerouteRequestOutput;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev230925.path.computation.reroute.request.input.EndpointsBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.RpcActions;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.sdnc.request.header.SdncRequestHeaderBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.operational.mode.catalog.rev230526.operational.mode.catalog.OpenroadmOperationalModes;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.operational.mode.catalog.rev230526.operational.mode.catalog.SpecificOperationalModes;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.HardConstraints;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constraints.rev221209.routing.constraints.SoftConstraints;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddOpenroadmOperationalModesToCatalog;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddOpenroadmOperationalModesToCatalogInput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddOpenroadmOperationalModesToCatalogOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalog;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogInput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.AddSpecificOperationalModesToCatalogOutput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalActivationRequest;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalActivationRequestInput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalActivationRequestOutput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalDeactivationRequest;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalDeactivationRequestInput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalDeactivationRequestOutput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalPerformanceInfoRequest;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalPerformanceInfoRequestInput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalPerformanceInfoRequestOutput;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalPowerControl;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalPowerControlInput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EndTerminalPowerControlOutput;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EquipmentNotification;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EquipmentNotificationInput;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.EquipmentNotificationOutput;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.NetworkReOptimization;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.NetworkReOptimizationInput;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.NetworkReOptimizationOutput;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OpticalTunnelCreate;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OpticalTunnelCreateInput;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OpticalTunnelCreateOutput;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OpticalTunnelRequestCancel;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OpticalTunnelRequestCancelInput;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OpticalTunnelRequestCancelOutput;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.OrgOpenroadmServiceService;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreate;
83 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateBulk;
84 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateBulkInput;
85 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateBulkOutput;
86 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateComplexResultNotificationRequest;
87 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateComplexResultNotificationRequestInput;
88 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateComplexResultNotificationRequestOutput;
89 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateInput;
90 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateOutput;
91 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateResultNotificationRequest;
92 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateResultNotificationRequestInput;
93 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceCreateResultNotificationRequestOutput;
94 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDelete;
95 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteComplexResultNotificationRequest;
96 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteComplexResultNotificationRequestInput;
97 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteComplexResultNotificationRequestOutput;
98 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInput;
99 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInputBuilder;
100 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteOutput;
101 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteResultNotificationRequest;
102 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteResultNotificationRequestInput;
103 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteResultNotificationRequestOutput;
104 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheck;
105 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckBulk;
106 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckBulkInput;
107 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckBulkOutput;
108 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckInput;
109 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceFeasibilityCheckOutput;
110 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigure;
111 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureBulk;
112 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureBulkInput;
113 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureBulkOutput;
114 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureInput;
115 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureOutput;
116 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureResultNotificationRequest;
117 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureResultNotificationRequestInput;
118 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReconfigureResultNotificationRequestOutput;
119 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReroute;
120 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteConfirm;
121 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteConfirmInput;
122 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteConfirmOutput;
123 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteConfirmResultNotificationRequest;
124 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteConfirmResultNotificationRequestInput;
125 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteConfirmResultNotificationRequestOutput;
126 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteInput;
127 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRerouteOutput;
128 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestoration;
129 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationInput;
130 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationOutput;
131 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationResultNotificationRequest;
132 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationResultNotificationRequestInput;
133 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRestorationResultNotificationRequestOutput;
134 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReversion;
135 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReversionInput;
136 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReversionOutput;
137 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReversionResultNotificationRequest;
138 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReversionResultNotificationRequestInput;
139 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceReversionResultNotificationRequestOutput;
140 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRoll;
141 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRollInput;
142 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRollOutput;
143 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRollResultNotificationRequest;
144 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRollResultNotificationRequestInput;
145 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceRollResultNotificationRequestOutput;
146 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceSrlgGet;
147 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceSrlgGetInput;
148 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceSrlgGetOutput;
149 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreate;
150 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateBulk;
151 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateBulkInput;
152 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateBulkOutput;
153 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateInput;
154 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceCreateOutput;
155 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDelete;
156 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteInput;
157 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteOutput;
158 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.delete.input.ServiceDeleteReqInfo.TailRetention;
159 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.delete.input.ServiceDeleteReqInfoBuilder;
160 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
161 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZ;
162 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.path.description.atoz.direction.AToZKey;
163 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev230501.pce.resource.resource.resource.TerminationPoint;
164 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
165 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationProcessService;
166 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.PublishNotificationProcessServiceBuilder;
167 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service.ServiceAEndBuilder;
168 import org.opendaylight.yang.gen.v1.nbi.notifications.rev230726.notification.process.service.ServiceZEndBuilder;
169 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
170 import org.opendaylight.yangtools.concepts.Registration;
171 import org.opendaylight.yangtools.yang.binding.Rpc;
172 import org.opendaylight.yangtools.yang.common.ErrorTag;
173 import org.opendaylight.yangtools.yang.common.ErrorType;
174 import org.opendaylight.yangtools.yang.common.RpcResult;
175 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
176 import org.osgi.service.component.annotations.Activate;
177 import org.osgi.service.component.annotations.Component;
178 import org.osgi.service.component.annotations.Deactivate;
179 import org.osgi.service.component.annotations.Reference;
180 import org.slf4j.Logger;
181 import org.slf4j.LoggerFactory;
182
183
184 /**
185  * Top level service interface providing main OpenROADM controller services.
186  */
187 @Component
188 public class ServicehandlerImpl implements OrgOpenroadmServiceService {
189     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerImpl.class);
190     private static final String PUBLISHER = "ServiceHandler";
191     private static final String TEMP_SERVICE_CREATE_MSG = "tempServiceCreate: {}";
192     private static final String TEMP_SERVICE_DELETE_MSG = "tempServiceDelete: {}";
193     private static final String SERVICE_RESTORATION_MSG = "serviceRestoration: {}";
194     private static final String SERVICE_RECONFIGURE_MSG = "serviceReconfigure: {}";
195     private static final String SERVICE_FEASIBILITY_CHECK_MSG = "serviceFeasibilityCheck: {}";
196     private static final String SERVICE_DELETE_MSG = "serviceDelete: {}";
197     private static final String SERVICE_CREATE_MSG = "serviceCreate: {}";
198     private static final String ADD_OR_TO_CATALOG_MSG = "addORToCatalog: {}";
199     private static final String ADD_SPECIFIC_TO_CATALOG_MSG = "addSpecificToCatalog: {}";
200
201     private ServiceDataStoreOperations serviceDataStoreOperations;
202     private PCEServiceWrapper pceServiceWrapper;
203     private RendererServiceWrapper rendererServiceWrapper;
204     private PceListener pceListenerImpl;
205     private RendererListener rendererListenerImpl;
206     private NetworkListener networkModelListenerImpl;
207     private NotificationPublishService notificationPublishService;
208     private CatalogDataStoreOperations catalogDataStoreOperations;
209     private Registration reg;
210
211     @Activate
212     public ServicehandlerImpl(@Reference RpcProviderService rpcProviderService,
213             @Reference PathComputationService pathComputationService,
214             @Reference RendererServiceOperations rendererServiceOperations,
215             @Reference NotificationPublishService notificationPublishService,
216             @Reference PceListener pceListenerImpl,
217             @Reference RendererListener rendererListenerImpl,
218             @Reference NetworkListener networkModelListenerImpl,
219             @Reference ServiceDataStoreOperations serviceDataStoreOperations,
220             @Reference CatalogDataStoreOperations catalogDataStoreOperations) {
221         this.catalogDataStoreOperations = catalogDataStoreOperations;
222         this.serviceDataStoreOperations = serviceDataStoreOperations;
223         this.notificationPublishService =  notificationPublishService;
224         this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
225         this.rendererServiceWrapper = new RendererServiceWrapper(rendererServiceOperations, notificationPublishService);
226         this.pceListenerImpl = pceListenerImpl;
227         this.rendererListenerImpl = rendererListenerImpl;
228         this.networkModelListenerImpl = networkModelListenerImpl;
229         this.reg = rpcProviderService.registerRpcImplementations(registerRPCs());
230         LOG.info("ServicehandlerImpl Initiated");
231     }
232
233     @Deactivate
234     public void close() {
235         this.reg.close();
236         LOG.info("ServicehandlerImpl Closed");
237     }
238
239
240     // This is class is public so that these messages can be accessed from Junit (avoid duplications).
241     public static final class LogMessages {
242
243         public static final String PCE_CALLING;
244         public static final String ABORT_PCE_FAILED;
245         public static final String PCE_FAILED;
246         public static final String ABORT_SERVICE_NON_COMPLIANT;
247         public static final String SERVICE_NON_COMPLIANT;
248         public static final String RENDERER_DELETE_FAILED;
249         public static final String ABORT_VALID_FAILED;
250         public static final String ABORT_OR_TO_CATALOG_FAILED;
251         public static final String ABORT_SPECIFIC_TO_CATALOG_FAILED;
252
253         // Static blocks are generated once and spare memory.
254         static {
255             PCE_CALLING = "Calling PCE";
256             ABORT_PCE_FAILED = "Aborting: PCE calculation failed ";
257             PCE_FAILED = "PCE calculation failed";
258             ABORT_SERVICE_NON_COMPLIANT = "Aborting: non-compliant service ";
259             SERVICE_NON_COMPLIANT = "non-compliant service";
260             RENDERER_DELETE_FAILED = "Renderer service delete failed";
261             ABORT_VALID_FAILED = "Aborting: validation of service create request failed";
262             ABORT_OR_TO_CATALOG_FAILED = "Aborting: validation of add OR to catalog request failed";
263             ABORT_SPECIFIC_TO_CATALOG_FAILED = "Aborting: validation of add Specific to catalog request failed";
264         }
265
266         public static String serviceInDS(String serviceName) {
267             return "Service '" + serviceName + "' already exists in datastore";
268         }
269
270         public static String serviceNotInDS(String serviceName) {
271             return "Service '" + serviceName + "' does not exist in datastore";
272         }
273
274         public static String servicePathNotInDS(String serviceName) {
275             return "Service Path from '" + serviceName + "' does not exist in datastore";
276         }
277
278         public static String serviceInService(String serviceName) {
279             return "Service '" + serviceName + "' is in 'inService' state";
280         }
281
282         private LogMessages() {
283         }
284     }
285
286     @Override
287     public final ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
288         LOG.info("RPC serviceCreate received");
289         // Validation
290         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
291                 new ServiceInput(input), RpcActions.ServiceCreate);
292         if (!validationResult.isSuccess()) {
293             LOG.warn(SERVICE_CREATE_MSG, LogMessages.ABORT_VALID_FAILED);
294             return ModelMappingUtils.createCreateServiceReply(
295                     input, ResponseCodes.FINAL_ACK_YES,
296                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
297         }
298         //Check any presence of services with the same nameequipmentNotification
299         String serviceName = input.getServiceName();
300         if (this.serviceDataStoreOperations.getService(serviceName).isPresent()) {
301             LOG.warn(SERVICE_CREATE_MSG, LogMessages.serviceInDS(serviceName));
302             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
303                     LogMessages.serviceInDS(serviceName), ResponseCodes.RESPONSE_FAILED);
304         }
305         // TODO: Here we also have to check if there is an associated temp-service.
306         // TODO: If there is one, delete it from the temp-service-list??
307         this.pceListenerImpl.setInput(new ServiceInput(input));
308         this.pceListenerImpl.setServiceReconfigure(false);
309         this.pceListenerImpl.setTempService(false);
310         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
311         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
312         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
313         // This ensures that the temp-service boolean is false, especially, when
314         // service-create is initiated after the temp-service-create
315         this.rendererListenerImpl.setTempService(false);
316         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
317         LOG.debug(SERVICE_CREATE_MSG, LogMessages.PCE_CALLING);
318         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
319         if (output == null) {
320             LOG.warn(SERVICE_CREATE_MSG, LogMessages.ABORT_PCE_FAILED);
321             sendNbiNotification(new PublishNotificationProcessServiceBuilder()
322                     .setServiceName(serviceName)
323                     .setServiceAEnd(new ServiceAEndBuilder(input.getServiceAEnd()).build())
324                     .setServiceZEnd(new ServiceZEndBuilder(input.getServiceZEnd()).build())
325                     .setCommonId(input.getCommonId())
326                     .setConnectionType(input.getConnectionType())
327                     .setResponseFailed(LogMessages.ABORT_PCE_FAILED)
328                     .setMessage("ServiceCreate request failed ...")
329                     .setOperationalState(State.Degraded)
330                     .setPublisherName(PUBLISHER)
331                     .build());
332             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
333                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
334         }
335         LOG.info("RPC serviceCreate in progress...");
336         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
337         return ModelMappingUtils.createCreateServiceReply(
338                 input, common.getAckFinalIndicator(),
339                 common.getResponseMessage(), common.getResponseCode());
340     }
341
342     @Override
343     public final ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
344         String serviceName = input.getServiceDeleteReqInfo().getServiceName();
345         LOG.info("RPC serviceDelete request received for {}", serviceName);
346
347         /*
348          * Upon receipt of service-deleteService RPC, service header and sdnc-request
349          * header compliance are verified.
350          */
351         ComplianceCheckResult serviceHandlerCheckResult =
352             ServicehandlerComplianceCheck.check(
353                 input.getServiceDeleteReqInfo().getServiceName(),
354                 input.getSdncRequestHeader(), null, RpcActions.ServiceDelete, false, true);
355         if (!serviceHandlerCheckResult.hasPassed()) {
356             LOG.warn(SERVICE_DELETE_MSG, LogMessages.ABORT_SERVICE_NON_COMPLIANT);
357             return ModelMappingUtils.createDeleteServiceReply(
358                     input, ResponseCodes.FINAL_ACK_YES,
359                     LogMessages.SERVICE_NON_COMPLIANT, ResponseCodes.RESPONSE_FAILED);
360         }
361
362         //Check presence of service to be deleted
363         Optional<Services> serviceOpt = this.serviceDataStoreOperations.getService(serviceName);
364         Services service;
365         if (serviceOpt.isEmpty()) {
366             LOG.warn(SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(serviceName));
367             return ModelMappingUtils.createDeleteServiceReply(
368                     input, ResponseCodes.FINAL_ACK_YES,
369                     LogMessages.serviceNotInDS(serviceName), ResponseCodes.RESPONSE_FAILED);
370         }
371         service = serviceOpt.orElseThrow();
372         LOG.debug("serviceDelete: Service '{}' found in datastore", serviceName);
373         this.pceListenerImpl.setInput(new ServiceInput(input));
374         this.pceListenerImpl.setServiceReconfigure(false);
375         this.pceListenerImpl.setTempService(false);
376         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
377         this.rendererListenerImpl.setTempService(false);
378         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
379         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
380         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
381         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
382                 serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
383         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput output =
384             this.rendererServiceWrapper.performRenderer(
385                 serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, service);
386
387         if (output == null) {
388             LOG.error(SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED);
389             sendNbiNotification(new PublishNotificationProcessServiceBuilder()
390                     .setServiceName(service.getServiceName())
391                     .setServiceAEnd(new ServiceAEndBuilder(service.getServiceAEnd()).build())
392                     .setServiceZEnd(new ServiceZEndBuilder(service.getServiceZEnd()).build())
393                     .setCommonId(service.getCommonId())
394                     .setConnectionType(service.getConnectionType())
395                     .setMessage("ServiceDelete request failed ...")
396                     .setOperationalState(State.InService)
397                     .setResponseFailed(LogMessages.RENDERER_DELETE_FAILED)
398                     .setPublisherName(PUBLISHER)
399                     .build());
400             return ModelMappingUtils.createDeleteServiceReply(
401                     input, ResponseCodes.FINAL_ACK_YES,
402                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
403         }
404
405         LOG.debug("RPC serviceDelete in progress...");
406         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
407         return ModelMappingUtils.createDeleteServiceReply(
408                 input, common.getAckFinalIndicator(),
409                 common.getResponseMessage(), common.getResponseCode());
410     }
411
412     @Override
413     public final ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
414             ServiceFeasibilityCheckInput input) {
415         LOG.info("RPC serviceFeasibilityCheck received");
416         // Validation
417         ServiceInput serviceInput = new ServiceInput(input);
418         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(serviceInput,
419                 RpcActions.ServiceFeasibilityCheck);
420         if (! validationResult.isSuccess()) {
421             LOG.warn(SERVICE_FEASIBILITY_CHECK_MSG, LogMessages.ABORT_VALID_FAILED);
422             return ModelMappingUtils.createCreateServiceReply(
423                     input, ResponseCodes.FINAL_ACK_YES,
424                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
425         }
426         this.pceListenerImpl.setInput(new ServiceInput(input));
427         this.pceListenerImpl.setServiceReconfigure(false);
428         this.pceListenerImpl.setServiceFeasiblity(true);
429         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
430         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
431         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
432         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
433         LOG.debug(SERVICE_FEASIBILITY_CHECK_MSG, LogMessages.PCE_CALLING);
434         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
435         if (output == null) {
436             LOG.warn(SERVICE_FEASIBILITY_CHECK_MSG, LogMessages.ABORT_PCE_FAILED);
437             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
438                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
439         }
440         LOG.info("RPC serviceFeasibilityCheck in progress...");
441         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
442         return ModelMappingUtils.createCreateServiceReply(
443                 input, common.getAckFinalIndicator(),
444                 common.getResponseMessage(), common.getResponseCode());
445     }
446
447     @Override
448     public final ListenableFuture<RpcResult<
449             ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
450         String serviceName = input.getServiceName();
451         LOG.info("RPC serviceReconfigure received for {}", serviceName);
452         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
453         if (servicesObject.isEmpty()) {
454             LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.serviceNotInDS(serviceName));
455             return ModelMappingUtils.createCreateServiceReply(
456                 input,
457                 LogMessages.serviceNotInDS(serviceName));
458         }
459         LOG.debug("Service '{}' found in datastore", serviceName);
460         OperationResult validationResult = ServiceCreateValidation
461                 .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure);
462         if (!validationResult.isSuccess()) {
463             LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.ABORT_VALID_FAILED);
464             return ModelMappingUtils.createCreateServiceReply(
465                     input,
466                     validationResult.getResultMessage());
467         }
468         this.pceListenerImpl.setInput(new ServiceInput(input));
469         this.pceListenerImpl.setServiceReconfigure(true);
470         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
471         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
472         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
473         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
474         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
475                 .ServiceDeleteInput serviceDeleteInput =
476                         ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
477         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
478                 .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
479                         ServiceNotificationTypes.ServiceDeleteResult, null);
480         if (output == null) {
481             LOG.error(SERVICE_RECONFIGURE_MSG, LogMessages.RENDERER_DELETE_FAILED);
482             return ModelMappingUtils.createCreateServiceReply(
483                     input,
484                     LogMessages.RENDERER_DELETE_FAILED);
485                     //TODO check if RpcStatus.Successful is really expected here
486         }
487         LOG.info("RPC serviceReconfigure in progress...");
488         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
489         return ModelMappingUtils.createCreateServiceReply(
490                 input,
491                 common.getResponseMessage());
492     }
493
494     @Override
495     public final ListenableFuture<RpcResult<
496             ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
497         String serviceName = input.getServiceName();
498         LOG.info("RPC serviceRestoration received for {}", serviceName);
499         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
500
501         if (!servicesObject.isPresent()) {
502             LOG.warn(SERVICE_RESTORATION_MSG, LogMessages.serviceNotInDS(serviceName));
503             return ModelMappingUtils.createRestoreServiceReply(
504                     LogMessages.serviceNotInDS(serviceName));
505         }
506
507         Services service = servicesObject.orElseThrow();
508         State state = service.getOperationalState();
509
510         if (state == State.InService) {
511             LOG.error(SERVICE_RESTORATION_MSG, LogMessages.serviceInService(serviceName));
512             return ModelMappingUtils.createRestoreServiceReply(
513                     LogMessages.serviceInService(serviceName));
514         }
515
516         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
517         OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
518         DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
519         SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder()
520                 .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl())
521                 .setRequestId(service.getSdncRequestHeader().getRequestId())
522                 .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId())
523                 .setRpcAction(RpcActions.ServiceDelete);
524         ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder()
525                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
526                     .setServiceName(serviceName)
527                     .setDueDate(datetime)
528                     .setTailRetention(TailRetention.No).build())
529                 .setSdncRequestHeader(sdncBuilder.build());
530         ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build());
531         serviceInput.setServiceAEnd(service.getServiceAEnd());
532         serviceInput.setServiceZEnd(service.getServiceZEnd());
533         serviceInput.setConnectionType(service.getConnectionType());
534         HardConstraints hardConstraints = service.getHardConstraints();
535         if (hardConstraints == null) {
536             LOG.warn("service '{}' HardConstraints is not set !", serviceName);
537         } else {
538             SoftConstraints softConstraints = service.getSoftConstraints();
539             if (softConstraints == null) {
540                 LOG.warn("service '{}' SoftConstraints is not set !", serviceName);
541                 serviceInput.setSoftConstraints(DowngradeConstraints.convertToSoftConstraints(hardConstraints));
542             } else {
543                 LOG.info("converting hard constraints to soft constraints ...");
544                 serviceInput.setSoftConstraints(
545                         DowngradeConstraints.updateSoftConstraints(hardConstraints, softConstraints));
546             }
547             serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints));
548         }
549         this.pceListenerImpl.setInput(serviceInput);
550         this.pceListenerImpl.setServiceReconfigure(true);
551         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
552         this.rendererListenerImpl.setServiceInput(serviceInput);
553         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
554         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
555         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
556             .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
557                     new ServiceInput(deleteInputBldr.build()));
558         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915
559             .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
560                 ServiceNotificationTypes.ServiceDeleteResult, null);
561         if (output == null) {
562             LOG.error(SERVICE_RESTORATION_MSG, LogMessages.RENDERER_DELETE_FAILED);
563             return ModelMappingUtils.createRestoreServiceReply(LogMessages.RENDERER_DELETE_FAILED);
564         }
565         LOG.info("RPC serviceRestore in progress...");
566         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
567         return ModelMappingUtils.createRestoreServiceReply(common.getResponseMessage());
568
569     }
570
571     @Override
572     public final ListenableFuture<RpcResult<EquipmentNotificationOutput>>
573             equipmentNotification(EquipmentNotificationInput input) {
574         // TODO Auto-generated method stub
575         return RpcResultBuilder.<EquipmentNotificationOutput>failed()
576             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
577             .buildFuture();
578     }
579
580     @Override
581     public final ListenableFuture<RpcResult<ServiceRerouteConfirmOutput>>
582             serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
583         // TODO Auto-generated method stub
584         return RpcResultBuilder.<ServiceRerouteConfirmOutput>failed()
585             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
586             .buildFuture();
587     }
588
589     @Override
590     public final ListenableFuture<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
591         String serviceName = input.getServiceName();
592         LOG.info("RPC serviceReroute received for {}", serviceName);
593         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
594         if (servicesObject.isEmpty()) {
595             LOG.warn("serviceReroute: {}", LogMessages.serviceNotInDS(serviceName));
596             return ModelMappingUtils.createRerouteServiceReply(
597                     input, ResponseCodes.FINAL_ACK_YES,
598                     LogMessages.serviceNotInDS(serviceName),
599                     ResponseCodes.RESPONSE_FAILED);
600         }
601         Services service = servicesObject.orElseThrow();
602         Optional<ServicePaths> servicePathsObject = this.serviceDataStoreOperations.getServicePath(serviceName);
603         if (servicePathsObject.isEmpty()) {
604             LOG.warn("serviceReroute: {}", LogMessages.servicePathNotInDS(serviceName));
605             return ModelMappingUtils.createRerouteServiceReply(
606                     input, ResponseCodes.FINAL_ACK_YES,
607                     LogMessages.servicePathNotInDS(serviceName),
608                     ResponseCodes.RESPONSE_FAILED);
609         }
610         ServicePaths servicePaths = servicePathsObject.orElseThrow();
611         // serviceInput for later use maybe...
612         ServiceInput serviceInput = new ServiceInput(input);
613         serviceInput.setServiceAEnd(service.getServiceAEnd());
614         serviceInput.setServiceZEnd(service.getServiceZEnd());
615         serviceInput.setConnectionType(service.getConnectionType());
616         serviceInput.setCommonId(service.getCommonId());
617         serviceInput.setHardConstraints(service.getHardConstraints());
618         serviceInput.setSoftConstraints(service.getSoftConstraints());
619         serviceInput.setCustomer(service.getCustomer());
620         serviceInput.setCustomerContact(service.getCustomerContact());
621
622         // Get the network xpdr termination points
623         Map<AToZKey, AToZ> mapaToz = servicePaths.getPathDescription().getAToZDirection().getAToZ();
624         String aendtp = ((TerminationPoint) mapaToz.get(new AToZKey(String.valueOf(mapaToz.size() - 3)))
625                 .getResource()
626                 .getResource())
627                 .getTpId();
628         String zendtp = ((TerminationPoint) mapaToz.get(new AToZKey("2"))
629                 .getResource()
630                 .getResource())
631                 .getTpId();
632
633         PathComputationRerouteRequestOutput output = this.pceServiceWrapper.performPCEReroute(
634                 service.getHardConstraints(), service.getSoftConstraints(), input.getSdncRequestHeader(),
635                 service.getServiceAEnd(), service.getServiceZEnd(),
636                 new EndpointsBuilder().setAEndTp(aendtp).setZEndTp(zendtp).build());
637
638         if (output == null) {
639             LOG.error("serviceReroute: {}", LogMessages.PCE_FAILED);
640             return ModelMappingUtils.createRerouteServiceReply(
641                     input, ResponseCodes.FINAL_ACK_YES,
642                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
643         }
644         LOG.info("RPC ServiceReroute is done");
645         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
646         return ModelMappingUtils.createRerouteServiceReply(input, common.getAckFinalIndicator(),
647                 common.getResponseMessage(), common.getResponseCode());
648     }
649
650     @Override
651     public final ListenableFuture<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
652         // TODO Auto-generated method stub
653         return RpcResultBuilder.<ServiceReversionOutput>failed()
654             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
655             .buildFuture();
656     }
657
658     @Override
659     public final ListenableFuture<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
660         // TODO Auto-generated method stub
661         return RpcResultBuilder.<ServiceRollOutput>failed()
662             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
663             .buildFuture();
664     }
665
666     @Override
667     public final ListenableFuture<RpcResult<NetworkReOptimizationOutput>>
668             networkReOptimization(NetworkReOptimizationInput input) {
669         // TODO Auto-generated method stub
670         return RpcResultBuilder.<NetworkReOptimizationOutput>failed()
671             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
672             .buildFuture();
673     }
674
675     @Override
676     public final ListenableFuture<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
677         String commonId = input.getCommonId();
678         LOG.info("RPC temp serviceDelete request received for {}", commonId);
679
680         /*
681          * Upon receipt of service-deleteService RPC, service header and sdnc-request
682          * header compliance are verified.
683          */
684         LOG.debug("checking Service Compliance ...");
685         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
686                 commonId, null, null, RpcActions.ServiceDelete, false, false
687             );
688         if (!serviceHandlerCheckResult.hasPassed()) {
689             LOG.warn(TEMP_SERVICE_DELETE_MSG, LogMessages.ABORT_SERVICE_NON_COMPLIANT);
690             return ModelMappingUtils.createDeleteServiceReply(
691                     input, ResponseCodes.FINAL_ACK_YES,
692                     LogMessages.SERVICE_NON_COMPLIANT, ResponseCodes.RESPONSE_FAILED);
693         }
694
695         //Check presence of service to be deleted
696         LOG.debug("service common-id '{}' is compliant", commonId);
697         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.temp.service.list.Services>
698                 serviceOpt =
699             this.serviceDataStoreOperations.getTempService(commonId);
700         if (serviceOpt.isEmpty()) {
701             LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(commonId));
702             return ModelMappingUtils.createDeleteServiceReply(
703                     input, ResponseCodes.FINAL_ACK_YES,
704                     LogMessages.serviceNotInDS(commonId), ResponseCodes.RESPONSE_FAILED);
705         }
706         LOG.info("Service '{}' present in datastore !", commonId);
707         this.pceListenerImpl.setInput(new ServiceInput(input));
708         this.pceListenerImpl.setServiceReconfigure(false);
709         this.pceListenerImpl.setTempService(true);
710         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
711         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
712         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
713         this.rendererListenerImpl.setTempService(true);
714         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
715         org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526
716                 .temp.service.list.Services service = serviceOpt.orElseThrow();
717         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput output =
718                 this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult,
719                         service);
720         if (output == null) {
721             LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED);
722             return ModelMappingUtils.createDeleteServiceReply(
723                     input, ResponseCodes.FINAL_ACK_YES,
724                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
725         }
726         LOG.info("RPC tempServiceDelete in progress...");
727         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
728         return ModelMappingUtils.createDeleteServiceReply(
729                 input, common.getAckFinalIndicator(),
730                 common.getResponseMessage(), common.getResponseCode());
731     }
732
733     @Override
734     public final ListenableFuture<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
735         LOG.info("RPC tempServiceCreate received");
736         // Validation
737         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
738                 new ServiceInput(input), RpcActions.TempServiceCreate);
739         if (! validationResult.isSuccess()) {
740             LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.ABORT_VALID_FAILED);
741             return ModelMappingUtils.createCreateServiceReply(
742                     input, ResponseCodes.FINAL_ACK_YES,
743                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
744         }
745
746         //Check any presence of temp-service with the same commonId
747         String commonId = input.getCommonId();
748         if (this.serviceDataStoreOperations.getTempService(commonId).isPresent()) {
749             LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.serviceInDS("Temp (" + commonId + ")"));
750             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
751                     LogMessages.serviceInDS("Temp (" + commonId + ")"), ResponseCodes.RESPONSE_FAILED);
752         }
753
754         // Starting service create operation
755         LOG.debug(TEMP_SERVICE_CREATE_MSG, LogMessages.PCE_CALLING);
756         this.pceListenerImpl.setInput(new ServiceInput(input));
757         this.pceListenerImpl.setServiceReconfigure(false);
758         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
759         this.pceListenerImpl.setTempService(true);
760         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
761         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
762         this.rendererListenerImpl.setTempService(true);
763         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
764         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
765         if (output == null) {
766             LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.ABORT_PCE_FAILED);
767             return ModelMappingUtils.createCreateServiceReply(
768                     input, ResponseCodes.FINAL_ACK_YES,
769                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
770         }
771         LOG.info("RPC tempServiceCreate in progress...");
772         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
773         return ModelMappingUtils.createCreateServiceReply(
774                 input, common.getAckFinalIndicator(),
775                 common.getResponseMessage(), common.getResponseCode());
776     }
777
778     @Override
779     public final ListenableFuture<RpcResult<
780         ServiceDeleteComplexResultNotificationRequestOutput>> serviceDeleteComplexResultNotificationRequest(
781             ServiceDeleteComplexResultNotificationRequestInput input) {
782         // TODO Auto-generated method stub
783         return RpcResultBuilder.<ServiceDeleteComplexResultNotificationRequestOutput>failed()
784             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
785             .buildFuture();
786     }
787
788     @Override
789     public final ListenableFuture<RpcResult<
790         ServiceCreateResultNotificationRequestOutput>> serviceCreateResultNotificationRequest(
791             ServiceCreateResultNotificationRequestInput input) {
792         // TODO Auto-generated method stub
793         return RpcResultBuilder.<ServiceCreateResultNotificationRequestOutput>failed()
794             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
795             .buildFuture();
796     }
797
798     @Override
799     public final ListenableFuture<RpcResult<
800         ServiceDeleteResultNotificationRequestOutput>> serviceDeleteResultNotificationRequest(
801             ServiceDeleteResultNotificationRequestInput input) {
802         // TODO Auto-generated method stub
803         return RpcResultBuilder.<ServiceDeleteResultNotificationRequestOutput>failed()
804             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
805             .buildFuture();
806     }
807
808     @Override
809     public final ListenableFuture<RpcResult<
810         ServiceCreateComplexResultNotificationRequestOutput>> serviceCreateComplexResultNotificationRequest(
811             ServiceCreateComplexResultNotificationRequestInput input) {
812         // TODO Auto-generated method stub
813         return RpcResultBuilder.<ServiceCreateComplexResultNotificationRequestOutput>failed()
814             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
815             .buildFuture();
816     }
817
818     @Override
819     public final ListenableFuture<RpcResult<ServiceFeasibilityCheckBulkOutput>> serviceFeasibilityCheckBulk(
820         ServiceFeasibilityCheckBulkInput input) {
821         // TODO Auto-generated method stub
822         return RpcResultBuilder.<ServiceFeasibilityCheckBulkOutput>failed()
823             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
824             .buildFuture();
825     }
826
827     @Override
828     public final ListenableFuture<RpcResult<ServiceCreateBulkOutput>> serviceCreateBulk(ServiceCreateBulkInput input) {
829         // TODO Auto-generated method stub
830         return RpcResultBuilder.<ServiceCreateBulkOutput>failed()
831             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
832             .buildFuture();
833     }
834
835     @Override
836     public final ListenableFuture<RpcResult<TempServiceCreateBulkOutput>> tempServiceCreateBulk(
837         TempServiceCreateBulkInput input) {
838         // TODO Auto-generated method stub
839         return RpcResultBuilder.<TempServiceCreateBulkOutput>failed()
840             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
841             .buildFuture();
842     }
843
844     @Override
845     public final ListenableFuture<RpcResult<
846         ServiceRollResultNotificationRequestOutput>> serviceRollResultNotificationRequest(
847             ServiceRollResultNotificationRequestInput input) {
848         // TODO Auto-generated method stub
849         return RpcResultBuilder.<ServiceRollResultNotificationRequestOutput>failed()
850             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
851             .buildFuture();
852     }
853
854     @Override
855     public final ListenableFuture<RpcResult<ServiceReconfigureBulkOutput>> serviceReconfigureBulk(
856         ServiceReconfigureBulkInput input) {
857         // TODO Auto-generated method stub
858         return RpcResultBuilder.<ServiceReconfigureBulkOutput>failed()
859             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
860             .buildFuture();
861     }
862
863     @Override
864     public final ListenableFuture<RpcResult<ServiceReconfigureResultNotificationRequestOutput>>
865             serviceReconfigureResultNotificationRequest(ServiceReconfigureResultNotificationRequestInput input) {
866         // TODO Auto-generated method stub
867         return RpcResultBuilder.<ServiceReconfigureResultNotificationRequestOutput>failed()
868             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
869             .buildFuture();
870     }
871
872     @Override
873     public final ListenableFuture<RpcResult<ServiceRestorationResultNotificationRequestOutput>>
874             serviceRestorationResultNotificationRequest(ServiceRestorationResultNotificationRequestInput input) {
875         // TODO Auto-generated method stub
876         return RpcResultBuilder.<ServiceRestorationResultNotificationRequestOutput>failed()
877             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
878             .buildFuture();
879     }
880
881     @Override
882     public final ListenableFuture<RpcResult<ServiceReversionResultNotificationRequestOutput>>
883             serviceReversionResultNotificationRequest(ServiceReversionResultNotificationRequestInput input) {
884         // TODO Auto-generated method stub
885         return RpcResultBuilder.<ServiceReversionResultNotificationRequestOutput>failed()
886             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
887             .buildFuture();
888     }
889
890     @Override
891     public final ListenableFuture<RpcResult<ServiceRerouteConfirmResultNotificationRequestOutput>>
892             serviceRerouteConfirmResultNotificationRequest(ServiceRerouteConfirmResultNotificationRequestInput input) {
893         // TODO Auto-generated method stub
894         return RpcResultBuilder.<ServiceRerouteConfirmResultNotificationRequestOutput>failed()
895             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
896             .buildFuture();
897     }
898
899     @Override
900     public final ListenableFuture<RpcResult<
901             OpticalTunnelCreateOutput>> opticalTunnelCreate(OpticalTunnelCreateInput input) {
902         // TODO Auto-generated method stub
903         return RpcResultBuilder.<OpticalTunnelCreateOutput>failed()
904             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
905             .buildFuture();
906     }
907
908     @Override
909     public final ListenableFuture<RpcResult<OpticalTunnelRequestCancelOutput>> opticalTunnelRequestCancel(
910             OpticalTunnelRequestCancelInput input) {
911         // TODO Auto-generated method stub
912         return RpcResultBuilder.<OpticalTunnelRequestCancelOutput>failed()
913             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
914             .buildFuture();
915     }
916
917     @Override
918     /**
919      * Implementation of the RPC to set OR  operational modes in the catalog of the controller.
920      * Semantics of the RPC is such that the information in the input replaces the full content
921      * of the OR operational modes catalog in the config data store. Incremental changes to the
922      * catalog, if required, must be done via individual PUT/POST/DELETE RESTconf APIs.
923      *
924      * @param input AddOpenroadmOperationalModesToCatalogInput to be added to Catalog
925      * @return Result of the request
926      */
927     public final ListenableFuture<RpcResult<AddOpenroadmOperationalModesToCatalogOutput>>
928         addOpenroadmOperationalModesToCatalog(AddOpenroadmOperationalModesToCatalogInput input) {
929
930         LOG.info("RPC addOpenroadmOperationalModesToCatalog in progress");
931         LOG.debug(" Input openRoadm {}", input);
932         // Validation
933         OperationResult validationResult = CatalogValidation.validateORCatalogRequest(
934                 new CatalogInput(input), RpcActions.FillCatalogWithOrOperationalModes);
935         if (! validationResult.isSuccess()) {
936             LOG.warn(ADD_OR_TO_CATALOG_MSG, LogMessages.ABORT_OR_TO_CATALOG_FAILED);
937             return ModelMappingUtils.addOpenroadmServiceReply(
938                     input, ResponseCodes.FINAL_ACK_YES,
939                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
940         }
941         LOG.info(" Request System Id {} " ,input.getSdncRequestHeader().getRequestSystemId());
942         LOG.info(" Rpc Action {} " ,input.getSdncRequestHeader().getRpcAction());
943
944         OpenroadmOperationalModes objToSave = CatalogMapper.createORModesToSave(input);
945         catalogDataStoreOperations.addOpenroadmOperationalModesToCatalog(objToSave);
946         LOG.info("RPC addOpenroadmOperationalModesToCatalog Completed");
947         return ModelMappingUtils.addOpenroadmServiceReply(input, ResponseCodes.FINAL_ACK_YES,
948                 validationResult.getResultMessage(), ResponseCodes.RESPONSE_OK);
949     }
950
951     @Override
952     /**
953      * Implementation of the RPC to set specific operational modes in the catalog of the controller.
954      * Semantics of the RPC is such that the information in the input replaces the full content
955      * of the specific operational modes catalog in the config data store. Incremental changes to the
956      * catalog, if required, must be done via individual PUT/POST/DELETE RESTconf APIs.
957      *
958      * @param input AddSpecificOperationalModesToCatalogInput to be added to Catalog
959      * @return Result of the request
960      */
961     public final ListenableFuture<RpcResult<AddSpecificOperationalModesToCatalogOutput>>
962             addSpecificOperationalModesToCatalog(AddSpecificOperationalModesToCatalogInput input) {
963
964         LOG.info("RPC addSpecificOperationalModesToCatalog in progress");
965         LOG.debug(" Input openSpecificRoadm {}", input);
966         // Validation
967         OperationResult validationResult = CatalogValidation.validateSpecificCatalogRequest(
968                 new CatalogInput(input), RpcActions.FillCatalogWithSpecificOperationalModes);
969         if (! validationResult.isSuccess()) {
970             LOG.warn(ADD_SPECIFIC_TO_CATALOG_MSG, LogMessages.ABORT_SPECIFIC_TO_CATALOG_FAILED);
971             return ModelMappingUtils.addSpecificOpenroadmServiceReply(
972                     input, ResponseCodes.FINAL_ACK_YES,
973                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
974         }
975         LOG.info(" Request System Id {} " ,input.getSdncRequestHeader().getRequestSystemId());
976         LOG.info(" Rpc Action {} " ,input.getSdncRequestHeader().getRpcAction());
977
978         SpecificOperationalModes objToSave = CatalogMapper.createSpecificModesToSave(input);
979         catalogDataStoreOperations.addSpecificOperationalModesToCatalog(objToSave);
980         LOG.info("RPC addSpecificOperationalModesToCatalog Completed");
981         return ModelMappingUtils.addSpecificOpenroadmServiceReply(input, ResponseCodes.FINAL_ACK_YES,
982                 validationResult.getResultMessage(), ResponseCodes.RESPONSE_OK);
983     }
984
985     @Override
986     public final ListenableFuture<RpcResult<ServiceSrlgGetOutput>> serviceSrlgGet(ServiceSrlgGetInput input) {
987         // TODO Auto-generated method stub
988         return RpcResultBuilder.<ServiceSrlgGetOutput>failed()
989             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
990             .buildFuture();
991     }
992
993     @Override
994     public final ListenableFuture<RpcResult<EndTerminalPerformanceInfoRequestOutput>> endTerminalPerformanceInfoRequest(
995         EndTerminalPerformanceInfoRequestInput input) {
996         // TODO Auto-generated method stub
997         return RpcResultBuilder.<EndTerminalPerformanceInfoRequestOutput>failed()
998             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
999             .buildFuture();
1000     }
1001
1002     @Override
1003     public final ListenableFuture<RpcResult<EndTerminalActivationRequestOutput>> endTerminalActivationRequest(
1004             EndTerminalActivationRequestInput input) {
1005         // TODO Auto-generated method stub
1006         return RpcResultBuilder.<EndTerminalActivationRequestOutput>failed()
1007             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
1008             .buildFuture();
1009     }
1010
1011     @Override
1012     public final ListenableFuture<RpcResult<EndTerminalDeactivationRequestOutput>> endTerminalDeactivationRequest(
1013             EndTerminalDeactivationRequestInput input) {
1014         // TODO Auto-generated method stub
1015         return RpcResultBuilder.<EndTerminalDeactivationRequestOutput>failed()
1016             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
1017             .buildFuture();
1018     }
1019
1020     @Override
1021     public final ListenableFuture<RpcResult<EndTerminalPowerControlOutput>> endTerminalPowerControl(
1022             EndTerminalPowerControlInput input) {
1023         // TODO Auto-generated method stub
1024         return RpcResultBuilder.<EndTerminalPowerControlOutput>failed()
1025             .withError(ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED, "RPC not implemented yet")
1026             .buildFuture();
1027     }
1028
1029     public Registration getRegisteredRpc() {
1030         return reg;
1031     }
1032
1033     /**
1034      * Send notification to NBI notification in order to publish message.
1035      * @param service PublishNotificationService
1036      */
1037     private void sendNbiNotification(PublishNotificationProcessService service) {
1038         try {
1039             notificationPublishService.putNotification(service);
1040         } catch (InterruptedException e) {
1041             LOG.warn("Cannot send notification to nbi", e);
1042             Thread.currentThread().interrupt();
1043         }
1044     }
1045
1046     private ImmutableClassToInstanceMap<Rpc<?, ?>> registerRPCs() {
1047         return ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
1048             .put(ServiceCreate.class, this::serviceCreate)
1049             .put(ServiceDelete.class, this::serviceDelete)
1050             .put(ServiceFeasibilityCheck.class, this::serviceFeasibilityCheck)
1051             .put(ServiceReconfigure.class, this::serviceReconfigure)
1052             .put(ServiceRestoration.class, this::serviceRestoration)
1053             .put(EquipmentNotification.class, this::equipmentNotification)
1054             .put(ServiceRerouteConfirm.class, this::serviceRerouteConfirm)
1055             .put(ServiceReroute.class, this::serviceReroute)
1056             .put(ServiceReversion.class, this::serviceReversion)
1057             .put(ServiceRoll.class, this::serviceRoll)
1058             .put(NetworkReOptimization.class, this::networkReOptimization)
1059             .put(TempServiceDelete.class, this::tempServiceDelete)
1060             .put(TempServiceCreate.class, this::tempServiceCreate)
1061             .put(ServiceDeleteComplexResultNotificationRequest.class,
1062                 this::serviceDeleteComplexResultNotificationRequest)
1063             .put(ServiceCreateResultNotificationRequest.class, this::serviceCreateResultNotificationRequest)
1064             .put(ServiceDeleteResultNotificationRequest.class, this::serviceDeleteResultNotificationRequest)
1065             .put(ServiceCreateComplexResultNotificationRequest.class,
1066                 this::serviceCreateComplexResultNotificationRequest)
1067             .put(ServiceFeasibilityCheckBulk.class, this::serviceFeasibilityCheckBulk)
1068             .put(ServiceCreateBulk.class, this::serviceCreateBulk)
1069             .put(TempServiceCreateBulk.class, this::tempServiceCreateBulk)
1070             .put(ServiceRollResultNotificationRequest.class, this::serviceRollResultNotificationRequest)
1071             .put(ServiceReconfigureBulk.class, this::serviceReconfigureBulk)
1072             .put(ServiceReconfigureResultNotificationRequest.class, this::serviceReconfigureResultNotificationRequest)
1073             .put(ServiceRestorationResultNotificationRequest.class, this::serviceRestorationResultNotificationRequest)
1074             .put(ServiceReversionResultNotificationRequest.class, this::serviceReversionResultNotificationRequest)
1075             .put(ServiceRerouteConfirmResultNotificationRequest.class,
1076                 this::serviceRerouteConfirmResultNotificationRequest)
1077             .put(OpticalTunnelCreate.class, this::opticalTunnelCreate)
1078             .put(OpticalTunnelRequestCancel.class, this::opticalTunnelRequestCancel)
1079             .put(AddOpenroadmOperationalModesToCatalog.class, this::addOpenroadmOperationalModesToCatalog)
1080             .put(AddSpecificOperationalModesToCatalog.class, this::addSpecificOperationalModesToCatalog)
1081             .put(ServiceSrlgGet.class, this::serviceSrlgGet)
1082             .put(EndTerminalPerformanceInfoRequest.class, this::endTerminalPerformanceInfoRequest)
1083             .put(EndTerminalActivationRequest.class, this::endTerminalActivationRequest)
1084             .put(EndTerminalDeactivationRequest.class, this::endTerminalDeactivationRequest)
1085             .put(EndTerminalPowerControl.class, this::endTerminalPowerControl)
1086             .build();
1087     }
1088 }
1089