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