Search in sources :

Example 1 with SystemConfig

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

the class DiagnosticsUtil method createDiagnosticsStream.

public static void createDiagnosticsStream(Config config) {
    if (!new JobConfig(config).getDiagnosticsEnabled()) {
        return;
    }
    // if diagnostics is enabled, create diagnostics stream if it doesnt exist
    String diagnosticsSystemStreamName = new MetricsConfig(config).getMetricsSnapshotReporterStream(MetricsConfig.METRICS_SNAPSHOT_REPORTER_NAME_FOR_DIAGNOSTICS).orElseThrow(() -> new ConfigException("Missing required config: " + String.format(MetricsConfig.METRICS_SNAPSHOT_REPORTER_STREAM, MetricsConfig.METRICS_SNAPSHOT_REPORTER_NAME_FOR_DIAGNOSTICS)));
    SystemStream diagnosticsSystemStream = StreamUtil.getSystemStreamFromNames(diagnosticsSystemStreamName);
    SystemConfig systemConfig = new SystemConfig(config);
    SystemAdmin diagnosticsSysAdmin = systemConfig.getSystemFactories().get(diagnosticsSystemStream.getSystem()).getAdmin(diagnosticsSystemStream.getSystem(), config, DiagnosticsUtil.class.getSimpleName());
    StreamSpec diagnosticsStreamSpec = new StreamSpec(DIAGNOSTICS_STREAM_ID, diagnosticsSystemStream.getStream(), diagnosticsSystemStream.getSystem(), new StreamConfig(config).getStreamProperties(DIAGNOSTICS_STREAM_ID));
    log.info("Creating diagnostics stream {}", diagnosticsSystemStream.getStream());
    diagnosticsSysAdmin.start();
    if (diagnosticsSysAdmin.createStream(diagnosticsStreamSpec)) {
        log.info("Created diagnostics stream {}", diagnosticsSystemStream.getStream());
    } else {
        log.info("Diagnostics stream {} already exists", diagnosticsSystemStream.getStream());
    }
    diagnosticsSysAdmin.stop();
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) SystemConfig(org.apache.samza.config.SystemConfig) SystemStream(org.apache.samza.system.SystemStream) StreamConfig(org.apache.samza.config.StreamConfig) ConfigException(org.apache.samza.config.ConfigException) SystemAdmin(org.apache.samza.system.SystemAdmin) JobConfig(org.apache.samza.config.JobConfig) MetricsConfig(org.apache.samza.config.MetricsConfig)

Example 2 with SystemConfig

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

the class DiagnosticsUtil method buildDiagnosticsManager.

/**
 * Create a {@link DiagnosticsManager} for the given jobName, jobId, containerId, and execEnvContainerId, if
 * diagnostics is enabled.
 * @param executionEnvContainerId ID assigned to the container by the cluster manager (e.g. YARN)
 * @param samzaEpochId ID assigned to the job deployment attempt by the cluster manager
 */
