d7cfab0e13ac2feb4481b7553b25c53c0f9dea7b
[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         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
231         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
232                 .ServiceDeleteInput serviceDeleteInput =
233             ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
234         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteOutput output =
235             this.rendererServiceWrapper.performRenderer(
236                 serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, service);
237
238         if (output == null) {
239             LOG.error(SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED);
240             return ModelMappingUtils.createDeleteServiceReply(
241                     input, ResponseCodes.FINAL_ACK_YES,
242                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
243         }
244
245         LOG.debug("RPC serviceDelete in progress...");
246         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
247         return ModelMappingUtils.createDeleteServiceReply(
248                 input, common.getAckFinalIndicator(),
249                 common.getResponseMessage(), common.getResponseCode());
250     }
251
252     @Override
253     public ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
254             ServiceFeasibilityCheckInput input) {
255         LOG.info("RPC serviceFeasibilityCheck received");
256         // Validation
257         ServiceInput serviceInput = new ServiceInput(input);
258         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(serviceInput,
259                 RpcActions.ServiceFeasibilityCheck);
260         if (! validationResult.isSuccess()) {
261             LOG.warn(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.ABORT_VALID_FAILED);
262             return ModelMappingUtils.createCreateServiceReply(
263                     input, ResponseCodes.FINAL_ACK_YES,
264                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
265         }
266         this.pceListenerImpl.setInput(new ServiceInput(input));
267         this.pceListenerImpl.setServiceReconfigure(false);
268         this.pceListenerImpl.setServiceFeasiblity(true);
269         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
270         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
271         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
272         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
273         LOG.debug(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.PCE_CALLING);
274         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
275         if (output == null) {
276             LOG.warn(SERVICE_FEASABILITY_CHECK_MSG, LogMessages.ABORT_PCE_FAILED);
277             return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
278                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
279         }
280         LOG.info("RPC serviceFeasibilityCheck in progress...");
281         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
282         return ModelMappingUtils.createCreateServiceReply(
283                 input, common.getAckFinalIndicator(),
284                 common.getResponseMessage(), common.getResponseCode());
285     }
286
287     @Override
288     public ListenableFuture<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
289         String serviceName = input.getServiceName();
290         LOG.info("RPC serviceReconfigure received for {}", serviceName);
291         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
292         if (!servicesObject.isPresent()) {
293             LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.serviceNotInDS(serviceName));
294             return ModelMappingUtils.createCreateServiceReply(
295                 input,
296                 LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
297         }
298         LOG.debug("Service '{}' found in datastore", serviceName);
299         OperationResult validationResult = ServiceCreateValidation
300                 .validateServiceCreateRequest(new ServiceInput(input), RpcActions.ServiceReconfigure);
301         if (!validationResult.isSuccess()) {
302             LOG.warn(SERVICE_RECONFIGURE_MSG, LogMessages.ABORT_VALID_FAILED);
303             return ModelMappingUtils.createCreateServiceReply(
304                     input,
305                     validationResult.getResultMessage(), RpcStatus.Failed);
306         }
307         this.pceListenerImpl.setInput(new ServiceInput(input));
308         this.pceListenerImpl.setServiceReconfigure(true);
309         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
310         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
311         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
312         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
313         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
314                 .ServiceDeleteInput serviceDeleteInput =
315                         ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
316         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
317                 .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
318                         ServiceNotificationTypes.ServiceDeleteResult, null);
319         if (output == null) {
320             LOG.error(SERVICE_RECONFIGURE_MSG, LogMessages.RENDERER_DELETE_FAILED);
321             return ModelMappingUtils.createCreateServiceReply(
322                     input,
323                     LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Successful);
324                     //TODO check if RpcStatus.Successful is really expected here
325         }
326         LOG.info("RPC serviceReconfigure in progress...");
327         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
328         return ModelMappingUtils.createCreateServiceReply(
329                 input,
330                 common.getResponseMessage(), RpcStatus.Successful);
331     }
332
333     @Override
334     public ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
335         String serviceName = input.getServiceName();
336         LOG.info("RPC serviceRestoration received for {}", serviceName);
337         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
338
339         if (!servicesObject.isPresent()) {
340             LOG.warn(SERVICE_RESTORATION_MSG, LogMessages.serviceNotInDS(serviceName));
341             return ModelMappingUtils.createRestoreServiceReply(
342                     LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
343         }
344
345         Services service = servicesObject.get();
346         State state = service.getOperationalState();
347
348         if (state == State.InService) {
349             LOG.error(SERVICE_RESTORATION_MSG, LogMessages.serviceInService(serviceName));
350             return ModelMappingUtils.createRestoreServiceReply(
351                     LogMessages.serviceInService(serviceName), RpcStatus.Failed);
352         }
353
354         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
355         OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
356         DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
357         SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder()
358                 .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl())
359                 .setRequestId(service.getSdncRequestHeader().getRequestId())
360                 .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId())
361                 .setRpcAction(RpcActions.ServiceDelete);
362         ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder()
363                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
364                     .setServiceName(serviceName)
365                     .setDueDate(datetime)
366                     .setTailRetention(TailRetention.No).build())
367                 .setSdncRequestHeader(sdncBuilder.build());
368         ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build());
369         serviceInput.setServiceAEnd(service.getServiceAEnd());
370         serviceInput.setServiceZEnd(service.getServiceZEnd());
371         serviceInput.setConnectionType(service.getConnectionType());
372         HardConstraints hardConstraints = service.getHardConstraints();
373         if (hardConstraints == null) {
374             LOG.warn("service '{}' HardConstraints is not set !", serviceName);
375         } else {
376             SoftConstraints softConstraints = service.getSoftConstraints();
377             if (softConstraints == null) {
378                 LOG.warn("service '{}' SoftConstraints is not set !", serviceName);
379                 serviceInput.setSoftConstraints(DowngradeConstraints.convertToSoftConstraints(hardConstraints));
380                 serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints));
381             } else {
382                 LOG.info("converting hard constraints to soft constraints ...");
383                 serviceInput.setSoftConstraints(
384                         DowngradeConstraints.updateSoftConstraints(hardConstraints, softConstraints));
385                 serviceInput.setHardConstraints(DowngradeConstraints.downgradeHardConstraints(hardConstraints));
386             }
387         }
388         this.pceListenerImpl.setInput(serviceInput);
389         this.pceListenerImpl.setServiceReconfigure(true);
390         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
391         this.rendererListenerImpl.setServiceInput(serviceInput);
392         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
393         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
394         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
395             .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
396                     new ServiceInput(deleteInputBldr.build()));
397         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
398             .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
399                 ServiceNotificationTypes.ServiceDeleteResult, null);
400         if (output == null) {
401             LOG.error(SERVICE_RESTORATION_MSG, LogMessages.RENDERER_DELETE_FAILED);
402             return ModelMappingUtils.createRestoreServiceReply(
403                      LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Failed);
404         }
405         LOG.info("RPC serviceRestore in progress...");
406         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
407         return ModelMappingUtils.createRestoreServiceReply(
408                 common.getResponseMessage(), RpcStatus.Successful);
409
410     }
411
412     @Override
413     public ListenableFuture<RpcResult<EquipmentNotificationOutput>>
414             equipmentNotification(EquipmentNotificationInput input) {
415         // TODO Auto-generated method stub
416         return null;
417     }
418
419     @Override
420     public ListenableFuture<RpcResult<ServiceRerouteConfirmOutput>>
421             serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
422         // TODO Auto-generated method stub
423         return null;
424     }
425
426     @Override
427     public ListenableFuture<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
428         String serviceName = input.getServiceName();
429         LOG.info("RPC serviceReroute received for {}", serviceName);
430         Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(serviceName);
431         if (!servicesObject.isPresent()) {
432             LOG.warn("serviceReroute: {}", LogMessages.serviceNotInDS(serviceName));
433             return ModelMappingUtils.createRerouteServiceReply(
434                     input, ResponseCodes.FINAL_ACK_NO,
435                     LogMessages.serviceNotInDS(serviceName), RpcStatus.Failed);
436         }
437         Services service = servicesObject.get();
438         DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
439         OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
440         DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
441         SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder()
442                 .setNotificationUrl(service.getSdncRequestHeader().getNotificationUrl())
443                 .setRequestId(service.getSdncRequestHeader().getRequestId())
444                 .setRequestSystemId(service.getSdncRequestHeader().getRequestSystemId())
445                 .setRpcAction(RpcActions.ServiceDelete);
446         ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder()
447                 .setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
448                     .setServiceName(serviceName).setDueDate(datetime)
449                     .setTailRetention(TailRetention.No).build())
450                 .setSdncRequestHeader(sdncBuilder.build());
451         ServiceInput serviceInput = new ServiceInput(deleteInputBldr.build());
452         serviceInput.setServiceAEnd(service.getServiceAEnd());
453         serviceInput.setServiceZEnd(service.getServiceZEnd());
454         serviceInput.setConnectionType(service.getConnectionType());
455         this.pceListenerImpl.setInput(serviceInput);
456         this.pceListenerImpl.setServiceReconfigure(true);
457         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
458         this.rendererListenerImpl.setServiceInput(serviceInput);
459         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
460         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
461         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
462             .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(
463                     new ServiceInput(deleteInputBldr.build()));
464         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
465             .ServiceDeleteOutput output = this.rendererServiceWrapper.performRenderer(serviceDeleteInput,
466                 ServiceNotificationTypes.ServiceDeleteResult, null);
467         if (output == null) {
468             LOG.error("serviceReroute: {}", LogMessages.RENDERER_DELETE_FAILED);
469             return ModelMappingUtils.createRerouteServiceReply(
470                     input, ResponseCodes.FINAL_ACK_YES,
471                     LogMessages.RENDERER_DELETE_FAILED, RpcStatus.Failed);
472         }
473         LOG.info("RPC ServiceReroute in progress...");
474         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
475         return ModelMappingUtils.createRerouteServiceReply(
476                 input, common.getAckFinalIndicator(),
477                 common.getResponseMessage(), RpcStatus.Successful);
478     }
479
480     @Override
481     public ListenableFuture<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
482         // TODO Auto-generated method stub
483         return null;
484     }
485
486     @Override
487     public ListenableFuture<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
488         // TODO Auto-generated method stub
489         return null;
490     }
491
492     @Override
493     public ListenableFuture<RpcResult<NetworkReOptimizationOutput>>
494             networkReOptimization(NetworkReOptimizationInput input) {
495         // TODO Auto-generated method stub
496         return null;
497     }
498
499     @Override
500     public ListenableFuture<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
501         String commonId = input.getCommonId();
502         LOG.info("RPC temp serviceDelete request received for {}", commonId);
503
504         /*
505          * Upon receipt of service-deleteService RPC, service header and sdnc-request
506          * header compliancy are verified.
507          */
508         LOG.debug("checking Service Compliance ...");
509         ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
510                 commonId, null, null, RpcActions.ServiceDelete, false, false
511             );
512         if (!serviceHandlerCheckResult.hasPassed()) {
513             LOG.warn(TEMP_SERVICE_DELETE_MSG, LogMessages.ABORT_SERVICE_NON_COMPLIANT);
514             return ModelMappingUtils.createDeleteServiceReply(
515                     input, ResponseCodes.FINAL_ACK_YES,
516                     LogMessages.SERVICE_NON_COMPLIANT, ResponseCodes.RESPONSE_FAILED);
517         }
518
519         //Check presence of service to be deleted
520         LOG.debug("service common-id '{}' is compliant", commonId);
521         Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.temp.service.list.Services>
522                 service =
523             this.serviceDataStoreOperations.getTempService(commonId);
524         if (!service.isPresent()) {
525             LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.serviceNotInDS(commonId));
526             return ModelMappingUtils.createDeleteServiceReply(
527                     input, ResponseCodes.FINAL_ACK_YES,
528                     LogMessages.serviceNotInDS(commonId), ResponseCodes.RESPONSE_FAILED);
529         }
530
531         LOG.info("Service '{}' present in datastore !", commonId);
532         this.pceListenerImpl.setInput(new ServiceInput(input));
533         this.pceListenerImpl.setServiceReconfigure(false);
534         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
535         this.rendererListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
536         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
537         this.rendererListenerImpl.setTempService(true);
538         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
539         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteOutput output =
540                 this.rendererServiceWrapper.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
541         if (output == null) {
542             LOG.error(TEMP_SERVICE_DELETE_MSG, LogMessages.RENDERER_DELETE_FAILED);
543             return ModelMappingUtils.createDeleteServiceReply(
544                     input, ResponseCodes.FINAL_ACK_YES,
545                     LogMessages.RENDERER_DELETE_FAILED, ResponseCodes.RESPONSE_FAILED);
546         }
547         LOG.info("RPC tempServiceDelete in progress...");
548         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
549         return ModelMappingUtils.createDeleteServiceReply(
550                 input, common.getAckFinalIndicator(),
551                 common.getResponseMessage(), common.getResponseCode());
552     }
553
554     @Override
555     public ListenableFuture<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
556         LOG.info("RPC tempServiceCreate received");
557         // Validation
558         OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(
559                 new ServiceInput(input), RpcActions.TempServiceCreate);
560         if (! validationResult.isSuccess()) {
561             LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.ABORT_VALID_FAILED);
562             return ModelMappingUtils.createCreateServiceReply(
563                     input, ResponseCodes.FINAL_ACK_YES,
564                     validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
565         }
566
567         // Starting service create operation
568         LOG.debug(TEMP_SERVICE_CREATE_MSG, LogMessages.PCE_CALLING);
569         this.pceListenerImpl.setInput(new ServiceInput(input));
570         this.pceListenerImpl.setServiceReconfigure(false);
571         this.pceListenerImpl.setserviceDataStoreOperations(this.serviceDataStoreOperations);
572         this.pceListenerImpl.setTempService(true);
573         this.rendererListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
574         this.rendererListenerImpl.setServiceInput(new ServiceInput(input));
575         this.rendererListenerImpl.setTempService(true);
576         this.networkModelListenerImpl.setserviceDataStoreOperations(serviceDataStoreOperations);
577         PathComputationRequestOutput output = this.pceServiceWrapper.performPCE(input, true);
578         if (output == null) {
579             LOG.warn(TEMP_SERVICE_CREATE_MSG, LogMessages.ABORT_PCE_FAILED);
580             return ModelMappingUtils.createCreateServiceReply(
581                     input, ResponseCodes.FINAL_ACK_YES,
582                     LogMessages.PCE_FAILED, ResponseCodes.RESPONSE_FAILED);
583         }
584         LOG.info("RPC tempServiceCreate in progress...");
585         ConfigurationResponseCommon common = output.getConfigurationResponseCommon();
586         return ModelMappingUtils.createCreateServiceReply(
587                 input, common.getAckFinalIndicator(),
588                 common.getResponseMessage(), common.getResponseCode());
589     }
590
591     @Override
592     public ListenableFuture<RpcResult<
593         ServiceDeleteComplexResultNotificationRequestOutput>> serviceDeleteComplexResultNotificationRequest(
594             ServiceDeleteComplexResultNotificationRequestInput input) {
595         // TODO Auto-generated method stub
596         return null;
597     }
598
599     @Override
600     public ListenableFuture<RpcResult<
601         ServiceCreateResultNotificationRequestOutput>> serviceCreateResultNotificationRequest(
602             ServiceCreateResultNotificationRequestInput input) {
603         // TODO Auto-generated method stub
604         return null;
605     }
606
607     @Override
608     public ListenableFuture<RpcResult<
609         ServiceDeleteResultNotificationRequestOutput>> serviceDeleteResultNotificationRequest(
610             ServiceDeleteResultNotificationRequestInput input) {
611         // TODO Auto-generated method stub
612         return null;
613     }
614
615     @Override
616     public ListenableFuture<RpcResult<
617         ServiceCreateComplexResultNotificationRequestOutput>> serviceCreateComplexResultNotificationRequest(
618             ServiceCreateComplexResultNotificationRequestInput input) {
619         // TODO Auto-generated method stub
620         return null;
621     }
622
623     @Override
624     public ListenableFuture<RpcResult<ServiceFeasibilityCheckBulkOutput>> serviceFeasibilityCheckBulk(
625         ServiceFeasibilityCheckBulkInput input) {
626         // TODO Auto-generated method stub
627         return null;
628     }
629
630 }