Search in sources :

Example 1 with Endpoint

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

the class ConsistentHashTest method emptyNodeThrowsTest.

@Test
public void emptyNodeThrowsTest() {
    List<Endpoint> nodes = new ArrayList<Endpoint>();
    try {
        ConsistentHash<Endpoint> ch = new ConsistentHash<Endpoint>(HashFunctions.ketama(), new EndpointConfiguration(), nodes);
        fail();
    } catch (Exception e) {
    }
}
Also used : ConsistentHash(io.mantisrx.common.network.ConsistentHash) Endpoint(io.mantisrx.common.network.Endpoint) ArrayList(java.util.ArrayList) EndpointConfiguration(io.mantisrx.common.network.EndpointConfiguration) Test(org.junit.Test)

Example 2 with Endpoint

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

the class ConsistentHashTest method oneNodeTest.

@Test
public void oneNodeTest() {
    Endpoint n1 = new Endpoint("host1", 7001);
    List<Endpoint> nodes = new ArrayList<Endpoint>();
    nodes.add(n1);
    ConsistentHash<Endpoint> ch = new ConsistentHash<Endpoint>(HashFunctions.ketama(), new EndpointConfiguration(), nodes);
    int hostHitCountNode1 = 0;
    int nonHitCount = 0;
    int MSG_COUNT = 100000;
    for (int i = 0; i < MSG_COUNT; i++) {
        Endpoint sn = ch.get(("msg:" + i).getBytes());
        if (sn.getHost().equals("host1")) {
            hostHitCountNode1++;
        } else {
            nonHitCount++;
        }
    }
    assertTrue(nonHitCount == 0);
    assertEquals(MSG_COUNT, hostHitCountNode1);
}
Also used : ConsistentHash(io.mantisrx.common.network.ConsistentHash) Endpoint(io.mantisrx.common.network.Endpoint) ArrayList(java.util.ArrayList) EndpointConfiguration(io.mantisrx.common.network.EndpointConfiguration) Endpoint(io.mantisrx.common.network.Endpoint) Test(org.junit.Test)

Example 3 with Endpoint

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

the class MasterClientWrapper method getAllNonJobMasterEndpoints.

private List<Endpoint> getAllNonJobMasterEndpoints(final String jobId, final Map<Integer, WorkerAssignments> workerAssignments) {
    List<Endpoint> endpoints = new ArrayList<>();
    int totalWorkers = 0;
    for (Map.Entry<Integer, WorkerAssignments> workerAssignment : workerAssignments.entrySet()) {
        final Integer stageNum = workerAssignment.getKey();
        // skip workers for stage 0
        if (stageNum == 0) {
            continue;
        }
        final WorkerAssignments assignments = workerAssignment.getValue();
        logger.info("job {} Creating endpoints conx from {} worker assignments for stage {}", jobId, assignments.getHosts().size(), stageNum);
        if (logger.isDebugEnabled()) {
            logger.debug("stage {} hosts: {}", stageNum, assignments.getHosts());
        }
        totalWorkers += assignments.getNumWorkers();
        for (WorkerHost host : assignments.getHosts().values()) {
            final int workerIndex = host.getWorkerIndex();
            if (host.getState() == MantisJobState.Started) {
                logger.info("job " + jobId + ": creating new endpoint for worker number=" + host.getWorkerNumber() + ", index=" + host.getWorkerIndex() + ", host:port=" + host.getHost() + ":" + host.getPort().get(0));
                Endpoint ep = new WorkerEndpoint(getWrappedHost(host.getHost(), host.getWorkerNumber()), host.getPort().get(0), stageNum, host.getMetricsPort(), host.getWorkerIndex(), host.getWorkerNumber(), // completed callback
                new Action0() {

                    @Override
                    public void call() {
                        logger.info("job " + jobId + " WorkerIndex " + workerIndex + " completed");
                    }
                }, // error callback
                new Action1<Throwable>() {

                    @Override
                    public void call(Throwable t1) {
                        logger.info("job " + jobId + " WorkerIndex " + workerIndex + " failed");
                    }
                });
                endpoints.add(ep);
            }
        }
    }
    numWorkersSubject.onNext(new JobNumWorkers(jobId, totalWorkers));
    return endpoints;
}
Also used : WorkerHost(io.mantisrx.server.core.WorkerHost) Action0(rx.functions.Action0) WorkerEndpoint(io.mantisrx.common.network.WorkerEndpoint) ArrayList(java.util.ArrayList) WorkerEndpoint(io.mantisrx.common.network.WorkerEndpoint) Endpoint(io.mantisrx.common.network.Endpoint) WorkerEndpoint(io.mantisrx.common.network.WorkerEndpoint) Endpoint(io.mantisrx.common.network.Endpoint) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) Map(java.util.Map)

