use of io.mantisrx.server.core.master.MasterDescription in project mantis by Netflix.
the class JobRouteTest method setup.
@BeforeClass
public static void setup() throws Exception {
JobTestHelper.deleteAllFiles();
JobTestHelper.createDirsIfRequired();
final CountDownLatch latch = new CountDownLatch(1);
TestHelpers.setupMasterConfig();
t = new Thread(() -> {
try {
// boot up server using the route as defined below
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
// SimpleCachedFileStorageProvider simpleCachedFileStorageProvider = new SimpleCachedFileStorageProvider();
// new File("/tmp/MantisSpool/namedJobs").mkdirs();
// IMantisStorageProvider storageProvider = new MantisStorageProviderAdapter(simpleCachedFileStorageProvider);
final LifecycleEventPublisher lifecycleEventPublisher = new LifecycleEventPublisherImpl(new AuditEventSubscriberLoggingImpl(), new StatusEventSubscriberLoggingImpl(), new WorkerEventSubscriberLoggingImpl());
ActorRef jobClustersManagerActor = system.actorOf(JobClustersManagerActor.props(new MantisJobStore(new io.mantisrx.server.master.persistence.SimpleCachedFileStorageProvider(true)), lifecycleEventPublisher), "jobClustersManager");
MantisScheduler fakeScheduler = new FakeMantisScheduler(jobClustersManagerActor);
jobClustersManagerActor.tell(new JobClusterManagerProto.JobClustersManagerInitialize(fakeScheduler, false), ActorRef.noSender());
final JobClusterRouteHandler jobClusterRouteHandler = new JobClusterRouteHandlerAkkaImpl(jobClustersManagerActor);
final JobRouteHandler jobRouteHandler = new JobRouteHandlerAkkaImpl(jobClustersManagerActor);
MasterDescription masterDescription = new MasterDescription("127.0.0.1", "127.0.0.1", serverPort, serverPort, serverPort, "api/postjobstatus", serverPort, System.currentTimeMillis());
Duration idleTimeout = system.settings().config().getDuration("akka.http.server.idle-timeout");
logger.info("idle timeout {} sec ", idleTimeout.getSeconds());
final JobDiscoveryRouteHandler jobDiscoveryRouteHandler = new JobDiscoveryRouteHandlerAkkaImpl(jobClustersManagerActor, idleTimeout);
final MasterDescriptionRoute masterDescriptionRoute = new MasterDescriptionRoute(masterDescription);
final JobRoute v0JobRoute = new JobRoute(jobRouteHandler, system);
final JobDiscoveryRoute v0JobDiscoveryRoute = new JobDiscoveryRoute(jobDiscoveryRouteHandler);
final JobClusterRoute v0JobClusterRoute = new JobClusterRoute(jobClusterRouteHandler, jobRouteHandler, system);
final JobClustersRoute v1JobClusterRoute = new JobClustersRoute(jobClusterRouteHandler, system);
final JobsRoute v1JobsRoute = new JobsRoute(jobClusterRouteHandler, jobRouteHandler, system);
final AdminMasterRoute v1AdminMasterRoute = new AdminMasterRoute(masterDescription);
final JobStatusRouteHandler jobStatusRouteHandler = mock(JobStatusRouteHandler.class);
when(jobStatusRouteHandler.jobStatus(anyString())).thenReturn(Flow.create());
final JobStatusRoute v0JobStatusRoute = new JobStatusRoute(jobStatusRouteHandler);
final AgentClusterOperations mockAgentClusterOps = mock(AgentClusterOperations.class);
final AgentClusterRoute v0AgentClusterRoute = new AgentClusterRoute(mockAgentClusterOps, system);
final AgentClustersRoute v1AgentClusterRoute = new AgentClustersRoute(mockAgentClusterOps);
final JobDiscoveryStreamRoute v1JobDiscoveryStreamRoute = new JobDiscoveryStreamRoute(jobDiscoveryRouteHandler);
final LastSubmittedJobIdStreamRoute v1LastSubmittedJobIdStreamRoute = new LastSubmittedJobIdStreamRoute(jobDiscoveryRouteHandler);
final JobStatusStreamRoute v1JobStatusStreamRoute = new JobStatusStreamRoute(jobStatusRouteHandler);
LocalMasterMonitor localMasterMonitor = new LocalMasterMonitor(masterDescription);
LeadershipManagerLocalImpl leadershipMgr = new LeadershipManagerLocalImpl(masterDescription);
leadershipMgr.setLeaderReady();
LeaderRedirectionFilter leaderRedirectionFilter = new LeaderRedirectionFilter(localMasterMonitor, leadershipMgr);
final MantisMasterRoute app = new MantisMasterRoute(leaderRedirectionFilter, masterDescriptionRoute, v0JobClusterRoute, v0JobRoute, v0JobDiscoveryRoute, v0JobStatusRoute, v0AgentClusterRoute, v1JobClusterRoute, v1JobsRoute, v1AdminMasterRoute, v1AgentClusterRoute, v1JobDiscoveryStreamRoute, v1LastSubmittedJobIdStreamRoute, v1JobStatusStreamRoute);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute().flow(system, materializer);
logger.info("starting test server on port {}", serverPort);
binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", serverPort), materializer);
latch.countDown();
} catch (Exception e) {
logger.info("caught exception", e);
latch.countDown();
e.printStackTrace();
}
});
t.setDaemon(true);
t.start();
latch.await();
Thread.sleep(100);
}
use of io.mantisrx.server.core.master.MasterDescription in project mantis by Netflix.
the class MantisMasterAPI method main.
public static void main(String[] args) throws Exception {
// boot up server using the route as defined below
int port = 8182;
TestHelpers.setupMasterConfig();
ActorSystem system = ActorSystem.create("MantisMasterAPI");
final ActorRef actor = system.actorOf(Props.create(DeadLetterActor.class));
system.eventStream().subscribe(actor, DeadLetter.class);
final Http http = Http.get(system);
final ActorMaterializer materializer = ActorMaterializer.create(system);
final AuditEventSubscriber auditEventSubscriber = new AuditEventSubscriberLoggingImpl();
ActorRef auditEventBrokerActor = system.actorOf(AuditEventBrokerActor.props(auditEventSubscriber), "AuditEventBroker");
final AuditEventSubscriber auditEventSubscriberAkka = new AuditEventSubscriberAkkaImpl(auditEventBrokerActor);
final LifecycleEventPublisher lifecycleEventPublisher = new LifecycleEventPublisherImpl(auditEventSubscriberAkka, new StatusEventSubscriberLoggingImpl(), new WorkerEventSubscriberLoggingImpl());
IMantisStorageProvider storageProvider = new MantisStorageProviderAdapter(new SimpleCachedFileStorageProvider(), lifecycleEventPublisher);
ActorRef jobClustersManager = system.actorOf(JobClustersManagerActor.props(new MantisJobStore(storageProvider), lifecycleEventPublisher), "JobClustersManager");
final FakeMantisScheduler fakeScheduler = new FakeMantisScheduler(jobClustersManager);
jobClustersManager.tell(new JobClusterManagerProto.JobClustersManagerInitialize(fakeScheduler, true), ActorRef.noSender());
// Schedulers.newThread().createWorker().schedulePeriodically(() -> jobClustersManager.tell(new NullPointerException(), ActorRef.noSender()),0, 100, TimeUnit.SECONDS);
setupDummyAgentClusterAutoScaler();
final JobClusterRouteHandler jobClusterRouteHandler = new JobClusterRouteHandlerAkkaImpl(jobClustersManager);
final JobRouteHandler jobRouteHandler = new JobRouteHandlerAkkaImpl(jobClustersManager);
MasterDescription masterDescription = new MasterDescription("localhost", "127.0.0.1", port, port + 2, port + 4, "api/postjobstatus", port + 6, System.currentTimeMillis());
final MasterDescriptionRoute masterDescriptionRoute = new MasterDescriptionRoute(masterDescription);
Duration idleTimeout = system.settings().config().getDuration("akka.http.server.idle-timeout");
logger.info("idle timeout {} sec ", idleTimeout.getSeconds());
ActorRef agentsErrorMonitorActor = system.actorOf(AgentsErrorMonitorActor.props(), "AgentsErrorMonitor");
ActorRef statusEventBrokerActor = system.actorOf(StatusEventBrokerActor.props(agentsErrorMonitorActor), "StatusEventBroker");
agentsErrorMonitorActor.tell(new AgentsErrorMonitorActor.InitializeAgentsErrorMonitor(fakeScheduler), ActorRef.noSender());
final JobStatusRouteHandler jobStatusRouteHandler = new JobStatusRouteHandlerAkkaImpl(system, statusEventBrokerActor);
final AgentClusterOperationsImpl agentClusterOperations = new AgentClusterOperationsImpl(storageProvider, new JobMessageRouterImpl(jobClustersManager), fakeScheduler, lifecycleEventPublisher, "cluster");
final JobDiscoveryRouteHandler jobDiscoveryRouteHandler = new JobDiscoveryRouteHandlerAkkaImpl(jobClustersManager, idleTimeout);
final JobRoute v0JobRoute = new JobRoute(jobRouteHandler, system);
final JobDiscoveryRoute v0JobDiscoveryRoute = new JobDiscoveryRoute(jobDiscoveryRouteHandler);
final JobClusterRoute v0JobClusterRoute = new JobClusterRoute(jobClusterRouteHandler, jobRouteHandler, system);
final JobStatusRoute v0JobStatusRoute = new JobStatusRoute(jobStatusRouteHandler);
final AgentClusterRoute v0AgentClusterRoute = new AgentClusterRoute(agentClusterOperations, system);
final JobClustersRoute v1JobClustersRoute = new JobClustersRoute(jobClusterRouteHandler, system);
final JobsRoute v1JobsRoute = new JobsRoute(jobClusterRouteHandler, jobRouteHandler, system);
final AdminMasterRoute v1AdminMasterRoute = new AdminMasterRoute(masterDescription);
final AgentClustersRoute v1AgentClustersRoute = new AgentClustersRoute(agentClusterOperations);
final JobDiscoveryStreamRoute v1JobDiscoveryStreamRoute = new JobDiscoveryStreamRoute(jobDiscoveryRouteHandler);
final LastSubmittedJobIdStreamRoute v1LastSubmittedJobIdStreamRoute = new LastSubmittedJobIdStreamRoute(jobDiscoveryRouteHandler);
final JobStatusStreamRoute v1JobStatusStreamRoute = new JobStatusStreamRoute(jobStatusRouteHandler);
LocalMasterMonitor localMasterMonitor = new LocalMasterMonitor(masterDescription);
LeadershipManagerLocalImpl leadershipMgr = new LeadershipManagerLocalImpl(masterDescription);
leadershipMgr.setLeaderReady();
LeaderRedirectionFilter leaderRedirectionFilter = new LeaderRedirectionFilter(localMasterMonitor, leadershipMgr);
final MantisMasterRoute app = new MantisMasterRoute(leaderRedirectionFilter, masterDescriptionRoute, v0JobClusterRoute, v0JobRoute, v0JobDiscoveryRoute, v0JobStatusRoute, v0AgentClusterRoute, v1JobClustersRoute, v1JobsRoute, v1AdminMasterRoute, v1AgentClustersRoute, v1JobDiscoveryStreamRoute, v1LastSubmittedJobIdStreamRoute, v1JobStatusStreamRoute);
final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute().flow(system, materializer);
final CompletionStage<ServerBinding> binding = http.bindAndHandle(routeFlow, ConnectHttp.toHost("localhost", port), materializer);
binding.exceptionally(failure -> {
System.err.println("Something very bad happened! " + failure.getMessage());
system.terminate();
return null;
});
// Schedulers.newThread().createWorker().schedule(() -> leadershipMgr.stopBeingLeader(), 10, TimeUnit.SECONDS);
System.out.println("Server online at http://localhost:" + port + "/\nPress RETURN to stop...");
// let it run until user presses return
System.in.read();
binding.thenCompose(// trigger unbinding from the port
ServerBinding::unbind).thenAccept(// and shutdown when done
unbound -> system.terminate());
}
use of io.mantisrx.server.core.master.MasterDescription in project mantis by Netflix.
the class TestGetMasterMonitor method main.
public static void main(String[] args) {
try {
Args.parse(TestGetMasterMonitor.class, args);
} catch (IllegalArgumentException e) {
Args.usage(TestGetMasterMonitor.class);
System.exit(1);
}
Properties properties = new Properties();
System.out.println("propfile=" + propFile);
try (InputStream inputStream = new FileInputStream(propFile)) {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
final AtomicInteger counter = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(5);
StaticPropertiesConfigurationFactory configurationFactory = new StaticPropertiesConfigurationFactory(properties);
CoreConfiguration config = configurationFactory.getConfig();
final CuratorService curatorService = new CuratorService(config, null);
MasterMonitor masterMonitor = curatorService.getMasterMonitor();
masterMonitor.getMasterObservable().filter(new Func1<MasterDescription, Boolean>() {
@Override
public Boolean call(MasterDescription masterDescription) {
return masterDescription != null;
}
}).doOnNext(new Action1<MasterDescription>() {
@Override
public void call(MasterDescription masterDescription) {
System.out.println(counter.incrementAndGet() + ": Got new master: " + masterDescription.toString());
latch.countDown();
}
}).subscribe();
curatorService.start();
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of io.mantisrx.server.core.master.MasterDescription in project mantis by Netflix.
the class MantisMasterClientApiTest method testScaleStageRequestRetries.
// @Test
// @Ignore
// public void testNamedJobCreate() throws InterruptedException {
//
// MasterMonitor mockMasterMonitor = mock(MasterMonitor.class);
// final BehaviorSubject<MasterDescription> mdSubject = BehaviorSubject.create();
// when(mockMasterMonitor.getMasterObservable()).thenReturn(mdSubject);
//
// MantisMasterClientApi mantisMasterClientApi = new MantisMasterClientApi(mockMasterMonitor);
//
// final int serverPort = 8182;
// final String jobName = "TestCreateJobCluster";
// mdSubject.onNext(new MasterDescription("localhost", "127.0.0.1", serverPort, 7090, 7091, "status", 8900, System.currentTimeMillis()));
//
// JobDefinition jobDefinition = JobDefinition.newBuilder()
// .setName(jobName)
// .setVersion("0.0.1")
// .setUrl("http://www.example.com")
// .setJobSla(io.mantisrx.master.core.proto.JobSla.newBuilder()
// .setUserProvidedType("")
// .setDurationType(io.mantisrx.master.core.proto.JobSla.MantisJobDurationType.Transient)
// .setSlaType(io.mantisrx.master.core.proto.JobSla.StreamSLAType.Lossy)
// .setMinRuntimeSecs(0)
// .setRuntimeLimitSecs(0))
// .setSchedulingInfo(io.mantisrx.master.core.proto.SchedulingInfo.newBuilder()
// .putStages(1, io.mantisrx.master.core.proto.SchedulingInfo.StageSchedulingInfo.newBuilder()
// .setNumberOfInstances(1)
// .setMachineDefinition(MachineDefinition.newBuilder()
// .setCpuCores(2)
// .setDiskMB(1024)
// .setMemoryMB(2048)
// .setNetworkMbps(64)
// .setNumPorts(1)
// .build())
// .build())
// .build())
// .build();
// io.mantisrx.master.core.proto.JobOwner owner = io.mantisrx.master.core.proto.JobOwner.newBuilder()
// .setName("Test")
// .setContactEmail("test@netflix.com")
// .setDescription("")
// .setRepo("http://www.example.com")
// .build();
// CreateJobClusterRequest req = CreateJobClusterRequest.newBuilder()
// .setJobDefinition(jobDefinition)
// .setOwner(owner)
// .build();
//
// Observable<Void> testCluster = mantisMasterClientApi.createNamedJob(req);
// final CountDownLatch latch = new CountDownLatch(1);
//
// testCluster.subscribe((x) -> {
// latch.countDown();
// System.out.println("job cluster create response complete");
// });
//
// latch.await();
//
// Observable<JobSubmitResponse> jobSubmitResponseObs = mantisMasterClientApi.submitJob(jobDefinition);
// final CountDownLatch latch2 = new CountDownLatch(1);
//
// jobSubmitResponseObs.subscribe((x) -> {
// latch2.countDown();
// System.out.println("job submit complete");
// });
//
// latch2.await();
// }
@Test
public void testScaleStageRequestRetries() throws InterruptedException {
MasterMonitor mockMasterMonitor = mock(MasterMonitor.class);
final BehaviorSubject<MasterDescription> mdSubject = BehaviorSubject.create();
when(mockMasterMonitor.getMasterObservable()).thenReturn(mdSubject);
MantisMasterClientApi mantisMasterClientApi = new MantisMasterClientApi(mockMasterMonitor);
final int serverPort = port.incrementAndGet();
final String jobId = "test-job-id";
final int stageNum = 1;
final int numWorkers = 2;
final String reason = "test reason";
mdSubject.onNext(new MasterDescription("localhost", "127.0.0.1", serverPort, 7090, 7091, "status", 8900, System.currentTimeMillis()));
final CountDownLatch retryLatch = new CountDownLatch(2);
final Func1<Observable<? extends Throwable>, Observable<?>> retryLogic = new Func1<Observable<? extends Throwable>, Observable<?>>() {
@Override
public Observable<?> call(Observable<? extends Throwable> attempts) {
return attempts.zipWith(Observable.range(1, 5), new Func2<Throwable, Integer, Integer>() {
@Override
public Integer call(Throwable t1, Integer integer) {
return integer;
}
}).flatMap(new Func1<Integer, Observable<?>>() {
@Override
public Observable<?> call(Integer retryCount) {
logger.info(retryCount + " retrying conx after sleeping for 250ms");
if (retryCount == 2) {
Schedulers.newThread().createWorker().schedule(new Action0() {
@Override
public void call() {
final HttpServer<String, String> httpServer = createHttpServer(serverPort);
startedServers.add(httpServer);
httpServer.start();
}
});
}
retryLatch.countDown();
return Observable.timer(250, TimeUnit.MILLISECONDS);
}
});
}
};
final Observable<Boolean> resultObs = mantisMasterClientApi.scaleJobStage(jobId, stageNum, numWorkers, reason).retryWhen(retryLogic);
final CountDownLatch completedLatch = new CountDownLatch(1);
resultObs.doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
fail("got unexpected error" + throwable.getMessage());
}
}).doOnCompleted(new Action0() {
@Override
public void call() {
completedLatch.countDown();
}
}).subscribe();
assertTrue(retryLatch.await(5, TimeUnit.SECONDS));
assertTrue(completedLatch.await(5, TimeUnit.SECONDS));
}
use of io.mantisrx.server.core.master.MasterDescription in project mantis by Netflix.
the class MantisMasterClientApiTest method testScaleStageRequestRetriesNewMaster.
@Test
public void testScaleStageRequestRetriesNewMaster() throws InterruptedException {
MasterMonitor mockMasterMonitor = mock(MasterMonitor.class);
final BehaviorSubject<MasterDescription> mdSubject = BehaviorSubject.create();
when(mockMasterMonitor.getMasterObservable()).thenReturn(mdSubject);
MantisMasterClientApi mantisMasterClientApi = new MantisMasterClientApi(mockMasterMonitor);
final int oldMasterPort = port.incrementAndGet();
final int newMasterPort = port.incrementAndGet();
final String jobId = "test-job-id";
final int stageNum = 1;
final int numWorkers = 2;
final String reason = "test reason";
mdSubject.onNext(new MasterDescription("localhost", "127.0.0.1", oldMasterPort, 7090, 7091, "status", 8900, System.currentTimeMillis()));
final CountDownLatch retryLatch = new CountDownLatch(3);
final Func1<Observable<? extends Throwable>, Observable<?>> retryLogic = new Func1<Observable<? extends Throwable>, Observable<?>>() {
@Override
public Observable<?> call(Observable<? extends Throwable> attempts) {
return attempts.zipWith(Observable.range(1, 5), new Func2<Throwable, Integer, Integer>() {
@Override
public Integer call(Throwable t1, Integer integer) {
return integer;
}
}).flatMap(new Func1<Integer, Observable<?>>() {
@Override
public Observable<?> call(Integer retryCount) {
logger.info(retryCount + " retrying conx after sleeping for 250ms");
if (retryCount == 2) {
Schedulers.newThread().createWorker().schedule(new Action0() {
@Override
public void call() {
final HttpServer<String, String> httpServer = createHttpServer(newMasterPort);
startedServers.add(httpServer);
httpServer.start();
}
});
}
if (retryCount == 3) {
mdSubject.onNext(new MasterDescription("localhost", "127.0.0.1", newMasterPort, 7090, 7091, "status", 8900, System.currentTimeMillis()));
}
retryLatch.countDown();
return Observable.timer(250, TimeUnit.MILLISECONDS);
}
});
}
};
final Observable<Boolean> resultObs = mantisMasterClientApi.scaleJobStage(jobId, stageNum, numWorkers, reason).retryWhen(retryLogic);
final CountDownLatch completedLatch = new CountDownLatch(1);
resultObs.doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
fail("got unexpected error" + throwable.getMessage());
}
}).doOnCompleted(new Action0() {
@Override
public void call() {
completedLatch.countDown();
}
}).subscribe();
assertTrue(retryLatch.await(5, TimeUnit.SECONDS));
assertTrue(completedLatch.await(5, TimeUnit.SECONDS));
}
Aggregations