From: K.V Suneelu Verma Date: Mon, 18 Dec 2017 12:50:33 +0000 (+0530) Subject: Added device transaction log cli X-Git-Tag: release/oxygen~3 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=5871c030272c102a91b34a97f77d0e233d958dc1;p=ovsdb.git Added device transaction log cli Added a cli to display device transaction history Change-Id: I00d8f5bd287342691c7b69b0b75f79c2cdcee1e8 Signed-off-by: K.V Suneelu Verma --- diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml b/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml index 9e9f443f7..41cced7ba 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/pom.xml @@ -56,6 +56,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html library ${project.version} + + org.apache.karaf.shell + org.apache.karaf.shell.console + provided + ${project.groupId} schema.hardwarevtep diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java index 203a4598a..555362080 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionInstance.java @@ -50,6 +50,7 @@ import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.lib.schema.TableSchema; import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.ConnectionInfo; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; @@ -80,6 +81,8 @@ public class HwvtepConnectionInstance { private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); private final SettableFuture reconciliationFt = SettableFuture.create(); private final AtomicBoolean firstUpdateTriggered = new AtomicBoolean(false); + private TransactionHistory controllerTxHistory; + private TransactionHistory deviceUpdateHistory; HwvtepConnectionInstance (HwvtepConnectionManager hwvtepConnectionManager, ConnectionInfo key, OvsdbClient client, InstanceIdentifier iid, TransactionInvoker txInvoker, DataBroker dataBroker) { @@ -363,4 +366,30 @@ public class HwvtepConnectionInstance { TableUpdates tableUpdates = hwvtepTableReader.readAllTables(); callback.update(tableUpdates, getDatabaseSchema(HwvtepSchemaConstants.HARDWARE_VTEP)); } + + public MonitorCallBack getCallback() { + return callback; + } + + public void setCallback(MonitorCallBack callback) { + this.callback = callback; + } + + public TransactionHistory getControllerTxHistory() { + return controllerTxHistory; + } + + public void setControllerTxHistory(TransactionHistory controllerTxLog) { + deviceInfo.setControllerTxHistory(controllerTxLog); + this.controllerTxHistory = controllerTxLog; + } + + public TransactionHistory getDeviceUpdateHistory() { + return deviceUpdateHistory; + } + + public void setDeviceUpdateHistory(TransactionHistory deviceUpdateLog) { + deviceInfo.setDeviceUpdateHistory(deviceUpdateLog); + this.deviceUpdateHistory = deviceUpdateLog; + } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java index 4a07e20f7..f044c5415 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepConnectionManager.java @@ -25,6 +25,7 @@ import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipS import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipState; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.ovsdb.hwvtepsouthbound.events.ClientConnected; import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.ReconciliationManager; import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.ReconciliationTask; import org.opendaylight.ovsdb.hwvtepsouthbound.reconciliation.configuration.HwvtepReconciliationTask; @@ -42,6 +43,8 @@ import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.GenericTableSchema; import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils; import org.opendaylight.ovsdb.schema.hardwarevtep.Global; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchAttributes; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.PhysicalSwitchAugmentation; @@ -73,6 +76,8 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo private static final Logger LOG = LoggerFactory.getLogger(HwvtepConnectionManager.class); private static final String ENTITY_TYPE = "hwvtep"; private static final int DB_FETCH_TIMEOUT = 1000; + private static final int TRANSACTION_HISTORY_CAPACITY = 10000; + private static final int TRANSACTION_HISTORY_WATERMARK = 7500; private DataBroker db; private TransactionInvoker txInvoker; @@ -84,6 +89,8 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo private final Map, HwvtepConnectionInstance> nodeIidVsConnectionInstance = new ConcurrentHashMap<>(); private HwvtepOperGlobalListener hwvtepOperGlobalListener; + private final Map, TransactionHistory> controllerTxHistory = new ConcurrentHashMap<>(); + private final Map, TransactionHistory> deviceUpdateHistory = new ConcurrentHashMap<>(); public HwvtepConnectionManager(DataBroker db, TransactionInvoker txInvoker, EntityOwnershipService entityOwnershipService) { @@ -140,6 +147,9 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo ConnectionInfo key = HwvtepSouthboundMapper.createConnectionInfo(client); HwvtepConnectionInstance hwvtepConnectionInstance = getConnectionInstance(key); if (hwvtepConnectionInstance != null) { + deviceUpdateHistory.get(hwvtepConnectionInstance.getInstanceIdentifier()).addToHistory( + TransactionType.DELETE, new ClientConnected(client.getConnectionInfo().getRemotePort())); + // Unregister Entity ownership as soon as possible ,so this instance should // not be used as a candidate in Entity election (given that this instance is // about to disconnect as well), if current owner get disconnected from @@ -424,7 +434,16 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo hwvtepConnectionInstance.setInstanceIdentifier(iid); LOG.info("InstanceIdentifier {} generated for device " + "connection {}",iid, hwvtepConnectionInstance.getConnectionInfo()); - + controllerTxHistory.putIfAbsent(iid, + new TransactionHistory(TRANSACTION_HISTORY_CAPACITY, TRANSACTION_HISTORY_WATERMARK)); + deviceUpdateHistory.putIfAbsent(iid, + new TransactionHistory(TRANSACTION_HISTORY_CAPACITY, TRANSACTION_HISTORY_WATERMARK)); + TransactionHistory controllerLog = controllerTxHistory.get(iid); + TransactionHistory deviceLog = deviceUpdateHistory.get(iid); + int port = hwvtepConnectionInstance.getOvsdbClient().getConnectionInfo().getRemotePort(); + deviceLog.addToHistory(TransactionType.ADD, new ClientConnected(port)); + hwvtepConnectionInstance.setControllerTxHistory(controllerLog); + hwvtepConnectionInstance.setDeviceUpdateHistory(deviceLog); } YangInstanceIdentifier entityId = HwvtepSouthboundUtil.getInstanceIdentifierCodec().getYangInstanceIdentifier(iid); @@ -586,6 +605,14 @@ public class HwvtepConnectionManager implements OvsdbConnectionListener, AutoClo } } + public Map, TransactionHistory> getControllerTxHistory() { + return controllerTxHistory; + } + + public Map, TransactionHistory> getDeviceUpdateHistory() { + return deviceUpdateHistory; + } + private class HwvtepDeviceEntityOwnershipListener implements EntityOwnershipListener { private HwvtepConnectionManager hcm; private EntityOwnershipListenerRegistration listenerRegistration; diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java index ec637a98a..38c69865c 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepDeviceInfo.java @@ -16,12 +16,12 @@ import org.opendaylight.ovsdb.lib.notation.UUID; import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch; import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalLocator; import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteMcastMacs; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.RemoteUcastMacs; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; -import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; @@ -118,6 +118,9 @@ public class HwvtepDeviceInfo { private Map, Map> opKeyVsData = new ConcurrentHashMap<>(); private Map, Map> uuidVsData = new ConcurrentHashMap<>(); private DependencyQueue dependencyQueue; + private TransactionHistory controllerTxHistory; + private TransactionHistory deviceUpdateHistory; + public HwvtepDeviceInfo(HwvtepConnectionInstance hwvtepConnectionInstance) { this.connectionInstance = hwvtepConnectionInstance; @@ -395,4 +398,24 @@ public class HwvtepDeviceInfo { public HwvtepConnectionInstance getConnectionInstance() { return connectionInstance; } + + public void setConfigKeyVsData(Map, Map> configKeyVsData) { + this.configKeyVsData = configKeyVsData; + } + + public void setControllerTxHistory(TransactionHistory controllerTxHistory) { + this.controllerTxHistory = controllerTxHistory; + } + + public void setDeviceUpdateHistory(TransactionHistory deviceUpdateHistory) { + this.deviceUpdateHistory = deviceUpdateHistory; + } + + public void addToControllerTx(TransactionType transactionType, Object object) { + controllerTxHistory.addToHistory(transactionType, object); + } + + public void addToDeviceUpdate(TransactionType transactionType, Object object) { + deviceUpdateHistory.addToHistory(transactionType, object); + } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java index ad1cf2096..9956f4ef6 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepSouthboundProvider.java @@ -212,4 +212,7 @@ public class HwvtepSouthboundProvider implements ClusteredDataTreeChangeListener } } + public HwvtepConnectionManager getHwvtepConnectionManager() { + return cm; + } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTransactionLogElement.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTransactionLogElement.java new file mode 100644 index 000000000..7d2f99d2e --- /dev/null +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/HwvtepTransactionLogElement.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.hwvtepsouthbound; + +import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.HwvtepOperationalCommandAggregator; +import org.opendaylight.ovsdb.hwvtepsouthbound.transactions.md.TransactionInvoker; +import org.opendaylight.ovsdb.lib.MonitorCallBack; +import org.opendaylight.ovsdb.lib.message.TableUpdates; +import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionElement; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HwvtepTransactionLogElement extends TransactionElement { + + private final boolean isDeviceLog; + + public HwvtepTransactionLogElement(TransactionType transactionType, + Object data, + boolean isDeviceLog) { + super(transactionType, data); + this.isDeviceLog = isDeviceLog; + } + + public HwvtepTransactionLogElement(TransactionElement element, + boolean isDeviceLog) { + super(element.getTransactionType(), element.getData()); + this.isDeviceLog = isDeviceLog; + } + + @Override + public String toString() { + return "{" + + "isDeviceLog=" + isDeviceLog + + super.toString() + + '}'; + } +} diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/TransactionHistoryCmd.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/TransactionHistoryCmd.java new file mode 100644 index 000000000..60b82c870 --- /dev/null +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/TransactionHistoryCmd.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.hwvtepsouthbound; + +import org.apache.karaf.shell.commands.Command; +import org.apache.karaf.shell.commands.Option; +import org.apache.karaf.shell.console.OsgiCommandSupport; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionElement; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Command(scope = "hwvtep", name = "txlog", description = "prints hwvtep tx log") +public class TransactionHistoryCmd extends OsgiCommandSupport { + + @Option(name = "-nodeid", description = "Node Id", + required = false, multiValued = false) + String nodeid; + + private HwvtepSouthboundProvider hwvtepProvider; + private DataBroker dataBroker; + + public void setDataBroker(DataBroker dataBroker) { + this.dataBroker = dataBroker; + } + + public void setHwvtepProvider(HwvtepSouthboundProvider hwvtepProvider) { + this.hwvtepProvider = hwvtepProvider; + } + + @Override + protected Object doExecute() throws Exception { + Map, TransactionHistory> controllerTxLogs + = hwvtepProvider.getHwvtepConnectionManager().getControllerTxHistory(); + Map, TransactionHistory> deviceUpdateLogs + = hwvtepProvider.getHwvtepConnectionManager().getDeviceUpdateHistory(); + if (nodeid != null) { + InstanceIdentifier iid = HwvtepSouthboundMapper.createInstanceIdentifier(new NodeId(nodeid)); + printLogs(controllerTxLogs, deviceUpdateLogs, iid); + } else { + Map, TransactionHistory> txlogs + = controllerTxLogs.isEmpty() ? deviceUpdateLogs : controllerTxLogs; + txlogs.keySet().forEach( (iid) -> { + printLogs(controllerTxLogs, deviceUpdateLogs, iid); + }); + session.getConsole().println("Device tx logs size "+deviceUpdateLogs.keySet().size()); + } + return null; + } + + private void printLogs(Map, TransactionHistory> controllerTxLogs, + Map, TransactionHistory> deviceUpdateLogs, + InstanceIdentifier iid) { + session.getConsole().println("Printing for iid "+ iid); + List controllerTxLog = controllerTxLogs.get(iid).getElements() + .stream().map(ele -> new HwvtepTransactionLogElement(ele, false)).collect(Collectors.toList()); + List deviceUpdateLog = deviceUpdateLogs.get(iid).getElements() + .stream().map(ele -> new HwvtepTransactionLogElement(ele, false)).collect(Collectors.toList()); + //deviceUpdateLog.forEach( (log) -> log.setDeviceLog(true)); + List allLogs = mergeLogsByDate(controllerTxLog, deviceUpdateLog); + session.getConsole().println("======================================"); + session.getConsole().println("======================================"); + session.getConsole().print("printing logs for node "); + session.getConsole().println(iid); + printLogs(allLogs); + } + + private void sortLogsByDate(ArrayList logs) { + Collections.sort(logs, new Comparator() { + @Override + public int compare(TransactionElement o1, TransactionElement o2) { + return (int) (o1.getDate() - o2.getDate()); + } + }); + } + + private List mergeLogsByDate( + List logs1, + List logs2) { + + ArrayList result = new ArrayList(); + int firstIdx = 0; + int secondIdx = 0; + int firstSize = logs1.size(); + int secondSize = logs2.size(); + while ( firstIdx < firstSize && secondIdx < secondSize) { + if (logs1.get(firstIdx).getDate() < logs2.get(secondIdx).getDate()) { + result.add(logs1.get(firstIdx)); + firstIdx++; + } else { + result.add(logs2.get(secondIdx)); + secondIdx++; + } + } + while (firstIdx < firstSize) { + result.add(logs1.get(firstIdx)); + firstIdx++; + } + while (secondIdx < secondSize) { + result.add(logs2.get(secondIdx)); + secondIdx++; + } + return result; + } + + private void printLogs(List logs) { + logs.forEach( (log) -> { + session.getConsole().print(new Date(log.getDate())); + session.getConsole().print(" "); + session.getConsole().print(log.getTransactionType()); + session.getConsole().print(" "); + session.getConsole().println(log.getData()); + }); + } +} diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ClientConnected.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ClientConnected.java new file mode 100644 index 000000000..653eab8c0 --- /dev/null +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ClientConnected.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.hwvtepsouthbound.events; + +public class ClientConnected { + + private final int port; + + public ClientConnected(int port) { + this.port = port; + } + + @Override + public String toString() { + return "ClientConnected{" + + "port=" + port + + '}'; + } +} diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ClientDisConnected.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ClientDisConnected.java new file mode 100644 index 000000000..6d554ca90 --- /dev/null +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ClientDisConnected.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.hwvtepsouthbound.events; + +public class ClientDisConnected { + + private final int port; + + public ClientDisConnected(int port) { + this.port = port; + } + + @Override + public String toString() { + return "ClientConnected{" + + "port=" + port + + '}'; + } +} diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/PortEvent.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/PortEvent.java new file mode 100644 index 000000000..408990a5c --- /dev/null +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/PortEvent.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.hwvtepsouthbound.events; + +import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +public class PortEvent { + + private final PhysicalPort port; + private final NodeId nodeId; + + public PortEvent(PhysicalPort port, NodeId nodeId) { + this.port = port; + this.nodeId = nodeId; + } + + @Override + public String toString() { + return "PortEvent{" + + "port=" + port + + "nodeId=" + nodeId + + '}'; + } +} diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ReconcilePortEvent.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ReconcilePortEvent.java new file mode 100644 index 000000000..252d86b50 --- /dev/null +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/events/ReconcilePortEvent.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.ovsdb.hwvtepsouthbound.events; + +import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +public class ReconcilePortEvent { + + private final PhysicalPort port; + private final NodeId nodeId; + + public ReconcilePortEvent(PhysicalPort port, NodeId nodeId) { + this.port = port; + this.nodeId = nodeId; + } + + @Override + public String toString() { + return "ReconcilePortEvent{" + + "port=" + port + + "nodeId=" + nodeId + + '}'; + } +} diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/AbstractTransactCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/AbstractTransactCommand.java index 813c54d62..0a1493d6e 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/AbstractTransactCommand.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transact/AbstractTransactCommand.java @@ -30,6 +30,7 @@ import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil; import org.opendaylight.ovsdb.lib.notation.UUID; import org.opendaylight.ovsdb.lib.operations.TransactionBuilder; import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; @@ -400,4 +401,8 @@ public abstract class AbstractTransactCommand { private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchRemoveCommand.class); @@ -136,6 +133,7 @@ public class LogicalSwitchRemoveCommand extends AbstractTransactCommand { private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchUpdateCommand.class); @@ -94,6 +92,7 @@ public class LogicalSwitchUpdateCommand extends AbstractTransactCommand implement public HwvtepDeviceInfo getDeviceInfo() { return key.getDeviceInfo(); } + + void addToDeviceUpdate(TransactionType transactionType, Object element) { + key.getDeviceInfo().addToDeviceUpdate(transactionType, element); + } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchRemoveCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchRemoveCommand.java index f4dcab33e..a6f4591e8 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchRemoveCommand.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchRemoveCommand.java @@ -17,6 +17,7 @@ import org.opendaylight.ovsdb.lib.message.TableUpdates; import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils; import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepNodeName; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches; @@ -40,6 +41,7 @@ public class HwvtepLogicalSwitchRemoveCommand extends AbstractTransactionCommand // TODO Delete any references transaction.delete(LogicalDatastoreType.OPERATIONAL, switchIid); getOvsdbConnectionInstance().getDeviceInfo().clearDeviceOperData(LogicalSwitches.class, switchIid); + addToDeviceUpdate(TransactionType.DELETE, lSwitch); } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchUpdateCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchUpdateCommand.java index c00f79145..13d2ad0a1 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchUpdateCommand.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepLogicalSwitchUpdateCommand.java @@ -24,6 +24,7 @@ import org.opendaylight.ovsdb.lib.notation.Version; import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils; import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder; @@ -67,6 +68,7 @@ public class HwvtepLogicalSwitchUpdateCommand extends AbstractTransactionCommand .child(LogicalSwitches.class, new LogicalSwitchesKey(new HwvtepNodeName(lSwitch.getName()))); getOvsdbConnectionInstance().getDeviceInfo().updateDeviceOperData(LogicalSwitches.class, switchIid, lSwitch.getUuid(), lSwitch); + addToDeviceUpdate(TransactionType.ADD, lSwitch); // TODO: Delete entries that are no longer needed } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortRemoveCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortRemoveCommand.java index cf29c3e53..a1a6ed112 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortRemoveCommand.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortRemoveCommand.java @@ -15,13 +15,16 @@ import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance; import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper; +import org.opendaylight.ovsdb.hwvtepsouthbound.events.PortEvent; import org.opendaylight.ovsdb.lib.message.TableUpdates; import org.opendaylight.ovsdb.lib.notation.UUID; import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils; import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort; import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -65,6 +68,8 @@ public class HwvtepPhysicalPortRemoveCommand extends AbstractTransactionCommand updatedPSwitchData).child(TerminationPoint.class, new TerminationPointKey(new TpId(portName))); transaction.delete(LogicalDatastoreType.OPERATIONAL, nodePath); + addToDeviceUpdate(TransactionType.DELETE, + new PortEvent(pPort, nodePath.firstKeyOf(Node.class).getNodeId())); getDeviceInfo().clearDeviceOperData(TerminationPoint.class, nodePath); } } diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortUpdateCommand.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortUpdateCommand.java index ce65d5c62..0b2ec4168 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortUpdateCommand.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/java/org/opendaylight/ovsdb/hwvtepsouthbound/transactions/md/HwvtepPhysicalPortUpdateCommand.java @@ -26,6 +26,8 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepConnectionInstance; import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundMapper; import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil; +import org.opendaylight.ovsdb.hwvtepsouthbound.events.PortEvent; +import org.opendaylight.ovsdb.hwvtepsouthbound.events.ReconcilePortEvent; import org.opendaylight.ovsdb.hwvtepsouthbound.transact.HwvtepOperationalState; import org.opendaylight.ovsdb.hwvtepsouthbound.transact.PhysicalPortUpdateCommand; import org.opendaylight.ovsdb.lib.message.TableUpdates; @@ -35,6 +37,7 @@ import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils; import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch; import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalPort; import org.opendaylight.ovsdb.schema.hardwarevtep.PhysicalSwitch; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid; import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; @@ -51,6 +54,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hw import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindings; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindingsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.physical.port.attributes.VlanBindingsKey; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TpId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; @@ -129,6 +133,12 @@ public class HwvtepPhysicalPortUpdateCommand extends AbstractTransactionCommand } else { transaction.put(LogicalDatastoreType.OPERATIONAL, tpPath, tpBuilder.build()); } + NodeId psNodeId = tpPath.firstKeyOf(Node.class).getNodeId(); + if (getDeviceInfo().getDeviceOperData(TerminationPoint.class, tpPath) == null) { + addToDeviceUpdate(TransactionType.ADD, new PortEvent(pPortUpdate, psNodeId)); + } else { + addToDeviceUpdate(TransactionType.UPDATE, new PortEvent(pPortUpdate, psNodeId)); + } reconcileToPort(transaction, pPortUpdate, tpPath); getDeviceInfo().updateDeviceOperData(TerminationPoint.class, tpPath, pPortUpdate.getUuid(), pPortUpdate); @@ -177,6 +187,8 @@ public class HwvtepPhysicalPortUpdateCommand extends AbstractTransactionCommand //TODO port came with some vlan bindings clean them up use PortRemovedCommand return; } + addToDeviceUpdate(TransactionType.ADD, + new ReconcilePortEvent(pPortUpdate, tpPath.firstKeyOf(Node.class).getNodeId())); getDeviceInfo().updateDeviceOperData(TerminationPoint.class, tpPath, pPortUpdate.getUuid(), pPortUpdate); TerminationPoint configTp = optionalConfigTp.get(); diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/org/opendaylight/blueprint/hwvtepsouthbound.xml b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/org/opendaylight/blueprint/hwvtepsouthbound.xml index 357b09efb..081d1ff98 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/org/opendaylight/blueprint/hwvtepsouthbound.xml +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/main/resources/org/opendaylight/blueprint/hwvtepsouthbound.xml @@ -24,4 +24,12 @@ + + + + + + + + diff --git a/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java b/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java index 59501ec12..90ae8ce3a 100644 --- a/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java +++ b/hwvtepsouthbound/hwvtepsouthbound-impl/src/test/java/org/opendaylight/ovsdb/hwvtepsouthbound/DataChangeListenerTestBase.java @@ -54,6 +54,7 @@ import org.opendaylight.ovsdb.lib.operations.Update; import org.opendaylight.ovsdb.lib.operations.Where; import org.opendaylight.ovsdb.lib.schema.DatabaseSchema; import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable; +import org.opendaylight.ovsdb.utils.mdsal.utils.TransactionHistory; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder; @@ -207,6 +208,8 @@ public class DataChangeListenerTestBase extends AbstractDataBrokerTest { doReturn(nodeIid).when(connectionInstance).getInstanceIdentifier(); field(HwvtepConnectionInstance.class, "deviceInfo").set(connectionInstance, new HwvtepDeviceInfo(connectionInstance)); + connectionInstance.setControllerTxHistory(new TransactionHistory(10000, 7500)); + connectionInstance.setDeviceUpdateHistory(new TransactionHistory(10000, 7500)); connectionInstance.createTransactInvokers(); } diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalObject.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalObject.java new file mode 100644 index 000000000..f8beee694 --- /dev/null +++ b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/MdsalObject.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.ovsdb.utils.mdsal.utils; + +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MdsalObject { + private final InstanceIdentifier iid; + private final DataObject dataObject; + + public MdsalObject(InstanceIdentifier iid, DataObject dataObject) { + this.dataObject = dataObject; + this.iid = iid; + } + + @Override + public String toString() { + return "MdsalObject{" + + "dataObject=" + dataObject + + ", iid=" + iid + + '}'; + } +} diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionElement.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionElement.java new file mode 100644 index 000000000..18c695b04 --- /dev/null +++ b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionElement.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.ovsdb.utils.mdsal.utils; + +public class TransactionElement { + private long date; + private TransactionType transactionType; + private Object data; + + public TransactionElement(TransactionType transactionType, Object data) { + this.data = data; + this.transactionType = transactionType; + this.date = System.currentTimeMillis(); + } + + public Object getData() { + return data; + } + + public long getDate() { + return date; + } + + public TransactionType getTransactionType() { + return transactionType; + } + + @Override + public String toString() { + return "TransactionElement{" + + "date=" + date + + ", transactionType=" + transactionType + + ", data=" + data + + '}'; + } +} diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionHistory.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionHistory.java new file mode 100644 index 000000000..ec45cb84f --- /dev/null +++ b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionHistory.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.ovsdb.utils.mdsal.utils; + +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; + +public class TransactionHistory extends ArrayList { + + private final int capacity; + private final int watermark; + + public TransactionHistory(int initialCapacity, int watermark) { + super(initialCapacity); + this.capacity = initialCapacity; + this.watermark = watermark; + } + + public void addToHistory(TransactionType updateType, Object object) { + add(new TransactionElement(updateType, object)); + } + + public void addToHistory(TransactionType updateType, InstanceIdentifier iid, DataObject dataObject) { + add(new TransactionElement(updateType, new MdsalObject(iid, dataObject))); + } + + @Override + public boolean add(TransactionElement element) { + if (size() >= watermark) { + removeRange(0, capacity - watermark); + } + return super.add(element); + } + + public ArrayList getElements() { + return new ArrayList<>(this); + } + + @Override + protected void removeRange(int fromIndex, int toIndex) { + super.removeRange(fromIndex, toIndex); + } +} diff --git a/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionType.java b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionType.java new file mode 100644 index 000000000..e061358e4 --- /dev/null +++ b/utils/mdsal-utils/src/main/java/org/opendaylight/ovsdb/utils/mdsal/utils/TransactionType.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.ovsdb.utils.mdsal.utils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; + +public enum TransactionType { + ADD, + UPDATE, + DELETE; +}