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