fix import extra separations
[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.ServicehandlerCompliancyCheck;
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     @Override
120     public ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
121         LOG.info("RPC service creation received");
122         // Validation
123         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
124                 new ServiceInput(input), RpcActions.ServiceCreate);
125         if (! validationResult.isSuccess()) {
126             LOG.warn("Aborting service create because validation of service create request failed: {}",
127                     validationResult.getResultMessage());
128             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
129                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
130         }
131         this.pceListenerImpl.setInput(new ServiceInput(input));
132         this.pceListenerImpl.setServiceReconfigure(false);
133         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
134         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
135         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
136         LOG.info("Commencing PCE");
137         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
138         if (output != null) {
139             LOG.info("Service compliant, serviceCreate in progress...");
140             ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
141             return ModelMappingUtils.createCreateServiceReply(input, common.getAckFinalIndicator(),
142                     common.getResponseMessage(), common.getResponseCode());
143         } else {
144             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
145                     "PCE calculation failed", ResponseCodes.RESPONSE_FAILED);
146         }
147     }
148
149     @Override
150     public ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
151         LOG.info("RPC serviceDelete request received for {}", input.getServiceDeleteReqInfo().getServiceName());
152         String message = "";
153
154         /*
155          * Upon receipt of service-deleteService RPC, service header and sdnc-request
156          * header compliancy are verified.
157          */
158         LOG.info("checking Service Compliancy ...");
159         ComplianceCheckResult serviceHandlerCheckResult =
160             ServicehandlerCompliancyCheck.check(
161                 input.getServiceDeleteReqInfo().getServiceName(),
162                 input.getSdncRequestHeader(), null, RpcActions.ServiceDelete, false, true);
163         if (serviceHandlerCheckResult.hasPassed()) {
164             LOG.info("Service compliant !");
165         } else {
166             LOG.info("Service is not compliant !");
167             return ModelMappingUtils
168                     .createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
169                             "Service not compliant !", ResponseCodes.RESPONSE_FAILED);
170         }
171
172         //Check presence of service to be deleted
173         String serviceName = input.getServiceDeleteReqInfo().getServiceName();
174         LOG.info("serviceName : {}", serviceName);
175         try {
176             Optional<Services> service = this.serviceDataStoreOperations.getService(serviceName);
177             if (!service.isPresent()) {
178                 message = "Service '" + serviceName + "' does not exist in datastore";
179                 LOG.error(message);
180                 return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
181                         message, ResponseCodes.RESPONSE_FAILED);
182             }
183         } catch (NullPointerException e) {
184             LOG.error("failed to get service '{}' from datastore : ", serviceName, e);
185             message = "Service '" + serviceName + "' does not exist in datastore";
186             LOG.error(message);
187             return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
188                     ResponseCodes.RESPONSE_FAILED);
189         }
190         LOG.info("Service '{}' present in datastore !", serviceName);
191         this.pceListenerImpl.setInput(new ServiceInput(input));
192         this.pceListenerImpl.setServiceReconfigure(false);
193         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
194         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
195         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
196         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
197             .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
198                     new ServiceInput(input));
199         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput output =
200                 this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
201                 ServiceNotificationTypes.ServiceDeleteResult);
202         if (output != null) {
203             LOG.info("Service present in datastore, service-delete in progress...");
204             ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
205             return ModelMappingUtils.createDeleteServiceReply(input, common.getAckFinalIndicator(),
206                     common.getResponseMessage(), common.getResponseCode());
207         } else {
208             return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
209                     "Renderer service delete failed !", ResponseCodes.RESPONSE_FAILED);
210         }
211     }
212
213     @Override
214     public ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
215             ServiceFeasibilityCheckInput input) {
216         LOG.info("RPC service feasibility check received");
217         // Validation
218         ServiceInput serviceInput = new ServiceInput(input);
219         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(serviceInput,
220                 RpcActions.ServiceFeasibilityCheck);
221         if (! validationResult.isSuccess()) {
222             LOG.warn("Aborting service feasibility check because validation of service create request failed: {}",
223                     validationResult.getResultMessage());
224             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
225                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
226         }
227         this.pceListenerImpl.setInput(new ServiceInput(input));
228         this.pceListenerImpl.setServiceReconfigure(false);
229         this.pceListenerImpl.setServiceFeasiblity(true);
230         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
231         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
232         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
233         LOG.info("Commencing PCE");
234         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
235         if (output != null) {
236             LOG.info("Service compliant, serviceFeasibilityCheck in progress...");
237             ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
238             return ModelMappingUtils.createCreateServiceReply(input, common.getAckFinalIndicator(),
239                     common.getResponseMessage(), common.getResponseCode());
240         } else {
241             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
242                     "PCE calculation failed", ResponseCodes.RESPONSE_FAILED);
243         }
244     }
245
246     @Override
247     public ListenableFuture<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
248         LOG.info("RPC service reconfigure received");
249         String message = "";
250         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName());
251         if (servicesObject.isPresent()) {
252             LOG.info("Service '{}' is present", input.getServiceName());
253             OperationResult validationResult = ServiceCreateValidation
254                     .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure);
255             if (!validationResult.isSuccess()) {
256                 LOG.warn("Aborting service reconfigure because validation of service create request failed: {}",
257                         validationResult.getResultMessage());
258                 return ModelMappingUtils.createCreateServiceReply(input, validationResult.getResultMessage(),
259                         RpcStatus.Failed);
260             }
261             this.pceListenerImpl.setInput(new ServiceInput(input));
262             this.pceListenerImpl.setServiceReconfigure(true);
263             this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
264             this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
265             this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
266             org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
267                     .ServiceDeleteInput serviceDeleteInput =
268                             ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
269             org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
270                     .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
271                             ServiceNotificationTypes.ServiceDeleteResult);
272             if (output != null) {
273                 LOG.info("Service compliant, service reconfigure in progress...");
274                 ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
275                 return ModelMappingUtils.createCreateServiceReply(input, common.getResponseMessage(),
276                         RpcStatus.Successful);
277             } else {
278                 return ModelMappingUtils.createCreateServiceReply(input, "Renderer service delete failed !",
279                         RpcStatus.Successful);
280             }
281         } else {
282             LOG.error("Service '{}' is not present", input.getServiceName());
283             message = "Service '" + input.getServiceName() + "' is not present";
284             return ModelMappingUtils.createCreateServiceReply(input, message, RpcStatus.Failed);
285         }
286     }
287
288     @Override
289     public ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
290         LOG.info("RPC service restoration received");
291         String message = "";
292         String serviceName = input.getServiceName();
293         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
294         if (servicesObject.isPresent()) {
295             Services service = servicesObject.get();
296             State state = service.getOperationalState();
297             if (state != State.InService) {
298                 ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder();
299                 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
300                 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
301                 DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
302                 deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
303                     .setServiceName(serviceName).setDueDate(datetime)
304                     .setTailRetention(TailRetention.No).build());
305                 SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder()
306                     .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl())
307                     .setRequestId(service.getSdncRequestHeader().getRequestId())
308                     .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId())
309                     .setRpcAction(RpcActions.ServiceDelete);
310                 deleteInputBldr.setSdncRequestHeader(sdncBuilder.build());
311                 ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build());
312                 serviceInput.setServiceAEnd(service.getServiceAEnd());
313                 serviceInput.setServiceZEnd(service.getServiceZEnd());
314                 serviceInput.setConnectionType(service.getConnectionType());
315                 HardConstraints hardConstraints = service.getHardConstraints();
316                 if (hardConstraints != null) {
317                     SoftConstraints softConstraints = service.getSoftConstraints();
318                     if (softConstraints != null) {
319                         LOG.info("converting hard constraints to soft constraints ...");
320                         serviceInput.setSoftConstraints(
321                                 DowngradeConstraints.updateSoftConstraints(hardConstraints, softConstraints));
322                         serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints));
323                     } else {
324                         LOG.warn("service '{}' SoftConstraints is not set !", serviceName);
325                         serviceInput.setSoftConstraints(DowngradeConstraints.convertToSoftConstraints(hardConstraints));
326                         serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints));
327                     }
328                 } else {
329                     LOG.warn("service '{}' HardConstraints is not set !", serviceName);
330                 }
331                 this.pceListenerImpl.setInput(serviceInput);
332                 this.pceListenerImpl.setServiceReconfigure(true);
333                 this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
334                 this.rendererListenerImpl.setServiceInput(serviceInput);
335                 this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
336                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
337                     .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
338                             new ServiceInput(deleteInputBldr.build()));
339                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
340                     .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
341                         ServiceNotificationTypes.ServiceDeleteResult);
342                 if (output != null) {
343                     LOG.info("Service present in datastore, service-restore in progress...");
344                     ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
345                     return ModelMappingUtils.createRestoreServiceReply(common.getResponseMessage(),
346                             RpcStatus.Successful);
347                 } else {
348                     return ModelMappingUtils.createRestoreServiceReply("Renderer service delete failed !",
349                             RpcStatus.Failed);
350                 }
351             } else {
352                 LOG.error("Service '{}' is in 'inService' state", input.getServiceName());
353                 message = "Service '" + input.getServiceName() + "' is in 'inService' state";
354                 return ModelMappingUtils.createRestoreServiceReply(message, RpcStatus.Failed);
355             }
356         } else {
357             LOG.error("Service '{}' is not present", input.getServiceName());
358             message = "Service '" + input.getServiceName() + "' is not present";
359             return ModelMappingUtils.createRestoreServiceReply(message, RpcStatus.Failed);
360         }
361     }
362
363     @Override
364     public ListenableFuture<RpcResult<EquipmentNotificationOutput>>
365             equipmentNotification(EquipmentNotificationInput input) {
366         // TODO Auto-generated method stub
367         return null;
368     }
369
370     @Override
371     public ListenableFuture<RpcResult<ServiceRerouteConfirmOutput>>
372             serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
373         // TODO Auto-generated method stub
374         return null;
375     }
376
377     @Override
378     public ListenableFuture<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
379         LOG.info("RPC service reroute received");
380         String message = "";
381         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName());
382         if (servicesObject.isPresent()) {
383             Services service = servicesObject.get();
384             ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder();
385             DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
386             OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
387             DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
388             deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
389                 .setServiceName(input.getServiceName()).setDueDate(datetime)
390                 .setTailRetention(TailRetention.No).build());
391             SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder()
392                 .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl())
393                 .setRequestId(service.getSdncRequestHeader().getRequestId())
394                 .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId())
395                 .setRpcAction(RpcActions.ServiceDelete);
396             deleteInputBldr.setSdncRequestHeader(sdncBuilder.build());
397             ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build());
398             serviceInput.setServiceAEnd(service.getServiceAEnd());
399             serviceInput.setServiceZEnd(service.getServiceZEnd());
400             serviceInput.setConnectionType(service.getConnectionType());
401             this.pceListenerImpl.setInput(serviceInput);
402             this.pceListenerImpl.setServiceReconfigure(true);
403             this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
404             this.rendererListenerImpl.setServiceInput(serviceInput);
405             this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
406             org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
407                 .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
408                         new ServiceInput(deleteInputBldr.build()));
409             org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
410                 .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
411                     ServiceNotificationTypes.ServiceDeleteResult);
412             if (output != null) {
413                 LOG.info("Service present in datastore, service-reroute in progress...");
414                 ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
415                 return ModelMappingUtils.createRerouteServiceReply(input, common.getAckFinalIndicator(),
416                         common.getResponseMessage(), RpcStatus.Successful);
417             } else {
418                 return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
419                         "Renderer service delete failed !", RpcStatus.Failed);
420             }
421         } else {
422             LOG.error("Service '{}' is not present", input.getServiceName());
423             message = "Service '" + input.getServiceName() + "' is not present";
424             return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_NO, message,
425                     RpcStatus.Failed);
426         }
427     }
428
429     @Override
430     public ListenableFuture<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
431         // TODO Auto-generated method stub
432         return null;
433     }
434
435     @Override
436     public ListenableFuture<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
437         // TODO Auto-generated method stub
438         return null;
439     }
440
441     @Override
442     public ListenableFuture<RpcResult<NetworkReOptimizationOutput>>
443             networkReOptimization(NetworkReOptimizationInput input) {
444         // TODO Auto-generated method stub
445         return null;
446     }
447
448     @Override
449     public ListenableFuture<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
450         LOG.info("RPC temp serviceDelete request received for {}", input.getCommonId());
451         String message = "";
452
453         /*
454          * Upon receipt of service-deleteService RPC, service header and sdnc-request
455          * header compliancy are verified.
456          */
457         LOG.info("checking Service Compliancy ...");
458         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerCompliancyCheck.check(input.getCommonId(),
459                 null, null, RpcActions.ServiceDelete, false, false);
460         if (serviceHandlerCheckResult.hasPassed()) {
461             LOG.info("Service compliant !");
462         } else {
463             LOG.info("Service is not compliant !");
464             return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
465                     "Service not compliant !", ResponseCodes.RESPONSE_FAILED);
466         }
467
468         //Check presence of service to be deleted
469         String commonId = input.getCommonId();
470         LOG.info("service common-id : {}", commonId);
471         try {
472             Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list
473                 .Services> service = this.serviceDataStoreOperations.getTempService(commonId);
474             if (!service.isPresent()) {
475                 message = "Service '" + commonId + "' does not exist in datastore";
476                 LOG.error(message);
477                 return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
478                         message, ResponseCodes.RESPONSE_FAILED);
479             }
480         } catch (NullPointerException e) {
481             LOG.info("failed to get service '{}' from datastore : ", commonId, e);
482         }
483
484         LOG.info("Service '{}' present in datastore !", commonId);
485         this.pceListenerImpl.setInput(new ServiceInput(input));
486         this.pceListenerImpl.setServiceReconfigure(false);
487         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
488         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
489         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
490         this.rendererListenerImpl.setTempService(true);
491         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput output =
492                 this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
493         if (output != null) {
494             LOG.info("Temp Service present in datastore, service-delete in progress...");
495             ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
496             return ModelMappingUtils.createDeleteServiceReply(input, common.getAckFinalIndicator(),
497                     common.getResponseMessage(), common.getResponseCode());
498         } else {
499             return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
500                     "Renderer service delete failed !", ResponseCodes.RESPONSE_FAILED);
501         }
502     }
503
504     @Override
505     public ListenableFuture<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
506         LOG.info("RPC temp service creation received");
507         // Validation
508         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
509                 new ServiceInput(input), RpcActions.TempServiceCreate);
510         if (! validationResult.isSuccess()) {
511             LOG.warn("Aborting service create because validation of service create request failed: {}",
512                     validationResult.getResultMessage());
513             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
514                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
515         }
516
517         // Starting service create operation
518         LOG.info("Commencing PCE");
519         this.pceListenerImpl.setInput(new ServiceInput(input));
520         this.pceListenerImpl.setServiceReconfigure(false);
521         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
522         this.pceListenerImpl.setTempService(true);
523         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
524         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
525         this.rendererListenerImpl.setTempService(true);
526         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
527         if (output != null) {
528             LOG.info("Service compliant, temp serviceCreate in progress...");
529             ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
530             return ModelMappingUtils.createCreateServiceReply(input, common.getAckFinalIndicator(),
531                     common.getResponseMessage(), common.getResponseCode());
532         } else {
533             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
534                     "PCE calculation failed", ResponseCodes.RESPONSE_FAILED);
535         }
536     }
537
538     @Override
539     public ListenableFuture<RpcResult<
540         ServiceDeleteComplexResultNotificationRequestOutput>> serviceDeleteComplexResultNotificationRequest(
541             ServiceDeleteComplexResultNotificationRequestInput input) {
542         // TODO Auto-generated method stub
543         return null;
544     }
545
546     @Override
547     public ListenableFuture<RpcResult<
548         ServiceCreateResultNotificationRequestOutput>> serviceCreateResultNotificationRequest(
549             ServiceCreateResultNotificationRequestInput input) {
550         // TODO Auto-generated method stub
551         return null;
552     }
553
554     @Override
555     public ListenableFuture<RpcResult<
556         ServiceDeleteResultNotificationRequestOutput>> serviceDeleteResultNotificationRequest(
557             ServiceDeleteResultNotificationRequestInput input) {
558         // TODO Auto-generated method stub
559         return null;
560     }
561
562     @Override
563     public ListenableFuture<RpcResult<
564         ServiceCreateComplexResultNotificationRequestOutput>> serviceCreateComplexResultNotificationRequest(
565             ServiceCreateComplexResultNotificationRequestInput input) {
566         // TODO Auto-generated method stub
567         return null;
568     }
569
570     @Override
571     public ListenableFuture<RpcResult<ServiceFeasibilityCheckBulkOutput>> serviceFeasibilityCheckBulk(
572         ServiceFeasibilityCheckBulkInput input) {
573         // TODO Auto-generated method stub
574         return null;
575     }
576
577 }