Search in sources :

Example 1 with AddPersonOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonOutput 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;
}
Also used : WriteTransaction(org.opendaylight.mdsal.binding.api.WriteTransaction) PersonBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.PersonBuilder) AddPersonOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonOutputBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) AddPersonOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonOutput) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo) Person(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.Person)

Aggregations

WriteTransaction (org.opendaylight.mdsal.binding.api.WriteTransaction)1 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)1 AddPersonOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonOutput)1 AddPersonOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.AddPersonOutputBuilder)1 Person (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.Person)1 PersonBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.PersonBuilder)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1