006c360ada0da957e82be20e6a9b27d78d6de080
[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.util.concurrent.ListenableFuture;
11 import java.time.OffsetDateTime;
12 import java.time.ZoneOffset;
13 import java.time.format.DateTimeFormatter;
14 import java.util.Optional;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
17 import org.opendaylight.transportpce.common.OperationResult;
18 import org.opendaylight.transportpce.common.ResponseCodes;
19 import org.opendaylight.transportpce.pce.service.PathComputationService;
20 import org.opendaylight.transportpce.renderer.NetworkModelWavelengthService;
21 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
22 import org.opendaylight.transportpce.servicehandler.DowngradeConstraints;
23 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
24 import org.opendaylight.transportpce.servicehandler.ServiceInput;
25 import org.opendaylight.transportpce.servicehandler.listeners.PceListenerImpl;
26 import org.opendaylight.transportpce.servicehandler.listeners.RendererListenerImpl;
27 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
28 import org.opendaylight.transportpce.servicehandler.service.RendererServiceWrapper;
29 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
30 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
31 import org.opendaylight.transportpce.servicehandler.validation.ServiceCreateValidation;
32 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
33 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev200128.PathComputationRequestOutput;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.RpcActions;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.sdnc.request.header.SdncRequestHeaderBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev181130.State;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev190531.RpcStatus;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.HardConstraints;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev190329.routing.constraints.SoftConstraints;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.EquipmentNotificationInput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.EquipmentNotificationOutput;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.NetworkReOptimizationInput;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.NetworkReOptimizationOutput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.OrgOpenroadmServiceService;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateComplexResultNotificationRequestInput;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateComplexResultNotificationRequestOutput;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateOutput;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateResultNotificationRequestInput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceCreateResultNotificationRequestOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteComplexResultNotificationRequestInput;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteComplexResultNotificationRequestOutput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInputBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteOutput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteResultNotificationRequestInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteResultNotificationRequestOutput;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckBulkInput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckBulkOutput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckInput;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceFeasibilityCheckOutput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureInput;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReconfigureOutput;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteConfirmInput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteConfirmOutput;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteInput;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRerouteOutput;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationInput;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRestorationOutput;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReversionInput;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceReversionOutput;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRollInput;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceRollOutput;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateInput;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceCreateOutput;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInput;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteOutput;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.delete.input.ServiceDeleteReqInfo.TailRetention;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.delete.input.ServiceDeleteReqInfoBuilder;
83 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.service.list.Services;
84 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
85 import org.opendaylight.yangtools.yang.common.RpcResult;
86 import org.slf4j.Logger;
87 import org.slf4j.LoggerFactory;
88
89
90 /**
91  * Top level service interface providing main OpenROADM controller services.
92  */
93 public class ServicehandlerImpl implements OrgOpenroadmServiceService {
94
95     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerImpl.class);
96
97     private DataBroker db;
98     private ServiceDataStoreOperations serviceDataStoreOperations;
99     private PCEServiceWrapper pceServiceWrapper;
100     private RendererServiceWrapper rendererServiceWrapper;
101     private PceListenerImpl pceListenerImpl;
102     private RendererListenerImpl rendererListenerImpl;
103
104     //TODO: remove private request fields as they are in global scope
105
106     public ServicehandlerImpl(DataBroker databroker, PathComputationService pathComputationService,
107             RendererServiceOperations rendererServiceOperations, NotificationPublishService notificationPublishService,
108             PceListenerImpl pceListenerImpl, RendererListenerImpl rendererListenerImpl,
109             NetworkModelWavelengthService networkModelWavelengthService) {
110         this.db = databroker;
111         this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.db);
112         this.serviceDataStoreOperations.initialize();
113         this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService, notificationPublishService);
114         this.rendererServiceWrapper = new RendererServiceWrapper(rendererServiceOperations, notificationPublishService);
115         this.pceListenerImpl = pceListenerImpl;
116         this.rendererListenerImpl = rendererListenerImpl;
117     }
118
119
120     // This is class is public so that these messages can be accessed from Junit (avoid duplications).
121     public static final class LogMessages {
122
123         public static final String PCE_CALLING;
124         public static final String ABORT_PCE_FAILED;
125         public static final String PCE_FAILED;
126         public static final String ABORT_SERVICE_NON_COMPLIANT;
127         public static final String SERVICE_NON_COMPLIANT;
128         public static final String RENDERER_DELETE_FAILED;
129         public static final String ABORT_VALID_FAILED;
130
131         // Static blocks are generated once and spare memory.
132         static {
133             PCE_CALLING = "Calling PCE";
134             ABORT_PCE_FAILED = "Aborting: PCE calculation failed ";
135             PCE_FAILED = "PCE calculation failed";
136             ABORT_SERVICE_NON_COMPLIANT = "Aborting: non-compliant service ";
137             SERVICE_NON_COMPLIANT = "non-compliant service";
138             RENDERER_DELETE_FAILED = "Renderer service delete failed";
139             ABORT_VALID_FAILED = "Aborting: validation of service create request failed";
140         }
141
142         public static String serviceNotInDS(String serviceName) {
143             return "Service '" + serviceName + "' does not exist in datastore";
144         }
145
146         public static String serviceInService(String serviceName) {
147             return "Service '" + serviceName + "' is in 'inService' state";
148         }
149
150         private LogMessages() {
151         }
152     }
153
154     @Override
155     public ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
156         LOG.info("RPC serviceCreate received");
157         // Validation
158         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
159                 new ServiceInput(input), RpcActions.ServiceCreate);
160         if (! validationResult.isSuccess()) {
161             LOG.warn("serviceCreate: {}", LogMessages.ABORT_VALID_FAILED);
162             return ModelMappingUtils.createCreateServiceReply(
163                     input, ResponseCodes.FINAL_ACK_YES,
164                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
165         }
166         this.pceListenerImpl.setInput(new ServiceInput(input));
167         this.pceListenerImpl.setServiceReconfigure(false);
168         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
169         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
170         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
171         LOG.debug("serviceCreate: {}", LogMessages.PCE_CALLING);
172         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
173         if (output == null) {
174             LOG.warn("serviceCreate: {}", LogMessages.ABORT_PCE_FAILED);
175             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
176                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
177         }
178         LOG.info("RPC serviceCreate in progress...");
179         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
180         return ModelMappingUtils.createCreateServiceReply(
181                 input, common.getAckFinalIndicator(),
182                 common.getResponseMessage(), common.getResponseCode());
183     }
184
185     @Override
186     public ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
187         String serviceName = input.getServiceDeleteReqInfo().getServiceName();
188         LOG.info("RPC serviceDelete request received for {}", serviceName);
189
190         /*
191          * Upon receipt of service-deleteService RPC, service header and sdnc-request
192          * header compliance are verified.
193          */
194         ComplianceCheckResult serviceHandlerCheckResult =
195             ServicehandlerComplianceCheck.check(
196                 input.getServiceDeleteReqInfo().getServiceName(),
197                 input.getSdncRequestHeader(), null, RpcActions.ServiceDelete, false, true);
198         if (!serviceHandlerCheckResult.hasPassed()) {
199             LOG.warn("serviceDelete: {}", LogMessages.ABORT_SERVICE_NON_COMPLIANT);
200             return ModelMappingUtils.createDeleteServiceReply(
201                     input, ResponseCodes.FINAL_ACK_YES,
202                     LogMessages.SERVICE_NON_COMPLIANT, ResponseCodes.RESPONSE_FAILED);
203         }
204
205         //Check presence of service to be deleted
206 //TODO check if an expected bug was justifying this NPE handling
207 //        try {
208         Optional<Services> service = this.serviceDataStoreOperations.getService(serviceName);
209 //        } catch (NullPointerException e) {
210 //            LOG.error("Something wrong when retrieving service '{}' from datastore : ", serviceName, e);
211 //            return ModelMappingUtils.createDeleteServiceReply(
212 //                    input, ResponseCodes.FINAL_ACK_YES,
213 //                    LogMessages.serviceNotInDS(serviceName), ResponseCodes.RESPONSE_FAILED);
214 //        }
215         if (!service.isPresent()) {
216             LOG.warn("serviceDelete: {}", LogMessages.serviceNotInDS(serviceName));
217             return ModelMappingUtils.createDeleteServiceReply(
218                     input, ResponseCodes.FINAL_ACK_YES,
219                     LogMessages.serviceNotInDS(serviceName), ResponseCodes.RESPONSE_FAILED);
220         }
221         LOG.debug("serviceDelete: Service '{}' found in datastore", serviceName);
222         this.pceListenerImpl.setInput(new ServiceInput(input));
223         this.pceListenerImpl.setServiceReconfigure(false);
224         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
225         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
226         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
227         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
228                 .ServiceDeleteInput serviceDeleteInput =
229             ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
230         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutput output =
231             this.rendererServiceWrapper.performRenderer(
232                 serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult);
233
234         if (output == null) {
235             LOG.error("serviceDelete: {}", LogMessages.RENDERER_DELETE_FAILED);
236             return ModelMappingUtils.createDeleteServiceReply(
237                     input, ResponseCodes.FINAL_ACK_YES,
238                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
239         }
240
241         LOG.debug("RPC serviceDelete in progress...");
242         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
243         return ModelMappingUtils.createDeleteServiceReply(
244                 input, common.getAckFinalIndicator(),
245                 common.getResponseMessage(), common.getResponseCode());
246     }
247
248     @Override
249     public ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
250             ServiceFeasibilityCheckInput input) {
251         LOG.info("RPC serviceFeasibilityCheck received");
252         // Validation
253         ServiceInput serviceInput = new ServiceInput(input);
254         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(serviceInput,
255                 RpcActions.ServiceFeasibilityCheck);
256         if (! validationResult.isSuccess()) {
257             LOG.warn("serviceFeasabilityCheck: {}", LogMessages.ABORT_VALID_FAILED);
258             return ModelMappingUtils.createCreateServiceReply(
259                     input, ResponseCodes.FINAL_ACK_YES,
260                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
261         }
262         this.pceListenerImpl.setInput(new ServiceInput(input));
263         this.pceListenerImpl.setServiceReconfigure(false);
264         this.pceListenerImpl.setServiceFeasiblity(true);
265         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
266         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
267         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
268         LOG.debug("serviceFeasabilityCheck: {}", LogMessages.PCE_CALLING);
269         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
270         if (output == null) {
271             LOG.warn("serviceFeasabilityCheck: {}", LogMessages.ABORT_PCE_FAILED);
272             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
273                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
274         }
275         LOG.info("RPC serviceFeasibilityCheck in progress...");
276         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
277         return ModelMappingUtils.createCreateServiceReply(
278                 input, common.getAckFinalIndicator(),
279                 common.getResponseMessage(), common.getResponseCode());
280     }
281
282     @Override
283     public ListenableFuture<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
284         String serviceName = input.getServiceName();
285         LOG.info("RPC serviceReconfigure received for {}", serviceName);
286         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
287         if (!servicesObject.isPresent()) {
288             LOG.warn("serviceReconfigure: {}", LogMessages.serviceNotInDS(serviceName));
289             return ModelMappingUtils.createCreateServiceReply(
290                 input,
291                 LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
292         }
293         LOG.debug("Service '{}' found in datastore", serviceName);
294         OperationResult validationResult = ServiceCreateValidation
295                 .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure);
296         if (!validationResult.isSuccess()) {
297             LOG.warn("serviceReconfigure: {}", LogMessages.ABORT_VALID_FAILED);
298             return ModelMappingUtils.createCreateServiceReply(
299                     input,
300                     validationResult.getResultMessage(), RpcStatus.Failed);
301         }
302         this.pceListenerImpl.setInput(new ServiceInput(input));
303         this.pceListenerImpl.setServiceReconfigure(true);
304         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
305         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
306         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
307         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
308                 .ServiceDeleteInput serviceDeleteInput =
309                         ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
310         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
311                 .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
312                         ServiceNotificationTypes.ServiceDeleteResult);
313         if (output == null) {
314             LOG.error("serviceReconfigure: {}", LogMessages.RENDERER_DELETE_FAILED);
315             return ModelMappingUtils.createCreateServiceReply(
316                     input,
317                     LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Successful);
318                     //TODO check if RpcStatus.Successful is really expected here
319         }
320         LOG.info("RPC serviceReconfigure in progress...");
321         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
322         return ModelMappingUtils.createCreateServiceReply(
323                 input,
324                 common.getResponseMessage(), RpcStatus.Successful);
325     }
326
327     @Override
328     public ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
329         String serviceName = input.getServiceName();
330         LOG.info("RPC serviceRestoration received for {}", serviceName);
331         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
332
333         if (!servicesObject.isPresent()) {
334             LOG.warn("serviceRestoration: {}", LogMessages.serviceNotInDS(serviceName));
335             return ModelMappingUtils.createRestoreServiceReply(
336                     LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
337         }
338
339         Services service = servicesObject.get();
340         State state = service.getOperationalState();
341
342         if (state == State.InService) {
343             LOG.error("serviceRestoration: {}", LogMessages.serviceInService(serviceName));
344             return ModelMappingUtils.createRestoreServiceReply(
345                     LogMessages.serviceInService(serviceName), RpcStatus.Failed);
346         }
347
348         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
349         OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
350         DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
351         SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder()
352                 .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl())
353                 .setRequestId(service.getSdncRequestHeader().getRequestId())
354                 .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId())
355                 .setRpcAction(RpcActions.ServiceDelete);
356         ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder()
357                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
358                     .setServiceName(serviceName)
359                     .setDueDate(datetime)
360                     .setTailRetention(TailRetention.No).build())
361                 .setSdncRequestHeader(sdncBuilder.build());
362         ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build());
363         serviceInput.setServiceAEnd(service.getServiceAEnd());
364         serviceInput.setServiceZEnd(service.getServiceZEnd());
365         serviceInput.setConnectionType(service.getConnectionType());
366         HardConstraints hardConstraints = service.getHardConstraints();
367         if (hardConstraints == null) {
368             LOG.warn("service '{}' HardConstraints is not set !", serviceName);
369         } else {
370             SoftConstraints softConstraints = service.getSoftConstraints();
371             if (softConstraints == null) {
372                 LOG.warn("service '{}' SoftConstraints is not set !", serviceName);
373                 serviceInput.setSoftConstraints(DowngradeConstraints.convertToSoftConstraints(hardConstraints));
374                 serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints));
375             } else {
376                 LOG.info("converting hard constraints to soft constraints ...");
377                 serviceInput.setSoftConstraints(
378                         DowngradeConstraints.updateSoftConstraints(hardConstraints, softConstraints));
379                 serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints));
380             }
381         }
382         this.pceListenerImpl.setInput(serviceInput);
383         this.pceListenerImpl.setServiceReconfigure(true);
384         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
385         this.rendererListenerImpl.setServiceInput(serviceInput);
386         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
387         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
388             .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
389                     new ServiceInput(deleteInputBldr.build()));
390         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
391             .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
392                 ServiceNotificationTypes.ServiceDeleteResult);
393         if (output == null) {
394             LOG.error("serviceRestoration: {}", LogMessages.RENDERER_DELETE_FAILED);
395             return ModelMappingUtils.createRestoreServiceReply(
396                      LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Failed);
397         }
398         LOG.info("RPC serviceRestore in progress...");
399         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
400         return ModelMappingUtils.createRestoreServiceReply(
401                 common.getResponseMessage(), RpcStatus.Successful);
402
403     }
404
405     @Override
406     public ListenableFuture<RpcResult<EquipmentNotificationOutput>>
407             equipmentNotification(EquipmentNotificationInput input) {
408         // TODO Auto-generated method stub
409         return null;
410     }
411
412     @Override
413     public ListenableFuture<RpcResult<ServiceRerouteConfirmOutput>>
414             serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
415         // TODO Auto-generated method stub
416         return null;
417     }
418
419     @Override
420     public ListenableFuture<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
421         String serviceName = input.getServiceName();
422         LOG.info("RPC serviceReroute received for {}", serviceName);
423         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
424         if (!servicesObject.isPresent()) {
425             LOG.warn("serviceReroute: {}", LogMessages.serviceNotInDS(serviceName));
426             return ModelMappingUtils.createRerouteServiceReply(
427                     input, ResponseCodes.FINAL_ACK_NO,
428                     LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
429         }
430         Services service = servicesObject.get();
431         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
432         OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
433         DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
434         SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder()
435                 .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl())
436                 .setRequestId(service.getSdncRequestHeader().getRequestId())
437                 .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId())
438                 .setRpcAction(RpcActions.ServiceDelete);
439         ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder()
440                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
441                     .setServiceName(serviceName).setDueDate(datetime)
442                     .setTailRetention(TailRetention.No).build())
443                 .setSdncRequestHeader(sdncBuilder.build());
444         ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build());
445         serviceInput.setServiceAEnd(service.getServiceAEnd());
446         serviceInput.setServiceZEnd(service.getServiceZEnd());
447         serviceInput.setConnectionType(service.getConnectionType());
448         this.pceListenerImpl.setInput(serviceInput);
449         this.pceListenerImpl.setServiceReconfigure(true);
450         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
451         this.rendererListenerImpl.setServiceInput(serviceInput);
452         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
453         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
454             .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
455                     new ServiceInput(deleteInputBldr.build()));
456         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
457             .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
458                 ServiceNotificationTypes.ServiceDeleteResult);
459         if (output == null) {
460             LOG.error("serviceReroute: {}", LogMessages.RENDERER_DELETE_FAILED);
461             return ModelMappingUtils.createRerouteServiceReply(
462                     input, ResponseCodes.FINAL_ACK_YES,
463                     LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Failed);
464         }
465         LOG.info("RPC ServiceReroute in progress...");
466         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
467         return ModelMappingUtils.createRerouteServiceReply(
468                 input, common.getAckFinalIndicator(),
469                 common.getResponseMessage(), RpcStatus.Successful);
470     }
471
472     @Override
473     public ListenableFuture<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
474         // TODO Auto-generated method stub
475         return null;
476     }
477
478     @Override
479     public ListenableFuture<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
480         // TODO Auto-generated method stub
481         return null;
482     }
483
484     @Override
485     public ListenableFuture<RpcResult<NetworkReOptimizationOutput>>
486             networkReOptimization(NetworkReOptimizationInput input) {
487         // TODO Auto-generated method stub
488         return null;
489     }
490
491     @Override
492     public ListenableFuture<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
493         String commonId = input.getCommonId();
494         LOG.info("RPC temp serviceDelete request received for {}", commonId);
495
496         /*
497          * Upon receipt of service-deleteService RPC, service header and sdnc-request
498          * header compliancy are verified.
499          */
500         LOG.debug("checking Service Compliance ...");
501         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
502                 commonId, null, null, RpcActions.ServiceDelete, false, false
503             );
504         if (!serviceHandlerCheckResult.hasPassed()) {
505             LOG.warn("tempServiceDelete: {}", LogMessages.ABORT_SERVICE_NON_COMPLIANT);
506             return ModelMappingUtils.createDeleteServiceReply(
507                     input, ResponseCodes.FINAL_ACK_YES,
508                     LogMessages.SERVICE_NON_COMPLIANT, ResponseCodes.RESPONSE_FAILED);
509         }
510
511         //Check presence of service to be deleted
512         LOG.debug("service common-id '{}' is compliant", commonId);
513 //TODO check if an expected bug was justifying this NPE handling
514 //        try {
515         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list.Services>
516                 service =
517             this.serviceDataStoreOperations.getTempService(commonId);
518 //        } catch (NullPointerException e) {
519 //            LOG.info("failed to get service '{}' from datastore : ", commonId, e);
520 //            return ModelMappingUtils.createDeleteServiceReply(
521 //                    input, ResponseCodes.FINAL_ACK_YES,
522 //                    LogMessages.serviceNotInDS(CommonId), ResponseCodes.RESPONSE_FAILED);
523 //        }
524         if (!service.isPresent()) {
525             LOG.error("tempServiceDelete: {}", LogMessages.serviceNotInDS(commonId));
526             return ModelMappingUtils.createDeleteServiceReply(
527                     input, ResponseCodes.FINAL_ACK_YES,
528                     LogMessages.serviceNotInDS(commonId), ResponseCodes.RESPONSE_FAILED);
529         }
530
531         LOG.info("Service '{}' present in datastore !", commonId);
532         this.pceListenerImpl.setInput(new ServiceInput(input));
533         this.pceListenerImpl.setServiceReconfigure(false);
534         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
535         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
536         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
537         this.rendererListenerImpl.setTempService(true);
538         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutput output =
539                 this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
540         if (output == null) {
541             LOG.error("tempServiceDelete: {}", LogMessages.RENDERER_DELETE_FAILED);
542             return ModelMappingUtils.createDeleteServiceReply(
543                     input, ResponseCodes.FINAL_ACK_YES,
544                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
545         }
546         LOG.info("RPC tempServiceDelete in progress...");
547         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
548         return ModelMappingUtils.createDeleteServiceReply(
549                 input, common.getAckFinalIndicator(),
550                 common.getResponseMessage(), common.getResponseCode());
551     }
552
553     @Override
554     public ListenableFuture<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
555         LOG.info("RPC tempServiceCreate received");
556         // Validation
557         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
558                 new ServiceInput(input), RpcActions.TempServiceCreate);
559         if (! validationResult.isSuccess()) {
560             LOG.warn("tempServiceCreate: {}", LogMessages.ABORT_VALID_FAILED);
561             return ModelMappingUtils.createCreateServiceReply(
562                     input, ResponseCodes.FINAL_ACK_YES,
563                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
564         }
565
566         // Starting service create operation
567         LOG.debug("tempServiceCreate: {}", LogMessages.PCE_CALLING);
568         this.pceListenerImpl.setInput(new ServiceInput(input));
569         this.pceListenerImpl.setServiceReconfigure(false);
570         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
571         this.pceListenerImpl.setTempService(true);
572         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
573         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
574         this.rendererListenerImpl.setTempService(true);
575         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
576         if (output == null) {
577             LOG.warn("tempServiceCreate: {}", LogMessages.ABORT_PCE_FAILED);
578             return ModelMappingUtils.createCreateServiceReply(
579                     input, ResponseCodes.FINAL_ACK_YES,
580                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
581         }
582         LOG.info("RPC tempServiceCreate in progress...");
583         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
584         return ModelMappingUtils.createCreateServiceReply(
585                 input, common.getAckFinalIndicator(),
586                 common.getResponseMessage(), common.getResponseCode());
587     }
588
589     @Override
590     public ListenableFuture<RpcResult<
591         ServiceDeleteComplexResultNotificationRequestOutput>> serviceDeleteComplexResultNotificationRequest(
592             ServiceDeleteComplexResultNotificationRequestInput input) {
593         // TODO Auto-generated method stub
594         return null;
595     }
596
597     @Override
598     public ListenableFuture<RpcResult<
599         ServiceCreateResultNotificationRequestOutput>> serviceCreateResultNotificationRequest(
600             ServiceCreateResultNotificationRequestInput input) {
601         // TODO Auto-generated method stub
602         return null;
603     }
604
605     @Override
606     public ListenableFuture<RpcResult<
607         ServiceDeleteResultNotificationRequestOutput>> serviceDeleteResultNotificationRequest(
608             ServiceDeleteResultNotificationRequestInput input) {
609         // TODO Auto-generated method stub
610         return null;
611     }
612
613     @Override
614     public ListenableFuture<RpcResult<
615         ServiceCreateComplexResultNotificationRequestOutput>> serviceCreateComplexResultNotificationRequest(
616             ServiceCreateComplexResultNotificationRequestInput input) {
617         // TODO Auto-generated method stub
618         return null;
619     }
620
621     @Override
622     public ListenableFuture<RpcResult<ServiceFeasibilityCheckBulkOutput>> serviceFeasibilityCheckBulk(
623         ServiceFeasibilityCheckBulkInput input) {
624         // TODO Auto-generated method stub
625         return null;
626     }
627
628 }