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