List of usage examples for com.google.common.base Optional get
public abstract T get();
From source file:org.opendaylight.bier.driver.common.util.DataGetter.java
public static <T extends DataObject> T readData(DataBroker dataBroker, InstanceIdentifier<T> path) { T data = null;// ww w . j av a2s . c o m final ReadOnlyTransaction transaction = dataBroker.newReadOnlyTransaction(); Optional<T> optionalData; try { optionalData = transaction.read(LogicalDatastoreType.CONFIGURATION, path).checkedGet(); if (optionalData.isPresent()) { data = optionalData.get(); } else { LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], path); } } catch (ReadFailedException e) { LOG.warn("Failed to read {} ", path, e); } transaction.close(); return data; }
From source file:org.opendaylight.faas.fabrics.vxlan.adapters.ovs.utils.OfFlowUtils.java
public static Flow getFlow(FlowBuilder flowBuilder, NodeBuilder nodeBuilder, ReadOnlyTransaction readTx, final LogicalDatastoreType store) { try {//from w w w . ja va2 s .co m Optional<Flow> data = readTx.read(store, createFlowPath(flowBuilder, nodeBuilder)).get(); if (data.isPresent()) { return data.get(); } } catch (InterruptedException | ExecutionException e) { LOG.error("Failed to get flow {}", flowBuilder.getFlowName(), e); } LOG.info("Cannot find data for Flow {} in {}", flowBuilder.getFlowName(), store); return null; }
From source file:org.opendaylight.sfc.sfc_netconf.provider.api.SfcNetconfReaderWriterAPI.java
public static <T extends DataObject> boolean put(NodeId nodeId, LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<T> iid, T dataObject) { boolean ret;/*from w w w . j a va2s. c o m*/ if (mountPointService == null) { mountPointService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService(); } try { Optional<MountPoint> mountPointOptional = mountPointService .getMountPoint(NETCONF_TOPO_IID.child(Node.class, new NodeKey(nodeId))); DataBroker broker = mountPointOptional.get().getService(DataBroker.class).get(); WriteTransaction tx = broker.newWriteOnlyTransaction(); tx.put(logicalDatastoreType, iid, dataObject); CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit(); future.checkedGet(); ret = true; } catch (Exception e) { LOG.error("Netconf put failed: {}", e.getMessage()); ret = false; } return ret; }
From source file:org.opendaylight.sfc.sfc_netconf.provider.api.SfcNetconfReaderWriterAPI.java
public static <T extends DataObject> boolean merge(NodeId nodeId, LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<T> iid, T dataObject) { boolean ret;//w w w.j ava2 s . c o m if (mountPointService == null) { mountPointService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService(); } try { Optional<MountPoint> mountPointOptional = mountPointService .getMountPoint(NETCONF_TOPO_IID.child(Node.class, new NodeKey(nodeId))); DataBroker broker = mountPointOptional.get().getService(DataBroker.class).get(); WriteTransaction tx = broker.newWriteOnlyTransaction(); tx.merge(logicalDatastoreType, iid, dataObject); CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit(); future.checkedGet(); ret = true; } catch (Exception e) { LOG.error("Netconf merge failed: {}", e.getMessage()); ret = false; } return ret; }
From source file:org.opendaylight.sfc.sfc_netconf.provider.api.SfcNetconfReaderWriterAPI.java
public static <T extends DataObject> boolean delete(NodeId nodeId, LogicalDatastoreType logicalDatastoreType, InstanceIdentifier<T> iid) { boolean ret;// ww w .j a v a2 s . c o m if (mountPointService == null) { mountPointService = SfcNetconfDataProvider.GetNetconfDataProvider().getMountService(); } try { Optional<MountPoint> mountPointOptional = mountPointService .getMountPoint(NETCONF_TOPO_IID.child(Node.class, new NodeKey(nodeId))); DataBroker broker = mountPointOptional.get().getService(DataBroker.class).get(); WriteTransaction tx = broker.newWriteOnlyTransaction(); tx.delete(logicalDatastoreType, iid); CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit(); future.checkedGet(); ret = true; } catch (Exception e) { LOG.error("Netconf delete failed: {}", e.getMessage()); ret = false; } return ret; }
From source file:com.dangdang.ddframe.job.internal.reg.RegistryCenterFactory.java
/** * .// ww w . j a v a 2s. c om * * @param connectString * @param namespace ?? * @param digest ? * @return */ public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) { Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8); if (digest.isPresent()) { hasher.putString(digest.get(), Charsets.UTF_8); } HashCode hashCode = hasher.hash(); if (registryCenterMap.containsKey(hashCode)) { return registryCenterMap.get(hashCode); } ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace); if (digest.isPresent()) { zkConfig.setDigest(digest.get()); } CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig); result.init(); registryCenterMap.putIfAbsent(hashCode, result); return result; }
From source file:io.mesosphere.mesos.util.ProtoUtils.java
@NotNull public static Optional<Double> resourceValueDouble(@NotNull final Optional<Resource> resource) { if (resource.isPresent()) { if (resource.get().getType() != Value.Type.SCALAR) { throw new IllegalArgumentException("Resource must be of type SCALAR"); }// w ww. j a v a2 s. c om return Optional.of(resource.get().getScalar().getValue()); } else { return Optional.absent(); } }
From source file:com.dangdang.ddframe.job.lite.internal.reg.RegistryCenterFactory.java
/** * ./*from ww w .j av a2s. co m*/ * * @param connectString * @param namespace ?? * @param digest ? * @return */ public static CoordinatorRegistryCenter createCoordinatorRegistryCenter(final String connectString, final String namespace, final Optional<String> digest) { Hasher hasher = Hashing.md5().newHasher().putString(connectString, Charsets.UTF_8).putString(namespace, Charsets.UTF_8); if (digest.isPresent()) { hasher.putString(digest.get(), Charsets.UTF_8); } HashCode hashCode = hasher.hash(); if (regCenterMap.containsKey(hashCode)) { return regCenterMap.get(hashCode); } ZookeeperConfiguration zkConfig = new ZookeeperConfiguration(connectString, namespace); if (digest.isPresent()) { zkConfig.setDigest(digest.get()); } CoordinatorRegistryCenter result = new ZookeeperRegistryCenter(zkConfig); result.init(); regCenterMap.putIfAbsent(hashCode, result); return result; }
From source file:org.onos.yangtools.yang.data.api.schema.NormalizedNodes.java
public static Optional<NormalizedNode<?, ?>> findNode(final YangInstanceIdentifier rootPath, final NormalizedNode<?, ?> rootNode, final YangInstanceIdentifier childPath) { final Optional<YangInstanceIdentifier> relativePath = childPath.relativeTo(rootPath); if (relativePath.isPresent()) { return findNode(rootNode, relativePath.get()); } else {//from w w w. j a va2 s. com return Optional.absent(); } }
From source file:org.opendaylight.controller.netconf.util.messages.NetconfMessageAdditionalHeader.java
public static String toString(String userName, String hostAddress, String port, String transport, Optional<String> sessionIdentifier) { Preconditions.checkNotNull(userName); Preconditions.checkNotNull(hostAddress); Preconditions.checkNotNull(port);//from w ww . jav a 2 s . c o m Preconditions.checkNotNull(transport); String identifier = sessionIdentifier.isPresent() ? sessionIdentifier.get() : ""; return "[" + userName + SC + hostAddress + ":" + port + SC + transport + SC + identifier + SC + "]" + System.lineSeparator(); }