@Override public ListenableFuture<Void> apply(List<Void> readyToSubmit) { return rwTx.submit(); } });
public CheckedFuture<Void, TransactionCommitFailedException> submit() { return readWriteTransaction.submit(); }
private ListenableFuture<Void> createIfaceOnVpp(ConfigCommand createIfaceWithoutBdCommand, DataBroker vppDataBroker, VppEndpoint vppEndpoint, InstanceIdentifier<?> vppNodeIid) { ReadWriteTransaction rwTx = vppDataBroker.newReadWriteTransaction(); createIfaceWithoutBdCommand.execute(rwTx); return Futures.transform(rwTx.submit(), new AsyncFunction<Void, Void>() { @Override public ListenableFuture<Void> apply(Void input) { LOG.debug("Create interface on VPP command was successful:\nVPP: {}\nCommand: {}", vppNodeIid, createIfaceWithoutBdCommand); return vppEndpointLocationProvider.createLocationForVppEndpoint(vppEndpoint); } }, netconfWorker); }
private ListenableFuture<Void> deleteIfaceOnVpp(ConfigCommand deleteIfaceWithoutBdCommand, DataBroker vppDataBroker, VppEndpoint vppEndpoint, InstanceIdentifier<?> vppNodeIid) { ReadWriteTransaction rwTx = vppDataBroker.newReadWriteTransaction(); deleteIfaceWithoutBdCommand.execute(rwTx); return Futures.transform(rwTx.submit(), new AsyncFunction<Void, Void>() { @Override public ListenableFuture<Void> apply(Void input) { LOG.debug("Delete interface on VPP command was successful:\nVPP: {}\nCommand: {}", vppNodeIid, deleteIfaceWithoutBdCommand); return vppEndpointLocationProvider.deleteLocationForVppEndpoint(vppEndpoint); } }, netconfWorker); }
@Override public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) { final ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction(); try { Map<String, CostType> costTypes = onEntryChanged(rwx); List<CostType> costTypeList = new LinkedList<>(costTypes.values()); setCostTypes(m_instance, costTypeList, rwx); rwx.submit(); } catch (Exception e) { LOG.error("Failed to update cost-types {}", m_instance); e.printStackTrace(); } }
@Override public <T extends DataObject> ListenableFuture<Void> writeConfiguration(final T data, final InstanceIdentifier<T> identifier) { final ReadWriteTransaction wTx = this.dataBroker.newReadWriteTransaction(); wTx.put(LogicalDatastoreType.CONFIGURATION, identifier, data); return wTx.submit(); }
@Override public void onDataChanged(final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) { ResourceId defaultNetworkmap = null; try { ReadWriteTransaction rwx = m_dataBroker.newReadWriteTransaction(); defaultNetworkmap = onConfigurationChanged(change, rwx); setDefaultNetworkMap(m_instance, defaultNetworkmap, rwx); rwx.submit(); } catch (Exception e) { LOG.error("Failed to update the default-network-map"); } }
@Override public ListenableFuture<Void> apply( final Optional<AlertFieldValueRuleRecord> alertFieldValueRuleRecord) throws Exception { List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>(); if (alertFieldValueRuleRecord.isPresent()) { streamAlertRuleList = alertFieldValueRuleRecord.get().getStreamAlertFieldValueRuleList(); StreamAlertFieldValueRuleList configObject = null; Iterator<StreamAlertFieldValueRuleList> iterator = streamAlertRuleList.iterator(); while (iterator.hasNext()) { configObject = iterator.next(); if (configObject.getConfigID().equalsIgnoreCase(configID)) { tx.delete(LogicalDatastoreType.CONFIGURATION, alertFieldValueRuleRecordId.child( StreamAlertFieldValueRuleList.class, configObject.getKey())); } } } return tx.submit(); }
@Override public ListenableFuture<Void> apply(final Optional<StreamRecord> streamRulesRecord) throws Exception { List<StreamList> streamRulesLists = new ArrayList<StreamList>(); if (streamRulesRecord.isPresent()) { streamRulesLists = streamRulesRecord.get().getStreamList(); } Iterator<StreamList> iterator = streamRulesLists.iterator(); while (iterator.hasNext()) { StreamList configObject = iterator.next(); if (configObject.getConfigID().equalsIgnoreCase(confID)) { tx.delete(LogicalDatastoreType.CONFIGURATION, streamRecordId.child(StreamList.class, configObject.getKey())); } } return tx.submit(); } });
private void unlock(final String lockName, final InstanceIdentifier<Lock> lockInstanceIdentifier) { ReadWriteTransaction tx = broker.newReadWriteTransaction(); Optional<Lock> result = Optional.absent(); try { result = tx.read(LogicalDatastoreType.OPERATIONAL, lockInstanceIdentifier).get(); if (!result.isPresent()) { LOG.info("{} is already unlocked", lockName); return; } tx.delete(LogicalDatastoreType.OPERATIONAL, lockInstanceIdentifier); CheckedFuture<Void, TransactionCommitFailedException> futures = tx.submit(); futures.get(); } catch (Exception e) { LOG.error("In unlock unable to unlock due to {}", e.getMessage()); } }
private void submitTransaction(ReadWriteTransaction tx) { try { tx.submit().checkedGet(); } catch (final TransactionCommitFailedException e) { LOG.warn("Stat DataStoreOperation unexpected State!", e); transactionChain.close(); transactionChain = dataBroker.createTransactionChain(this); cleanDataStoreOperQueue(); } }
@Override public ListenableFuture<Void> apply(Optional<MonitoringState> optState) throws Exception { if(optState.isPresent()) { MonitoringState state = optState.get(); if(isValidStatus.apply(state.getStatus())) { MonitoringState updatedState = new MonitoringStateBuilder().setMonitorKey(monitorKey) .setStatus(newStatus).build(); tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey), updatedState); } else { LOG.warn("Invalid Monitoring status {}, cannot be updated to {} for monitorId {}" , state.getStatus(), newStatus, monitorId); } } else { LOG.warn("No associated monitoring state data available to update the status to {} for {}", newStatus, monitorId); } return tx.submit(); } });
@Override public ListenableFuture<Void> apply(Optional<InterfaceMonitorEntry> optEntry) throws Exception { if(optEntry.isPresent()) { InterfaceMonitorEntry entry = optEntry.get(); List<Long> monitorIds = entry.getMonitorIds(); monitorIds.remove(monitorId); InterfaceMonitorEntry newEntry = new InterfaceMonitorEntryBuilder(entry) .setKey(new InterfaceMonitorEntryKey(interfaceName)).setMonitorIds(monitorIds).build(); tx.put(LogicalDatastoreType.OPERATIONAL, getInterfaceMonitorMapId(interfaceName), newEntry, CREATE_MISSING_PARENT); return tx.submit(); } else { LOG.warn("No Interface map entry found {} to remove monitorId {}", interfaceName, monitorId); tx.cancel(); return Futures.immediateFuture(null); } } });
private void initializeTopology(LogicalDatastoreType type) { ReadWriteTransaction transaction = db.newReadWriteTransaction(); InstanceIdentifier<NetworkTopology> path = InstanceIdentifier.create(NetworkTopology.class); CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = transaction.read(type,path); try { if (!topology.get().isPresent()) { NetworkTopologyBuilder ntb = new NetworkTopologyBuilder(); transaction.put(type,path,ntb.build()); transaction.submit(); } else { transaction.cancel(); } } catch (InterruptedException | ExecutionException e) { LOG.error("Error initializing ovsdb topology", e); } }
private void initializeTZNode(DataBroker db) { ReadWriteTransaction transaction = db.newReadWriteTransaction(); InstanceIdentifier<TransportZones> path = InstanceIdentifier.create(TransportZones.class); CheckedFuture<Optional<TransportZones>, ReadFailedException> tzones = transaction.read(LogicalDatastoreType.CONFIGURATION,path); try { if (!tzones.get().isPresent()) { TransportZonesBuilder tzb = new TransportZonesBuilder(); transaction.put(LogicalDatastoreType.CONFIGURATION,path,tzb.build()); transaction.submit(); } else { transaction.cancel(); } } catch (Exception e) { LOG.error("Error initializing TransportZones {}",e); } }
private void initializeTopology(final LogicalDatastoreType type) { final ReadWriteTransaction transaction = dataBroker.newReadWriteTransaction(); final InstanceIdentifier<NetworkTopology> path = InstanceIdentifier.create(NetworkTopology.class); final CheckedFuture<Optional<NetworkTopology>, ReadFailedException> topology = transaction.read(type,path); try { if (!topology.get().isPresent()) { final NetworkTopologyBuilder ntb = new NetworkTopologyBuilder(); transaction.put(type,path,ntb.build()); transaction.submit().get(); } else { transaction.cancel(); } } catch (final Exception e) { LOG.error("Error initializing unimgr topology {}", e); } }
private void initializeOvsdbTopology(LogicalDatastoreType type) { InstanceIdentifier<Topology> path = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(SouthboundConstants.OVSDB_TOPOLOGY_ID)); initializeTopology(type); ReadWriteTransaction transaction = db.newReadWriteTransaction(); CheckedFuture<Optional<Topology>, ReadFailedException> ovsdbTp = transaction.read(type, path); try { if (!ovsdbTp.get().isPresent()) { TopologyBuilder tpb = new TopologyBuilder(); tpb.setTopologyId(SouthboundConstants.OVSDB_TOPOLOGY_ID); transaction.put(type, path, tpb.build()); transaction.submit(); } else { transaction.cancel(); } } catch (InterruptedException | ExecutionException e) { LOG.error("Error initializing ovsdb topology", e); } }
private void writeGroup(GroupBuilder groupBuilder, NodeBuilder nodeBuilder) { if (NetvirtProvidersProvider.isMasterProviderInstance()) { ReadWriteTransaction modification = dataBroker.newReadWriteTransaction(); InstanceIdentifier<Group> path1 = InstanceIdentifier.builder(Nodes.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory .rev130819.nodes.Node.class, nodeBuilder.getKey()).augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(groupBuilder.getGroupId())).build(); modification.put(LogicalDatastoreType.CONFIGURATION, path1, groupBuilder.build(), true /*createMissingParents*/); CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit(); try { commitFuture.get(); // TODO: Make it async (See bug 1362) LOG.debug("Transaction success for write of Group {}", groupBuilder.getGroupName()); } catch (InterruptedException|ExecutionException e) { LOG.error("Failed to write group {}", groupBuilder.getGroupName(), e); } } }
/** * Gets called on start of a bundle. */ public void start() { final TopologyKey key = new TopologyKey(new TopologyId(TOPOLOGY_ID)); final InstanceIdentifier<Topology> path = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, key); final FlowCapableTopologyExporter listener = new FlowCapableTopologyExporter(processor, path); this.listenerRegistration = notificationService.registerNotificationListener(listener); if(!isFlowTopologyExist(dataBroker, path)){ final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction(); tx.put(LogicalDatastoreType.OPERATIONAL, path, new TopologyBuilder().setKey(key).build(), true); try { tx.submit().get(); } catch (InterruptedException | ExecutionException e) { LOG.warn("Initial topology export failed, continuing anyway", e); } } LOG.info("FlowCapableTopologyProvider started"); }
private void writeMeter(final CommandInterpreter ci, Meter meter) { ReadWriteTransaction modification = dataBroker.newReadWriteTransaction(); InstanceIdentifier<Meter> path1 = InstanceIdentifier.create(Nodes.class).child(Node.class, testNode.getKey()) .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(meter.getMeterId())); modification.merge(LogicalDatastoreType.CONFIGURATION, nodeToInstanceId(testNode), testNode, true); modification.merge(LogicalDatastoreType.CONFIGURATION, path1, meter, true); CheckedFuture<Void, TransactionCommitFailedException> commitFuture = modification.submit(); Futures.addCallback(commitFuture, new FutureCallback<Void>() { @Override public void onSuccess(Void aVoid) { ci.println("Status of Group Data Loaded Transaction: success."); } @Override public void onFailure(Throwable throwable) { ci.println(String.format("Status of Group Data Loaded Transaction : failure. Reason : %s", throwable)); } }); }