2 * Copyright © 2017 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.servicehandler.impl;
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 java.util.concurrent.ExecutionException;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
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.ModelMappingUtils;
22 import org.opendaylight.transportpce.servicehandler.service.PCEServiceWrapper;
23 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperations;
24 import org.opendaylight.transportpce.servicehandler.service.ServiceDataStoreOperationsImpl;
25 import org.opendaylight.transportpce.servicehandler.validation.ServiceCreateValidation;
26 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
27 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerCompliancyCheck;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev171017.PathComputationRequestOutput;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestInput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceImplementationRequestOutput;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeaderBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationInput;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationOutput;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationInput;
38 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationOutput;
39 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService;
40 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
41 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInputBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
43 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInputBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInput;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutput;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmInput;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmOutput;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionInput;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionOutput;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollInput;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollOutput;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input.ServiceAEndBuilder;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.create.input.ServiceZEndBuilder;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfo.TailRetention;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.delete.input.ServiceDeleteReqInfoBuilder;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
70 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
71 import org.opendaylight.yangtools.yang.common.RpcResult;
72 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
78 * Top level service interface providing main OpenROADM controller services.
80 public class ServicehandlerImpl implements OrgOpenroadmServiceService {
82 private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerImpl.class);
84 private DataBroker db;
85 private ServiceDataStoreOperations serviceDataStoreOperations;
86 private RendererServiceOperations rendererServiceOperations;
87 private PCEServiceWrapper pceServiceWrapper;
89 //TODO: remove private request fields as they are in global scope
91 public ServicehandlerImpl(DataBroker databroker, PathComputationService pathComputationService,
92 RendererServiceOperations rendererServiceOperations) {
94 this.rendererServiceOperations = rendererServiceOperations;
95 this.serviceDataStoreOperations = new ServiceDataStoreOperationsImpl(this.db);
96 this.serviceDataStoreOperations.initialize();
97 this.pceServiceWrapper = new PCEServiceWrapper(pathComputationService);
101 public ListenableFuture<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
102 LOG.info("RPC service creation received");
104 OperationResult validationResult = ServiceCreateValidation.validateServiceCreateRequest(input);
105 if (! validationResult.isSuccess()) {
106 LOG.warn("Aborting service create because validation of service create request failed: {}",
107 validationResult.getResultMessage());
108 return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
109 validationResult.getResultMessage(), ResponseCodes.RESPONSE_FAILED);
112 // Starting service create operation
113 LOG.info("Commencing PCE");
114 //TODO: createService service status into datastore
115 PathComputationRequestOutput pceResponse = this.pceServiceWrapper.performPCE(input, true);
116 String pceResponseCode = pceResponse.getConfigurationResponseCommon().getResponseCode();
117 if (!ResponseCodes.RESPONSE_OK.equals(pceResponseCode)) {
118 LOG.info("PCE calculation failed {}", pceResponseCode);
119 return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES,
120 pceResponse.getConfigurationResponseCommon().getResponseMessage(), ResponseCodes.RESPONSE_FAILED);
123 LOG.info("PCE calculation done OK {}", pceResponseCode);
125 OperationResult operationResult = this.serviceDataStoreOperations.createService(input, pceResponse);
126 if (!operationResult.isSuccess()) {
127 String message = "Service status not updated in datastore !";
129 return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
130 ResponseCodes.RESPONSE_FAILED);
133 OperationResult operationServicePathSaveResult = this.serviceDataStoreOperations.createServicePath(input,
135 if (!operationServicePathSaveResult.isSuccess()) {
136 String message = "Service Path not updated in datastore !";
138 return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
139 ResponseCodes.RESPONSE_FAILED);
142 ServiceImplementationRequestInput serviceImplementationRequest =
143 ModelMappingUtils.createServiceImplementationRequest(input, pceResponse);
144 ServiceImplementationRequestOutput serviceImplementationRequestOutput = this.rendererServiceOperations
145 .serviceImplementation(serviceImplementationRequest);
146 if (ResponseCodes.RESPONSE_OK
147 .equals(serviceImplementationRequestOutput.getConfigurationResponseCommon().getResponseCode())) {
148 String message = "Service rendered successfully !";
150 operationResult = this.serviceDataStoreOperations.modifyService(input.getServiceName(), State.InService,
152 if (!operationResult.isSuccess()) {
153 LOG.warn("Service status not updated in datastore !");
155 return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
156 ResponseCodes.RESPONSE_OK);
158 String message = "Service rendering has failed !";
161 OperationResult deleteServicePathOperationResult =
162 this.serviceDataStoreOperations.deleteServicePath(input.getServiceName());
163 if (!deleteServicePathOperationResult.isSuccess()) {
164 LOG.warn("Service path was not removed from datastore!");
167 OperationResult deleteServiceOperationResult =
168 this.serviceDataStoreOperations.deleteService(input.getServiceName());
169 if (!deleteServiceOperationResult.isSuccess()) {
170 LOG.warn("Service was not removed from datastore!");
173 return ModelMappingUtils.createCreateServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
174 ResponseCodes.RESPONSE_FAILED);
179 public ListenableFuture<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
180 LOG.info("RPC serviceDelete request received for {}", input.getServiceDeleteReqInfo().getServiceName());
184 * Upon receipt of service-deleteService RPC, service header and sdnc-request
185 * header compliancy are verified.
187 LOG.info("checking Service Compliancy ...");
188 ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerCompliancyCheck.check(
189 input.getServiceDeleteReqInfo().getServiceName(),
190 input.getSdncRequestHeader(), null, RpcActions.ServiceDelete, false, true);
191 if (serviceHandlerCheckResult.hasPassed()) {
192 LOG.info("Service compliant !");
194 LOG.info("Service is not compliant !");
195 return ModelMappingUtils
196 .createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
197 "Service not compliant !", ResponseCodes.RESPONSE_FAILED);
200 //Check presence of service to be deleted
201 String serviceName = input.getServiceDeleteReqInfo().getServiceName();
202 LOG.info("serviceName : {}", serviceName);
204 Optional<Services> service = this.serviceDataStoreOperations.getService(serviceName);
205 if (!service.isPresent()) {
206 message = "Service '" + serviceName + "' does not exist in datastore";
208 return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
209 message, ResponseCodes.RESPONSE_FAILED);
211 } catch (NullPointerException e) {
212 LOG.info("failed to get service '{}' from datastore : ", serviceName, e);
215 LOG.debug("Service '{}' present in datastore !", serviceName);
216 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
217 .ServiceDeleteInput serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(input);
218 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
219 .ServiceDeleteOutput output = this.rendererServiceOperations.serviceDelete(serviceDeleteInput);
221 if (!ResponseCodes.RESPONSE_OK
222 .equals(output.getConfigurationResponseCommon().getResponseCode())) {
223 message = "Service delete failed!";
224 return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES, message,
225 ResponseCodes.RESPONSE_FAILED);
228 OperationResult deleteServicePathOperationResult =
229 this.serviceDataStoreOperations.deleteServicePath(input.getServiceDeleteReqInfo().getServiceName());
230 if (!deleteServicePathOperationResult.isSuccess()) {
231 LOG.warn("Service path was not removed from datastore!");
234 OperationResult deleteServiceOperationResult =
235 this.serviceDataStoreOperations.deleteService(input.getServiceDeleteReqInfo().getServiceName());
236 if (!deleteServiceOperationResult.isSuccess()) {
237 LOG.warn("Service was not removed from datastore!");
240 return ModelMappingUtils.createDeleteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
241 "Service delete was successful!", ResponseCodes.RESPONSE_OK);
245 public ListenableFuture<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
246 ServiceFeasibilityCheckInput input) {
247 throw new UnsupportedOperationException("Not implemented yet");
251 public ListenableFuture<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
252 throw new UnsupportedOperationException("Not implemented yet");
256 public ListenableFuture<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
257 throw new UnsupportedOperationException("Not implemented yet");
261 public ListenableFuture<RpcResult<EquipmentNotificationOutput>>
262 equipmentNotification(EquipmentNotificationInput input) {
263 // TODO Auto-generated method stub
268 public ListenableFuture<RpcResult<ServiceRerouteConfirmOutput>>
269 serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
270 // TODO Auto-generated method stub
275 public ListenableFuture<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
276 LOG.info("RPC service reroute received");
279 Optional<Services> servicesObject = this.serviceDataStoreOperations.getService(input.getServiceName());
280 if (servicesObject.isPresent()) {
281 ServiceDeleteInputBuilder deleteInputBldr = new ServiceDeleteInputBuilder();
282 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssxxx");
283 OffsetDateTime offsetDateTime = OffsetDateTime.now(ZoneOffset.UTC);
284 DateAndTime datetime = new DateAndTime(dtf.format(offsetDateTime));
285 deleteInputBldr.setServiceDeleteReqInfo(new ServiceDeleteReqInfoBuilder()
286 .setServiceName(input.getServiceName()).setDueDate(datetime)
287 .setTailRetention(TailRetention.No).build());
288 SdncRequestHeaderBuilder sdncBuilder = new SdncRequestHeaderBuilder();
289 sdncBuilder.setNotificationUrl(servicesObject.get().getSdncRequestHeader().getNotificationUrl());
290 sdncBuilder.setRequestId(servicesObject.get().getSdncRequestHeader().getRequestId());
291 sdncBuilder.setRequestSystemId(servicesObject.get().getSdncRequestHeader().getRequestSystemId());
292 sdncBuilder.setRpcAction(RpcActions.ServiceDelete);
293 deleteInputBldr.setSdncRequestHeader(sdncBuilder.build());
294 // Calling delete service
295 ServiceDeleteOutput serviceDeleteOutput = serviceDelete(deleteInputBldr.build()).get().getResult();
296 // Calling create request now
297 if (!ResponseCodes.RESPONSE_OK
298 .equals(serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode())) {
299 message = "Service delete failed!";
300 return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
301 message, RpcStatus.Failed);
303 ServiceCreateInputBuilder serviceCreateBldr = new ServiceCreateInputBuilder();
304 serviceCreateBldr.setServiceName(input.getServiceName() + 2);
305 serviceCreateBldr.setCommonId(servicesObject.get().getCommonId());
306 serviceCreateBldr.setConnectionType(servicesObject.get().getConnectionType());
307 serviceCreateBldr.setCustomer(servicesObject.get().getCustomer());
308 serviceCreateBldr.setCustomerContact(servicesObject.get().getCustomerContact());
309 serviceCreateBldr.setDueDate(servicesObject.get().getDueDate());
310 serviceCreateBldr.setEndDate(servicesObject.get().getEndDate());
311 serviceCreateBldr.setHardConstraints(servicesObject.get().getHardConstraints());
312 serviceCreateBldr.setNcCode(servicesObject.get().getNcCode());
313 serviceCreateBldr.setNciCode(servicesObject.get().getNciCode());
314 serviceCreateBldr.setOperatorContact(servicesObject.get().getOperatorContact());
315 serviceCreateBldr.setSdncRequestHeader(servicesObject.get().getSdncRequestHeader());
316 serviceCreateBldr.setSecondaryNciCode(servicesObject.get().getSecondaryNciCode());
317 ServiceAEndBuilder serviceAendBuilder = new ServiceAEndBuilder(servicesObject.get().getServiceAEnd());
318 serviceCreateBldr.setServiceAEnd(serviceAendBuilder.build());
319 ServiceZEndBuilder serviceZendBuilder = new ServiceZEndBuilder(servicesObject.get().getServiceZEnd());
320 serviceCreateBldr.setServiceZEnd(serviceZendBuilder.build());
321 serviceCreateBldr.setSoftConstraints(servicesObject.get().getSoftConstraints());
322 ServiceCreateOutput serviceCreateOutput = serviceCreate(serviceCreateBldr.build()).get().getResult();
323 if (!ResponseCodes.RESPONSE_OK
324 .equals(serviceCreateOutput.getConfigurationResponseCommon().getResponseCode())) {
325 message = "Service create failed!";
326 return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
327 message, RpcStatus.Failed);
329 message = "Service reroute successfully !";
330 return ModelMappingUtils.createRerouteServiceReply(input, ResponseCodes.FINAL_ACK_YES,
331 message, RpcStatus.Successful);
333 LOG.error("Service '{}' is not present", input.getServiceName());
334 message = "Service '" + input.getServiceName() + "' is not present";
336 } catch (InterruptedException | ExecutionException e) {
337 LOG.info("Exception caught" , e);
339 ServiceRerouteOutputBuilder output = new ServiceRerouteOutputBuilder()
340 .setHardConstraints(null).setSoftConstraints(null).setStatus(RpcStatus.Failed).setStatusMessage(message);
341 return RpcResultBuilder.success(output).buildFuture();
345 public ListenableFuture<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
346 // TODO Auto-generated method stub
351 public ListenableFuture<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
352 // TODO Auto-generated method stub
357 public ListenableFuture<RpcResult<NetworkReOptimizationOutput>>
358 networkReOptimization(NetworkReOptimizationInput input) {
359 // TODO Auto-generated method stub
364 public ListenableFuture<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
365 // TODO Auto-generated method stub
370 public ListenableFuture<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
371 // TODO Auto-generated method stub