2 * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.listeners;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.vpnservice.datastoreutils.AsyncDataTreeChangeListenerBase;
14 import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
15 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.confighelpers.FlowBasedServicesConfigBindHelper;
16 import org.opendaylight.vpnservice.interfacemgr.servicebindings.flowbased.confighelpers.FlowBasedServicesConfigUnbindHelper;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.ServiceBindings;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.ServicesInfo;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.servicebinding.rev151015.service.bindings.services.info.BoundServices;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 import java.util.List;
25 import java.util.concurrent.Callable;
27 public class FlowBasedServicesConfigListener extends AsyncDataTreeChangeListenerBase<BoundServices, FlowBasedServicesConfigListener> {
28 private static final Logger LOG = LoggerFactory.getLogger(FlowBasedServicesConfigListener.class);
29 private DataBroker dataBroker;
31 public FlowBasedServicesConfigListener(final DataBroker dataBroker) {
32 super(BoundServices.class, FlowBasedServicesConfigListener.class);
33 this.dataBroker = dataBroker;
37 protected InstanceIdentifier<BoundServices> getWildCardPath() {
38 return InstanceIdentifier.create(ServiceBindings.class).child(ServicesInfo.class)
39 .child(BoundServices.class);
43 protected void remove(InstanceIdentifier<BoundServices> key, BoundServices boundServiceOld) {
44 String interfaceName = InstanceIdentifier.keyOf(key.firstIdentifierOf(ServicesInfo.class)).getInterfaceName();
45 LOG.info("Service Binding Entry removed for Interface: {}, Data: {}",
46 interfaceName, boundServiceOld);
48 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
49 RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, boundServiceOld);
50 coordinator.enqueueJob(interfaceName, configWorker);
54 protected void update(InstanceIdentifier<BoundServices> key, BoundServices boundServiceOld,
55 BoundServices boundServiceNew) {
56 LOG.error("Service Binding entry update not allowed for: {}, Data: {}",
57 InstanceIdentifier.keyOf(key.firstIdentifierOf(ServicesInfo.class)).getInterfaceName(), boundServiceNew);
61 protected void add(InstanceIdentifier<BoundServices> key, BoundServices boundServicesNew) {
62 String interfaceName = InstanceIdentifier.keyOf(key.firstIdentifierOf(ServicesInfo.class)).getInterfaceName();
63 LOG.info("Service Binding Entry created for Interface: {}, Data: {}",
64 interfaceName, boundServicesNew);
66 DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
67 RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, boundServicesNew);
68 coordinator.enqueueJob(interfaceName, configWorker);
72 protected FlowBasedServicesConfigListener getDataTreeChangeListener() {
73 return FlowBasedServicesConfigListener.this;
76 private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
77 InstanceIdentifier<BoundServices> instanceIdentifier;
78 BoundServices boundServicesNew;
80 public RendererConfigAddWorker(InstanceIdentifier<BoundServices> instanceIdentifier,
81 BoundServices boundServicesNew) {
82 this.instanceIdentifier = instanceIdentifier;
83 this.boundServicesNew = boundServicesNew;
87 public List<ListenableFuture<Void>> call() throws Exception {
88 return FlowBasedServicesConfigBindHelper.bindService(instanceIdentifier,
89 boundServicesNew, dataBroker);
93 private class RendererConfigRemoveWorker implements Callable<List<ListenableFuture<Void>>> {
94 InstanceIdentifier<BoundServices> instanceIdentifier;
95 BoundServices boundServicesNew;
97 public RendererConfigRemoveWorker(InstanceIdentifier<BoundServices> instanceIdentifier,
98 BoundServices boundServicesNew) {
99 this.instanceIdentifier = instanceIdentifier;
100 this.boundServicesNew = boundServicesNew;
104 public List<ListenableFuture<Void>> call() throws Exception {
105 return FlowBasedServicesConfigUnbindHelper.unbindService(instanceIdentifier,
106 boundServicesNew, dataBroker);