public static Optional<DiagnosticsManager> buildDiagnosticsManager(String jobName, String jobId, JobModel jobModel, String containerId, Optional<String> executionEnvContainerId, Optional<String> samzaEpochId, Config config) {
    JobConfig jobConfig = new JobConfig(config);
    MetricsConfig metricsConfig = new MetricsConfig(config);
    Optional<DiagnosticsManager> diagnosticsManagerOptional = Optional.empty();
    if (jobConfig.getDiagnosticsEnabled()) {
        ClusterManagerConfig clusterManagerConfig = new ClusterManagerConfig(config);
        int containerMemoryMb = clusterManagerConfig.getContainerMemoryMb();
        int containerNumCores = clusterManagerConfig.getNumCores();
        long maxHeapSizeBytes = Runtime.getRuntime().maxMemory();
        int containerThreadPoolSize = jobConfig.getThreadPoolSize();
        String taskClassVersion = Util.getTaskClassVersion(config);
        String samzaVersion = Util.getSamzaVersion();
        String hostName = Util.getLocalHost().getHostName();
        Optional<String> diagnosticsReporterStreamName = metricsConfig.getMetricsSnapshotReporterStream(MetricsConfig.METRICS_SNAPSHOT_REPORTER_NAME_FOR_DIAGNOSTICS);
        if (!diagnosticsReporterStreamName.isPresent()) {
            throw new ConfigException("Missing required config: " + String.format(MetricsConfig.METRICS_SNAPSHOT_REPORTER_STREAM, MetricsConfig.METRICS_SNAPSHOT_REPORTER_NAME_FOR_DIAGNOSTICS));
        }
        SystemStream diagnosticsSystemStream = StreamUtil.getSystemStreamFromNames(diagnosticsReporterStreamName.get());
        // Create a SystemProducer for DiagnosticsManager. This producer is used by the DiagnosticsManager
        // to write to the same stream as the MetricsSnapshotReporter called `diagnosticsreporter`.
        Optional<String> diagnosticsSystemFactoryName = new SystemConfig(config).getSystemFactory(diagnosticsSystemStream.getSystem());
        if (!diagnosticsSystemFactoryName.isPresent()) {
            throw new SamzaException("Missing factory in config for system " + diagnosticsSystemStream.getSystem());
        }
        SystemFactory systemFactory = ReflectionUtil.getObj(diagnosticsSystemFactoryName.get(), SystemFactory.class);
        SystemProducer systemProducer = systemFactory.getProducer(diagnosticsSystemStream.getSystem(), config, new MetricsRegistryMap(), DiagnosticsUtil.class.getSimpleName());
        DiagnosticsManager diagnosticsManager = new DiagnosticsManager(jobName, jobId, jobModel.getContainers(), containerMemoryMb, containerNumCores, new StorageConfig(config).getNumPersistentStores(), maxHeapSizeBytes, containerThreadPoolSize, containerId, executionEnvContainerId.orElse(""), samzaEpochId.orElse(""), taskClassVersion, samzaVersion, hostName, diagnosticsSystemStream, systemProducer, Duration.ofMillis(new TaskConfig(config).getShutdownMs()), jobConfig.getAutosizingEnabled(), config);
        diagnosticsManagerOptional = Optional.of(diagnosticsManager);
    }
    return diagnosticsManagerOptional;
}
Also used : SystemConfig(org.apache.samza.config.SystemConfig) SystemFactory(org.apache.samza.system.SystemFactory) DiagnosticsManager(org.apache.samza.diagnostics.DiagnosticsManager) StorageConfig(org.apache.samza.config.StorageConfig) SystemStream(org.apache.samza.system.SystemStream) SystemProducer(org.apache.samza.system.SystemProducer) ConfigException(org.apache.samza.config.ConfigException) TaskConfig(org.apache.samza.config.TaskConfig) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig) MetricsConfig(org.apache.samza.config.MetricsConfig) ClusterManagerConfig(org.apache.samza.config.ClusterManagerConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap)

Example 3 with SystemConfig

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

the class ChangelogStreamManager method createChangelogStreams.

/**
 * Creates and validates the changelog streams of a samza job.
 *
 * @param config the configuration with changelog info.
 * @param maxChangeLogStreamPartitions the maximum number of changelog stream partitions to create.
 */
public static void createChangelogStreams(Config config, int maxChangeLogStreamPartitions) {
    // Get changelog store config
    StorageConfig storageConfig = new StorageConfig(config);
    ImmutableMap.Builder<String, SystemStream> storeNameSystemStreamMapBuilder = new ImmutableMap.Builder<>();
    storageConfig.getStoreNames().forEach(storeName -> {
        Optional<String> changelogStream = storageConfig.getChangelogStream(storeName);
        if (changelogStream.isPresent() && StringUtils.isNotBlank(changelogStream.get())) {
            storeNameSystemStreamMapBuilder.put(storeName, StreamUtil.getSystemStreamFromNames(changelogStream.get()));
        }
    });
    Map<String, SystemStream> storeNameSystemStreamMapping = storeNameSystemStreamMapBuilder.build();
    // Get SystemAdmin for changelog store's system and attempt to create the stream
    SystemConfig systemConfig = new SystemConfig(config);
    storeNameSystemStreamMapping.forEach((storeName, systemStream) -> {
        // Load system admin for this system.
        SystemAdmin systemAdmin = systemConfig.getSystemFactories().get(systemStream.getSystem()).getAdmin(systemStream.getSystem(), config, ChangelogStreamManager.class.getSimpleName());
        if (systemAdmin == null) {
            throw new SamzaException(String.format("Error creating changelog. Changelog on store %s uses system %s, which is missing from the configuration.", storeName, systemStream.getSystem()));
        }
        StreamSpec changelogSpec = StreamSpec.createChangeLogStreamSpec(systemStream.getStream(), systemStream.getSystem(), maxChangeLogStreamPartitions);
        systemAdmin.start();
        if (systemAdmin.createStream(changelogSpec)) {
            LOG.info(String.format("created changelog stream %s.", systemStream.getStream()));
        } else {
            LOG.info(String.format("changelog stream %s already exists.", systemStream.getStream()));
        }
        systemAdmin.validateStream(changelogSpec);
        if (storageConfig.getAccessLogEnabled(storeName)) {
            String accesslogStream = storageConfig.getAccessLogStream(systemStream.getStream());
            StreamSpec accesslogSpec = new StreamSpec(accesslogStream, accesslogStream, systemStream.getSystem(), maxChangeLogStreamPartitions);
            systemAdmin.createStream(accesslogSpec);
            systemAdmin.validateStream(accesslogSpec);
        }
        systemAdmin.stop();
    });
}
Also used : StreamSpec(org.apache.samza.system.StreamSpec) SystemConfig(org.apache.samza.config.SystemConfig) StorageConfig(org.apache.samza.config.StorageConfig) SystemStream(org.apache.samza.system.SystemStream) SamzaException(org.apache.samza.SamzaException) ImmutableMap(com.google.common.collect.ImmutableMap) SystemAdmin(org.apache.samza.system.SystemAdmin)

