Search in sources :

Example 16 with ContainerContext

use of org.apache.samza.context.ContainerContext in project samza by apache.

the class TestLocalTableWrite method createTable.

private LocalTable createTable(boolean isTimerDisabled) {
    Map<String, String> config = new HashMap<>();
    if (isTimerDisabled) {
        config.put(MetricsConfig.METRICS_TIMER_ENABLED, "false");
    }
    Context context = mock(Context.class);
    JobContext jobContext = mock(JobContext.class);
    when(context.getJobContext()).thenReturn(jobContext);
    when(jobContext.getConfig()).thenReturn(new MapConfig(config));
    ContainerContext containerContext = mock(ContainerContext.class);
    when(context.getContainerContext()).thenReturn(containerContext);
    when(containerContext.getContainerMetricsRegistry()).thenReturn(metricsRegistry);
    LocalTable table = new LocalTable("t1", kvStore);
    table.init(context);
    return table;
}
Also used : JobContext(org.apache.samza.context.JobContext) ContainerContext(org.apache.samza.context.ContainerContext) Context(org.apache.samza.context.Context) ContainerContext(org.apache.samza.context.ContainerContext) HashMap(java.util.HashMap) JobContext(org.apache.samza.context.JobContext) MapConfig(org.apache.samza.config.MapConfig)

Example 17 with ContainerContext

use of org.apache.samza.context.ContainerContext in project samza by apache.

the class OperatorImpl method init.

/**
 * Initialize this {@link OperatorImpl} and its user-defined functions.
 *
 * @param internalTaskContext the {@link InternalTaskContext} for the task
 */
public final void init(InternalTaskContext internalTaskContext) {
    final Context context = internalTaskContext.getContext();
    String opId = getOpImplId();
    if (initialized) {
        throw new IllegalStateException(String.format("Attempted to initialize Operator %s more than once.", opId));
    }
    if (closed) {
        throw new IllegalStateException(String.format("Attempted to initialize Operator %s after it was closed.", opId));
    }
    this.highResClock = createHighResClock(context.getJobContext().getConfig());
    registeredOperators = new LinkedHashSet<>();
    prevOperators = new LinkedHashSet<>();
    inputStreams = new LinkedHashSet<>();
    final ContainerContext containerContext = context.getContainerContext();
    final MetricsRegistry metricsRegistry = containerContext.getContainerMetricsRegistry();
    this.numMessage = metricsRegistry.newCounter(METRICS_GROUP, opId + "-messages");
    this.handleMessageNs = metricsRegistry.newTimer(METRICS_GROUP, opId + "-handle-message-ns");
    this.handleTimerNs = metricsRegistry.newTimer(METRICS_GROUP, opId + "-handle-timer-ns");
    final TaskContext taskContext = context.getTaskContext();
    this.taskName = taskContext.getTaskModel().getTaskName();
    this.eosStates = (EndOfStreamStates) internalTaskContext.fetchObject(EndOfStreamStates.class.getName());
    this.watermarkStates = (WatermarkStates) internalTaskContext.fetchObject(WatermarkStates.class.getName());
    this.controlMessageSender = new ControlMessageSender(internalTaskContext.getStreamMetadataCache());
    this.taskModel = taskContext.getTaskModel();
    this.callbackScheduler = taskContext.getCallbackScheduler();
    handleInit(context);
    this.elasticityFactor = new JobConfig(context.getJobContext().getConfig()).getElasticityFactor();
    initialized = true;
}
Also used : TaskContext(org.apache.samza.context.TaskContext) ContainerContext(org.apache.samza.context.ContainerContext) Context(org.apache.samza.context.Context) InternalTaskContext(org.apache.samza.context.InternalTaskContext) ContainerContext(org.apache.samza.context.ContainerContext) MetricsRegistry(org.apache.samza.metrics.MetricsRegistry) TaskContext(org.apache.samza.context.TaskContext) InternalTaskContext(org.apache.samza.context.InternalTaskContext) JobConfig(org.apache.samza.config.JobConfig)

Aggregations

ContainerContext (org.apache.samza.context.ContainerContext)17 HashMap (java.util.HashMap)11 JobContext (org.apache.samza.context.JobContext)9 Context (org.apache.samza.context.Context)8 Config (org.apache.samza.config.Config)6 MapConfig (org.apache.samza.config.MapConfig)6 ContainerModel (org.apache.samza.job.model.ContainerModel)6 Map (java.util.Map)5 SamzaSqlExecutionContext (org.apache.samza.sql.data.SamzaSqlExecutionContext)5 CheckpointManager (org.apache.samza.checkpoint.CheckpointManager)4 StorageConfig (org.apache.samza.config.StorageConfig)4 TaskConfig (org.apache.samza.config.TaskConfig)4 SamzaContainerMetrics (org.apache.samza.container.SamzaContainerMetrics)4 TaskContext (org.apache.samza.context.TaskContext)4 TaskModel (org.apache.samza.job.model.TaskModel)4 MetricsRegistry (org.apache.samza.metrics.MetricsRegistry)4 Serde (org.apache.samza.serializers.Serde)4 StreamMetadataCache (org.apache.samza.system.StreamMetadataCache)4 SystemAdmins (org.apache.samza.system.SystemAdmins)4 File (java.io.File)3