Example usage for com.google.common.util.concurrent CheckedFuture checkedGet

List of usage examples for com.google.common.util.concurrent CheckedFuture checkedGet

Introduction

In this page you can find the example usage for com.google.common.util.concurrent CheckedFuture checkedGet.

Prototype

V checkedGet() throws X;

Source Link

Document

Exception checking version of Future#get() that will translate InterruptedException , CancellationException and ExecutionException into application-specific exceptions.

Usage

From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginCleaner.java

private static boolean deleteElanInterfacesShadows(DataBroker db, LogicalDatastoreType type,
        int remainingRetries, IEntityDeleteDecision<ElanInterface> entityDeleteDecision) {

    InstanceIdentifier<ElanInterfaces> path = InstanceIdentifier.create(ElanInterfaces.class);
    ReadTransaction readTx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<ElanInterfaces>, ReadFailedException> future = readTx.read(type, path);

    Optional<ElanInterfaces> optional = null;

    try {//from   w  w w.j a  va 2  s. c  o  m
        optional = future.get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("deleteElanInterfacesShadows failed to get data");
        return false;
    }
    if (optional.isPresent()) {
        WriteTransaction deleteTx = db.newWriteOnlyTransaction();
        ElanInterfaces interfaces = optional.get();
        for (ElanInterface iface : interfaces.getElanInterface()) {
            if (entityDeleteDecision.shouldDelete(iface)) {
                LOG.debug("Delete shadow elan interface: DataStoreType {}, interface {}", type, iface);
                FederationPluginCounters.removed_shadow_elan_interface.inc();
                InstanceIdentifier<ElanInterface> iid = InstanceIdentifier.create(ElanInterfaces.class)
                        .child(ElanInterface.class, new ElanInterfaceKey(iface.getKey()));
                deleteTx.delete(type, iid);
            }
        }
        CheckedFuture<Void, TransactionCommitFailedException> future1 = deleteTx.submit();
        try {
            future1.checkedGet();
        } catch (TransactionCommitFailedException e) {
            if (remainingRetries > 0) {
                LOG.warn("deleteElanInterfacesShadows - Failed to delete! {} {}" + e.getMessage(), e);
                deleteElanInterfacesShadows(db, type, --remainingRetries, entityDeleteDecision);
            } else {
                LOG.error("deleteElanInterfacesShadows - Failed to delete - no more retries! {} {}"
                        + e.getMessage(), e);
            }
        }
        return true;
    } else {
        return false;
    }
}

From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginCleaner.java

private static boolean deleteL2GatewayConnectionShadows(DataBroker db, LogicalDatastoreType type,
        int remainingRetries, IEntityDeleteDecision<L2gatewayConnection> entityDeleteDecision) {

    InstanceIdentifier<L2gatewayConnections> path = InstanceIdentifier.create(Neutron.class)
            .child(L2gatewayConnections.class);
    ReadTransaction readTx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<L2gatewayConnections>, ReadFailedException> future = readTx.read(type, path);

    Optional<L2gatewayConnections> optional = null;

    try {/*from ww w  .ja v a  2  s.  co m*/
        optional = future.get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("deleteL2GatewayConnectionShadows failed to get data");
        return false;
    }
    if (optional.isPresent()) {
        WriteTransaction deleteTx = db.newWriteOnlyTransaction();
        L2gatewayConnections l2gws = optional.get();
        for (L2gatewayConnection iface : l2gws.getL2gatewayConnection()) {
            if (entityDeleteDecision.shouldDelete(iface)) {
                LOG.debug("Delete shadow l2 gateway: DataStoreType {}, interface {}", type, iface);
                FederationPluginCounters.removed_shadow_l2_gateway.inc();
                InstanceIdentifier<L2gatewayConnection> iid = InstanceIdentifier.create(Neutron.class)
                        .child(L2gatewayConnections.class)
                        .child(L2gatewayConnection.class, new L2gatewayConnectionKey(iface.getKey()));
                deleteTx.delete(type, iid);
            }
        }
        CheckedFuture<Void, TransactionCommitFailedException> future1 = deleteTx.submit();
        try {
            future1.checkedGet();
        } catch (TransactionCommitFailedException e) {
            if (remainingRetries > 0) {
                LOG.warn("deleteL2GatewayShadows - Failed to delete! {} {}" + e.getMessage(), e);
                deleteL2GatewayConnectionShadows(db, type, --remainingRetries, entityDeleteDecision);
            } else {
                LOG.error("deleteL2GatewayShadows - Failed to delete - no more retries! {} {}" + e.getMessage(),
                        e);
            }
        }
        return true;
    } else {
        return false;
    }
}

