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.service;
10 import com.google.common.util.concurrent.FluentFuture;
11 import java.util.Optional;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.Future;
14 import java.util.concurrent.TimeUnit;
15 import java.util.concurrent.TimeoutException;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.binding.api.ReadTransaction;
19 import org.opendaylight.mdsal.binding.api.WriteTransaction;
20 import org.opendaylight.mdsal.common.api.CommitInfo;
21 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
22 import org.opendaylight.transportpce.common.OperationResult;
23 import org.opendaylight.transportpce.common.Timeouts;
24 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
25 import org.opendaylight.transportpce.servicehandler.ServiceInput;
26 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev220808.PathComputationRequestOutput;
27 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.state.types.rev191129.State;
28 import org.opendaylight.yang.gen.v1.http.org.openroadm.equipment.states.types.rev191129.AdminStates;
29 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceCreateInput;
30 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceList;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceListBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceCreateInput;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceList;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceListBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.Services;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.service.list.ServicesKey;
38 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.path.PathDescription;
39 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
40 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
41 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 import org.osgi.service.component.annotations.Activate;
45 import org.osgi.service.component.annotations.Component;
46 import org.osgi.service.component.annotations.Reference;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
50 @Component(immediate = true)
51 public class ServiceDataStoreOperationsImpl implements ServiceDataStoreOperations {
52 private static final Logger LOG = LoggerFactory.getLogger(ServiceDataStoreOperationsImpl.class);
53 private static final String CREATE_MSG = "create";
54 private static final String DELETING_SERVICE_MSG = "Deleting '{}' Service";
55 private DataBroker dataBroker;
57 // This is class is public so that these messages can be accessed from Junit (avoid duplications).
58 public static final class LogMessages {
60 public static final String SUCCESSFUL_MESSAGE;
61 public static final String SERVICE_NOT_FOUND;
62 public static final String SERVICE_PATH_NOT_FOUND;
64 // Static blocks are generated once and spare memory.
66 SUCCESSFUL_MESSAGE = "Successful";
67 SERVICE_NOT_FOUND = "Service not found";
68 SERVICE_PATH_NOT_FOUND = "Service path not found";
71 public static String failedTo(String action, String serviceName) {
72 return "Failed to " + action + " service " + serviceName;
75 private LogMessages() {
81 public ServiceDataStoreOperationsImpl(@Reference DataBroker dataBroker) {
82 this.dataBroker = dataBroker;
86 public void initialize() {
87 initializeServiceList();
88 initializeTempServiceList();
91 private void initializeServiceList() {
93 LOG.info("initializing service registry");
94 WriteTransaction transaction = this.dataBroker.newWriteOnlyTransaction();
95 InstanceIdentifier<ServiceList> iid = InstanceIdentifier.create(ServiceList.class);
96 ServiceList initialRegistry = new ServiceListBuilder().build();
97 transaction.put(LogicalDatastoreType.OPERATIONAL, iid, initialRegistry);
98 FluentFuture<? extends @NonNull CommitInfo> future = transaction.commit();
99 future.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
100 } catch (InterruptedException | ExecutionException | TimeoutException e) {
101 LOG.error("init failed: ", e);
105 private void initializeTempServiceList() {
107 LOG.info("initializing temp service registry");
108 WriteTransaction transaction = this.dataBroker.newWriteOnlyTransaction();
109 InstanceIdentifier<TempServiceList> iid = InstanceIdentifier.create(TempServiceList.class);
110 TempServiceList initialRegistry = new TempServiceListBuilder().build();
111 transaction.put(LogicalDatastoreType.OPERATIONAL, iid, initialRegistry);
112 FluentFuture<? extends @NonNull CommitInfo> future = transaction.commit();
113 future.get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
114 } catch (InterruptedException | ExecutionException | TimeoutException e) {
115 LOG.error("init failed: ", e);
120 public Optional<Services> getService(String serviceName) {
122 ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction();
123 InstanceIdentifier<Services> iid =
124 InstanceIdentifier.create(ServiceList.class).child(Services.class, new ServicesKey(serviceName));
125 Future<java.util.Optional<Services>> future =
126 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
127 return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
128 } catch (InterruptedException | ExecutionException | TimeoutException e) {
129 LOG.warn("Reading service {} failed:", serviceName, e);
131 return Optional.empty();
135 public Optional<ServiceList> getServices() {
137 ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction();
138 InstanceIdentifier<ServiceList> iid =
139 InstanceIdentifier.create(ServiceList.class);
140 Future<java.util.Optional<ServiceList>> future =
141 readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
142 return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
143 } catch (InterruptedException | ExecutionException | TimeoutException e) {
144 LOG.warn("Reading services failed:", e);
146 return Optional.empty();
150 public Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.Services>
151 getTempService(String serviceName) {
153 ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction();
154 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
155 .Services> iid = InstanceIdentifier.create(TempServiceList.class).child(
156 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.Services.class,
157 new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.ServicesKey(
159 FluentFuture<Optional<
160 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.Services>> future
161 = readTx.read(LogicalDatastoreType.OPERATIONAL, iid);
162 return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
163 } catch (InterruptedException | ExecutionException | TimeoutException e) {
164 LOG.warn("Reading service {} failed:", serviceName, e);
166 return Optional.empty();
170 public OperationResult deleteService(String serviceName) {
171 LOG.debug(DELETING_SERVICE_MSG, serviceName);
173 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
174 InstanceIdentifier<Services> iid =
175 InstanceIdentifier.create(ServiceList.class).child(Services.class, new ServicesKey(serviceName));
176 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
177 writeTx.commit().get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
178 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
179 } catch (TimeoutException | InterruptedException | ExecutionException e) {
180 LOG.warn("deleteService : {}", LogMessages.failedTo("delete", serviceName), e);
181 return OperationResult.failed(LogMessages.failedTo("delete", serviceName));
186 public OperationResult deleteTempService(String commonId) {
187 LOG.debug(DELETING_SERVICE_MSG, commonId);
189 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
190 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
191 .Services> iid = InstanceIdentifier.create(TempServiceList.class).child(org.opendaylight.yang.gen.v1
192 .http.org.openroadm.service.rev211210.temp.service.list.Services.class,
193 new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
194 .ServicesKey(commonId));
195 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
196 writeTx.commit().get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
197 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
198 } catch (TimeoutException | InterruptedException | ExecutionException e) {
199 LOG.warn("deleteTempService : {}", LogMessages.failedTo("delete Temp", commonId), e);
200 return OperationResult.failed(LogMessages.failedTo("delete Temp", commonId));
205 public OperationResult modifyService(String serviceName, State operationalState, AdminStates administrativeState) {
206 LOG.debug("Modifying '{}' Service", serviceName);
207 Optional<Services> readService = getService(serviceName);
208 if (!readService.isPresent()) {
209 LOG.warn("modifyService: {}", LogMessages.SERVICE_NOT_FOUND);
210 return OperationResult.failed(LogMessages.SERVICE_NOT_FOUND);
213 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
214 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class)
215 .child(Services.class, new ServicesKey(serviceName));
216 Services services = new ServicesBuilder(readService.get())
217 .setOperationalState(operationalState)
218 .setAdministrativeState(administrativeState)
220 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, services);
221 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
222 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
223 } catch (TimeoutException | InterruptedException | ExecutionException e) {
224 LOG.warn("modifyService : {}", LogMessages.failedTo("modify", serviceName), e);
225 return OperationResult.failed(LogMessages.failedTo("modify", serviceName));
230 public OperationResult modifyTempService(String serviceName, State operationalState,
231 AdminStates administrativeState) {
232 LOG.debug("Modifying '{}' Temp Service", serviceName);
233 Optional<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
234 .Services> readService = getTempService(serviceName);
235 if (!readService.isPresent()) {
236 LOG.warn("modifyTempService: {}", LogMessages.SERVICE_NOT_FOUND);
237 return OperationResult.failed(LogMessages.SERVICE_NOT_FOUND);
240 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
241 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
242 .Services> iid = InstanceIdentifier.create(TempServiceList.class)
243 .child(org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
244 .Services.class, new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210
245 .temp.service.list.ServicesKey(serviceName));
246 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.Services services =
247 new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list.ServicesBuilder(
249 .setOperationalState(operationalState)
250 .setAdministrativeState(administrativeState)
252 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, services);
253 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
254 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
255 } catch (TimeoutException | InterruptedException | ExecutionException e) {
256 LOG.warn("modifyTempService : {}", LogMessages.failedTo("modify Temp", serviceName), e);
257 return OperationResult.failed(LogMessages.failedTo("modify Temp", serviceName));
262 public OperationResult createService(ServiceCreateInput serviceCreateInput) {
263 LOG.debug("Writing '{}' Service", serviceCreateInput.getServiceName());
265 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class)
266 .child(Services.class, new ServicesKey(serviceCreateInput.getServiceName()));
267 Services service = ModelMappingUtils.mappingServices(serviceCreateInput, null);
268 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
269 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
270 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
271 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
272 } catch (TimeoutException | InterruptedException | ExecutionException e) {
273 LOG.warn("createService : {}", LogMessages.failedTo(CREATE_MSG, serviceCreateInput.getServiceName()), e);
274 return OperationResult.failed(LogMessages.failedTo(CREATE_MSG, serviceCreateInput.getServiceName()));
279 public OperationResult createTempService(TempServiceCreateInput tempServiceCreateInput) {
280 LOG.debug("Writing '{}' Temp Service", tempServiceCreateInput.getCommonId());
282 InstanceIdentifier<org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
283 .Services> iid = InstanceIdentifier.create(TempServiceList.class)
284 .child(org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
285 .Services.class, new org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp
286 .service.list.ServicesKey(tempServiceCreateInput.getCommonId()));
287 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.temp.service.list
288 .Services service = ModelMappingUtils.mappingServices(tempServiceCreateInput);
289 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
290 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
291 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
292 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
293 } catch (TimeoutException | InterruptedException | ExecutionException e) {
294 LOG.warn("createTempService : {}",
295 LogMessages.failedTo("create Temp", tempServiceCreateInput.getCommonId()), e);
296 return OperationResult.failed(LogMessages.failedTo("create Temp", tempServiceCreateInput.getCommonId()));
301 public Optional<ServicePathList> getServicePaths() {
302 LOG.debug("Retrieving list of ServicePath...");
304 ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction();
305 InstanceIdentifier<ServicePathList> servicePathListIID = InstanceIdentifier.create(ServicePathList.class);
306 Future<java.util.Optional<ServicePathList>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,
308 return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
309 } catch (InterruptedException | ExecutionException | TimeoutException e) {
310 LOG.error("Reading service path list failed. Error={}", e.getMessage());
312 return Optional.empty();
316 public Optional<ServicePaths> getServicePath(String serviceName) {
317 LOG.debug("Retrieving service path of service {}", serviceName);
319 ReadTransaction readTx = this.dataBroker.newReadOnlyTransaction();
320 InstanceIdentifier<ServicePaths> servicePathsIID = InstanceIdentifier.create(ServicePathList.class)
321 .child(ServicePaths.class, new ServicePathsKey(serviceName));
322 Future<java.util.Optional<ServicePaths>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,
324 return future.get(Timeouts.DATASTORE_READ, TimeUnit.MILLISECONDS);
325 } catch (InterruptedException | ExecutionException | TimeoutException e) {
326 LOG.error("Reading service path failed. Error={}", e.getMessage());
328 return Optional.empty();
332 public OperationResult createServicePath(ServiceInput serviceInput, PathComputationRequestOutput outputFromPce) {
333 LOG.debug("Writing '{}' ServicePath ", serviceInput.getServiceName());
335 InstanceIdentifier<ServicePaths> servicePathsIID = InstanceIdentifier.create(ServicePathList.class)
336 .child(ServicePaths.class, new ServicePathsKey(serviceInput.getServiceName()));
337 ServicePaths servicePath = ModelMappingUtils.mappingServicePaths(serviceInput, outputFromPce);
338 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
339 writeTx.put(LogicalDatastoreType.OPERATIONAL, servicePathsIID, servicePath);
340 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
341 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
342 } catch (TimeoutException | InterruptedException | ExecutionException e) {
343 LOG.warn("createServicePath : {}",
344 LogMessages.failedTo("create servicePath", serviceInput.getCommonId()), e);
345 return OperationResult.failed(LogMessages.failedTo("create servicePath", serviceInput.getCommonId()));
350 public OperationResult modifyServicePath(PathDescription pathDescription, String serviceName) {
351 LOG.debug("Updating servicePath because of a change in the openroadm-topology");
352 Optional<ServicePaths> readServicePath = getServicePath(serviceName);
353 if (!readServicePath.isPresent()) {
354 LOG.warn("modifyServicePath: {}", LogMessages.SERVICE_PATH_NOT_FOUND);
355 return OperationResult.failed(LogMessages.SERVICE_PATH_NOT_FOUND);
358 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
359 InstanceIdentifier<ServicePaths> iid = InstanceIdentifier.create(ServicePathList.class)
360 .child(ServicePaths.class, new ServicePathsKey(serviceName));
361 ServicePaths servicePaths = new ServicePathsBuilder()
362 .setServiceAEnd(readServicePath.get().getServiceAEnd())
363 .setServiceHandlerHeader(readServicePath.get().getServiceHandlerHeader())
364 .setServicePathName(readServicePath.get().getServicePathName())
365 .setServiceZEnd(readServicePath.get().getServiceZEnd())
366 .setSupportingServiceName(readServicePath.get().getSupportingServiceName())
367 .setEquipmentSrgs(readServicePath.get().getEquipmentSrgs())
368 .setFiberSpanSrlgs(readServicePath.get().getFiberSpanSrlgs())
369 .setHardConstraints(readServicePath.get().getHardConstraints())
370 .setLatency(readServicePath.get().getLatency())
371 .setPathDescription(pathDescription)
372 .setPceRoutingMetric(readServicePath.get().getPceRoutingMetric())
373 .setSoftConstraints(readServicePath.get().getSoftConstraints())
376 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, servicePaths);
377 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
378 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
379 } catch (TimeoutException | InterruptedException | ExecutionException e) {
380 LOG.warn("modifyServicePath : {}", LogMessages.failedTo("modify service path", serviceName), e);
381 return OperationResult.failed(LogMessages.failedTo("modify service path", serviceName));
386 public OperationResult deleteServicePath(String serviceName) {
387 InstanceIdentifier<ServicePaths> servicePathsIID = InstanceIdentifier.create(ServicePathList.class)
388 .child(ServicePaths.class, new ServicePathsKey(serviceName));
389 LOG.debug("Deleting service from {}", servicePathsIID);
390 WriteTransaction servicePathsWriteTx = this.dataBroker.newWriteOnlyTransaction();
391 servicePathsWriteTx.delete(LogicalDatastoreType.OPERATIONAL, servicePathsIID);
393 servicePathsWriteTx.commit().get(Timeouts.DATASTORE_DELETE, TimeUnit.MILLISECONDS);
394 return OperationResult.ok(LogMessages.SUCCESSFUL_MESSAGE);
395 } catch (InterruptedException | ExecutionException | TimeoutException e) {
396 LOG.error("deleteServicePath : {}", LogMessages.failedTo("delete servicePath", serviceName), e);
397 return OperationResult.failed(LogMessages.failedTo("delete servicePath", serviceName));
402 * Write or Modify or Delete Service from/to SreviceList.
404 * @param serviceName Name of service
406 * @param input ServiceCreateInput
408 * @param output PathComputationRequestOutput
410 * @param choice 0 - Modify 1 - Delete 2 - Write
412 * @return String operations result, null if ok or not otherwise
416 public String writeOrModifyOrDeleteServiceList(String serviceName, ServiceCreateInput input,
417 PathComputationRequestOutput output, int choice) {
418 LOG.debug("WriteOrModifyOrDeleting '{}' Service", serviceName);
419 WriteTransaction writeTx = this.dataBroker.newWriteOnlyTransaction();
420 Optional<Services> readService = getService(serviceName);
425 if (!readService.isPresent()) {
427 LOG.warn("writeOrModifyOrDeleteServiceList: {}", LogMessages.SERVICE_NOT_FOUND);
428 return LogMessages.SERVICE_NOT_FOUND;
431 LOG.debug("Writing '{}' Service", serviceName);
432 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class)
433 .child(Services.class, new ServicesKey(serviceName));
434 Services service = ModelMappingUtils.mappingServices(input, null);
435 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
437 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
439 } catch (InterruptedException | TimeoutException | ExecutionException e) {
440 LOG.error("writeOrModifyOrDeleteServiceList : {}", LogMessages.failedTo(CREATE_MSG, serviceName), e);
441 return LogMessages.failedTo(CREATE_MSG, serviceName);
446 * Modify / Delete Service.
448 InstanceIdentifier<Services> iid =
449 InstanceIdentifier.create(ServiceList.class).child(Services.class, new ServicesKey(serviceName));
450 ServicesBuilder service = new ServicesBuilder(readService.get());
451 String action = null;
453 case 0 : /* Modify. */
454 LOG.debug("Modifying '{}' Service", serviceName);
455 service.setOperationalState(State.InService)
456 .setAdministrativeState(AdminStates.InService);
457 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build());
458 action = "modifyService";
460 case 1 : /* Delete */
461 LOG.debug(DELETING_SERVICE_MSG, serviceName);
462 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
463 action = "deleteService";
466 LOG.debug("No choice found");
470 writeTx.commit().get(Timeouts.DATASTORE_WRITE, TimeUnit.MILLISECONDS);
471 } catch (InterruptedException | ExecutionException | TimeoutException e) {
472 LOG.error("writeOrModifyOrDeleteServiceList : {}", LogMessages.failedTo(action, serviceName), e);
473 return LogMessages.failedTo(action, serviceName);