Search in sources :

Example 36 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class ShardManager method onFlipShardMembersVotingStatus.

private void onFlipShardMembersVotingStatus(final FlipShardMembersVotingStatus flipMembersVotingStatus) {
    LOG.debug("{}: onFlipShardMembersVotingStatus: {}", persistenceId(), flipMembersVotingStatus);
    ActorRef sender = getSender();
    final String shardName = flipMembersVotingStatus.getShardName();
    findLocalShard(shardName, sender, localShardFound -> {
        Future<Object> future = ask(localShardFound.getPath(), GetOnDemandRaftState.INSTANCE, Timeout.apply(30, TimeUnit.SECONDS));
        future.onComplete(new OnComplete<Object>() {

            @Override
            public void onComplete(final Throwable failure, final Object response) {
                if (failure != null) {
                    sender.tell(new Status.Failure(new RuntimeException(String.format("Failed to access local shard %s", shardName), failure)), self());
                    return;
                }
                OnDemandRaftState raftState = (OnDemandRaftState) response;
                Map<String, Boolean> serverVotingStatusMap = new HashMap<>();
                for (Entry<String, Boolean> e : raftState.getPeerVotingStates().entrySet()) {
                    serverVotingStatusMap.put(e.getKey(), !e.getValue());
                }
                serverVotingStatusMap.put(getShardIdentifier(cluster.getCurrentMemberName(), shardName).toString(), !raftState.isVoting());
                changeShardMembersVotingStatus(new ChangeServersVotingStatus(serverVotingStatusMap), shardName, localShardFound.getPath(), sender);
            }
        }, new Dispatchers(context().system().dispatchers()).getDispatcher(Dispatchers.DispatcherType.Client));
    });
}
Also used : ActorRef(akka.actor.ActorRef) GetOnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.GetOnDemandRaftState) OnDemandRaftState(org.opendaylight.controller.cluster.raft.client.messages.OnDemandRaftState) Entry(java.util.Map.Entry) ChangeServersVotingStatus(org.opendaylight.controller.cluster.raft.messages.ChangeServersVotingStatus) Map(java.util.Map) HashMap(java.util.HashMap) SaveSnapshotFailure(akka.persistence.SaveSnapshotFailure) DeleteSnapshotsFailure(akka.persistence.DeleteSnapshotsFailure) Dispatchers(org.opendaylight.controller.cluster.common.actor.Dispatchers)

Example 37 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class DistributedShardedDOMDataTree method createShardFrontend.

private void createShardFrontend(final DOMDataTreeIdentifier prefix) {
    LOG.debug("{}: Creating CDS shard for prefix: {}", memberName, prefix);
    final String shardName = ClusterUtils.getCleanShardName(prefix.getRootIdentifier());
    final AbstractDataStore distributedDataStore = prefix.getDatastoreType().equals(org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION) ? distributedConfigDatastore : distributedOperDatastore;
    try (DOMDataTreeProducer producer = localCreateProducer(Collections.singletonList(prefix))) {
        final Entry<DataStoreClient, ActorRef> entry = createDatastoreClient(shardName, distributedDataStore.getActorContext());
        final DistributedShardFrontend shard = new DistributedShardFrontend(distributedDataStore, entry.getKey(), prefix);
        final DOMDataTreeShardRegistration<DOMDataTreeShard> reg = shardedDOMDataTree.registerDataTreeShard(prefix, shard, producer);
        synchronized (shards) {
            shards.store(prefix, reg);
        }
    } catch (final DOMDataTreeShardingConflictException e) {
        LOG.error("{}: Prefix {} is already occupied by another shard", distributedConfigDatastore.getActorContext().getClusterWrapper().getCurrentMemberName(), prefix, e);
    } catch (DOMDataTreeProducerException e) {
        LOG.error("Unable to close producer", e);
    } catch (DOMDataTreeShardCreationFailedException e) {
        LOG.error("Unable to create datastore client for shard {}", prefix, e);
    }
}
Also used : DOMDataTreeProducerException(org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException) ActorRef(akka.actor.ActorRef) DOMDataTreeProducer(org.opendaylight.mdsal.dom.api.DOMDataTreeProducer) AbstractDataStore(org.opendaylight.controller.cluster.datastore.AbstractDataStore) DOMDataTreeShard(org.opendaylight.mdsal.dom.api.DOMDataTreeShard) DOMDataTreeShardingConflictException(org.opendaylight.mdsal.dom.api.DOMDataTreeShardingConflictException) DataStoreClient(org.opendaylight.controller.cluster.databroker.actors.dds.DataStoreClient)

Example 38 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class DistributedShardedDOMDataTree method createDatastoreClient.