From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginCleaner.java

@SuppressWarnings("deprecation")
private static void deleteInventoryNodes(DataBroker db, LogicalDatastoreType type, int remainingRetries,
        IEntityDeleteDecision<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> entityDeleteDecision) {
    InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes> path = InstanceIdentifier
            .create(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes.class);
    ReadTransaction readTx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes>, ReadFailedException> future = readTx
            .read(type, path);/* w  w  w  .j a  v  a2  s  . c  o m*/

    Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes> optional = null;

    try {
        optional = future.get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.info("deleteInventoryNodes failed to get data");
    }
    if (optional != null && optional.isPresent()) {
        WriteTransaction deleteTx = db.newWriteOnlyTransaction();
        org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes nodes = optional.get();
        for (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node node : nodes
                .getNode()) {
            if (entityDeleteDecision.shouldDelete(node)) {
                LOG.debug("Delete shadow inventory node: DataStoreType {}, node {}", type, node);
                FederationPluginCounters.removed_shadow_inventory_node.inc();
                org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey key = new org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey(
                        node.getId());
                InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node> iid = InstanceIdentifier
                        .create(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes.class)
                        .child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class,
                                key);
                deleteTx.delete(type, iid);
            }
        }
        CheckedFuture<Void, TransactionCommitFailedException> future1 = deleteTx.submit();
        try {
            future1.checkedGet();
        } catch (TransactionCommitFailedException e) {
            if (remainingRetries > 0) {
                LOG.warn("deleteInventoryNodes - Failed to delete! {} {}" + e.getMessage(), e);
                deleteInventoryNodes(db, type, --remainingRetries, entityDeleteDecision);
            } else {
                LOG.error("deleteInventoryNodes - Failed to delete - no more retries! {} {}" + e.getMessage(),
                        e);
            }
        }
    }
}

From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginCleaner.java

private static boolean deleteTopologyShadowNodes(DataBroker db, LogicalDatastoreType type,
        TopologyKey topologyKey, int remainingRetries,
        IEntityDeleteDecision<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> entityDeleteDecision) {
    InstanceIdentifier<Topology> path = InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
            topologyKey);//from ww  w.j ava  2 s.  c om
    ReadTransaction readTx = db.newReadOnlyTransaction();
    CheckedFuture<Optional<Topology>, ReadFailedException> future = readTx.read(type, path);

    Optional<Topology> optional = null;

    try {
        optional = future.get();
    } catch (InterruptedException | ExecutionException e) {
        LOG.error("deleteTopologyShadowNodes failed to get data");
        return false;
    }
    if (optional.isPresent()) {
        WriteTransaction deleteTx = db.newWriteOnlyTransaction();
        Topology topology = optional.get();
        for (org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node node : topology
                .getNode()) {
            if (entityDeleteDecision.shouldDelete(node)) {
                LOG.debug("Delete shadow topolog node: DataStoreType {}, node {}", type, node);
                FederationPluginCounters.removed_shadow_topology_node.inc();
                InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node> iid = InstanceIdentifier
                        .create(NetworkTopology.class)
                        .child(Topology.class, FederationPluginConstants.OVSDB_TOPOLOGY_KEY)
                        .child(org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node.class,
                                node.getKey());
                deleteTx.delete(type, iid);
            }
        }
        CheckedFuture<Void, TransactionCommitFailedException> future1 = deleteTx.submit();
        try {
            future1.checkedGet();
        } catch (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException e) {
            if (remainingRetries > 0) {
                LOG.warn("deleteTopologyShadowNodes - Failed to delete! {} {}" + e.getMessage(), e);
                deleteTopologyShadowNodes(db, type, topologyKey, --remainingRetries, entityDeleteDecision);
            } else {
                LOG.error("deleteTopologyShadowNodes - Failed to delete - no more retries! {} {}"
                        + e.getMessage(), e);
            }
        }
        return true;
    } else {
        return false;
    }
}

From source file:org.opendaylight.netvirt.federation.plugin.FederationPluginUtils.java

