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