*/
package org.opendaylight.controller.clustering.it.provider;
-import static akka.actor.ActorRef.noSender;
-
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
-import akka.actor.PoisonPill;
-import akka.actor.Props;
import akka.dispatch.OnComplete;
import akka.pattern.Patterns;
-import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.opendaylight.controller.cluster.ActorSystemProvider;
-import org.opendaylight.controller.cluster.databroker.actors.dds.ClientLocalHistory;
-import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
-import org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient;
-import org.opendaylight.controller.cluster.databroker.actors.dds.SimpleDataStoreClientActor;
import org.opendaylight.controller.cluster.datastore.DistributedDataStoreInterface;
import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
import org.opendaylight.controller.cluster.datastore.utils.ClusterUtils;
import org.opendaylight.controller.cluster.raft.client.messages.Shutdown;
-import org.opendaylight.controller.cluster.sharding.DistributedShardFactory;
import org.opendaylight.controller.clustering.it.provider.impl.FlappingSingletonService;
import org.opendaylight.controller.clustering.it.provider.impl.GetConstantService;
-import org.opendaylight.controller.clustering.it.provider.impl.IdIntsDOMDataTreeLIstener;
import org.opendaylight.controller.clustering.it.provider.impl.IdIntsListener;
-import org.opendaylight.controller.clustering.it.provider.impl.PrefixLeaderHandler;
-import org.opendaylight.controller.clustering.it.provider.impl.PrefixShardHandler;
-import org.opendaylight.controller.clustering.it.provider.impl.ProduceTransactionsHandler;
import org.opendaylight.controller.clustering.it.provider.impl.PublishNotificationsTask;
import org.opendaylight.controller.clustering.it.provider.impl.RoutedGetConstantService;
import org.opendaylight.controller.clustering.it.provider.impl.SingletonGetConstantService;
import org.opendaylight.controller.clustering.it.provider.impl.WriteTransactionsHandler;
import org.opendaylight.controller.clustering.it.provider.impl.YnlListener;
-import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
-import org.opendaylight.controller.md.sal.binding.api.NotificationService;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeListener;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcImplementationRegistration;
-import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.NotificationService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
+import org.opendaylight.mdsal.dom.api.DOMDataTreeReadTransaction;
+import org.opendaylight.mdsal.dom.api.DOMRpcImplementationRegistration;
+import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.StartPublishNotificationsOutputBuilder;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeDdtlInput;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeDdtlOutput;
-import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeDdtlOutputBuilder;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeDtclInput;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeDtclOutput;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.SubscribeDtclOutputBuilder;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnregisterSingletonConstantOutputBuilder;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDdtlInput;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDdtlOutput;
-import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDdtlOutputBuilder;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclInput;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutput;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.UnsubscribeDtclOutputBuilder;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsInput;
import org.opendaylight.yang.gen.v1.tag.opendaylight.org._2017.controller.yang.lowlevel.control.rev170215.WriteTransactionsOutput;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import scala.concurrent.duration.FiniteDuration;
public class MdsalLowLevelTestProvider implements OdlMdsalLowlevelControlService {
-
private static final Logger LOG = LoggerFactory.getLogger(MdsalLowLevelTestProvider.class);
- private static final org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType CONTROLLER_CONFIG =
- org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
- private final RpcProviderRegistry rpcRegistry;
- private final BindingAwareBroker.RpcRegistration<OdlMdsalLowlevelControlService> registration;
- private final DistributedShardFactory distributedShardFactory;
+ private final RpcProviderService rpcRegistry;
+ private final ObjectRegistration<OdlMdsalLowlevelControlService> registration;
private final DistributedDataStoreInterface configDataStore;
- private final DOMDataTreeService domDataTreeService;
private final BindingNormalizedNodeSerializer bindingNormalizedNodeSerializer;
private final DOMDataBroker domDataBroker;
private final NotificationPublishService notificationPublishService;
private final DOMSchemaService schemaService;
private final ClusterSingletonServiceProvider singletonService;
private final DOMRpcProviderService domRpcService;
- private final PrefixLeaderHandler prefixLeaderHandler;
- private final PrefixShardHandler prefixShardHandler;
private final DOMDataTreeChangeService domDataTreeChangeService;
private final ActorSystem actorSystem;
private ListenerRegistration<DOMDataTreeChangeListener> dtclReg;
private IdIntsListener idIntsListener;
private final Map<String, PublishNotificationsTask> publishNotificationsTasks = new HashMap<>();
- private ListenerRegistration<IdIntsDOMDataTreeLIstener> ddtlReg;
- private IdIntsDOMDataTreeLIstener idIntsDdtl;
-
-
- public MdsalLowLevelTestProvider(final RpcProviderRegistry rpcRegistry,
+ public MdsalLowLevelTestProvider(final RpcProviderService rpcRegistry,
final DOMRpcProviderService domRpcService,
final ClusterSingletonServiceProvider singletonService,
final DOMSchemaService schemaService,
final NotificationPublishService notificationPublishService,
final NotificationService notificationService,
final DOMDataBroker domDataBroker,
- final DOMDataTreeService domDataTreeService,
- final DistributedShardFactory distributedShardFactory,
final DistributedDataStoreInterface configDataStore,
final ActorSystemProvider actorSystemProvider) {
this.rpcRegistry = rpcRegistry;
this.notificationPublishService = notificationPublishService;
this.notificationService = notificationService;
this.domDataBroker = domDataBroker;
- this.domDataTreeService = domDataTreeService;
- this.distributedShardFactory = distributedShardFactory;
this.configDataStore = configDataStore;
this.actorSystem = actorSystemProvider.getActorSystem();
- this.prefixLeaderHandler = new PrefixLeaderHandler(domDataTreeService, bindingNormalizedNodeSerializer);
-
- domDataTreeChangeService =
- (DOMDataTreeChangeService) domDataBroker.getSupportedExtensions().get(DOMDataTreeChangeService.class);
-
- registration = rpcRegistry.addRpcImplementation(OdlMdsalLowlevelControlService.class, this);
+ domDataTreeChangeService = domDataBroker.getExtensions().getInstance(DOMDataTreeChangeService.class);
- prefixShardHandler = new PrefixShardHandler(distributedShardFactory, domDataTreeService,
- bindingNormalizedNodeSerializer);
+ registration = rpcRegistry.registerRpcImplementation(OdlMdsalLowlevelControlService.class, this);
}
@Override
idIntsListener = new IdIntsListener();
- dtclReg = domDataTreeChangeService
- .registerDataTreeChangeListener(
- new org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier(
- CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID),
- idIntsListener);
+ dtclReg = domDataTreeChangeService.registerDataTreeChangeListener(
+ new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, WriteTransactionsHandler.ID_INT_YID),
+ idIntsListener);
return RpcResultBuilder.success(new SubscribeDtclOutputBuilder().build()).buildFuture();
}
@Override
public ListenableFuture<RpcResult<RemovePrefixShardOutput>> removePrefixShard(final RemovePrefixShardInput input) {
- LOG.info("In removePrefixShard - input: {}", input);
-
- return prefixShardHandler.onRemovePrefixShard(input);
+ throw new UnsupportedOperationException();
}
@Override
public ListenableFuture<RpcResult<BecomePrefixLeaderOutput>> becomePrefixLeader(
final BecomePrefixLeaderInput input) {
- LOG.info("n becomePrefixLeader - input: {}", input);
-
- return prefixLeaderHandler.makeLeaderLocal(input);
+ throw new UnsupportedOperationException();
}
@Override
@Override
public ListenableFuture<RpcResult<AddShardReplicaOutput>> addShardReplica(final AddShardReplicaInput input) {
- return null;
+ throw new UnsupportedOperationException();
}
@Override
public ListenableFuture<RpcResult<SubscribeDdtlOutput>> subscribeDdtl(final SubscribeDdtlInput input) {
- LOG.info("In subscribeDdtl");
-
- if (ddtlReg != null) {
- return RpcResultBuilder.<SubscribeDdtlOutput>failed().withError(ErrorType.RPC,
- "data-exists", "There is already a listener registered for id-ints").buildFuture();
- }
-
- idIntsDdtl = new IdIntsDOMDataTreeLIstener();
-
- try {
- ddtlReg = domDataTreeService.registerListener(idIntsDdtl,
- Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
- ProduceTransactionsHandler.ID_INT_YID)),
- true, Collections.emptyList());
- } catch (DOMDataTreeLoopException e) {
- LOG.error("Failed to register DOMDataTreeListener", e);
- return RpcResultBuilder.<SubscribeDdtlOutput>failed().withError(
- ErrorType.APPLICATION, "Failed to register DOMDataTreeListener", e).buildFuture();
- }
-
- return RpcResultBuilder.success(new SubscribeDdtlOutputBuilder().build()).buildFuture();
+ throw new UnsupportedOperationException();
}
@Override
"id-ints listener has not received any notifications.").buildFuture();
}
- final DOMDataReadOnlyTransaction rTx = domDataBroker.newReadOnlyTransaction();
- try {
- final Optional<NormalizedNode<?, ?>> readResult =
- rTx.read(CONTROLLER_CONFIG, WriteTransactionsHandler.ID_INT_YID).get();
+ try (DOMDataTreeReadTransaction rTx = domDataBroker.newReadOnlyTransaction()) {
+ final Optional<NormalizedNode<?, ?>> readResult = rTx.read(LogicalDatastoreType.CONFIGURATION,
+ WriteTransactionsHandler.ID_INT_YID).get();
if (!readResult.isPresent()) {
return RpcResultBuilder.<UnsubscribeDtclOutput>failed().withError(ErrorType.APPLICATION, "data-missing",
@Override
public ListenableFuture<RpcResult<CreatePrefixShardOutput>> createPrefixShard(final CreatePrefixShardInput input) {
- LOG.info("In createPrefixShard - input: {}", input);
-
- return prefixShardHandler.onCreatePrefixShard(input);
+ throw new UnsupportedOperationException();
}
@Override
@Override
public ListenableFuture<RpcResult<ProduceTransactionsOutput>> produceTransactions(
final ProduceTransactionsInput input) {
- LOG.info("In produceTransactions - input: {}", input);
- return ProduceTransactionsHandler.start(domDataTreeService, input);
+ throw new UnsupportedOperationException();
}
@Override
@Override
public ListenableFuture<RpcResult<UnregisterDefaultConstantOutput>> unregisterDefaultConstant(
final UnregisterDefaultConstantInput input) {
- return null;
+ throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<RpcResult<UnsubscribeDdtlOutput>> unsubscribeDdtl(final UnsubscribeDdtlInput input) {
- LOG.info("In unsubscribeDdtl");
-
- if (idIntsDdtl == null || ddtlReg == null) {
- return RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withError(
- ErrorType.RPC, "data-missing", "No prior listener was registered").buildFuture();
- }
-
- long timeout = 120L;
- try {
- idIntsDdtl.tryFinishProcessing().get(timeout, TimeUnit.SECONDS);
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- LOG.error("Unable to finish notification processing", e);
- return RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withError(ErrorType.APPLICATION,
- "Unable to finish notification processing in " + timeout + " seconds", e).buildFuture();
- }
-
- ddtlReg.close();
- ddtlReg = null;
-
- if (!idIntsDdtl.hasTriggered()) {
- return RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withError(ErrorType.APPLICATION,
- "No notification received.", "id-ints listener has not received any notifications").buildFuture();
- }
-
- final String shardName = ClusterUtils.getCleanShardName(ProduceTransactionsHandler.ID_INTS_YID);
- LOG.debug("Creating distributed datastore client for shard {}", shardName);
-
- final ActorUtils actorUtils = configDataStore.getActorUtils();
- final Props distributedDataStoreClientProps =
- SimpleDataStoreClientActor.props(actorUtils.getCurrentMemberName(),
- "Shard-" + shardName, actorUtils, shardName);
-
- final ActorRef clientActor = actorSystem.actorOf(distributedDataStoreClientProps);
- final DataStoreClient distributedDataStoreClient;
- try {
- distributedDataStoreClient = SimpleDataStoreClientActor
- .getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS);
- } catch (RuntimeException e) {
- LOG.error("Failed to get actor for {}", distributedDataStoreClientProps, e);
- clientActor.tell(PoisonPill.getInstance(), noSender());
- return RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
- .withError(ErrorType.APPLICATION, "Unable to create DataStoreClient for read", e).buildFuture();
- }
-
- final ClientLocalHistory localHistory = distributedDataStoreClient.createLocalHistory();
- final ClientTransaction tx = localHistory.createTransaction();
- final ListenableFuture<java.util.Optional<NormalizedNode<?, ?>>> read =
- tx.read(YangInstanceIdentifier.of(ProduceTransactionsHandler.ID_INT));
-
- tx.abort();
- localHistory.close();
- try {
- final java.util.Optional<NormalizedNode<?, ?>> optional = read.get();
- if (!optional.isPresent()) {
- return RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withError(ErrorType.APPLICATION,
- "data-missing", "Final read from id-ints is empty").buildFuture();
- }
-
- return RpcResultBuilder.success(new UnsubscribeDdtlOutputBuilder().setCopyMatches(
- idIntsDdtl.checkEqual(optional.get()))).buildFuture();
-
- } catch (InterruptedException | ExecutionException e) {
- LOG.error("Unable to read data to verify ddtl data", e);
- return RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
- .withError(ErrorType.APPLICATION, "Final read from id-ints failed", e).buildFuture();
- } finally {
- distributedDataStoreClient.close();
- clientActor.tell(PoisonPill.getInstance(), noSender());
- }
+ throw new UnsupportedOperationException();
}
}