Search in sources :

Example 1 with FlowCapableStatisticsGatheringStatus

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatus in project openflowplugin by opendaylight.

the class SimplifiedOperationalListener method isConsistentForReconcile.

/**
 * Check if modification is consistent for reconciliation. We need fresh data, which means that current statistics
 * were collected after registration for reconcile and whole bunch of statistics was collected successfully.
 * @param modification from DS
 * @return status of modification
 */
private boolean isConsistentForReconcile(final DataTreeModification<Node> modification) {
    final NodeId nodeId = PathUtil.digNodeId(modification.getRootPath().getRootIdentifier());
    final FlowCapableStatisticsGatheringStatus gatheringStatus = modification.getRootNode().getDataAfter().getAugmentation(FlowCapableStatisticsGatheringStatus.class);
    if (gatheringStatus == null) {
        LOG.trace("Statistics gathering never started: {}", nodeId.getValue());
        return false;
    }
    final SnapshotGatheringStatusEnd gatheringStatusEnd = gatheringStatus.getSnapshotGatheringStatusEnd();
    if (gatheringStatusEnd == null) {
        LOG.trace("Statistics gathering is not over yet: {}", nodeId.getValue());
        return false;
    }
    if (!gatheringStatusEnd.isSucceeded()) {
        LOG.trace("Statistics gathering was not successful: {}", nodeId.getValue());
        return false;
    }
    try {
        Date timestampOfRegistration = reconciliationRegistry.getRegistrationTimestamp(nodeId);
        final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_AND_TIME_FORMAT);
        Date timestampOfStatistics = simpleDateFormat.parse(gatheringStatusEnd.getEnd().getValue());
        if (timestampOfStatistics.after(timestampOfRegistration)) {
            LOG.debug("Fresh operational present: {}", nodeId.getValue());
            return true;
        }
    } catch (ParseException e) {
        LOG.warn("Timestamp parsing error {}", e);
    }
    LOG.debug("Fresh operational not present: {}", nodeId.getValue());
    return false;
}
Also used : FlowCapableStatisticsGatheringStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatus) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) ParseException(java.text.ParseException) SnapshotGatheringStatusEnd(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.snapshot.gathering.status.grouping.SnapshotGatheringStatusEnd) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with FlowCapableStatisticsGatheringStatus

use of org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatus in project openflowplugin by opendaylight.

the class StatisticsGatheringUtils method markDeviceStateSnapshotStart.

/**
 * Writes snapshot gathering start timestamp + cleans end mark.
 *
 * @param deviceInfo device info
 * @param txFacade tx manager
 */
static void markDeviceStateSnapshotStart(final DeviceInfo deviceInfo, final TxFacade txFacade) {
    final InstanceIdentifier<FlowCapableStatisticsGatheringStatus> statusPath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableStatisticsGatheringStatus.class);
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_AND_TIME_FORMAT);
    final FlowCapableStatisticsGatheringStatus gatheringStatus = new FlowCapableStatisticsGatheringStatusBuilder().setSnapshotGatheringStatusStart(new SnapshotGatheringStatusStartBuilder().setBegin(new DateAndTime(simpleDateFormat.format(new Date()))).build()).setSnapshotGatheringStatusEnd(// TODO: reconsider if really need to clean end mark here
    null).build();
    try {
        txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, statusPath, gatheringStatus);
    } catch (final TransactionChainClosedException e) {
        LOG.warn("Can't write to transaction, transaction chain probably closed.");
        LOG.trace("Write to transaction exception: ", e);
    }
    txFacade.submitTransaction();
}
Also used : FlowCapableStatisticsGatheringStatus(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatus) DateAndTime(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime) FlowCapableStatisticsGatheringStatusBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatusBuilder) TransactionChainClosedException(org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException) SimpleDateFormat(java.text.SimpleDateFormat) SnapshotGatheringStatusStartBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.snapshot.gathering.status.grouping.SnapshotGatheringStatusStartBuilder) Date(java.util.Date)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 FlowCapableStatisticsGatheringStatus (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatus)2 ParseException (java.text.ParseException)1 TransactionChainClosedException (org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException)1 DateAndTime (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime)1 FlowCapableStatisticsGatheringStatusBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableStatisticsGatheringStatusBuilder)1 SnapshotGatheringStatusEnd (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.snapshot.gathering.status.grouping.SnapshotGatheringStatusEnd)1 SnapshotGatheringStatusStartBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.snapshot.gathering.status.grouping.SnapshotGatheringStatusStartBuilder)1 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)1