private boolean programExists(ProgramId id, ApplicationSpecification appSpec) { switch (id.getType()) { case MAPREDUCE: return appSpec.getMapReduce().containsKey(id.getProgram()); case SERVICE: return appSpec.getServices().containsKey(id.getProgram()); case SPARK: return appSpec.getSpark().containsKey(id.getProgram()); case WORKER: return appSpec.getWorkers().containsKey(id.getProgram()); case WORKFLOW: return appSpec.getWorkflows().containsKey(id.getProgram()); default: throw new IllegalArgumentException("Unexpected ProgramType " + id.getType()); } }
private static WorkerSpecification getWorkerSpecOrFail(ProgramId id, ApplicationSpecification appSpec) { WorkerSpecification workerSpecification = appSpec.getWorkers().get(id.getProgram()); if (workerSpecification == null) { throw new NoSuchElementException("no such worker @ namespace id: " + id.getNamespaceId() + ", app id: " + id.getApplication() + ", worker id: " + id.getProgram()); } return workerSpecification; }
@Override public void setInstances(int instances) { Preconditions.checkArgument(instances > 0, "Instance count should be > 0."); try { appFabricClient.setServiceInstances(programId.getNamespace(), programId.getApplication(), programId.getProgram(), instances); } catch (Exception e) { throw Throwables.propagate(e); } }
private static Map<String, String> getMetricsContext(ProgramType type, ProgramId programId) { return ImmutableMap.of(Constants.Metrics.Tag.NAMESPACE, programId.getNamespace(), Constants.Metrics.Tag.APP, programId.getApplication(), ProgramTypeMetricTag.getTagName(type), programId.getProgram()); }
private ServiceInstances getInstances() { try { return appFabricClient.getServiceInstances(programId.getNamespace(), programId.getApplication(), programId.getProgram()); } catch (Exception e) { throw Throwables.propagate(e); } }
/** * Returns the Twill app name to be used for a Twill app launched for a given program. */ public static String toTwillAppName(ProgramId programId) { return String.format("%s.%s.%s.%s", programId.getType().name().toLowerCase(), programId.getNamespace(), programId.getApplication(), programId.getProgram()); }
public ProgramLiveInfo(ProgramId programId, String runtime) { this.app = programId.getApplication(); this.type = programId.getType().getPrettyName(); this.name = programId.getProgram(); this.runtime = runtime; }
@Override public int getFlowletInstances(String flowletName) { try { return appFabricClient.getFlowletInstances(programId.getNamespace(), programId.getApplication(), programId.getProgram(), flowletName).getInstances(); } catch (Exception e) { throw Throwables.propagate(e); } }
private boolean isInState(ProgramId programId, ProgramStatus status) { try { String actual = appFabricClient.getStatus(application.getNamespace(), programId.getApplication(), programId.getVersion(), programId.getProgram(), programId.getType()); return status.name().equals(actual); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void startProgram(ProgramId programId, Map<String, String> arguments) { try { appFabricClient.startProgram(application.getNamespace(), application.getApplication(), application.getVersion(), programId.getProgram(), programId.getType(), arguments); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { ProgramId programId = parseProgramId(arguments, elementType); String appName = programId.getApplication(); String appVersion = programId.getVersion(); String programName = programId.getProgram(); programClient.stop(programId); output.printf("Successfully stopped %s '%s' of application '%s.%s'\n", elementType.getName(), programName, appName, appVersion); }
private LoggingContext createLoggingContext(ProgramId programId, RunId runId, @Nullable WorkflowProgramInfo workflowProgramInfo) { if (workflowProgramInfo == null) { return new MapReduceLoggingContext(programId.getNamespace(), programId.getApplication(), programId.getProgram(), runId.getId()); } ProgramId workflowProramId = programId.getParent().workflow(workflowProgramInfo.getName()); return new WorkflowProgramLoggingContext(workflowProramId.getNamespace(), workflowProramId.getApplication(), workflowProramId.getProgram(), workflowProgramInfo.getRunId().getId(), ProgramType.MAPREDUCE, programId.getProgram(), runId.getId()); }
public static Program fromEntityId(ProgramId programId) { return new Program(Id.Application.fromEntityId(programId.getParent()), programId.getType(), programId.getProgram()); } }
protected List<BatchProgramHistory> getProgramRuns(NamespaceId namespace, List<ProgramId> programs) throws Exception { List<BatchProgram> request = programs.stream() .map(program -> new BatchProgram(program.getApplication(), program.getType(), program.getProgram())) .collect(Collectors.toList()); HttpResponse response = doPost(getVersionedAPIPath("runs", namespace.getNamespace()), GSON.toJson(request)); Assert.assertEquals(200, response.getResponseCode()); return GSON.fromJson(response.getResponseBodyAsString(), BATCH_PROGRAM_RUNS_TYPE); }
private WorkflowTokenDetail getWorkflowToken(ProgramId workflowId, String runId, @Nullable WorkflowToken.Scope scope, @Nullable String key) throws Exception { String workflowTokenUrl = String.format("apps/%s/workflows/%s/runs/%s/token", workflowId.getApplication(), workflowId.getProgram(), runId); String versionedUrl = getVersionedAPIPath(appendScopeAndKeyToUrl(workflowTokenUrl, scope, key), Constants.Gateway.API_VERSION_3_TOKEN, workflowId.getNamespace()); HttpResponse response = doGet(versionedUrl); return readResponse(response, new TypeToken<WorkflowTokenDetail>() { }.getType(), GSON); }
protected void stopProgram(ProgramId program, @Nullable String runId, int expectedStatusCode, String expectedMessage) throws Exception { String path; if (runId == null) { path = String.format("apps/%s/versions/%s/%s/%s/stop", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram()); } else { // TODO: HTTP endpoint for stopping a program run of an app version not implemented path = null; } stopProgram(path, program.getNamespace(), expectedStatusCode, expectedMessage); }
protected MDSKey.Builder getProgramKeyBuilder(String recordType, @Nullable ProgramId programId) { MDSKey.Builder builder = new MDSKey.Builder().add(recordType); if (programId != null) { builder.add(programId.getNamespace()); builder.add(programId.getApplication()); builder.add(programId.getVersion()); builder.add(programId.getType().name()); builder.add(programId.getProgram()); } return builder; }
/** * Tries to start the given program with the given runtime arguments and expect the call completed with the status. */ protected void startProgram(ProgramId program, Map<String, String> args, int expectedStatusCode) throws Exception { String path = String.format("apps/%s/versions/%s/%s/%s/start", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram()); startProgram(path, program.getNamespace(), args, expectedStatusCode); }
private void testVersionedProgramRuntimeArgs(ProgramId programId) throws Exception { String versionedRuntimeArgsUrl = getVersionedAPIPath("apps/" + programId.getApplication() + "/versions/" + programId.getVersion() + "/" + programId.getType().getCategoryName() + "/" + programId.getProgram() + "/runtimeargs", Constants.Gateway.API_VERSION_3_TOKEN, programId.getNamespace()); verifyRuntimeArgs(versionedRuntimeArgsUrl); }
public ScheduleDetail toScheduleDetail() { ScheduleProgramInfo programInfo = new ScheduleProgramInfo(schedule.getProgramId().getType().getSchedulableType(), schedule.getProgramId().getProgram()); ScheduleId scheduleId = schedule.getScheduleId(); return new ScheduleDetail(scheduleId.getNamespace(), scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule(), schedule.getDescription(), programInfo, schedule.getProperties(), schedule.getTrigger(), schedule.getConstraints(), schedule.getTimeoutMillis(), meta.getStatus().name()); } }