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.openflowplugin.applications.frm.impl;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
13 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
14 import org.opendaylight.openflowplugin.applications.frm.FlowCapableNodeConnectorCommitter;
15 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesCommiter;
16 import org.opendaylight.openflowplugin.applications.frm.ForwardingRulesManager;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
19 import org.opendaylight.yangtools.yang.binding.DataObject;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import java.util.Collection;
24 public abstract class AbstractNodeConnectorCommitter <T extends DataObject> implements FlowCapableNodeConnectorCommitter<T> {
25 protected ForwardingRulesManager provider;
27 protected final Class<T> clazz;
29 public AbstractNodeConnectorCommitter (ForwardingRulesManager provider, Class<T> clazz) {
30 this.provider = Preconditions.checkNotNull(provider, "ForwardingRulesManager can not be null!");
31 this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!");
35 public void onDataTreeChanged(Collection<DataTreeModification<T>> changes) {
36 Preconditions.checkNotNull(changes, "Changes may not be null!");
38 for (DataTreeModification<T> change : changes) {
39 final InstanceIdentifier<T> key = change.getRootPath().getRootIdentifier();
40 final DataObjectModification<T> mod = change.getRootNode();
41 final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent =
42 key.firstIdentifierOf(FlowCapableNodeConnector.class);
44 if (preConfigurationCheck(nodeConnIdent)) {
45 switch (mod.getModificationType()) {
47 remove(key, mod.getDataBefore(), nodeConnIdent);
49 case SUBTREE_MODIFIED:
50 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
53 if (mod.getDataBefore() == null) {
54 add(key, mod.getDataAfter(), nodeConnIdent);
56 update(key, mod.getDataBefore(), mod.getDataAfter(), nodeConnIdent);
60 throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType());
67 * Method return wildCardPath for Listener registration
68 * and for identify the correct KeyInstanceIdentifier from data;
70 protected abstract InstanceIdentifier<T> getWildCardPath();
72 private boolean preConfigurationCheck(final InstanceIdentifier<FlowCapableNodeConnector> nodeConnIdent) {
73 Preconditions.checkNotNull(nodeConnIdent, "FlowCapableNodeConnector ident can not be null!");
75 //return provider.isNodeActive(nodeConnIdent);