use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.
the class PeopleCarListener method onCarBought.
@Override
public void onCarBought(final CarBought notification) {
final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
carPersonBuilder.setCarId(notification.getCarId());
carPersonBuilder.setPersonId(notification.getPersonId());
CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
carPersonBuilder.withKey(key);
final CarPerson carPerson = carPersonBuilder.build();
LOG.info("Car bought, adding car-person entry: [{}]", carPerson);
InstanceIdentifier<CarPerson> carPersonIId = InstanceIdentifier.builder(CarPeople.class).child(CarPerson.class, carPerson.key()).build();
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson);
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.info("Successfully added car-person entry: [{}]", carPerson);
}
@Override
public void onFailure(final Throwable ex) {
LOG.error("Failed to add car-person entry: [{}]", carPerson, ex);
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.
the class CarProvider method stressTest.
@Override
public ListenableFuture<RpcResult<StressTestOutput>> stressTest(final StressTestInput input) {
final int inputRate;
final long inputCount;
// If rate is not provided, or given as zero, then just return.
if (input.getRate() == null || input.getRate().toJava() == 0) {
LOG_PURCHASE_CAR.info("Exiting stress test as no rate is given.");
return Futures.immediateFuture(RpcResultBuilder.<StressTestOutput>failed().withError(ErrorType.PROTOCOL, "invalid rate").build());
}
inputRate = input.getRate().toJava();
if (input.getCount() != null) {
inputCount = input.getCount().toJava();
} else {
inputCount = 0;
}
LOG_PURCHASE_CAR.info("Stress test starting : rate: {} count: {}", inputRate, inputCount);
stopThread();
// clear counters
succcessCounter.set(0);
failureCounter.set(0);
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
InstanceIdentifier<Cars> carsId = InstanceIdentifier.create(Cars.class);
tx.merge(LogicalDatastoreType.CONFIGURATION, carsId, new CarsBuilder().build());
try {
tx.commit().get(5, TimeUnit.SECONDS);
} catch (TimeoutException | InterruptedException | ExecutionException e) {
LOG_PURCHASE_CAR.error("Put Cars failed", e);
return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build());
}
stopThread = false;
final long sleep = TimeUnit.NANOSECONDS.convert(1000, TimeUnit.MILLISECONDS) / inputRate;
final Stopwatch sw = Stopwatch.createUnstarted();
testThread = new Thread(() -> {
sw.start();
AtomicLong count = new AtomicLong();
while (!stopThread) {
long id = count.incrementAndGet();
WriteTransaction tx1 = dataProvider.newWriteOnlyTransaction();
CarEntry car = new CarEntryBuilder().setId(new CarId("car" + id)).build();
tx1.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.key()).build(), car);
tx1.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
// Transaction succeeded
succcessCounter.getAndIncrement();
}
@Override
public void onFailure(final Throwable ex) {
// Transaction failed
failureCounter.getAndIncrement();
LOG_CAR_PROVIDER.error("Put Cars failed", ex);
}
}, MoreExecutors.directExecutor());
try {
TimeUnit.NANOSECONDS.sleep(sleep);
} catch (InterruptedException e) {
break;
}
if (count.get() % 1000 == 0) {
LOG_PURCHASE_CAR.info("Cars created {}, time: {}", count.get(), sw.elapsed(TimeUnit.SECONDS));
}
// Check if a count is specified in input and we have created that many cars.
if (inputCount != 0 && count.get() >= inputCount) {
stopThread = true;
}
}
LOG_PURCHASE_CAR.info("Stress test thread stopping after creating {} cars.", count.get());
});
testThread.start();
return Futures.immediateFuture(RpcResultBuilder.success(new StressTestOutputBuilder().build()).build());
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.
the class PeopleProvider method addPerson.
@Override
public ListenableFuture<RpcResult<AddPersonOutput>> addPerson(final AddPersonInput input) {
LOG.info("RPC addPerson : adding person [{}]", input);
PersonBuilder builder = new PersonBuilder(input);
final Person person = builder.build();
final SettableFuture<RpcResult<AddPersonOutput>> futureResult = SettableFuture.create();
// Each entry will be identifiable by a unique key, we have to create that identifier
final InstanceIdentifier<Person> personId = InstanceIdentifier.builder(People.class).child(Person.class, person.key()).build();
// Place entry in data store tree
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
tx.put(LogicalDatastoreType.CONFIGURATION, personId, person);
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
LOG.info("RPC addPerson : person added successfully [{}]", person);
regs.add(rpcProviderService.registerRpcImplementation(CarPurchaseService.class, rpcImplementation, ImmutableSet.of(personId)));
LOG.info("RPC addPerson : routed rpc registered for instance ID [{}]", personId);
futureResult.set(RpcResultBuilder.success(new AddPersonOutputBuilder().build()).build());
}
@Override
public void onFailure(final Throwable ex) {
LOG.error("RPC addPerson : person addition failed [{}]", person, ex);
futureResult.set(RpcResultBuilder.<AddPersonOutput>failed().withError(RpcError.ErrorType.APPLICATION, ex.getMessage()).build());
}
}, MoreExecutors.directExecutor());
return futureResult;
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.
the class TxchainDomDelete method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final org.opendaylight.yangtools.yang.common.QName olId = QName.create(OuterList.QNAME, "id");
final YangInstanceIdentifier pid = YangInstanceIdentifier.builder().node(TestExec.QNAME).node(OuterList.QNAME).build();
final DOMTransactionChain chain = domDataBroker.createMergingTransactionChain(this);
DOMDataTreeWriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (int l = 0; l < outerListElem; l++) {
YangInstanceIdentifier yid = pid.node(NodeIdentifierWithPredicates.of(OuterList.QNAME, olId, l));
tx.delete(dsType, yid);
writeCnt++;
if (writeCnt == writesPerTx) {
txSubmitted++;
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
txOk++;
}
@Override
public void onFailure(final Throwable cause) {
LOG.error("Transaction failed", cause);
txError++;
}
}, MoreExecutors.directExecutor());
tx = chain.newWriteOnlyTransaction();
writeCnt = 0;
}
}
// We need to empty the transaction chain before closing it
try {
txSubmitted++;
tx.commit().get();
txOk++;
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Transaction failed", e);
txError++;
}
try {
chain.close();
} catch (final IllegalStateException e) {
LOG.error("Transaction close failed,", e);
}
LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
}
use of org.opendaylight.mdsal.common.api.CommitInfo in project controller by opendaylight.
the class TxchainBaDelete method executeList.
@Override
public void executeList() {
final LogicalDatastoreType dsType = getDataStoreType();
final TransactionChain chain = bindingDataBroker.createMergingTransactionChain(this);
WriteTransaction tx = chain.newWriteOnlyTransaction();
int txSubmitted = 0;
int writeCnt = 0;
for (int l = 0; l < outerListElem; l++) {
InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class).child(OuterList.class, new OuterListKey(l));
tx.delete(dsType, iid);
writeCnt++;
if (writeCnt == writesPerTx) {
txSubmitted++;
tx.commit().addCallback(new FutureCallback<CommitInfo>() {
@Override
public void onSuccess(final CommitInfo result) {
txOk++;
}
@Override
public void onFailure(final Throwable cause) {
LOG.error("Transaction failed", cause);
txError++;
}
}, MoreExecutors.directExecutor());
tx = chain.newWriteOnlyTransaction();
writeCnt = 0;
}
}
// We need to empty the chain before closing it
try {
if (writeCnt > 0) {
txSubmitted++;
}
tx.commit().get();
} catch (final InterruptedException | ExecutionException e) {
LOG.error("Transaction failed", e);
}
try {
chain.close();
} catch (final IllegalStateException e) {
LOG.error("Transaction close failed", e);
}
LOG.debug("Transactions: submitted {}, completed {}", txSubmitted, txOk + txError);
}
Aggregations