Search in sources :

Example 16 with Address

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

the class RemoteRpcRegistryMXBeanImpl method findRpcByName.

@Override
public Map<String, String> findRpcByName(final String name) {
    RoutingTable localTable = getLocalData();
    // Get all RPCs from local bucket
    Map<String, String> rpcMap = new HashMap<>(getRpcMemberMapByName(localTable, name, LOCAL_CONSTANT));
    // Get all RPCs from remote bucket
    Map<Address, Bucket<RoutingTable>> buckets = getRemoteBuckets();
    for (Entry<Address, Bucket<RoutingTable>> entry : buckets.entrySet()) {
        RoutingTable table = entry.getValue().getData();
        rpcMap.putAll(getRpcMemberMapByName(table, name, entry.getKey().toString()));
    }
    log.debug("list of RPCs {} searched by name {}", rpcMap, name);
    return rpcMap;
}
Also used : RoutingTable(org.opendaylight.controller.remote.rpc.registry.RoutingTable) Address(akka.actor.Address) HashMap(java.util.HashMap) Bucket(org.opendaylight.controller.remote.rpc.registry.gossip.Bucket)

Example 17 with Address

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

the class BucketStoreActor method getBucketsByMembers.

/**
 * Helper to collect buckets for requested members.
 *
 * @param members requested members
 */
private void getBucketsByMembers(final Collection<Address> members) {
    Map<Address, Bucket<T>> buckets = new HashMap<>();
    // first add the local bucket if asked
    if (members.contains(selfAddress)) {
        buckets.put(selfAddress, getLocalBucket().snapshot());
    }
    // then get buckets for requested remote nodes
    for (Address address : members) {
        if (remoteBuckets.containsKey(address)) {
            buckets.put(address, remoteBuckets.get(address));
        }
    }
    getSender().tell(buckets, getSelf());
}
Also used : Address(akka.actor.Address) HashMap(java.util.HashMap)

Example 18 with Address

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

the class BucketStoreActor method actorTerminated.

private void actorTerminated(final Terminated message) {
    LOG.info("Actor termination {} received", message);
    for (Address addr : watchedActors.removeAll(message.getActor())) {
        versions.remove(addr);
        final Bucket<T> bucket = remoteBuckets.remove(addr);
        if (bucket != null) {
            LOG.debug("Source actor dead, removing bucket {} from ", bucket, addr);
            onBucketRemoved(addr, bucket);
        }
    }
}
Also used : Address(akka.actor.Address)

Example 19 with Address

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

the class BucketStoreActor method updateRemoteBuckets.

/**
 * Update local copy of remote buckets where local copy's version is older.
 *
 * @param receivedBuckets buckets sent by remote
 *                        {@link org.opendaylight.controller.remote.rpc.registry.gossip.Gossiper}
 */
