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