Search in sources :

Example 21 with ActorContext

use of org.opendaylight.controller.cluster.datastore.utils.ActorContext in project controller by opendaylight.

the class DistributedShardedDOMDataTree method initDefaultShard.

@SuppressWarnings("checkstyle:IllegalCatch")
private void initDefaultShard(final LogicalDatastoreType logicalDatastoreType) throws ExecutionException, InterruptedException {
    final PrefixedShardConfigWriter writer = writerMap.get(logicalDatastoreType);
    if (writer.checkDefaultIsPresent()) {
        LOG.debug("{}: Default shard for {} is already present in the config. Possibly saved in snapshot.", memberName, logicalDatastoreType);
    } else {
        try {
            // Currently the default shard configuration is present in the out-of-box modules.conf and is
            // expected to be present. So look up the local default shard here and create the frontend.
            // TODO we don't have to do it for config and operational default shard separately. Just one of them
            // should be enough
            final ActorContext actorContext = logicalDatastoreType == LogicalDatastoreType.CONFIGURATION ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
            final Optional<ActorRef> defaultLocalShardOptional = actorContext.findLocalShard(ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY));
            if (defaultLocalShardOptional.isPresent()) {
                LOG.debug("{}: Default shard for {} is already started, creating just frontend", memberName, logicalDatastoreType);
                createShardFrontend(new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY));
            }
        // The local shard isn't present - we assume that means the local member isn't in the replica list
        // and will be dynamically created later via an explicit add-shard-replica request. This is the
        // bootstrapping mechanism to add a new node into an existing cluster. The following code to create
        // the default shard as a prefix shard is problematic in this scenario so it is commented out. Since
        // the default shard is a module-based shard by default, it makes sense to always treat it as such,
        // ie bootstrap it in the same manner as the special prefix-configuration and EOS shards.
        // final Collection<MemberName> names = distributedConfigDatastore.getActorContext().getConfiguration()
        // .getUniqueMemberNamesForAllShards();
        // Await.result(FutureConverters.toScala(createDistributedShard(
        // new DOMDataTreeIdentifier(logicalDatastoreType, YangInstanceIdentifier.EMPTY), names)),
        // SHARD_FUTURE_TIMEOUT_DURATION);
        // } catch (DOMDataTreeShardingConflictException e) {
        // LOG.debug("{}: Default shard for {} already registered, possibly due to other node doing it faster",
        // memberName, logicalDatastoreType);
        } catch (Exception e) {
            LOG.error("{}: Default shard initialization for {} failed", memberName, logicalDatastoreType, e);
            throw new RuntimeException(e);
        }
    }
}
Also used : ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) TimeoutException(java.util.concurrent.TimeoutException) DOMDataTreeLoopException(org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException) DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) DOMDataTreeShardingConflictException(org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException) ExecutionException(java.util.concurrent.ExecutionException) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Example 22 with ActorContext

use of org.opendaylight.controller.cluster.datastore.utils.ActorContext in project controller by opendaylight.

the class ShardedDataTreeActor method onLookupPrefixShard.

@SuppressWarnings("checkstyle:IllegalCatch")
private void onLookupPrefixShard(final LookupPrefixShard message) {
    LOG.debug("Member: {}, Received LookupPrefixShard: {}", clusterWrapper.getCurrentMemberName(), message);
    final DOMDataTreeIdentifier prefix = message.getPrefix();
    final ActorContext context = prefix.getDatastoreType() == LogicalDatastoreType.CONFIGURATION ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
    // schedule a notification task for the reply
    actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL, new ShardCreationLookupTask(actorSystem, getSender(), clusterWrapper, context, shardingService, prefix, lookupTaskMaxRetries), actorSystem.dispatcher());
}
Also used : DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Example 23 with ActorContext

use of org.opendaylight.controller.cluster.datastore.utils.ActorContext in project controller by opendaylight.

the class ShardedDataTreeActor method onStartConfigShardLookup.

private void onStartConfigShardLookup(final StartConfigShardLookup message) {
    LOG.debug("Received StartConfigShardLookup: {}", message);
    final ActorContext context = message.getType().equals(LogicalDatastoreType.CONFIGURATION) ? distributedConfigDatastore.getActorContext() : distributedOperDatastore.getActorContext();
    // schedule a notification task for the reply
    actorSystem.scheduler().scheduleOnce(SHARD_LOOKUP_TASK_INTERVAL, new ConfigShardLookupTask(actorSystem, getSender(), context, message, lookupTaskMaxRetries), actorSystem.dispatcher());
}
Also used : ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext)

Example 24 with ActorContext

use of org.opendaylight.controller.cluster.datastore.utils.ActorContext in project controller by opendaylight.

the class AbstractClientHistoryTest method createActorContextMock.

protected static ActorContext createActorContextMock(final ActorSystem system, final ActorRef actor) {
    final ActorContext mock = mock(ActorContext.class);
    final Promise<PrimaryShardInfo> promise = new DefaultPromise<>();
    final ActorSelection selection = system.actorSelection(actor.path());
    final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0);
    promise.success(shardInfo);
    when(mock.findPrimaryShardAsync(any())).thenReturn(promise.future());
    return mock;
}
Also used : ActorSelection(akka.actor.ActorSelection) DefaultPromise(scala.concurrent.impl.Promise.DefaultPromise) PrimaryShardInfo(org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext)

Example 25 with ActorContext

use of org.opendaylight.controller.cluster.datastore.utils.ActorContext in project controller by opendaylight.

the class AbstractDataStoreClientBehaviorTest method setUp.

@Before
public void setUp() throws Exception {
    system = ActorSystem.apply();
    clientActorProbe = new TestProbe(system, "client");
    actorContextProbe = new TestProbe(system, "actor-context");
    final ActorContext context = createActorContextMock(system, actorContextProbe.ref());
    clientContext = AccessClientUtil.createClientActorContext(system, clientActorProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    behavior = createBehavior(clientContext, context);
}
Also used : TestProbe(akka.testkit.TestProbe) ActorContext(org.opendaylight.controller.cluster.datastore.utils.ActorContext) ClientActorContext(org.opendaylight.controller.cluster.access.client.ClientActorContext) Before(org.junit.Before)

Aggregations

ActorContext (org.opendaylight.controller.cluster.datastore.utils.ActorContext)36 Test (org.junit.Test)15 ActorRef (akka.actor.ActorRef)13 TestKit (akka.testkit.javadsl.TestKit)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)13 Configuration (org.opendaylight.controller.cluster.datastore.config.Configuration)11 FiniteDuration (scala.concurrent.duration.FiniteDuration)11 FindLocalShard (org.opendaylight.controller.cluster.datastore.messages.FindLocalShard)10 Before (org.junit.Before)7 ClientActorContext (org.opendaylight.controller.cluster.access.client.ClientActorContext)7 Props (akka.actor.Props)6 LocalShardFound (org.opendaylight.controller.cluster.datastore.messages.LocalShardFound)6 ClusteredDOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.ClusteredDOMDataTreeChangeListener)6 TestProbe (akka.testkit.TestProbe)5 RegisterDataTreeNotificationListenerReply (org.opendaylight.controller.cluster.datastore.messages.RegisterDataTreeNotificationListenerReply)5 DOMDataTreeChangeListener (org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener)5 ActorSelection (akka.actor.ActorSelection)4 ActorSystem (akka.actor.ActorSystem)4 Timeout (akka.util.Timeout)4 PrimaryShardInfo (org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo)4