Search in sources :

Example 21 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class ToDeltaEndpointInjectorTest method deltaTest.

@Test
public void deltaTest() {
    ReplaySubject<List<Endpoint>> subject = ReplaySubject.create();
    ToDeltaEndpointInjector service = new ToDeltaEndpointInjector(subject);
    // 1 add endpoints
    List<Endpoint> endpoints = new LinkedList<Endpoint>();
    endpoints.add(new Endpoint("localhost", 1234));
    endpoints.add(new Endpoint("localhost", 2468));
    subject.onNext(endpoints);
    // 2 remove endpoint by leaving out second endpoint
    endpoints = new LinkedList<Endpoint>();
    endpoints.add(new Endpoint("localhost", 1234));
    subject.onNext(endpoints);
    // 3 remove other
    endpoints = new LinkedList<Endpoint>();
    subject.onNext(endpoints);
    // 4 add back
    endpoints = new LinkedList<Endpoint>();
    endpoints.add(new Endpoint("localhost", 1234));
    endpoints.add(new Endpoint("localhost", 2468));
    subject.onNext(endpoints);
    subject.onCompleted();
    BlockingObservable<EndpointChange> be = service.deltas().toBlocking();
    // check for two adds
    Iterator<EndpointChange> iter = be.getIterator();
    Assert.assertTrue(iter.hasNext());
    EndpointChange ce1 = iter.next();
    Assert.assertEquals(ce1.getEndpoint().getSlotId(), "localhost:1234");
    Assert.assertEquals(ce1.getType(), EndpointChange.Type.add);
    EndpointChange ce2 = iter.next();
    Assert.assertEquals(ce2.getEndpoint().getSlotId(), "localhost:2468");
    Assert.assertEquals(ce2.getType(), EndpointChange.Type.add);
    // check for complete
    EndpointChange ce3 = iter.next();
    Assert.assertEquals(ce3.getEndpoint().getSlotId(), "localhost:2468");
    Assert.assertEquals(ce3.getType(), EndpointChange.Type.complete);
    // check for complete
    EndpointChange ce4 = iter.next();
    Assert.assertEquals(ce4.getEndpoint().getSlotId(), "localhost:1234");
    Assert.assertEquals(ce4.getType(), EndpointChange.Type.complete);
    // check for add
    EndpointChange ce5 = iter.next();
    Assert.assertEquals(ce5.getEndpoint().getSlotId(), "localhost:1234");
    Assert.assertEquals(ce5.getType(), EndpointChange.Type.add);
    EndpointChange ce6 = iter.next();
    Assert.assertEquals(ce6.getEndpoint().getSlotId(), "localhost:2468");
    Assert.assertEquals(ce6.getType(), EndpointChange.Type.add);
}
Also used : Endpoint(io.mantisrx.common.network.Endpoint) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 22 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class ToDeltaEndpointInjector method changes.