@VisibleForTesting
void updateRemoteBuckets(final Map<Address, Bucket<?>> receivedBuckets) {
    LOG.debug("{}: receiveUpdateRemoteBuckets: {}", selfAddress, receivedBuckets);
    if (receivedBuckets == null || receivedBuckets.isEmpty()) {
        // nothing to do
        return;
    }
    final Map<Address, Bucket<T>> newBuckets = new HashMap<>(receivedBuckets.size());
    for (Entry<Address, Bucket<?>> entry : receivedBuckets.entrySet()) {
        final Address addr = entry.getKey();
        if (selfAddress.equals(addr)) {
            // Remote cannot update our bucket
            continue;
        }
        @SuppressWarnings("unchecked") final Bucket<T> receivedBucket = (Bucket<T>) entry.getValue();
        if (receivedBucket == null) {
            LOG.debug("Ignoring null bucket from {}", addr);
            continue;
        }
        // update only if remote version is newer
        final long remoteVersion = receivedBucket.getVersion();
        final Long localVersion = versions.get(addr);
        if (localVersion != null && remoteVersion <= localVersion.longValue()) {
            LOG.debug("Ignoring down-versioned bucket from {} ({} local {} remote)", addr, localVersion, remoteVersion);
            continue;
        }
        newBuckets.put(addr, receivedBucket);
        versions.put(addr, remoteVersion);
        final Bucket<T> prevBucket = remoteBuckets.put(addr, receivedBucket);
        // Deal with DeathWatch subscriptions
        final Optional<ActorRef> prevRef = prevBucket != null ? prevBucket.getWatchActor() : Optional.empty();
        final Optional<ActorRef> curRef = receivedBucket.getWatchActor();
        if (!curRef.equals(prevRef)) {
            prevRef.ifPresent(ref -> removeWatch(addr, ref));
            curRef.ifPresent(ref -> addWatch(addr, ref));
        }
        LOG.debug("Updating bucket from {} to version {}", entry.getKey(), remoteVersion);
    }
    LOG.debug("State after update - Local Bucket [{}], Remote Buckets [{}]", localBucket, remoteBuckets);
    onBucketsUpdated(newBuckets);
}
Also used : Address(akka.actor.Address) HashMap(java.util.HashMap) ActorRef(akka.actor.ActorRef) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 20 with Address

use of akka.actor.Address in project flink by apache.

the class BootstrapTools method startWebMonitorIfConfigured.

/**
	 * Starts the web frontend.
	 * @param config The Flink config.
	 * @param actorSystem The ActorSystem to start the web frontend in.
	 * @param logger Logger for log output
	 * @return WebMonitor instance.
	 * @throws Exception
	 */
public static WebMonitor startWebMonitorIfConfigured(Configuration config, ActorSystem actorSystem, ActorRef jobManager, Logger logger) throws Exception {
    // this ensures correct values are present in the web frontend
    final Address address = AkkaUtils.getAddress(actorSystem);
    config.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, address.host().get());
    config.setString(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, address.port().get().toString());
    if (config.getInteger(ConfigConstants.JOB_MANAGER_WEB_PORT_KEY, 0) >= 0) {
        logger.info("Starting JobManager Web Frontend");
        LeaderRetrievalService leaderRetrievalService = LeaderRetrievalUtils.createLeaderRetrievalService(config, jobManager);
        // start the web frontend. we need to load this dynamically
        // because it is not in the same project/dependencies
        WebMonitor monitor = WebMonitorUtils.startWebRuntimeMonitor(config, leaderRetrievalService, actorSystem);
        // start the web monitor
        if (monitor != null) {
            String jobManagerAkkaURL = AkkaUtils.getAkkaURL(actorSystem, jobManager);
            monitor.start(jobManagerAkkaURL);
        }
        return monitor;
    } else {
        return null;
    }
}
Also used : Address(akka.actor.Address) LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) WebMonitor(org.apache.flink.runtime.webmonitor.WebMonitor)

Aggregations

Address (akka.actor.Address)36 Test (org.junit.Test)15 Bucket (org.opendaylight.controller.remote.rpc.registry.gossip.Bucket)9 UniqueAddress (akka.cluster.UniqueAddress)7 HashMap (java.util.HashMap)6 DOMRpcIdentifier (org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier)6 RemoteRpcEndpoint (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.RemoteRpcEndpoint)6 TestKit (akka.testkit.javadsl.TestKit)5 Optional (java.util.Optional)5 AddOrUpdateRoutes (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.AddOrUpdateRoutes)4 UpdateRemoteEndpoints (org.opendaylight.controller.remote.rpc.registry.RpcRegistry.Messages.UpdateRemoteEndpoints)4 ActorRef (akka.actor.ActorRef)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ActorSelection (akka.actor.ActorSelection)2 ActorSystem (akka.actor.ActorSystem)2 Props (akka.actor.Props)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)2 WebMonitor (org.apache.flink.runtime.webmonitor.WebMonitor)2