2 * Copyright (c) 2016 Hewlett Packard Enterprise, Co. 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.unimgr.mef.netvirt;
11 import org.apache.commons.lang3.StringUtils;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.unimgr.api.UnimgrDataTreeChangeListener;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
18 import org.opendaylight.yangtools.concepts.ListenerRegistration;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class ElanListener extends UnimgrDataTreeChangeListener<ElanInstance> {
24 private static final Logger log = LoggerFactory.getLogger(ElanListener.class);
25 private ListenerRegistration<ElanListener> elanListenerRegistration;
27 public ElanListener(final DataBroker dataBroker) {
33 public void registerListener() {
35 final DataTreeIdentifier<ElanInstance> dataTreeIid = new DataTreeIdentifier<>(
36 LogicalDatastoreType.CONFIGURATION, NetvirtUtils.getElanInstanceInstanceIdentifier());
37 elanListenerRegistration = dataBroker.registerDataTreeChangeListener(dataTreeIid, this);
38 log.info("ElanDataTreeChangeListener created and registered");
39 } catch (final Exception e) {
40 log.error("Elan DataChange listener registration failed !", e);
41 throw new IllegalStateException("Elan registration Listener failed.", e);
46 public void close() throws Exception {
47 elanListenerRegistration.close();
51 public void add(DataTreeModification<ElanInstance> newDataObject) {
52 log.info("org.opendaylight.unimgr.mef.netvirt.ElanListener in add");
53 ElanInstance instance = newDataObject.getRootNode().getDataAfter();
55 String instanceName = instance.getElanInstanceName();
56 if (!StringUtils.isNumericSpace(instanceName)) {
57 instanceName = String.valueOf(instanceName.hashCode());
59 if (!MefUtils.EvcExists(dataBroker, instanceName)) {
60 log.info("creating evc {}", instance);
61 MefUtils.createEvcInstance(dataBroker, instanceName);
63 log.info("evc {} exists, skipping", instance);
69 public void remove(DataTreeModification<ElanInstance> removedDataObject) {
70 log.info("org.opendaylight.unimgr.mef.netvirt.ElanListener in remove");
74 public void update(DataTreeModification<ElanInstance> modifiedDataObject) {
75 log.info("org.opendaylight.unimgr.mef.netvirt.ElanListener in update");