private List<EndpointChange> changes(List<Endpoint> previous, List<Endpoint> current) {
    logger.info("Sets to evaluate for differences, current: " + current + " previous: " + previous);
    Map<String, Endpoint> previousSet = new HashMap<>();
    // fill previous
    for (Endpoint endpoint : previous) {
        previousSet.put(uniqueHost(endpoint.getHost(), endpoint.getPort(), endpoint.getSlotId()), endpoint);
    }
    // collect into two buckets: add, complete
    List<EndpointChange> toAdd = new LinkedList<>();
    Set<String> completeCheck = new HashSet<>();
    for (Endpoint endpoint : current) {
        String id = uniqueHost(endpoint.getHost(), endpoint.getPort(), endpoint.getSlotId());
        if (!previousSet.containsKey(id)) {
            EndpointChange ce = new EndpointChange(EndpointChange.Type.add, endpoint);
            toAdd.add(ce);
        } else {
            completeCheck.add(id);
        }
    }
    List<EndpointChange> toComplete = new LinkedList<EndpointChange>();
    // check if need to complete any from current set: set difference
    for (Map.Entry<String, Endpoint> controlledEndpoint : previousSet.entrySet()) {
        if (!completeCheck.contains(controlledEndpoint.getKey())) {
            Endpoint ce = controlledEndpoint.getValue();
            EndpointChange ceToCompletd = new EndpointChange(EndpointChange.Type.complete, ce);
            toComplete.add(ceToCompletd);
        }
    }
    Map<String, EndpointChange> nextSet = new HashMap<>();
    // apply completes
    for (EndpointChange controlledEndpoint : toComplete) {
        nextSet.put(uniqueHost(controlledEndpoint.getEndpoint().getHost(), controlledEndpoint.getEndpoint().getPort(), controlledEndpoint.getEndpoint().getSlotId()), controlledEndpoint);
    }
    // apply adds
    for (EndpointChange controlledEndpoint : toAdd) {
        nextSet.put(uniqueHost(controlledEndpoint.getEndpoint().getHost(), controlledEndpoint.getEndpoint().getPort(), controlledEndpoint.getEndpoint().getSlotId()), controlledEndpoint);
    }
    logger.info("Differences to be applied: " + nextSet);
    return new ArrayList<>(nextSet.values());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Endpoint(io.mantisrx.common.network.Endpoint) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 23 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class LocalJobExecutorNetworked method startSink.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void startSink(StageConfig previousStage, int[] previousStagePorts, StageConfig stage, PortSelector portSelector, SinkHolder sink, Context context, Action0 sinkObservableCompletedCallback, Action0 sinkObservableTerminatedCompletedCallback, Action1<Throwable> sinkObservableErrorCallback, int stageNumber, int workerIndex, int workersAtPreviousStage) {
    if (logger.isDebugEnabled()) {
        StringBuilder portsToString = new StringBuilder();
        for (int previousPort : previousStagePorts) {
            portsToString.append(previousPort + " ");
        }
        logger.debug("Creating sink consumer connecting to publishers on ports " + portsToString);
    }
    Observable<Set<Endpoint>> endpoints = staticEndpoints(previousStagePorts, stageNumber, workerIndex, numPartitions);
    WorkerConsumerRemoteObservable sinkConsumer = new // name=null for local
    WorkerConsumerRemoteObservable(// name=null for local
    null, staticInjector(endpoints));
    StageExecutors.executeSink(sinkConsumer, stage, sink, portSelector, new RxMetrics(), context, sinkObservableTerminatedCompletedCallback, null, null, sinkObservableCompletedCallback, sinkObservableErrorCallback);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) RxMetrics(io.reactivex.mantis.remote.observable.RxMetrics) Endpoint(io.mantisrx.common.network.Endpoint)

Example 24 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class MasterClientWrapper method getSinkLocations.

public Observable<EndpointChange> getSinkLocations(final String jobId, final int sinkStage, final int forPartition, final int totalPartitions) {
    final ConditionalRetry schedInfoRetry = new ConditionalRetry(masterConnectRetryCounter, "SchedInfoRetry", 10);
    Observable<List<Endpoint>> schedulingUpdates = getMasterClientApi().take(1).flatMap((MantisMasterClientApi mantisMasterClientApi) -> {
        return mantisMasterClientApi.schedulingChanges(jobId).doOnError((Throwable throwable) -> {
            logger.warn(throwable.getMessage());
        }).retryWhen(schedInfoRetry.getRetryLogic()).map((JobSchedulingInfo jobSchedulingInfo) -> {
            logger.info("Got scheduling info for {}", jobId);
            if (logger.isDebugEnabled()) {
                logger.debug("Worker Assignments {}", jobSchedulingInfo.getWorkerAssignments().get(sinkStage));
            }
            return jobSchedulingInfo.getWorkerAssignments().get(sinkStage);
        }).map((WorkerAssignments workerAssignments) -> {
            List<Endpoint> endpoints = new ArrayList<>();
            if (workerAssignments != null) {
                logger.info("job " + jobId + " Creating endpoints conx from " + workerAssignments.getHosts().size() + " worker assignments");
                for (WorkerHost host : workerAssignments.getHosts().values()) {
                    final int workerIndex = host.getWorkerIndex();
                    final int totalFromPartitions = workerAssignments.getNumWorkers();
                    numSinkWorkersSubject.onNext(new JobSinkNumWorkers(jobId, totalFromPartitions));
                    if (usePartition(workerIndex, totalFromPartitions, forPartition, totalPartitions)) {
                        // logger.info("Using partition " + workerIndex);
                        if (host.getState() == MantisJobState.Started) {
                            Endpoint ep = new Endpoint(getWrappedHost(host.getHost(), host.getWorkerNumber()), host.getPort().get(0), // completed callback
                            () -> logger.info("job " + jobId + " WorkerIndex " + workerIndex + " completed"), // error callback
                            t1 -> logger.info("job " + jobId + " WorkerIndex " + workerIndex + " failed"));
                            endpoints.add(ep);
                        }
                    }
                }
            } else {
                logger.info("job " + jobId + " Has no active workers!");
            }
            return endpoints;
        }).doOnError((Throwable throwable) -> {
            logger.error(throwable.getMessage(), throwable);
        });
    });
    return (new ToDeltaEndpointInjector(schedulingUpdates)).deltas();
}
Also used : EndpointChange(io.reactivex.mantis.remote.observable.EndpointChange) CuratorService(io.mantisrx.server.core.zookeeper.CuratorService) MantisJobState(io.mantisrx.runtime.MantisJobState) MasterDescription(io.mantisrx.server.core.master.MasterDescription) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Action1(rx.functions.Action1) ArrayList(java.util.ArrayList) Observable(rx.Observable) MasterMonitor(io.mantisrx.server.core.master.MasterMonitor) Func1(rx.functions.Func1) Map(java.util.Map) ConfigurationFactory(io.mantisrx.server.master.client.config.ConfigurationFactory) WorkerEndpoint(io.mantisrx.common.network.WorkerEndpoint) Metrics(io.mantisrx.common.metrics.Metrics) NamedJobInfo(io.mantisrx.server.core.NamedJobInfo) Counter(io.mantisrx.common.metrics.Counter) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) StaticPropertiesConfigurationFactory(io.mantisrx.server.master.client.config.StaticPropertiesConfigurationFactory) Properties(java.util.Properties) Logger(org.slf4j.Logger) Endpoint(io.mantisrx.common.network.Endpoint) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) Observer(rx.Observer) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ToDeltaEndpointInjector(io.reactivex.mantis.remote.observable.ToDeltaEndpointInjector) Action0(rx.functions.Action0) CoreConfiguration(io.mantisrx.server.core.CoreConfiguration) BehaviorSubject(rx.subjects.BehaviorSubject) PublishSubject(rx.subjects.PublishSubject) WorkerHost(io.mantisrx.server.core.WorkerHost) WorkerHost(io.mantisrx.server.core.WorkerHost) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) ToDeltaEndpointInjector(io.reactivex.mantis.remote.observable.ToDeltaEndpointInjector) WorkerEndpoint(io.mantisrx.common.network.WorkerEndpoint) Endpoint(io.mantisrx.common.network.Endpoint) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with Endpoint

