X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fstatistics%2FStatisticsGatheringUtils.java;h=e0dd990709409adce8828531d92d5cf0364ed19c;hb=0ac8877c3539d82e55ffe49dc0a2c8bcb0c82b19;hp=cc97c8fcc6bab1c55863c43ce6ab049126d1344b;hpb=8a3b468428a26205b1e19e1f50eba01b6e5386a1;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java index cc97c8fcc6..e0dd990709 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/statistics/StatisticsGatheringUtils.java @@ -21,17 +21,26 @@ import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; import java.util.List; +import java.util.Objects; import javax.annotation.Nullable; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException; import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceInfo; +import org.opendaylight.openflowplugin.api.openflow.device.DeviceRegistry; +import org.opendaylight.openflowplugin.api.openflow.device.TxFacade; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.DeviceFlowRegistry; +import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowDescriptor; import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey; +import org.opendaylight.openflowplugin.api.openflow.registry.group.DeviceGroupRegistry; +import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier; import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.StatisticsGatherer; import org.opendaylight.openflowplugin.impl.registry.flow.FlowRegistryKeyFactory; import org.opendaylight.openflowplugin.impl.statistics.ofpspecific.EventsTimeCounter; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatus; @@ -106,47 +115,54 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Created by Martin Bobak <mbobak@cisco.com> on 2.4.2015. + * Utils for gatherig statistics */ public final class StatisticsGatheringUtils { - public static String DATE_AND_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; + private static String DATE_AND_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"; private static final Logger LOG = LoggerFactory.getLogger(StatisticsGatheringUtils.class); - private static final SinglePurposeMultipartReplyTranslator MULTIPART_REPLY_TRANSLATOR = new SinglePurposeMultipartReplyTranslator(); - public static final String QUEUE2_REQCTX = "QUEUE2REQCTX-"; + private static final String QUEUE2_REQCTX = "QUEUE2REQCTX-"; private StatisticsGatheringUtils() { throw new IllegalStateException("This class should not be instantiated."); } - - public static ListenableFuture gatherStatistics(final StatisticsGatherer statisticsGatheringService, - final DeviceContext deviceContext, - final MultipartType type) { - final String deviceId = deviceContext.getPrimaryConnectionContext().getNodeId().toString(); + //TODO: Flow-,Group- and Meter- registry should be not in device context, consider move it in separate class + static ListenableFuture gatherStatistics(final StatisticsGatherer statisticsGatheringService, + final DeviceInfo deviceInfo, + final MultipartType type, + final TxFacade txFacade, + final DeviceRegistry registry, + final Boolean initial, + final SinglePurposeMultipartReplyTranslator multipartReplyTranslator) { EventIdentifier wholeProcessEventIdentifier = null; if (MultipartType.OFPMPFLOW.equals(type)) { - wholeProcessEventIdentifier = new EventIdentifier(type.toString(), deviceId); + wholeProcessEventIdentifier = new EventIdentifier(type.toString(), deviceInfo.getNodeId().getValue()); EventsTimeCounter.markStart(wholeProcessEventIdentifier); } - final EventIdentifier ofpQueuToRequestContextEventIdentifier = new EventIdentifier(QUEUE2_REQCTX + type.toString(), deviceId); + final EventIdentifier ofpQueuToRequestContextEventIdentifier = new EventIdentifier(QUEUE2_REQCTX + type.toString(), deviceInfo.getNodeId().toString()); final ListenableFuture>> statisticsDataInFuture = JdkFutureAdapters.listenInPoolThread(statisticsGatheringService.getStatisticsOfType( ofpQueuToRequestContextEventIdentifier, type)); - return transformAndStoreStatisticsData(statisticsDataInFuture, deviceContext, wholeProcessEventIdentifier, type); + return transformAndStoreStatisticsData(statisticsDataInFuture, deviceInfo, wholeProcessEventIdentifier, type, txFacade, registry, initial, multipartReplyTranslator); } private static ListenableFuture transformAndStoreStatisticsData(final ListenableFuture>> statisticsDataInFuture, - final DeviceContext deviceContext, - final EventIdentifier eventIdentifier, final MultipartType type) { + final DeviceInfo deviceInfo, + final EventIdentifier eventIdentifier, + final MultipartType type, + final TxFacade txFacade, + final DeviceRegistry registry, + final boolean initial, + final SinglePurposeMultipartReplyTranslator multipartReplyTranslator) { return Futures.transform(statisticsDataInFuture, new AsyncFunction>, Boolean>() { @Nullable @Override public ListenableFuture apply(final RpcResult> rpcResult) { boolean isMultipartProcessed = Boolean.TRUE; if (rpcResult.isSuccessful()) { - LOG.debug("Stats reply successfully received for node {} of type {}", deviceContext.getDeviceState().getNodeId(), type); + LOG.debug("Stats reply successfully received for node {} of type {}", deviceInfo.getNodeId(), type); // TODO: in case the result value is null then multipart data probably got processed on the fly - // TODO: this contract should by clearly stated and enforced - now simple true value is returned @@ -157,55 +173,57 @@ public final class StatisticsGatheringUtils { try { for (final MultipartReply singleReply : rpcResult.getResult()) { - final List multipartDataList = MULTIPART_REPLY_TRANSLATOR.translate(deviceContext, singleReply); + final List multipartDataList = multipartReplyTranslator.translate( + deviceInfo.getDatapathId(), + deviceInfo.getVersion(), singleReply); multipartData = multipartDataList.get(0); allMultipartData = Iterables.concat(allMultipartData, multipartDataList); } } catch (final Exception e) { LOG.warn("stats processing of type {} for node {} failed during transfomation step", - type, deviceContext.getDeviceState().getNodeId(), e); + type, deviceInfo.getNodeId(), e); return Futures.immediateFailedFuture(e); } try { if (multipartData instanceof GroupStatisticsUpdated) { - processGroupStatistics((Iterable) allMultipartData, deviceContext); + processGroupStatistics((Iterable) allMultipartData, deviceInfo, txFacade); } else if (multipartData instanceof MeterStatisticsUpdated) { - processMetersStatistics((Iterable) allMultipartData, deviceContext); + processMetersStatistics((Iterable) allMultipartData, deviceInfo, txFacade); } else if (multipartData instanceof NodeConnectorStatisticsUpdate) { - processNodeConnectorStatistics((Iterable) allMultipartData, deviceContext); + processNodeConnectorStatistics((Iterable) allMultipartData, deviceInfo, txFacade); } else if (multipartData instanceof FlowTableStatisticsUpdate) { - processFlowTableStatistics((Iterable) allMultipartData, deviceContext); + processFlowTableStatistics((Iterable) allMultipartData, deviceInfo, txFacade); } else if (multipartData instanceof QueueStatisticsUpdate) { - processQueueStatistics((Iterable) allMultipartData, deviceContext); + processQueueStatistics((Iterable) allMultipartData, deviceInfo, txFacade); } else if (multipartData instanceof FlowsStatisticsUpdate) { /* FlowStat Processing is realized by NettyThread only by initPhase, otherwise it is realized * by MD-SAL thread */ - return processFlowStatistics((Iterable) allMultipartData, deviceContext, eventIdentifier); + return processFlowStatistics((Iterable) allMultipartData, deviceInfo, txFacade, registry.getDeviceFlowRegistry(), initial, eventIdentifier); } else if (multipartData instanceof GroupDescStatsUpdated) { - processGroupDescStats((Iterable) allMultipartData, deviceContext); + processGroupDescStats((Iterable) allMultipartData, deviceInfo, txFacade, registry.getDeviceGroupRegistry()); } else if (multipartData instanceof MeterConfigStatsUpdated) { - processMeterConfigStatsUpdated((Iterable) allMultipartData, deviceContext); + processMeterConfigStatsUpdated((Iterable) allMultipartData, deviceInfo, txFacade, registry.getDeviceMeterRegistry()); } else { isMultipartProcessed = Boolean.FALSE; } } catch (final Exception e) { LOG.warn("stats processing of type {} for node {} failed during write-to-tx step", - type, deviceContext.getDeviceState().getNodeId(), e); + type, deviceInfo.getNodeId(), e); return Futures.immediateFailedFuture(e); } - LOG.debug("Stats reply added to transaction for node {} of type {}", deviceContext.getDeviceState().getNodeId(), type); + LOG.debug("Stats reply added to transaction for node {} of type {}", deviceInfo.getNodeId(), type); //TODO : implement experimenter } else { - LOG.debug("Stats reply was empty for node {} of type {}", deviceContext.getDeviceState().getNodeId(), type); + LOG.debug("Stats reply was empty for node {} of type {}", deviceInfo.getNodeId(), type); } } else { - LOG.debug("Stats reply FAILED for node {} of type {}: {}", deviceContext.getDeviceState().getNodeId(), type, rpcResult.getErrors()); + LOG.debug("Stats reply FAILED for node {} of type {}: {}", deviceInfo.getNodeId(), type, rpcResult.getErrors()); isMultipartProcessed = Boolean.FALSE; } return Futures.immediateFuture(isMultipartProcessed); @@ -213,9 +231,12 @@ public final class StatisticsGatheringUtils { }); } - private static void processMeterConfigStatsUpdated(final Iterable data, final DeviceContext deviceContext) throws Exception { - final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); - deleteAllKnownMeters(deviceContext, fNodeIdent); + private static void processMeterConfigStatsUpdated(final Iterable data, + final DeviceInfo deviceInfo, + final TxFacade txFacade, + final DeviceMeterRegistry meterRegistry) throws Exception { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceInfo); + deleteAllKnownMeters(meterRegistry, fNodeIdent, txFacade); for (final MeterConfigStatsUpdated meterConfigStatsUpdated : data) { for (final MeterConfigStats meterConfigStats : meterConfigStatsUpdated.getMeterConfigStats()) { final MeterId meterId = meterConfigStats.getMeterId(); @@ -224,30 +245,38 @@ public final class StatisticsGatheringUtils { final MeterBuilder meterBuilder = new MeterBuilder(meterConfigStats); meterBuilder.setKey(new MeterKey(meterId)); meterBuilder.addAugmentation(NodeMeterStatistics.class, new NodeMeterStatisticsBuilder().build()); - deviceContext.getDeviceMeterRegistry().store(meterId); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, meterInstanceIdentifier, meterBuilder.build()); + meterRegistry.store(meterId); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, meterInstanceIdentifier, meterBuilder.build()); } } - deviceContext.submitTransaction(); + txFacade.submitTransaction(); } private static ListenableFuture processFlowStatistics(final Iterable data, - final DeviceContext deviceContext, final EventIdentifier eventIdentifier) { - final ListenableFuture deleFuture = deleteAllKnownFlows(deviceContext); - return Futures.transform(deleFuture, new Function() { + final DeviceInfo deviceInfo, + final TxFacade txFacade, + final DeviceFlowRegistry flowRegistry, + final boolean initial, + final EventIdentifier eventIdentifier) { + final ListenableFuture deleteFuture = initial ? Futures.immediateFuture(null) : deleteAllKnownFlows(deviceInfo, + flowRegistry, txFacade); + return Futures.transform(deleteFuture, new Function() { @Override public Boolean apply(final Void input) { - writeFlowStatistics(data, deviceContext); - deviceContext.submitTransaction(); + writeFlowStatistics(data, deviceInfo, flowRegistry, txFacade); + txFacade.submitTransaction(); EventsTimeCounter.markEnd(eventIdentifier); return Boolean.TRUE; } }); } - public static void writeFlowStatistics(final Iterable data, final DeviceContext deviceContext) { - final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); + public static void writeFlowStatistics(final Iterable data, + final DeviceInfo deviceInfo, + final DeviceFlowRegistry registry, + final TxFacade txFacade) { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceInfo); try { for (final FlowsStatisticsUpdate flowsStatistics : data) { for (final FlowAndStatisticsMapList flowStat : flowsStatistics.getFlowAndStatisticsMapList()) { @@ -255,14 +284,14 @@ public final class StatisticsGatheringUtils { flowBuilder.addAugmentation(FlowStatisticsData.class, refineFlowStatisticsAugmentation(flowStat).build()); final short tableId = flowStat.getTableId(); - final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(flowBuilder.build()); - final FlowId flowId = deviceContext.getDeviceFlowRegistry().storeIfNecessary(flowRegistryKey, tableId); + final FlowRegistryKey flowRegistryKey = FlowRegistryKeyFactory.create(deviceInfo.getVersion(), flowBuilder.build()); + final FlowId flowId = registry.storeIfNecessary(flowRegistryKey); final FlowKey flowKey = new FlowKey(flowId); flowBuilder.setKey(flowKey); final TableKey tableKey = new TableKey(tableId); final InstanceIdentifier flowIdent = fNodeIdent.child(Table.class, tableKey).child(Flow.class, flowKey); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build()); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowIdent, flowBuilder.build()); } } } catch (Exception e) { @@ -282,51 +311,48 @@ public final class StatisticsGatheringUtils { return flowStatisticsDataBld; } - public static ListenableFuture deleteAllKnownFlows(final DeviceContext deviceContext) { - /* DeviceState.deviceSynchronized is a marker for actual phase - false means initPhase, true means noInitPhase */ - if (deviceContext.getDeviceState().deviceSynchronized()) { - final InstanceIdentifier flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceContext); - final ReadOnlyTransaction readTx = deviceContext.getReadTransaction(); - final CheckedFuture, ReadFailedException> flowCapableNodeFuture = readTx.read( - LogicalDatastoreType.OPERATIONAL, flowCapableNodePath); - - /* we wish to close readTx for fallBack */ - Futures.withFallback(flowCapableNodeFuture, new FutureFallback>() { - - @Override - public ListenableFuture> create(final Throwable t) throws Exception { - readTx.close(); - return Futures.immediateFailedFuture(t); - } - }); - /* - * we have to read actual tables with all information before we set empty Flow list, merge is expensive and - * not applicable for lists - */ - return Futures.transform(flowCapableNodeFuture, new AsyncFunction, Void>() { - - @Override - public ListenableFuture apply(final Optional flowCapNodeOpt) throws Exception { - if (flowCapNodeOpt.isPresent()) { - for (final Table tableData : flowCapNodeOpt.get().getTable()) { - final Table table = new TableBuilder(tableData).setFlow(Collections.emptyList()).build(); - final InstanceIdentifier iiToTable = flowCapableNodePath.child(Table.class, tableData.getKey()); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table); - } + public static ListenableFuture deleteAllKnownFlows(final DeviceInfo deviceInfo, + final DeviceFlowRegistry registry, + final TxFacade txFacade) { + final InstanceIdentifier flowCapableNodePath = assembleFlowCapableNodeInstanceIdentifier(deviceInfo); + final ReadOnlyTransaction readTx = txFacade.getReadTransaction(); + final CheckedFuture, ReadFailedException> flowCapableNodeFuture = readTx.read( + LogicalDatastoreType.OPERATIONAL, flowCapableNodePath); + + /* we wish to close readTx for fallBack */ + Futures.withFallback(flowCapableNodeFuture, new FutureFallback>() { + + @Override + public ListenableFuture> create(final Throwable t) throws Exception { + readTx.close(); + return Futures.immediateFailedFuture(t); + } + }); + /* + * we have to read actual tables with all information before we set empty Flow list, merge is expensive and + * not applicable for lists + */ + return Futures.transform(flowCapableNodeFuture, new AsyncFunction, Void>() { + + @Override + public ListenableFuture apply(final Optional flowCapNodeOpt) throws Exception { + if (flowCapNodeOpt.isPresent()) { + for (final Table tableData : flowCapNodeOpt.get().getTable()) { + final Table table = new TableBuilder(tableData).setFlow(Collections.emptyList()).build(); + final InstanceIdentifier
iiToTable = flowCapableNodePath.child(Table.class, tableData.getKey()); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, iiToTable, table); } - deviceContext.getDeviceFlowRegistry().removeMarked(); - readTx.close(); - return Futures.immediateFuture(null); } + readTx.close(); + return Futures.immediateFuture(null); + } - }); - } - return Futures.immediateFuture(null); + }); } - private static void processQueueStatistics(final Iterable data, final DeviceContext deviceContext) throws Exception { + private static void processQueueStatistics(final Iterable data, final DeviceInfo deviceInfo, final TxFacade txFacade) throws Exception { // TODO: clean all queues of all node-connectors before writing up-to-date stats - final InstanceIdentifier nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier(); + final InstanceIdentifier nodeIdent = deviceInfo.getNodeInstanceIdentifier(); for (final QueueStatisticsUpdate queueStatisticsUpdate : data) { for (final QueueIdAndStatisticsMap queueStat : queueStatisticsUpdate.getQueueIdAndStatisticsMap()) { if (queueStat.getQueueId() != null) { @@ -345,29 +371,29 @@ public final class StatisticsGatheringUtils { .setQueueId(queueStat.getQueueId()) // node-connector-id is already contained in parent node and the port-id here is of incompatible format .addAugmentation(FlowCapableNodeConnectorQueueStatisticsData.class, statBuild.build()); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueIdent, queueBuilder.build()); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, queueIdent, queueBuilder.build()); } } } - deviceContext.submitTransaction(); + txFacade.submitTransaction(); } - private static void processFlowTableStatistics(final Iterable data, final DeviceContext deviceContext) throws Exception { - final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); + private static void processFlowTableStatistics(final Iterable data, final DeviceInfo deviceInfo, final TxFacade txFacade) throws Exception { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceInfo); for (final FlowTableStatisticsUpdate flowTableStatisticsUpdate : data) { for (final FlowTableAndStatisticsMap tableStat : flowTableStatisticsUpdate.getFlowTableAndStatisticsMap()) { final InstanceIdentifier tStatIdent = fNodeIdent.child(Table.class, new TableKey(tableStat.getTableId().getValue())) .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class); final FlowTableStatistics stats = new FlowTableStatisticsBuilder(tableStat).build(); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tStatIdent, stats); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, tStatIdent, stats); } } - deviceContext.submitTransaction(); + txFacade.submitTransaction(); } - private static void processNodeConnectorStatistics(final Iterable data, final DeviceContext deviceContext) throws Exception { - final InstanceIdentifier nodeIdent = deviceContext.getDeviceState().getNodeInstanceIdentifier(); + private static void processNodeConnectorStatistics(final Iterable data, final DeviceInfo deviceInfo, final TxFacade txFacade) throws Exception { + final InstanceIdentifier nodeIdent = deviceInfo.getNodeInstanceIdentifier(); for (final NodeConnectorStatisticsUpdate nodeConnectorStatisticsUpdate : data) { for (final NodeConnectorStatisticsAndPortNumberMap nConnectPort : nodeConnectorStatisticsUpdate.getNodeConnectorStatisticsAndPortNumberMap()) { final FlowCapableNodeConnectorStatistics stats = new FlowCapableNodeConnectorStatisticsBuilder(nConnectPort).build(); @@ -377,15 +403,16 @@ public final class StatisticsGatheringUtils { .augmentation(FlowCapableNodeConnectorStatisticsData.class); final InstanceIdentifier flowCapNodeConnStatIdent = nodeConnStatIdent.child(FlowCapableNodeConnectorStatistics.class); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowCapNodeConnStatIdent, stats); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, flowCapNodeConnStatIdent, stats); } } - deviceContext.submitTransaction(); + txFacade.submitTransaction(); } private static void processMetersStatistics(final Iterable data, - final DeviceContext deviceContext) throws Exception { - final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); + final DeviceInfo deviceInfo, + final TxFacade txFacade) throws Exception { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceInfo); for (final MeterStatisticsUpdated meterStatisticsUpdated : data) { for (final MeterStats mStat : meterStatisticsUpdated.getMeterStats()) { final MeterStatistics stats = new MeterStatisticsBuilder(mStat).build(); @@ -394,24 +421,23 @@ public final class StatisticsGatheringUtils { final InstanceIdentifier nodeMeterStatIdent = meterIdent .augmentation(NodeMeterStatistics.class); final InstanceIdentifier msIdent = nodeMeterStatIdent.child(MeterStatistics.class); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, msIdent, stats); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, msIdent, stats); } } - deviceContext.submitTransaction(); + txFacade.submitTransaction(); } - private static void deleteAllKnownMeters(final DeviceContext deviceContext, final InstanceIdentifier fNodeIdent) throws Exception { - for (final MeterId meterId : deviceContext.getDeviceMeterRegistry().getAllMeterIds()) { + private static void deleteAllKnownMeters(final DeviceMeterRegistry meterRegistry, final InstanceIdentifier fNodeIdent, final TxFacade txFacade) throws Exception { + for (final MeterId meterId : meterRegistry.getAllMeterIds()) { final InstanceIdentifier meterIdent = fNodeIdent.child(Meter.class, new MeterKey(meterId)); - deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, meterIdent); + txFacade.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, meterIdent); } - deviceContext.getDeviceMeterRegistry().removeMarked(); + meterRegistry.removeMarked(); } - private static void processGroupDescStats(final Iterable data, final DeviceContext deviceContext) throws Exception { - final InstanceIdentifier fNodeIdent = - deviceContext.getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); - deleteAllKnownGroups(deviceContext, fNodeIdent); + private static void processGroupDescStats(final Iterable data, final DeviceInfo deviceInfo, final TxFacade txFacade, final DeviceGroupRegistry groupRegistry) throws Exception { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceInfo); + deleteAllKnownGroups(txFacade, fNodeIdent, groupRegistry); for (final GroupDescStatsUpdated groupDescStatsUpdated : data) { for (final GroupDescStats groupDescStats : groupDescStatsUpdated.getGroupDescStats()) { @@ -423,23 +449,23 @@ public final class StatisticsGatheringUtils { final InstanceIdentifier groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId)); - deviceContext.getDeviceGroupRegistry().store(groupId); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, groupIdent, groupBuilder.build()); + groupRegistry.store(groupId); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, groupIdent, groupBuilder.build()); } } - deviceContext.submitTransaction(); + txFacade.submitTransaction(); } - private static void deleteAllKnownGroups(final DeviceContext deviceContext, final InstanceIdentifier fNodeIdent) throws Exception { - for (final GroupId groupId : deviceContext.getDeviceGroupRegistry().getAllGroupIds()) { + private static void deleteAllKnownGroups(final TxFacade txFacade, final InstanceIdentifier fNodeIdent, final DeviceGroupRegistry groupRegistry) throws Exception { + for (final GroupId groupId : groupRegistry.getAllGroupIds()) { final InstanceIdentifier groupIdent = fNodeIdent.child(Group.class, new GroupKey(groupId)); - deviceContext.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, groupIdent); + txFacade.addDeleteToTxChain(LogicalDatastoreType.OPERATIONAL, groupIdent); } - deviceContext.getDeviceGroupRegistry().removeMarked(); + groupRegistry.removeMarked(); } - private static void processGroupStatistics(final Iterable data, final DeviceContext deviceContext) throws Exception { - final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceContext); + private static void processGroupStatistics(final Iterable data, final DeviceInfo deviceInfo, final TxFacade txFacade) throws Exception { + final InstanceIdentifier fNodeIdent = assembleFlowCapableNodeInstanceIdentifier(deviceInfo); for (final GroupStatisticsUpdated groupStatistics : data) { for (final GroupStats groupStats : groupStatistics.getGroupStats()) { @@ -449,14 +475,14 @@ public final class StatisticsGatheringUtils { final InstanceIdentifier gsIdent = nGroupStatIdent.child(GroupStatistics.class); final GroupStatistics stats = new GroupStatisticsBuilder(groupStats).build(); - deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gsIdent, stats); + txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, gsIdent, stats); } } - deviceContext.submitTransaction(); + txFacade.submitTransaction(); } - private static InstanceIdentifier assembleFlowCapableNodeInstanceIdentifier(final DeviceContext deviceContext) { - return deviceContext.getDeviceState().getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); + private static InstanceIdentifier assembleFlowCapableNodeInstanceIdentifier(final DeviceInfo deviceInfo) { + return deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableNode.class); } /** @@ -465,7 +491,7 @@ public final class StatisticsGatheringUtils { * @param deviceContext txManager + node path keeper */ static void markDeviceStateSnapshotStart(final DeviceContext deviceContext) { - final InstanceIdentifier statusPath = deviceContext.getDeviceState() + final InstanceIdentifier statusPath = deviceContext.getDeviceInfo() .getNodeInstanceIdentifier().augmentation(FlowCapableStatisticsGatheringStatus.class); final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_AND_TIME_FORMAT); @@ -477,8 +503,9 @@ public final class StatisticsGatheringUtils { .build(); try { deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, statusPath, gatheringStatus); - } catch (final Exception e) { - LOG.warn("Can't write to transaction: {}", e); + } catch (final TransactionChainClosedException e) { + LOG.warn("Can't write to transaction, transaction chain probably closed."); + LOG.trace("Write to transaction exception: ", e); } deviceContext.submitTransaction(); @@ -491,7 +518,7 @@ public final class StatisticsGatheringUtils { * @param succeeded outcome of currently finished gathering */ static void markDeviceStateSnapshotEnd(final DeviceContext deviceContext, final boolean succeeded) { - final InstanceIdentifier statusEndPath = deviceContext.getDeviceState() + final InstanceIdentifier statusEndPath = deviceContext.getDeviceInfo() .getNodeInstanceIdentifier().augmentation(FlowCapableStatisticsGatheringStatus.class) .child(SnapshotGatheringStatusEnd.class); @@ -502,8 +529,9 @@ public final class StatisticsGatheringUtils { .build(); try { deviceContext.writeToTransaction(LogicalDatastoreType.OPERATIONAL, statusEndPath, gatheringStatus); - } catch (Exception e) { - LOG.warn("Can't write to transaction: {}", e); + } catch (TransactionChainClosedException e) { + LOG.warn("Can't write to transaction, transaction chain probably closed."); + LOG.trace("Write to transaction exception: ", e); } deviceContext.submitTransaction();