@SuppressWarnings("checkstyle:IllegalCatch")
private Entry<DataStoreClient, ActorRef> createDatastoreClient(final String shardName, final ActorContext actorContext) throws DOMDataTreeShardCreationFailedException {
    LOG.debug("{}: Creating distributed datastore client for shard {}", memberName, shardName);
    final Props distributedDataStoreClientProps = SimpleDataStoreClientActor.props(memberName, "Shard-" + shardName, actorContext, shardName);
    final ActorRef clientActor = actorSystem.actorOf(distributedDataStoreClientProps);
    try {
        return new SimpleEntry<>(SimpleDataStoreClientActor.getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS), clientActor);
    } catch (final Exception e) {
        LOG.error("{}: Failed to get actor for {}", distributedDataStoreClientProps, memberName, e);
        clientActor.tell(PoisonPill.getInstance(), noSender());
        throw new DOMDataTreeShardCreationFailedException("Unable to create datastore client for shard{" + shardName + "}", e);
    }
}
Also used : ActorRef(akka.actor.ActorRef) SimpleEntry(java.util.AbstractMap.SimpleEntry) Props(akka.actor.Props) 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)

Example 39 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class ShardedDataTreeActor method onProducerRemoved.

private void onProducerRemoved(final ProducerRemoved message) {
    LOG.debug("Received ProducerRemoved: {}", message);
    final List<CompletableFuture<Object>> futures = new ArrayList<>();
    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection selection = actorSystem.actorSelection(address);
        futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(selection, new NotifyProducerRemoved(message.getSubtrees()))).toCompletableFuture());
    }
    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
    final ActorRef respondTo = getSender();
    combinedFuture.thenRun(() -> respondTo.tell(new Status.Success(null), self())).exceptionally(e -> {
        respondTo.tell(new Status.Failure(null), self());
        return null;
    });
}
Also used : Status(akka.actor.Status) CompletableFuture(java.util.concurrent.CompletableFuture) ActorSelection(akka.actor.ActorSelection) ActorRef(akka.actor.ActorRef) ArrayList(java.util.ArrayList) NotifyProducerRemoved(org.opendaylight.controller.cluster.sharding.messages.NotifyProducerRemoved) Success(akka.actor.Status.Success)

Example 40 with ActorRef

use of akka.actor.ActorRef in project controller by opendaylight.

the class ShardedDataTreeActor method onProducerCreated.

private void onProducerCreated(final ProducerCreated message) {
    LOG.debug("Received ProducerCreated: {}", message);
    // fastpath if we have no peers
    if (resolver.getShardingServicePeerActorAddresses().isEmpty()) {
        getSender().tell(new Status.Success(null), noSender());
    }
    final ActorRef sender = getSender();
    final Collection<DOMDataTreeIdentifier> subtrees = message.getSubtrees();
    final List<CompletableFuture<Object>> futures = new ArrayList<>();
    for (final String address : resolver.getShardingServicePeerActorAddresses()) {
        final ActorSelection actorSelection = actorSystem.actorSelection(address);
        futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(actorSelection, new NotifyProducerCreated(subtrees), DEFAULT_ASK_TIMEOUT)).toCompletableFuture());
    }
    final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
    combinedFuture.thenRun(() -> sender.tell(new Success(null), noSender())).exceptionally(throwable -> {
        sender.tell(new Status.Failure(throwable), self());
        return null;
    });
}
Also used : Status(akka.actor.Status) ActorRef(akka.actor.ActorRef) DOMDataTreeIdentifier(org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier) ArrayList(java.util.ArrayList) Success(akka.actor.Status.Success) Success(akka.actor.Status.Success) CompletableFuture(java.util.concurrent.CompletableFuture) ActorSelection(akka.actor.ActorSelection) NotifyProducerCreated(org.opendaylight.controller.cluster.sharding.messages.NotifyProducerCreated)

Aggregations

ActorRef (akka.actor.ActorRef)383 Test (org.junit.Test)253 TestActorRef (akka.testkit.TestActorRef)124 TestKit (akka.testkit.javadsl.TestKit)84 ActorSystem (akka.actor.ActorSystem)53 FiniteDuration (scala.concurrent.duration.FiniteDuration)53 Props (akka.actor.Props)46 Timeout (akka.util.Timeout)43 Configuration (org.apache.flink.configuration.Configuration)42 AbstractShardManagerTest (org.opendaylight.controller.cluster.datastore.AbstractShardManagerTest)38 UpdateSchemaContext (org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext)37 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)33 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)30 ActorInitialized (org.opendaylight.controller.cluster.datastore.messages.ActorInitialized)26 NormalizedNodeAggregatorTest (org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregatorTest)26 AddressFromURIString (akka.actor.AddressFromURIString)24 ArrayList (java.util.ArrayList)22 JobID (org.apache.flink.api.common.JobID)22 IOException (java.io.IOException)21 RoleChangeNotification (org.opendaylight.controller.cluster.notifications.RoleChangeNotification)20