@Override public Future<RpcResult<ReadServiceFunctionOutput>> readServiceFunction( ReadServiceFunctionInput input) { printTraceStart(LOG); LOG.info("Input: " + input); if (dataBroker != null) { ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName()); InstanceIdentifier<ServiceFunction> sfIID; sfIID = InstanceIdentifier.builder(ServiceFunctions.class) .child(ServiceFunction.class, sfkey) .toInstance(); ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction(); Optional<ServiceFunction> dataObject = null; try { dataObject = readTx.read(LogicalDatastoreType.CONFIGURATION, sfIID).get(); } catch (InterruptedException | ExecutionException e) { LOG.debug("Failed to readServiceFunction : {}", e.getMessage()); } if (dataObject instanceof ServiceFunction) { LOG.debug("readServiceFunction Success: {}", ((ServiceFunction) dataObject).getName()); ServiceFunction serviceFunction = (ServiceFunction) dataObject; ReadServiceFunctionOutput readServiceFunctionOutput = null; ReadServiceFunctionOutputBuilder outputBuilder = new ReadServiceFunctionOutputBuilder(); outputBuilder .setName(serviceFunction.getName()) .setIpMgmtAddress(serviceFunction.getIpMgmtAddress()) .setType(serviceFunction.getType()); readServiceFunctionOutput = outputBuilder.build(); printTraceStop(LOG); return Futures.immediateFuture( Rpcs.<ReadServiceFunctionOutput>getRpcResult( true, readServiceFunctionOutput, Collections.<RpcError>emptySet())); } printTraceStop(LOG); return Futures.immediateFuture( Rpcs.<ReadServiceFunctionOutput>getRpcResult( true, null, Collections.<RpcError>emptySet())); } else { LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]); printTraceStop(LOG); return Futures.immediateFuture( Rpcs.<ReadServiceFunctionOutput>getRpcResult( true, null, Collections.<RpcError>emptySet())); } }
@Override public Future<RpcResult<Void>> putServiceFunctionChains(PutServiceFunctionChainsInput input) { printTraceStart(LOG); ServiceFunctionChainsBuilder serviceFunctionChainsBuilder = new ServiceFunctionChainsBuilder(); serviceFunctionChainsBuilder = serviceFunctionChainsBuilder.setServiceFunctionChain(input.getServiceFunctionChain()); ServiceFunctionChains sfcs = serviceFunctionChainsBuilder.build(); if (!SfcDataStoreAPI.writeMergeTransactionAPI( OpendaylightSfc.SFC_IID, sfcs, LogicalDatastoreType.CONFIGURATION)) { LOG.error( "Failed to create service function chain: {}", input.getServiceFunctionChain().toString()); } return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true, Collections.<RpcError>emptySet())); }
private RpcResult<Void> commitToPlugin(InternalTransaction transaction) { DataModification<InstanceIdentifier<?>, DataObject> modification = transaction.modification; // get created entries Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> createdEntries = modification.getCreatedConfigurationData().entrySet(); // get updated entries Set<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> updatedEntries = new HashSet<Entry<InstanceIdentifier<? extends DataObject>, DataObject>>(); updatedEntries.addAll(modification.getUpdatedConfigurationData().entrySet()); updatedEntries.removeAll(createdEntries); // get removed entries Set<InstanceIdentifier<? extends DataObject>> removeEntriesInstanceIdentifiers = modification.getRemovedConfigurationData(); for (Entry<InstanceIdentifier<? extends DataObject>, DataObject> entry : createdEntries) { if (entry.getValue() instanceof Meter) { addMeter(entry.getKey(), (Meter) entry.getValue()); } } for (Entry<InstanceIdentifier<?>, DataObject> entry : updatedEntries) { if (entry.getValue() instanceof Meter) { Meter originalMeter = (Meter) modification.getOriginalConfigurationData().get(entry.getKey()); Meter updatedMeter = (Meter) entry.getValue(); updateMeter(entry.getKey(), originalMeter, updatedMeter); } } for (InstanceIdentifier<?> instanceId : removeEntriesInstanceIdentifiers) { DataObject removeValue = modification.getOriginalConfigurationData().get(instanceId); if (removeValue instanceof Meter) { removeMeter(instanceId, (Meter) removeValue); } } return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet()); }
@Override public Future<RpcResult<Void>> putServiceFunction(PutServiceFunctionInput input) { printTraceStart(LOG); LOG.info("\n####### Input: " + input); if (dataBroker != null) { // Data PLane Locator List<SfDataPlaneLocator> sfDataPlaneLocatorList = input.getSfDataPlaneLocator(); ServiceFunctionBuilder sfbuilder = new ServiceFunctionBuilder(); ServiceFunctionKey sfkey = new ServiceFunctionKey(input.getName()); ServiceFunction sf = sfbuilder .setName(input.getName()) .setType(input.getType()) .setKey(sfkey) .setIpMgmtAddress(input.getIpMgmtAddress()) .setSfDataPlaneLocator(sfDataPlaneLocatorList) .build(); InstanceIdentifier<ServiceFunction> sfEntryIID = InstanceIdentifier.builder(ServiceFunctions.class) .child(ServiceFunction.class, sf.getKey()) .toInstance(); WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction(); writeTx.merge(LogicalDatastoreType.CONFIGURATION, sfEntryIID, sf); writeTx.commit(); } else { LOG.warn("\n####### Data Provider is NULL : {}", Thread.currentThread().getStackTrace()[1]); } printTraceStop(LOG); return Futures.immediateFuture(Rpcs.<Void>getRpcResult(true, Collections.<RpcError>emptySet())); }
/** We should rollback our preparation */ @Override public RpcResult<Void> rollback() throws IllegalStateException { return Rpcs.getRpcResult(true, null, Collections.<RpcError>emptySet()); }