use of io.mantisrx.common.network.Endpoint in project mantis by Netflix.

the class DynamicConnectionSet method addConnection.

public void addConnection(String id, Endpoint toAdd) {
    try {
        activeConnectionsLock.lock();
        if (!currentActiveConnections.containsKey(id)) {
            currentActiveConnections.put(id, new Endpoint(toAdd.getHost(), toAdd.getPort(), toAdd.getSlotId(), toAdd.getCompletedCallback(), toAdd.getErrorCallback()));
            activeConnectionsGauge.increment();
            activeConnectionsSubject.onNext(new HashSet<Endpoint>(currentActiveConnections.values()));
        }
    } finally {
        activeConnectionsLock.unlock();
    }
}
Also used : Endpoint(io.mantisrx.common.network.Endpoint)

Aggregations

Endpoint (io.mantisrx.common.network.Endpoint)27 Test (org.junit.Test)16 Action0 (rx.functions.Action0)8 EndpointChange (io.reactivex.mantis.remote.observable.EndpointChange)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 Map (java.util.Map)6 Observable (rx.Observable)6 Set (java.util.Set)5 Action1 (rx.functions.Action1)5 Func1 (rx.functions.Func1)5 Context (io.mantisrx.runtime.Context)4 StageConfig (io.mantisrx.runtime.StageConfig)4 EndpointInjector (io.reactivex.mantis.remote.observable.EndpointInjector)4 RemoteRxServer (io.reactivex.mantis.remote.observable.RemoteRxServer)4 HashMap (java.util.HashMap)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4