public void provisioning(ProgramRunId programRunId, ProgramOptions programOptions, ProgramDescriptor programDescriptor, String userId) { publish(ImmutableMap.<String, String>builder() .put(ProgramOptionConstants.PROGRAM_RUN_ID, GSON.toJson(programRunId)) .put(ProgramOptionConstants.PROGRAM_DESCRIPTOR, GSON.toJson(programDescriptor)) .put(ProgramOptionConstants.USER_ID, userId) .put(ProgramOptionConstants.CLUSTER_STATUS, ProgramRunClusterStatus.PROVISIONING.name()) .put(ProgramOptionConstants.DEBUG_ENABLED, String.valueOf(programOptions.isDebug())) .put(ProgramOptionConstants.USER_OVERRIDES, GSON.toJson(programOptions.getUserArguments().asMap())) .put(ProgramOptionConstants.SYSTEM_OVERRIDES, GSON.toJson(programOptions.getArguments().asMap())) .put(ProgramOptionConstants.ARTIFACT_ID, GSON.toJson(programDescriptor.getArtifactId().toApiArtifactId())) .build()); }
/** * Validates the options for the program. * Subclasses can override this to also validate the options for their sub-programs. */ protected void validateOptions(Program program, ProgramOptions options) { // this will throw an exception if the custom tx timeout is invalid SystemArguments.validateTransactionTimeout(options.getUserArguments().asMap(), cConf); }
/** * Validates the options for the program. * Subclasses can override this to also validate the options for their sub-programs. */ protected void validateOptions(Program program, ProgramOptions options) { // this will throw an exception if the custom tx timeout is invalid SystemArguments.validateTransactionTimeout(options.getUserArguments().asMap(), cConf); }
private ProgramOptions createComponentOptions(int instanceId, int instances, RunId runId, ProgramOptions options) { Map<String, String> systemOptions = Maps.newHashMap(); systemOptions.putAll(options.getArguments().asMap()); systemOptions.put(ProgramOptionConstants.INSTANCE_ID, Integer.toString(instanceId)); systemOptions.put(ProgramOptionConstants.INSTANCES, Integer.toString(instances)); systemOptions.put(ProgramOptionConstants.RUN_ID, runId.getId()); systemOptions.put(ProgramOptionConstants.HOST, host); return new SimpleProgramOptions(options.getProgramId(), new BasicArguments(systemOptions), options.getUserArguments()); }
private ProgramOptions createComponentOptions(int instanceId, int instances, RunId runId, ProgramOptions options) { Map<String, String> systemOptions = Maps.newHashMap(); systemOptions.putAll(options.getArguments().asMap()); systemOptions.put(ProgramOptionConstants.INSTANCE_ID, Integer.toString(instanceId)); systemOptions.put(ProgramOptionConstants.INSTANCES, Integer.toString(instances)); systemOptions.put(ProgramOptionConstants.RUN_ID, runId.getId()); systemOptions.put(ProgramOptionConstants.HOST, host); return new SimpleProgramOptions(options.getProgramId(), new BasicArguments(systemOptions), options.getUserArguments()); }
private ProgramOptions createFlowletOptions(int instanceId, int instances, ProgramOptions options) { Map<String, String> systemArgs = new HashMap<>(); systemArgs.putAll(options.getArguments().asMap()); systemArgs.put(ProgramOptionConstants.INSTANCE_ID, Integer.toString(instanceId)); systemArgs.put(ProgramOptionConstants.INSTANCES, Integer.toString(instances)); return new SimpleProgramOptions(options.getProgramId(), new BasicArguments(systemArgs), options.getUserArguments()); }
@Override public JsonElement serialize(ProgramOptions src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.add("programId", context.serialize(src.getProgramId(), ProgramId.class)); json.add("arguments", context.serialize(src.getArguments(), Arguments.class)); json.add("userArguments", context.serialize(src.getUserArguments(), Arguments.class)); json.addProperty("debug", src.isDebug()); return json; } }
@Override public JsonElement serialize(ProgramOptions src, Type typeOfSrc, JsonSerializationContext context) { JsonObject json = new JsonObject(); json.add("programId", context.serialize(src.getProgramId(), ProgramId.class)); json.add("arguments", context.serialize(src.getArguments(), Arguments.class)); json.add("userArguments", context.serialize(src.getUserArguments(), Arguments.class)); json.addProperty("debug", src.isDebug()); return json; } }
@Override protected void doStart() { try { initializer.initialize(); SystemArguments.setLogLevel(programOptions.getUserArguments(), initializer); notifyStarted(); } catch (Throwable t) { notifyFailed(t); } }
@Override protected void doStart() { try { initializer.initialize(); SystemArguments.setLogLevel(programOptions.getUserArguments(), initializer); notifyStarted(); } catch (Throwable t) { notifyFailed(t); } }
@Override protected void validateOptions(Program program, ProgramOptions options) { super.validateOptions(program, options); FlowSpecification spec = program.getApplicationSpecification().getFlows().get(program.getName()); for (String flowlet : spec.getFlowlets().keySet()) { SystemArguments.validateTransactionTimeout(options.getUserArguments().asMap(), cConf, "flowlet", flowlet); } }
@Override protected void doStart() { try { initializer.initialize(); SystemArguments.setLogLevel(programOptions.getUserArguments(), initializer); notifyStarted(); } catch (Throwable t) { notifyFailed(t); } }
@Override protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) { ApplicationSpecification appSpec = program.getApplicationSpecification(); WorkerSpecification workerSpec = appSpec.getWorkers().get(program.getName()); String instances = options.getArguments().getOption(ProgramOptionConstants.INSTANCES, String.valueOf(workerSpec.getInstances())); launchConfig.addRunnable(workerSpec.getName(), new WorkerTwillRunnable(workerSpec.getName()), Integer.parseInt(instances), options.getUserArguments().asMap(), workerSpec.getResources()); } }
@Override protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) { ApplicationSpecification appSpec = program.getApplicationSpecification(); WorkerSpecification workerSpec = appSpec.getWorkers().get(program.getName()); String instances = options.getArguments().getOption(ProgramOptionConstants.INSTANCES, String.valueOf(workerSpec.getInstances())); launchConfig.addRunnable(workerSpec.getName(), new WorkerTwillRunnable(workerSpec.getName()), Integer.parseInt(instances), options.getUserArguments().asMap(), workerSpec.getResources()); } }
/** * Creates a {@link ProgramOptions} by deserializing the given json file. */ private ProgramOptions createProgramOptions(File programOptionsFile) throws IOException { ProgramOptions original = readJsonFile(programOptionsFile, ProgramOptions.class); // Overwrite them with environmental information Map<String, String> arguments = new HashMap<>(original.getArguments().asMap()); arguments.putAll(getExtraSystemArguments()); // Use the name passed in by the constructor as the program name to construct the ProgramId return new SimpleProgramOptions(original.getProgramId(), new BasicArguments(arguments), resolveScope(original.getUserArguments()), original.isDebug()); }
/** * Creates a {@link ProgramOptions} by deserializing the given json file. */ private ProgramOptions createProgramOptions(File programOptionsFile) throws IOException { ProgramOptions original = readJsonFile(programOptionsFile, ProgramOptions.class); // Overwrite them with environmental information Map<String, String> arguments = new HashMap<>(original.getArguments().asMap()); arguments.putAll(getExtraSystemArguments()); // Use the name passed in by the constructor as the program name to construct the ProgramId return new SimpleProgramOptions(original.getProgramId(), new BasicArguments(arguments), resolveScope(original.getUserArguments()), original.isDebug()); }
private ProgramOptions resolveFlowletOptions(ProgramOptions options, String flowlet) { Map<String, String> systemArgs = new HashMap<>(options.getArguments().asMap()); systemArgs.put(ProgramOptionConstants.FLOWLET_NAME, flowlet); return new SimpleProgramOptions(options.getProgramId(), new BasicArguments(systemArgs), new BasicArguments(RuntimeArguments.extractScope( FlowUtils.FLOWLET_SCOPE, flowlet, options.getUserArguments().asMap()))); }
@Override protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) { ApplicationSpecification appSpec = program.getApplicationSpecification(); ServiceSpecification serviceSpec = appSpec.getServices().get(program.getName()); // Add a runnable for the service handler launchConfig.addRunnable(serviceSpec.getName(), new ServiceTwillRunnable(serviceSpec.getName()), serviceSpec.getInstances(), options.getUserArguments().asMap(), serviceSpec.getResources()); } }
@Override protected void setupLaunchConfig(ProgramLaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) { ApplicationSpecification appSpec = program.getApplicationSpecification(); ServiceSpecification serviceSpec = appSpec.getServices().get(program.getName()); // Add a runnable for the service handler launchConfig.addRunnable(serviceSpec.getName(), new ServiceTwillRunnable(serviceSpec.getName()), serviceSpec.getInstances(), options.getUserArguments().asMap(), serviceSpec.getResources()); } }
private boolean programOptionsEquals(ProgramOptions opt1, ProgramOptions opt2) { return Objects.equals(opt1.getProgramId(), opt2.getProgramId()) && opt1.isDebug() == opt2.isDebug() && Objects.equals(opt1.getArguments().asMap(), opt2.getArguments().asMap()) && Objects.equals(opt1.getUserArguments().asMap(), opt2.getUserArguments().asMap()); } }