Search in sources :

Example 11 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class TestExecutionPlanner method testTriggerIntervalForJoins.

@Test
public void testTriggerIntervalForJoins() throws Exception {
    Map<String, String> map = new HashMap<>(config);
    map.put(JobConfig.JOB_INTERMEDIATE_STREAM_PARTITIONS(), String.valueOf(DEFAULT_PARTITIONS));
    Config cfg = new MapConfig(map);
    ExecutionPlanner planner = new ExecutionPlanner(cfg, streamManager);
    StreamGraphImpl streamGraph = createStreamGraphWithJoin();
    ExecutionPlan plan = planner.plan(streamGraph);
    List<JobConfig> jobConfigs = plan.getJobConfigs();
    for (JobConfig config : jobConfigs) {
        System.out.println(config);
    }
}
Also used : HashMap(java.util.HashMap) JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) TaskConfig(org.apache.samza.config.TaskConfig) Config(org.apache.samza.config.Config) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) MapConfig(org.apache.samza.config.MapConfig) JobConfig(org.apache.samza.config.JobConfig) Test(org.junit.Test)

Example 12 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class JobNode method generateConfig.

/**
   * Generate the configs for a job
   * @param executionPlanJson JSON representation of the execution plan
   * @return config of the job
   */
public JobConfig generateConfig(String executionPlanJson) {
    Map<String, String> configs = new HashMap<>();
    configs.put(JobConfig.JOB_NAME(), jobName);
    List<String> inputs = inEdges.stream().map(edge -> edge.getFormattedSystemStream()).collect(Collectors.toList());
    configs.put(TaskConfig.INPUT_STREAMS(), Joiner.on(',').join(inputs));
    // set triggering interval if a window or join is defined
    if (streamGraph.hasWindowOrJoins()) {
        if ("-1".equals(config.get(TaskConfig.WINDOW_MS(), "-1"))) {
            long triggerInterval = computeTriggerInterval();
            log.info("Using triggering interval: {} for jobName: {}", triggerInterval, jobName);
            configs.put(TaskConfig.WINDOW_MS(), String.valueOf(triggerInterval));
        }
    }
    log.info("Job {} has generated configs {}", jobName, configs);
    configs.put(CONFIG_INTERNAL_EXECUTION_PLAN, executionPlanJson);
    String configPrefix = String.format(CONFIG_JOB_PREFIX, jobName);
    // TODO: Disallow user specifying job inputs/outputs. This info comes strictly from the pipeline.
    return new JobConfig(Util.rewriteConfig(extractScopedConfig(config, new MapConfig(configs), configPrefix)));
}
Also used : Util(org.apache.samza.util.Util) Logger(org.slf4j.Logger) TaskConfig(org.apache.samza.config.TaskConfig) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) JobConfig(org.apache.samza.config.JobConfig) WindowOperatorSpec(org.apache.samza.operators.spec.WindowOperatorSpec) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) StreamGraphImpl(org.apache.samza.operators.StreamGraphImpl) MathUtils(org.apache.samza.operators.util.MathUtils) List(java.util.List) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) PartialJoinOperatorSpec(org.apache.samza.operators.spec.PartialJoinOperatorSpec) Map(java.util.Map) Config(org.apache.samza.config.Config) MapConfig(org.apache.samza.config.MapConfig) Joiner(com.google.common.base.Joiner) HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) JobConfig(org.apache.samza.config.JobConfig)

Example 13 with JobConfig

use of org.apache.samza.config.JobConfig in project samza by apache.

the class LocalContainerRunner method main.

public static void main(String[] args) throws Exception {
    Thread.setDefaultUncaughtExceptionHandler(new SamzaContainerExceptionHandler(() -> {
        log.info("Exiting process now.");
        System.exit(1);
    }));
    String containerId = System.getenv(ShellCommandConfig.ENV_CONTAINER_ID());
    log.info(String.format("Got container ID: %s", containerId));
    String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL());
    log.info(String.format("Got coordinator URL: %s", coordinatorUrl));
    int delay = new Random().nextInt(SamzaContainer.DEFAULT_READ_JOBMODEL_DELAY_MS()) + 1;
    JobModel jobModel = SamzaContainer.readJobModel(coordinatorUrl, delay);
    Config config = jobModel.getConfig();
    JobConfig jobConfig = new JobConfig(config);
    if (jobConfig.getName().isEmpty()) {
        throw new SamzaException("can not find the job name");
    }
    String jobName = jobConfig.getName().get();
    String jobId = jobConfig.getJobId().getOrElse(ScalaToJavaUtils.defaultValue("1"));
    MDC.put("containerName", "samza-container-" + containerId);
    MDC.put("jobName", jobName);
    MDC.put("jobId", jobId);
    StreamApplication streamApp = TaskFactoryUtil.createStreamApplication(config);
    LocalContainerRunner localContainerRunner = new LocalContainerRunner(jobModel, containerId);
    localContainerRunner.run(streamApp);
}
Also used : Random(java.util.Random) JobConfig(org.apache.samza.config.JobConfig) ShellCommandConfig(org.apache.samza.config.ShellCommandConfig) Config(org.apache.samza.config.Config) StreamApplication(org.apache.samza.application.StreamApplication) SamzaContainerExceptionHandler(org.apache.samza.container.SamzaContainerExceptionHandler) JobModel(org.apache.samza.job.model.JobModel) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig)

Aggregations

JobConfig (org.apache.samza.config.JobConfig)13 HashMap (java.util.HashMap)10 MapConfig (org.apache.samza.config.MapConfig)10 Test (org.junit.Test)9 Config (org.apache.samza.config.Config)8 TaskConfig (org.apache.samza.config.TaskConfig)6 StreamGraphImpl (org.apache.samza.operators.StreamGraphImpl)6 StreamApplication (org.apache.samza.application.StreamApplication)5 ExecutionPlan (org.apache.samza.execution.ExecutionPlan)5 Field (java.lang.reflect.Field)4 ExecutionPlanner (org.apache.samza.execution.ExecutionPlanner)4 StreamSpec (org.apache.samza.system.StreamSpec)4 Matchers.anyString (org.mockito.Matchers.anyString)4 List (java.util.List)3 SamzaException (org.apache.samza.SamzaException)2 StreamManager (org.apache.samza.execution.StreamManager)2 StreamProcessor (org.apache.samza.processor.StreamProcessor)2 StreamProcessorLifecycleListener (org.apache.samza.processor.StreamProcessorLifecycleListener)2 Joiner (com.google.common.base.Joiner)1 ArrayList (java.util.ArrayList)1