Search in sources :

Example 1 with PersonBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.PersonBuilder in project controller by opendaylight.

the class PeopleProvider method addPerson.

@Override
public Future<RpcResult<Void>> addPerson(final AddPersonInput input) {
    LOG.info("RPC addPerson : adding person [{}]", input);
    PersonBuilder builder = new PersonBuilder(input);
    final Person person = builder.build();
    final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
    // Each entry will be identifiable by a unique key, we have to create that identifier
    final InstanceIdentifier.InstanceIdentifierBuilder<Person> personIdBuilder = InstanceIdentifier.<People>builder(People.class).child(Person.class, person.getKey());
    final InstanceIdentifier<Person> personId = personIdBuilder.build();
    // Place entry in data store tree
    WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
    tx.put(LogicalDatastoreType.CONFIGURATION, personId, person, true);
    Futures.addCallback(tx.submit(), new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void result) {
            LOG.info("RPC addPerson : person added successfully [{}]", person);
            rpcRegistration.registerPath(PersonContext.class, personId);
            LOG.info("RPC addPerson : routed rpc registered for instance ID [{}]", personId);
            futureResult.set(RpcResultBuilder.<Void>success().build());
        }

        @Override
        public void onFailure(final Throwable ex) {
            LOG.error(String.format("RPC addPerson : person addition failed [%s]", person), ex);
            futureResult.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, ex.getMessage()).build());
        }
    }, MoreExecutors.directExecutor());
    return futureResult;
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) PersonContext(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PersonContext) PersonBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.people.PersonBuilder) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) People(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.People) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) 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.controller.md.sal.binding.api.WriteTransaction)1 People (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.People)1 PersonContext (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.people.rev140818.PersonContext)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 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1