public static boolean updateGenerationInfo(DataBroker broker, String remoteIp, int generationNumber) {
    if (remoteIp == null) {
        LOG.error("Cannot write generation number - remote IP is null");
        return false;
    }/*from  w w w. j a  v a 2s .co m*/

    LOG.info("Writing generation number {} for remote site {}", remoteIp, generationNumber);
    WriteTransaction putTx = broker.newWriteOnlyTransaction();
    RemoteSiteGenerationInfoBuilder builder = new RemoteSiteGenerationInfoBuilder();
    builder.setRemoteIp(remoteIp);
    builder.setGenerationNumber(generationNumber);
    InstanceIdentifier<RemoteSiteGenerationInfo> path = InstanceIdentifier.create(FederationGenerations.class)
            .child(RemoteSiteGenerationInfo.class, new RemoteSiteGenerationInfoKey(remoteIp));
    putTx.put(LogicalDatastoreType.CONFIGURATION, path, builder.build());
    CheckedFuture<Void, TransactionCommitFailedException> future1 = putTx.submit();

    try {
        future1.checkedGet();
    } catch (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException e) {
        return false;
    }

    return true;
}

From source file:org.opendaylight.unimgr.utils.OvsdbUtils.java

private static void updateQueuesMaxRate(DataBroker dataBroker, Optional<Node> optionalOvsdbNode,
        EvcAugmentation evc) {// w  w  w  .ja  va  2  s  .c o  m
    final NodeId ovsdbNodeId = optionalOvsdbNode.get().getNodeId();
    final List<Queues> queues = optionalOvsdbNode.get().getAugmentation(OvsdbNodeAugmentation.class)
            .getQueues();
    QueuesKey queuesKey = null;
    for (final Queues queue : queues) {
        queuesKey = queue.getKey();
    }
    final InstanceIdentifier<QueuesOtherConfig> queuesOtherConfigIid = UnimgrMapper
            .getQueuesOtherConfigIid(ovsdbNodeId, queuesKey);
    final QueuesOtherConfig queuesOtherConfig = new QueuesOtherConfigBuilder()
            .setKey(new QueuesOtherConfigKey(UnimgrConstants.QOS_MAX_RATE))
            .setQueueOtherConfigKey(UnimgrConstants.QOS_MAX_RATE)
            .setQueueOtherConfigValue(UniUtils.getSpeed(evc.getIngressBw().getSpeed())).build();
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.put(LogicalDatastoreType.CONFIGURATION, queuesOtherConfigIid, queuesOtherConfig, true);
    final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
    try {
        future.checkedGet();
        LOG.info("Update queues max-rate to ovsdb for node {} {}", ovsdbNodeId, queuesOtherConfigIid);
    } catch (final TransactionCommitFailedException e) {
        LOG.warn("Failed to put {} ", queuesOtherConfigIid, e);
    }
}

From source file:org.opendaylight.unimgr.utils.OvsdbUtils.java

private static void updateQosMaxRate(DataBroker dataBroker, Optional<Node> optionalOvsdbNode,
        EvcAugmentation evc) {// ww w. j av a2  s . c om
    final NodeId ovsdbNodeId = optionalOvsdbNode.get().getNodeId();
    final List<QosEntries> qosList = optionalOvsdbNode.get().getAugmentation(OvsdbNodeAugmentation.class)
            .getQosEntries();
    LOG.trace("QOS entries list {} for node {}", qosList, ovsdbNodeId);
    QosEntriesKey qosEntryKey = null;
    for (final QosEntries qosEntry : qosList) {
        qosEntryKey = qosEntry.getKey();
    }
    final InstanceIdentifier<QosOtherConfig> qosOtherConfigIid = UnimgrMapper.getQosOtherConfigIid(ovsdbNodeId,
            qosEntryKey);
    final QosOtherConfig qOtherConfig = new QosOtherConfigBuilder()
            .setKey(new QosOtherConfigKey(UnimgrConstants.QOS_MAX_RATE))
            .setOtherConfigKey(UnimgrConstants.QOS_MAX_RATE)
            .setOtherConfigValue(UniUtils.getSpeed(evc.getIngressBw().getSpeed())).build();
    final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
    transaction.put(LogicalDatastoreType.CONFIGURATION, qosOtherConfigIid, qOtherConfig, true);
    final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
    try {
        future.checkedGet();
        LOG.info("Update qos-entries max-rate to ovsdb for node {} {}", ovsdbNodeId, qosOtherConfigIid);
    } catch (final TransactionCommitFailedException e) {
        LOG.warn("Failed to put {}", qosOtherConfigIid, e);
    }
}

From source file:org.opendaylight.unimgr.utils.OvsdbUtils.java

