@Override public WorkerManager getWorkerManager(String workerName) { return new RemoteWorkerManager(application.worker(workerName), clientConfig, restClient, this); }
/** * Returns number of instances of a worker. */ @GET @Path("/apps/{app-id}/workers/{worker-id}/instances") public void getWorkerInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("worker-id") String workerId) throws Exception { try { ProgramId workderId = validateAndGetNamespace(namespaceId).app(appId).worker(workerId); if (!lifecycleService.programExists(workderId)) { throw new NotFoundException(workderId); } int count = store.getWorkerInstances(workderId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(new Instances(count))); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (Throwable e) { if (respondIfElementNotFound(e, responder)) { return; } throw e; } }
/** * Returns number of instances of a worker. */ @GET @Path("/apps/{app-id}/workers/{worker-id}/instances") public void getWorkerInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("worker-id") String workerId) throws Exception { try { ProgramId workderId = validateAndGetNamespace(namespaceId).app(appId).worker(workerId); if (!lifecycleService.programExists(workderId)) { throw new NotFoundException(workderId); } int count = store.getWorkerInstances(workderId); responder.sendJson(HttpResponseStatus.OK, GSON.toJson(new Instances(count))); } catch (SecurityException e) { responder.sendStatus(HttpResponseStatus.UNAUTHORIZED); } catch (Throwable e) { if (respondIfElementNotFound(e, responder)) { return; } throw e; } }
@Override public ProgramId getId() { return new ApplicationId(NamespaceId.DEFAULT.getNamespace(), "dummyApp").worker("dummy"); }
private void testContainingTrigger(ProtoTrigger proto, Trigger trigger) { ProgramSchedule proto1 = new ProgramSchedule("sched1", "one partition schedule", new NamespaceId("test").app("a").worker("ww"), ImmutableMap.of("prop3", "abc"), proto, ImmutableList.of()); ProgramSchedule sched1 = new ProgramSchedule("sched1", "one partition schedule", new NamespaceId("test").app("a").worker("ww"), ImmutableMap.of("prop3", "abc"), trigger, ImmutableList.of()); Assert.assertEquals(sched1, GSON.fromJson(GSON.toJson(proto1), ProgramSchedule.class)); } }
@Override @SuppressWarnings("deprecation") public void perform(Arguments arguments, PrintStream output) throws Exception { String[] programIdParts = arguments.get(elementType.getArgumentName().toString()).split("\\."); ApplicationId appId = cliConfig.getCurrentNamespace().app(programIdParts[0]); int instances; switch (elementType) { case WORKER: if (programIdParts.length < 2) { throw new CommandInputError(this); } String workerId = programIdParts[1]; ProgramId worker = appId.worker(workerId); instances = programClient.getWorkerInstances(worker); break; case SERVICE: if (programIdParts.length < 2) { throw new CommandInputError(this); } String serviceName = programIdParts[1]; instances = programClient.getServiceInstances(appId.service(serviceName)); break; default: // TODO: remove this throw new IllegalArgumentException("Unrecognized program element type for scaling: " + elementType); } output.println(instances); }
ProgramId workerId = appId.worker(workerName); programClient.setWorkerInstances(workerId, numInstances); output.printf("Successfully set worker '%s' of app '%s' to %d instances\n",
ProgramId worker = appId.worker(workerId); instances = programClient.getWorkerInstances(worker); break;
ProgramId workerId = appId.worker(workerName); programClient.setWorkerInstances(workerId, numInstances); output.printf("Successfully set worker '%s' of app '%s' to %d instances\n",
@Test public void testWorkerInstances() { ApplicationSpecification spec = Specifications.from(new AppWithWorker()); ApplicationId appId = NamespaceId.DEFAULT.app(spec.getName()); store.addApplication(appId, spec); ProgramId programId = appId.worker(AppWithWorker.WORKER); int instancesFromSpec = spec.getWorkers().get(AppWithWorker.WORKER).getInstances(); Assert.assertEquals(1, instancesFromSpec); int instances = store.getWorkerInstances(programId); Assert.assertEquals(instancesFromSpec, instances); store.setWorkerInstances(programId, 9); instances = store.getWorkerInstances(programId); Assert.assertEquals(9, instances); }
@Test public void testGetProgramProfile() { ProfileId profileId = NamespaceId.DEFAULT.profile("p"); Map<String, String> args = Collections.singletonMap(SystemArguments.PROFILE_NAME, profileId.getScopedName()); ApplicationId appId = NamespaceId.DEFAULT.app("a"); ProgramId mrId = appId.mr("mr"); ProgramId serviceId = appId.service("serv"); ProgramId sparkId = appId.spark("spark"); ProgramId workerId = appId.worker("worker"); ProgramId workflowID = appId.workflow("wf"); Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(mrId, args)); Assert.assertEquals(ProfileId.NATIVE, SystemArguments.getProfileIdForProgram(serviceId, args)); Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(sparkId, args)); Assert.assertEquals(ProfileId.NATIVE, SystemArguments.getProfileIdForProgram(workerId, args)); Assert.assertEquals(profileId, SystemArguments.getProfileIdForProgram(workflowID, args)); }
ProgramId worker = appId.worker(AppWithProgramsUsingGuava.NoOpWorker.NAME); startProgram(Id.Program.fromEntityId(worker)); waitForRuns(1, worker, ProgramRunStatus.FAILED);
NamespaceId nsId = new NamespaceId("ns"); MetadataEntity service = nsId.app("app").service("service").toMetadataEntity(); MetadataEntity worker = nsId.app("app2").worker("worker").toMetadataEntity(); MetadataEntity dataset = nsId.dataset("dataset").toMetadataEntity();
final ProgramId program2 = NamespaceId.DEFAULT.app("app2").worker("worker2"); final ProgramId program3 = NamespaceId.DEFAULT.app("app3").service("service3");
final MetadataEntity program = appId.worker("wk1").toMetadataEntity(); final MetadataEntity dataset = nsId.dataset("ds2").toMetadataEntity();
@Test public void testUpdateSearch() throws IOException { MetadataStorage mds = getMetadataStorage(); final String ns = "ns"; final MetadataEntity program = new NamespaceId(ns).app("app1").worker("wk1").toMetadataEntity(); Metadata meta = new Metadata(USER, tags("tag1", "tag2"), props("key1", "value1", "key2", "value2")); MetadataRecord programRecord = new MetadataRecord(program, meta); mds.apply(new Update(program, meta)); assertResults(mds, SearchRequest.of("value1").addNamespace(ns).build(), programRecord); assertResults(mds, SearchRequest.of("value2").addNamespace(ns).build(), programRecord); assertResults(mds, SearchRequest.of("tag2").addNamespace(ns).build(), programRecord); mds.apply(new Update(program, new Metadata(USER, props("key1", "value3")))); mds.apply(new Remove(program, ImmutableSet.of(new ScopedNameOfKind(PROPERTY, USER, "key2"), new ScopedNameOfKind(TAG, USER, "tag2")))); programRecord = new MetadataRecord(program, new Metadata(USER, tags("tag1"), props("key1", "value3"))); // Searching for value1 should be empty assertEmpty(mds, SearchRequest.of("value1").addNamespace(ns).build()); // Instead key1 has value value3 now assertResults(mds, SearchRequest.of("value3").addNamespace(ns).build(), programRecord); // key2 and tag2 were deleted assertEmpty(mds, SearchRequest.of("value2").addNamespace(ns).build()); assertEmpty(mds, SearchRequest.of("tag2").addNamespace(ns).build()); // tag1 is still here assertResults(mds, SearchRequest.of("tag1").addNamespace(ns).build(), programRecord); // clean up mds.apply(new Drop(program)); }
final MetadataEntity program = appId.worker("wk1").toMetadataEntity(); final MetadataEntity dataset = nsId.dataset("ds2").toMetadataEntity();
final NamespaceId ns2Id = new NamespaceId(ns2); final ApplicationId appId = ns1Id.app("app1"); final MetadataEntity program = appId.worker("wk1").toMetadataEntity();
NamespaceId nsId = new NamespaceId(ns); MetadataEntity service = nsId.app("app").service("service").toMetadataEntity(); MetadataEntity worker = nsId.app("app2").worker("worker").toMetadataEntity(); MetadataEntity dataset = nsId.dataset("dataset").toMetadataEntity(); MetadataEntity hidden = nsId.dataset("_auditLog").toMetadataEntity();
final ApplicationId app1Id = ns1Id.app("app"); final MetadataEntity app = app1Id.toMetadataEntity(); final MetadataEntity program = app1Id.worker(programName).toMetadataEntity(); final MetadataEntity dataset = ns1Id.dataset("ds").toMetadataEntity();