Example 4 with Endpoint

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

the class WorkerExecutionOperationsNetworkStage method connectToObservableAtPreviousStages.

@SuppressWarnings({ "rawtypes" })
private WorkerConsumer connectToObservableAtPreviousStages(Observable<JobSchedulingInfo> selfSchedulingInfo, final String jobId, final int previousStageNum, int numInstanceAtPreviousStage, final StageConfig previousStage, final AtomicBoolean acceptSchedulingChanges, final Observer<Status> jobStatus, final int stageNumToExecute, final int workerIndex, final int workerNumber) {
    logger.info("Watching for scheduling changes");
    // Observable<List<Endpoint>> schedulingUpdates = mantisMasterApi.schedulingChanges(jobId)
    Observable<List<Endpoint>> schedulingUpdates = selfSchedulingInfo.flatMap((Func1<JobSchedulingInfo, Observable<WorkerAssignments>>) schedulingChange -> {
        Map<Integer, WorkerAssignments> assignments = schedulingChange.getWorkerAssignments();
        if (assignments != null && !assignments.isEmpty()) {
            return Observable.from(assignments.values());
        } else {
            return Observable.empty();
        }
    }).filter(assignments -> (assignments.getStage() == previousStageNum) && acceptSchedulingChanges.get()).map(assignments -> {
        List<Endpoint> endpoints = new LinkedList<>();
        for (WorkerHost host : assignments.getHosts().values()) {
            if (host.getState() == MantisJobState.Started) {
                logger.info("Received scheduling update from master, connect request for host: " + host.getHost() + " port: " + host.getPort() + " state: " + host.getState() + " adding: " + connectionsPerEndpoint + " connections to host");
                for (int i = 1; i <= connectionsPerEndpoint; i++) {
                    final String endpointId = "stage_" + stageNumToExecute + "_index_" + Integer.toString(workerIndex) + "_partition_" + i;
                    logger.info("Adding endpoint to endpoint injector to be considered for add, with id: " + endpointId);
                    endpoints.add(new Endpoint(host.getHost(), host.getPort().get(0), endpointId));
                }
            }
        }
        return endpoints;
    }).filter(t1 -> (t1.size() > 0));
    String name = jobId + "_" + previousStageNum;
    return new WorkerConsumerRemoteObservable(name, new ToDeltaEndpointInjector(schedulingUpdates));
}
Also used : Strings(io.mantisrx.shaded.com.google.common.base.Strings) Arrays(java.util.Arrays) MantisJobDurationType(io.mantisrx.runtime.MantisJobDurationType) MantisJobState(io.mantisrx.runtime.MantisJobState) LoggerFactory(org.slf4j.LoggerFactory) StageSchedulingInfo(io.mantisrx.runtime.descriptor.StageSchedulingInfo) JobMasterStageConfig(io.mantisrx.server.worker.jobmaster.JobMasterStageConfig) Lifecycle(io.mantisrx.runtime.lifecycle.Lifecycle) WorkerConsumer(io.mantisrx.runtime.executor.WorkerConsumer) ServiceRegistry(io.mantisrx.server.core.ServiceRegistry) JOB_MASTER_AUTOSCALE_METRIC_SYSTEM_PARAM(io.mantisrx.runtime.parameter.ParameterUtils.JOB_MASTER_AUTOSCALE_METRIC_SYSTEM_PARAM) WorkerPorts(io.mantisrx.common.WorkerPorts) ParameterUtils(io.mantisrx.runtime.parameter.ParameterUtils) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) VirtualMachineTaskStatus(io.mantisrx.server.worker.mesos.VirtualMachineTaskStatus) RxMetrics(io.reactivex.mantis.remote.observable.RxMetrics) Status(io.mantisrx.server.core.Status) StageExecutors(io.mantisrx.runtime.executor.StageExecutors) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) Observer(rx.Observer) Collectors(java.util.stream.Collectors) JobMasterService(io.mantisrx.server.worker.jobmaster.JobMasterService) WorkerConsumerRemoteObservable(io.mantisrx.runtime.executor.WorkerConsumerRemoteObservable) CountDownLatch(java.util.concurrent.CountDownLatch) WorkerId(io.mantisrx.server.core.domain.WorkerId) List(java.util.List) ToDeltaEndpointInjector(io.reactivex.mantis.remote.observable.ToDeltaEndpointInjector) Action0(rx.functions.Action0) BehaviorSubject(rx.subjects.BehaviorSubject) Splitter(io.mantisrx.shaded.com.google.common.base.Splitter) Optional(java.util.Optional) WorkerMap(io.mantisrx.runtime.WorkerMap) PortSelector(io.mantisrx.runtime.executor.PortSelector) WorkerPublisherRemoteObservable(io.mantisrx.runtime.executor.WorkerPublisherRemoteObservable) StageConfig(io.mantisrx.runtime.StageConfig) MantisMasterClientApi(io.mantisrx.server.master.client.MantisMasterClientApi) MetricsRegistry(io.mantisrx.common.metrics.MetricsRegistry) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Parameters(io.mantisrx.runtime.parameter.Parameters) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Observable(rx.Observable) Func1(rx.functions.Func1) WorkerMetricsClient(io.mantisrx.server.worker.client.WorkerMetricsClient) LinkedList(java.util.LinkedList) RemoteRxServer(io.reactivex.mantis.remote.observable.RemoteRxServer) AutoScaleMetricsConfig(io.mantisrx.server.worker.jobmaster.AutoScaleMetricsConfig) JobSchedulingInfo(io.mantisrx.server.core.JobSchedulingInfo) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Endpoint(io.mantisrx.common.network.Endpoint) TYPE(io.mantisrx.server.core.Status.TYPE) Context(io.mantisrx.runtime.Context) StatusPayloads(io.mantisrx.server.core.StatusPayloads) TimeUnit(java.util.concurrent.TimeUnit) ServiceLocator(io.mantisrx.runtime.lifecycle.ServiceLocator) ExecuteStageRequest(io.mantisrx.server.core.ExecuteStageRequest) Registry(com.netflix.spectator.api.Registry) WorkerConfiguration(io.mantisrx.server.worker.config.WorkerConfiguration) SpectatorRegistryFactory(io.mantisrx.common.metrics.spectator.SpectatorRegistryFactory) WorkerInfo(io.mantisrx.runtime.WorkerInfo) WorkerHost(io.mantisrx.server.core.WorkerHost) WorkerHost(io.mantisrx.server.core.WorkerHost) ToDeltaEndpointInjector(io.reactivex.mantis.remote.observable.ToDeltaEndpointInjector) Endpoint(io.mantisrx.common.network.Endpoint) WorkerAssignments(io.mantisrx.server.core.WorkerAssignments) WorkerConsumerRemoteObservable(io.mantisrx.runtime.executor.WorkerConsumerRemoteObservable) List(java.util.List) LinkedList(java.util.LinkedList) Func1(rx.functions.Func1)

Example 5 with Endpoint

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

the class LocalJobExecutorNetworked method startIntermediate.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static void startIntermediate(int[] previousStagePorts, int port, StageConfig stage, Context context, int workerIndex, int workersAtNextStage, int stageNumber, int workersAtPreviousStage) {
    if (logger.isDebugEnabled()) {
        StringBuilder portsToString = new StringBuilder();
        for (int previousPort : previousStagePorts) {
            portsToString.append(previousPort + " ");
        }
        logger.debug("Creating intermediate consumer connecting to publishers on ports " + portsToString);
    }
    Observable<Set<Endpoint>> endpoints = staticEndpoints(previousStagePorts, stageNumber, workerIndex, numPartitions);
    WorkerConsumerRemoteObservable intermediateConsumer = new // name=null local
    WorkerConsumerRemoteObservable(// name=null local
    null, staticInjector(endpoints));
    logger.debug("Creating intermediate publisher on port " + port);
    WorkerPublisherRemoteObservable intermediatePublisher = new WorkerPublisherRemoteObservable<>(port, null, Observable.just(workersAtNextStage * numPartitions), // name is null for local
    null);
    StageExecutors.executeIntermediate(intermediateConsumer, stage, intermediatePublisher, context);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) 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