X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Fclustering-test-app%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fit%2Fprovider%2Fimpl%2FPrefixShardHandler.java;h=a58883c3e2befef45ef9237d2cb1e24df07ffa03;hb=0cb5ce07fc959deed2e7887ed22dfde81cb2c9a2;hp=e3b6f980616a4d040b946372890f40a19beaec76;hpb=7c6334fbe717fd51f76984e5789ae3d8ee2eb29a;p=controller.git diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixShardHandler.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixShardHandler.java index e3b6f98061..a58883c3e2 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixShardHandler.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/impl/PrefixShardHandler.java @@ -5,7 +5,6 @@ * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ - package org.opendaylight.controller.clustering.it.provider.impl; import static org.opendaylight.controller.clustering.it.provider.impl.AbstractTransactionHandler.ID; @@ -23,10 +22,9 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletionStage; import java.util.stream.Collectors; -import javax.annotation.Nullable; import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.sharding.DistributedShardFactory; -import org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration; +import org.opendaylight.controller.cluster.sharding.DistributedShardRegistration; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction; @@ -37,7 +35,11 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeService; import org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException; import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.CreatePrefixShardInput; +import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.CreatePrefixShardOutput; +import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.CreatePrefixShardOutputBuilder; import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RemovePrefixShardInput; +import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RemovePrefixShardOutput; +import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.RemovePrefixShardOutputBuilder; import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; import org.opendaylight.yangtools.yang.common.RpcResultBuilder; @@ -73,9 +75,10 @@ public class PrefixShardHandler { this.serializer = serializer; } - public ListenableFuture> onCreatePrefixShard(final CreatePrefixShardInput input) { + public ListenableFuture> onCreatePrefixShard( + final CreatePrefixShardInput input) { - final SettableFuture> future = SettableFuture.create(); + final SettableFuture> future = SettableFuture.create(); final CompletionStage completionStage; final YangInstanceIdentifier identifier = serializer.toYangInstanceIdentifier(input.getPrefix()); @@ -89,12 +92,12 @@ public class PrefixShardHandler { LOG.debug("Shard[{}] created successfully.", identifier); registrations.put(identifier, registration); - final ListenableFuture ensureFuture = ensureListExists(); - Futures.addCallback(ensureFuture, new FutureCallback() { + final ListenableFuture ensureFuture = ensureListExists(); + Futures.addCallback(ensureFuture, new FutureCallback() { @Override - public void onSuccess(@Nullable final Void result) { + public void onSuccess(final Object result) { LOG.debug("Initial list write successful."); - future.set(RpcResultBuilder.success().build()); + future.set(RpcResultBuilder.success(new CreatePrefixShardOutputBuilder().build()).build()); } @Override @@ -103,7 +106,7 @@ public class PrefixShardHandler { final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Shard creation failed", "cluster-test-app", "", throwable); - future.set(RpcResultBuilder.failed().withRpcError(error).build()); + future.set(RpcResultBuilder.failed().withRpcError(error).build()); } }, MoreExecutors.directExecutor()); }); @@ -112,7 +115,7 @@ public class PrefixShardHandler { final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Shard creation failed", "cluster-test-app", "", throwable); - future.set(RpcResultBuilder.failed().withRpcError(error).build()); + future.set(RpcResultBuilder.failed().withRpcError(error).build()); return null; }); } catch (final DOMDataTreeShardingConflictException e) { @@ -120,13 +123,14 @@ public class PrefixShardHandler { final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed", "Sharding conflict", "cluster-test-app", "", e); - future.set(RpcResultBuilder.failed().withRpcError(error).build()); + future.set(RpcResultBuilder.failed().withRpcError(error).build()); } return future; } - public ListenableFuture> onRemovePrefixShard(final RemovePrefixShardInput input) { + public ListenableFuture> onRemovePrefixShard( + final RemovePrefixShardInput input) { final YangInstanceIdentifier identifier = serializer.toYangInstanceIdentifier(input.getPrefix()); final DistributedShardRegistration registration = registrations.get(identifier); @@ -134,26 +138,27 @@ public class PrefixShardHandler { if (registration == null) { final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "registration-missing", "No shard registered at this prefix."); - return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error).build()); + return Futures.immediateFuture(RpcResultBuilder.failed().withRpcError(error) + .build()); } - final SettableFuture> future = SettableFuture.create(); + final SettableFuture> future = SettableFuture.create(); final CompletionStage close = registration.close(); - close.thenRun(() -> future.set(RpcResultBuilder.success().build())); + close.thenRun(() -> future.set(RpcResultBuilder.success(new RemovePrefixShardOutputBuilder().build()).build())); close.exceptionally(throwable -> { LOG.warn("Shard[{}] removal failed:", identifier, throwable); final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "remove-shard-failed", "Shard removal failed", "cluster-test-app", "", throwable); - future.set(RpcResultBuilder.failed().withRpcError(error).build()); + future.set(RpcResultBuilder.failed().withRpcError(error).build()); return null; }); return future; } - private ListenableFuture ensureListExists() { + private ListenableFuture ensureListExists() { final CollectionNodeBuilder mapBuilder = ImmutableNodes.mapNodeBuilder(ID_INT); @@ -172,21 +177,21 @@ public class PrefixShardHandler { .build(); final DOMDataTreeProducer producer = domDataTreeService.createProducer(Collections.singleton( - new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY))); + new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty()))); final DOMDataTreeCursorAwareTransaction tx = producer.createTransaction(false); final DOMDataTreeWriteCursor cursor = tx.createCursor(new DOMDataTreeIdentifier( - LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY)); + LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.empty())); cursor.merge(containerNode.getIdentifier(), containerNode); cursor.close(); - final ListenableFuture future = tx.submit(); - Futures.addCallback(future, new FutureCallback() { + final ListenableFuture future = tx.commit(); + Futures.addCallback(future, new FutureCallback() { @Override - public void onSuccess(@Nullable final Void result) { + public void onSuccess(final Object result) { try { LOG.debug("Closing producer for initial list."); producer.close();