private static void updateQosEntries(DataBroker dataBroker, UniAugmentation uni) {
    final Optional<Node> optionalNode = findOvsdbNode(dataBroker, uni);
    if (optionalNode.isPresent()) {
        final NodeId ovsdbNodeId = optionalNode.get().getNodeId();
        final Long queueNumber = 0L;
        final List<QosEntries> qosList = optionalNode.get().getAugmentation(OvsdbNodeAugmentation.class)
                .getQosEntries();//from  w  w  w.  j a v a2s.c om
        LOG.trace("QOS entries list {} for node {}", qosList, ovsdbNodeId);
        QosEntriesKey qosEntryKey = null;
        for (final QosEntries qosEntry : qosList) {
            qosEntryKey = qosEntry.getKey();
        }
        final InstanceIdentifier<QueueList> queueIid = UnimgrMapper.getOvsdbQueueListIid(ovsdbNodeId,
                qosEntryKey, queueNumber);

        Uuid queueUuid = null;
        final List<Queues> queuesList = optionalNode.get().getAugmentation(OvsdbNodeAugmentation.class)
                .getQueues();
        for (final Queues queue : queuesList) {
            queueUuid = queue.getQueueUuid();
        }
        final QueueList queueList = new QueueListBuilder().setKey(new QueueListKey(queueNumber))
                .setQueueNumber(queueNumber).setQueueUuid(queueUuid).build();

        final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
        transaction.delete(LogicalDatastoreType.CONFIGURATION, queueIid);
        transaction.put(LogicalDatastoreType.CONFIGURATION, queueIid, queueList, true);
        final CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
        try {
            future.checkedGet();
            LOG.info("Update qos-entries to ovsdb for node {} {}", ovsdbNodeId, queueIid);
        } catch (final TransactionCommitFailedException e) {
            LOG.warn("Failed to put {} ", queueIid, e);
        }
    }
}

From source file:org.opendaylight.sfc.iosxe.provider.utils.RspStatus.java

public void writeStatus(ConfiguredRenderedPath.PathStatus status) {
    final ConfiguredRenderedPathBuilder configuredRenderedPathBuilder = new ConfiguredRenderedPathBuilder();
    configuredRenderedPathBuilder.setKey(new ConfiguredRenderedPathKey(rspName)).setRspName(rspName);
    configuredRenderedPathBuilder.setPathStatus(status);
    final ConfiguredRenderedPath configuredRenderedPath = configuredRenderedPathBuilder.build();
    final InstanceIdentifier<ConfiguredRenderedPath> statusIid = InstanceIdentifier
            .builder(RendererPathStates.class)
            .child(RendererPathState.class, new RendererPathStateKey(new RendererName("ios-xe-renderer")))
            .child(ConfiguredRenderedPaths.class)
            .child(ConfiguredRenderedPath.class, configuredRenderedPath.getKey()).build();
    // Write new status
    final ReadWriteTransaction wtx = dataBroker.newReadWriteTransaction();
    wtx.merge(LogicalDatastoreType.OPERATIONAL, statusIid, configuredRenderedPath, true);
    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = wtx.submit();
    try {/*from  w  ww .j a  v  a 2 s  .com*/
        submitFuture.checkedGet();
    } catch (TransactionCommitFailedException e) {
        LOG.error("Write transaction failed to {}", e.getMessage());
    }
}

From source file:org.opendaylight.sfc.util.openflow.writer.FlowSetRemoverTask.java

@Override
public void run() {

    WriteTransaction writeTx = tx == null ? dataProvider.newWriteOnlyTransaction() : tx;

    LOG.debug("FlowSetRemoverTask: starting deletion of {} flows", flowsToDelete.size());

    for (FlowDetails f : flowsToDelete) {
        NodeKey theKey = new NodeKey(new NodeId(f.getSffNodeName()));
        InstanceIdentifier<Flow> iidFlow = InstanceIdentifier.builder(Nodes.class).child(Node.class, theKey)
                .augmentation(FlowCapableNode.class).child(Table.class, f.getTableKey())
                .child(Flow.class, f.getFlowKey()).build();

        writeTx.delete(LogicalDatastoreType.CONFIGURATION, iidFlow);
    }/*ww  w  . j  av a2  s . c o m*/

    CheckedFuture<Void, TransactionCommitFailedException> submitFuture = writeTx.submit();
    try {
        submitFuture.checkedGet();
    } catch (TransactionCommitFailedException e) {
        LOG.error("deleteTransactionAPI: Transaction failed. Message: {}", e.getMessage(), e);
    }
}