Example 4 with SystemConfig

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

the class StorageRecovery method getContainerStorageManagers.

/**
 * create one TaskStorageManager for each task. Add all of them to the
 * List<TaskStorageManager>
 */
@SuppressWarnings("rawtypes")
private void getContainerStorageManagers() {
    Set<String> factoryClasses = new StorageConfig(jobConfig).getRestoreFactories();
    Map<String, StateBackendFactory> stateBackendFactories = factoryClasses.stream().collect(Collectors.toMap(factoryClass -> factoryClass, factoryClass -> ReflectionUtil.getObj(factoryClass, StateBackendFactory.class)));
    Clock clock = SystemClock.instance();
    StreamMetadataCache streamMetadataCache = new StreamMetadataCache(systemAdmins, 5000, clock);
    // don't worry about prefetching for this; looks like the tool doesn't flush to offset files anyways
    Map<String, SystemFactory> systemFactories = new SystemConfig(jobConfig).getSystemFactories();
    CheckpointManager checkpointManager = new TaskConfig(jobConfig).getCheckpointManager(new MetricsRegistryMap()).orElse(null);
    for (ContainerModel containerModel : containers.values()) {
        ContainerContext containerContext = new ContainerContextImpl(containerModel, new MetricsRegistryMap());
        ContainerStorageManager containerStorageManager = new ContainerStorageManager(checkpointManager, containerModel, streamMetadataCache, systemAdmins, changeLogSystemStreams, new HashMap<>(), storageEngineFactories, systemFactories, this.getSerdes(), jobConfig, new HashMap<>(), new SamzaContainerMetrics(containerModel.getId(), new MetricsRegistryMap(), ""), JobContextImpl.fromConfigWithDefaults(jobConfig, jobModel), containerContext, stateBackendFactories, new HashMap<>(), storeBaseDir, storeBaseDir, null, new SystemClock());
        this.containerStorageManagers.put(containerModel.getId(), containerStorageManager);
    }
}
Also used : StreamMetadataCache(org.apache.samza.system.StreamMetadataCache) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) JobContextImpl(org.apache.samza.context.JobContextImpl) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) TaskModel(org.apache.samza.job.model.TaskModel) Serde(org.apache.samza.serializers.Serde) ContainerContextImpl(org.apache.samza.context.ContainerContextImpl) JobModelManager(org.apache.samza.coordinator.JobModelManager) SerdeFactory(org.apache.samza.serializers.SerdeFactory) CheckpointManager(org.apache.samza.checkpoint.CheckpointManager) SamzaContainerMetrics(org.apache.samza.container.SamzaContainerMetrics) SystemStream(org.apache.samza.system.SystemStream) Map(java.util.Map) SystemConfig(org.apache.samza.config.SystemConfig) StreamUtil(org.apache.samza.util.StreamUtil) JobModel(org.apache.samza.job.model.JobModel) StorageConfig(org.apache.samza.config.StorageConfig) Logger(org.slf4j.Logger) SerializerConfig(org.apache.samza.config.SerializerConfig) TaskConfig(org.apache.samza.config.TaskConfig) ContainerContext(org.apache.samza.context.ContainerContext) Set(java.util.Set) SystemFactory(org.apache.samza.system.SystemFactory) Clock(org.apache.samza.util.Clock) Collectors(java.util.stream.Collectors) File(java.io.File) SamzaException(org.apache.samza.SamzaException) List(java.util.List) SystemClock(org.apache.samza.util.SystemClock) ReflectionUtil(org.apache.samza.util.ReflectionUtil) ContainerModel(org.apache.samza.job.model.ContainerModel) Optional(java.util.Optional) Config(org.apache.samza.config.Config) CoordinatorStreamUtil(org.apache.samza.util.CoordinatorStreamUtil) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) SystemAdmins(org.apache.samza.system.SystemAdmins) StreamMetadataCache(org.apache.samza.system.StreamMetadataCache) SystemFactory(org.apache.samza.system.SystemFactory) SystemConfig(org.apache.samza.config.SystemConfig) SystemClock(org.apache.samza.util.SystemClock) StorageConfig(org.apache.samza.config.StorageConfig) CheckpointManager(org.apache.samza.checkpoint.CheckpointManager) TaskConfig(org.apache.samza.config.TaskConfig) ContainerContextImpl(org.apache.samza.context.ContainerContextImpl) Clock(org.apache.samza.util.Clock) SystemClock(org.apache.samza.util.SystemClock) ContainerModel(org.apache.samza.job.model.ContainerModel) ContainerContext(org.apache.samza.context.ContainerContext) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) SamzaContainerMetrics(org.apache.samza.container.SamzaContainerMetrics)

