X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fstatistics-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fstatistics%2Fmanager%2Fimpl%2FStatListenCommitFlow.java;h=230425999e3215045ac632a4d291e8cd5507c943;hb=a2563a94253f9c2603e0ab25b8f412ea07fcf51d;hp=e54fcc6fa2100cb21af3c41b0f78fc9bb51a872c;hpb=9b50c69a6daa839289e9fd9a1e4649c2710349be;p=controller.git diff --git a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/impl/StatListenCommitFlow.java b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/impl/StatListenCommitFlow.java index e54fcc6fa2..230425999e 100644 --- a/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/impl/StatListenCommitFlow.java +++ b/opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/impl/StatListenCommitFlow.java @@ -35,6 +35,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.no import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMapBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.nodes.node.table.FlowHashIdMapKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; @@ -86,6 +87,8 @@ public class StatListenCommitFlow extends StatAbstractListenCommit fNodeIdent = InstanceIdentifier.create(Nodes.class) .child(Node.class, new NodeKey(nodeId)).augmentation(FlowCapableNode.class); - final InstanceIdentifier tableStatRef = fNodeIdent - .child(Table.class, table.getKey()).augmentation(AggregateFlowStatisticsData.class); + final InstanceIdentifier tableRef = fNodeIdent.child(Table.class, table.getKey()); + final InstanceIdentifier tableStatRef = tableRef + .augmentation(AggregateFlowStatisticsData.class); Optional fNode = Optional.absent(); try { fNode = tx.read(LogicalDatastoreType.OPERATIONAL, fNodeIdent).checkedGet(); - } - catch (final ReadFailedException e) { + } catch (final ReadFailedException e) { LOG.debug("Read Operational/DS for FlowCapableNode fail! {}", fNodeIdent, e); return; } if (fNode.isPresent()) { - tx.put(LogicalDatastoreType.OPERATIONAL, tableStatRef, stats, true); + ensureTable(tx, table.getId(), tableRef); + tx.put(LogicalDatastoreType.OPERATIONAL, tableStatRef, stats); } } } @@ -156,6 +160,11 @@ public class StatListenCommitFlow extends StatAbstractListenCommit tableRef) { + final Table tableNew = new TableBuilder().setId(tableId).build(); + tx.merge(LogicalDatastoreType.OPERATIONAL, tableRef, tableNew); + } + @Override public void onFlowsStatisticsUpdate(final FlowsStatisticsUpdate notification) { final TransactionId transId = notification.getTransactionId(); @@ -192,6 +201,20 @@ public class StatListenCommitFlow extends StatAbstractListenCommit, Integer> listAliens = mapNodesForDelete.get(nodeIdent); + if (listAliens != null) { + for (final Entry, Integer> nodeForDelete : listAliens.entrySet()) { + final Integer lifeIndex = nodeForDelete.getValue(); + if (nodeForDelete.getValue() > 0) { + nodeForDelete.setValue(Integer.valueOf(lifeIndex.intValue() - 1)); + } else { + final InstanceIdentifier flowNodeIdent = nodeForDelete.getKey(); + mapNodesForDelete.get(nodeIdent).remove(flowNodeIdent); + tx.delete(LogicalDatastoreType.OPERATIONAL, flowNodeIdent); + } + } + } /* Notification for continue collecting statistics */ notifyToCollectNextStatistics(nodeIdent); } @@ -246,14 +269,13 @@ public class StatListenCommitFlow extends StatAbstractListenCommit tableRef; final TableKey tableKey; @@ -304,7 +327,7 @@ public class StatListenCommitFlow extends StatAbstractListenCommit {}", flowHashId.getKey(), flowHashId.getFlowId()); } } @@ -312,11 +335,12 @@ public class StatListenCommitFlow extends StatAbstractListenCommit emptyList()).build(); - tx.merge(LogicalDatastoreType.OPERATIONAL, tableRef.augmentation(FlowHashIdMapping.class), emptyMapping, true); + tx.merge(LogicalDatastoreType.OPERATIONAL, tableRef.augmentation(FlowHashIdMapping.class), emptyMapping); tableEnsured = true; } } @@ -338,12 +362,7 @@ public class StatListenCommitFlow extends StatAbstractListenCommit table = readLatestConfiguration(tableRef); - try { - table = trans.read(LogicalDatastoreType.CONFIGURATION, tableRef).checkedGet(); - } catch (final ReadFailedException e) { - table = Optional.absent(); - } + final Optional
table = readLatestConfiguration(tableRef); List localList = null; if(table.isPresent()) { localList = table.get().getFlow(); @@ -377,8 +396,8 @@ public class StatListenCommitFlow extends StatAbstractListenCommit nodeIdent = tableRef.firstIdentifierOf(Node.class); + final List> listMissingConfigFlows = notStatReportedConfigFlows(); + final Map, Integer> nodeDeleteMap = mapNodesForDelete.get(nodeIdent); final Map listForRemove = getRemovalList(); - final Optional
configTable = readLatestConfiguration(tableRef); - List configFlows = Collections.emptyList(); - if (configTable.isPresent() && configTable.get().getFlow() != null) { - configFlows = new ArrayList<>(configTable.get().getFlow()); - } for (final Entry entryForRemove : listForRemove.entrySet()) { final FlowKey flowKey = new FlowKey(entryForRemove.getValue()); final InstanceIdentifier flowRef = tableRef.child(Flow.class, flowKey); - final InstanceIdentifier flowStatIdent = flowRef.augmentation(FlowStatisticsData.class); - if (flowKey.getId().getValue().startsWith(ALIEN_SYSTEM_FLOW_ID)) { - final InstanceIdentifier nodeIdent = tableRef.firstIdentifierOf(Node.class); - final Integer lifeIndex = mapNodesForDelete.get(nodeIdent).remove(flowRef); + if (nodeDeleteMap != null && flowKey.getId().getValue().startsWith(ALIEN_SYSTEM_FLOW_ID)) { + final Integer lifeIndex = nodeDeleteMap.get(flowRef); if (lifeIndex > 0) { - mapNodesForDelete.get(nodeIdent).put(flowRef, Integer.valueOf(lifeIndex.intValue() - 1)); break; + } else { + nodeDeleteMap.remove(flowRef); } } else { - if (configFlows.remove(flowRef)) { - /* Node is still presented in Config/DataStore - probably lost some multipart msg */ - break; + if (listMissingConfigFlows.remove(flowRef)) { + break; // we probably lost some multipart msg } } - final Optional flowStatNodeCheck; - try { - flowStatNodeCheck = tx.read(LogicalDatastoreType.OPERATIONAL, flowStatIdent).checkedGet(); - } - catch (final ReadFailedException e) { - LOG.debug("Read FlowStatistics {} in Operational/DS fail! Statisticscan not beupdated.", flowStatIdent, e); - break; - } - if (flowStatNodeCheck.isPresent()) { - /* Node isn't new and it has not been removed yet */ - final InstanceIdentifier flHashIdent = tableRef.augmentation(FlowHashIdMapping.class).child(FlowHashIdMap.class, entryForRemove.getKey()); - tx.delete(LogicalDatastoreType.OPERATIONAL, flowRef); - tx.delete(LogicalDatastoreType.OPERATIONAL, flHashIdent); + final InstanceIdentifier flHashIdent = + tableRef.augmentation(FlowHashIdMapping.class).child(FlowHashIdMap.class, entryForRemove.getKey()); + tx.delete(LogicalDatastoreType.OPERATIONAL, flowRef); + tx.delete(LogicalDatastoreType.OPERATIONAL, flHashIdent); + } + } + + List> notStatReportedConfigFlows() { + if (configFlows != null) { + final List> returnList = new ArrayList<>(configFlows.size()); + for (final Flow confFlow : configFlows) { + final InstanceIdentifier confFlowIdent = tableRef.child(Flow.class, confFlow.getKey()); + returnList.add(confFlowIdent); } + return returnList; } + return Collections.emptyList(); } } }