Example 5 with SystemConfig

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

the class SystemConsumerWithSamzaBench method start.

public void start() throws IOException, InterruptedException {
    super.start();
    MessageConsumer consumeFn = new MessageConsumer();
    StreamApplication app = appDesc -> {
        String systemFactoryName = new SystemConfig(config).getSystemFactory(systemName).get();
        GenericSystemDescriptor sd = new GenericSystemDescriptor(systemName, systemFactoryName);
        GenericInputDescriptor<Object> isd = sd.getInputDescriptor(streamId, new NoOpSerde<>());
        MessageStream<Object> stream = appDesc.getInputStream(isd);
        stream.map(consumeFn);
    };
    ApplicationRunner runner = ApplicationRunners.getApplicationRunner(app, new MapConfig());
    runner.run();
    while (consumeFn.getEventsConsumed() < totalEvents) {
        Thread.sleep(10);
    }
    Instant endTime = Instant.now();
    runner.kill();
    System.out.println("\n*******************");
    System.out.println(String.format("Started at %s Ending at %s ", consumeFn.startTime, endTime));
    System.out.println(String.format("Event Rate is %s Messages/Sec ", consumeFn.getEventsConsumed() * 1000 / Duration.between(consumeFn.startTime, Instant.now()).toMillis()));
    System.out.println("Event Rate is " + consumeFn.getEventsConsumed() * 1000 / Duration.between(consumeFn.startTime, endTime).toMillis());
    System.out.println("*******************\n");
    System.exit(0);
}
Also used : IntStream(java.util.stream.IntStream) GenericSystemDescriptor(org.apache.samza.system.descriptors.GenericSystemDescriptor) JobConfig(org.apache.samza.config.JobConfig) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) MapFunction(org.apache.samza.operators.functions.MapFunction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ApplicationConfig(org.apache.samza.config.ApplicationConfig) SystemConfig(org.apache.samza.config.SystemConfig) ApplicationRunners(org.apache.samza.runtime.ApplicationRunners) MapConfig(org.apache.samza.config.MapConfig) NoOpSerde(org.apache.samza.serializers.NoOpSerde) MessageStream(org.apache.samza.operators.MessageStream) ApplicationRunner(org.apache.samza.runtime.ApplicationRunner) LocalApplicationRunner(org.apache.samza.runtime.LocalApplicationRunner) Properties(java.util.Properties) TaskConfig(org.apache.samza.config.TaskConfig) IOException(java.io.IOException) Instant(java.time.Instant) PassthroughJobCoordinatorFactory(org.apache.samza.standalone.PassthroughJobCoordinatorFactory) Collectors(java.util.stream.Collectors) List(java.util.List) ParseException(org.apache.commons.cli.ParseException) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) StreamApplication(org.apache.samza.application.StreamApplication) Joiner(com.google.common.base.Joiner) SystemConfig(org.apache.samza.config.SystemConfig) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) ApplicationRunner(org.apache.samza.runtime.ApplicationRunner) LocalApplicationRunner(org.apache.samza.runtime.LocalApplicationRunner) StreamApplication(org.apache.samza.application.StreamApplication) NoOpSerde(org.apache.samza.serializers.NoOpSerde) MessageStream(org.apache.samza.operators.MessageStream) Instant(java.time.Instant) MapConfig(org.apache.samza.config.MapConfig) GenericSystemDescriptor(org.apache.samza.system.descriptors.GenericSystemDescriptor)

Aggregations

SystemConfig (org.apache.samza.config.SystemConfig)7 SystemStream (org.apache.samza.system.SystemStream)5 SamzaException (org.apache.samza.SamzaException)4 JobConfig (org.apache.samza.config.JobConfig)3 StorageConfig (org.apache.samza.config.StorageConfig)3 TaskConfig (org.apache.samza.config.TaskConfig)3 SystemFactory (org.apache.samza.system.SystemFactory)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ConfigException (org.apache.samza.config.ConfigException)2 MetricsConfig (org.apache.samza.config.MetricsConfig)2 SerializerConfig (org.apache.samza.config.SerializerConfig)2 StreamConfig (org.apache.samza.config.StreamConfig)2 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)2 StreamSpec (org.apache.samza.system.StreamSpec)2 SystemAdmin (org.apache.samza.system.SystemAdmin)2 Joiner (com.google.common.base.Joiner)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 IOException (java.io.IOException)1