Search in sources :

Example 6 with MetadataStore

use of org.apache.samza.metadatastore.MetadataStore in project samza by apache.

the class TestZkLocalApplicationRunner method getConfigFromCoordinatorStream.

private MapConfig getConfigFromCoordinatorStream(Config config) {
    MetadataStoreFactory metadataStoreFactory = ReflectionUtil.getObj(new JobConfig(config).getMetadataStoreFactory(), MetadataStoreFactory.class);
    MetadataStore metadataStore = metadataStoreFactory.getMetadataStore("set-config", config, new MetricsRegistryMap());
    metadataStore.init();
    Map<String, String> configMap = new HashMap<>();
    CoordinatorStreamValueSerde jsonSerde = new CoordinatorStreamValueSerde("set-config");
    metadataStore.all().forEach((key, value) -> {
        CoordinatorStreamStore.CoordinatorMessageKey coordinatorMessageKey = CoordinatorStreamStore.deserializeCoordinatorMessageKeyFromJson(key);
        String deserializedValue = jsonSerde.fromBytes(value);
        configMap.put(coordinatorMessageKey.getKey(), deserializedValue);
    });
    return new MapConfig(configMap);
}
Also used : MetadataStore(org.apache.samza.metadatastore.MetadataStore) ZkMetadataStore(org.apache.samza.zk.ZkMetadataStore) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) MetadataStoreFactory(org.apache.samza.metadatastore.MetadataStoreFactory) CoordinatorStreamValueSerde(org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde) JobConfig(org.apache.samza.config.JobConfig)

Example 7 with MetadataStore

use of org.apache.samza.metadatastore.MetadataStore in project samza by apache.

the class JobCoordinatorLaunchUtil method run.

/**
 * Run {@link ClusterBasedJobCoordinator} with full job config.
 *
 * @param app SamzaApplication to run.
 * @param config full job config.
 */
@SuppressWarnings("rawtypes")
public static void run(SamzaApplication app, Config config) {
    // Execute planning
    ApplicationDescriptorImpl<? extends ApplicationDescriptor> appDesc = ApplicationDescriptorUtil.getAppDescriptor(app, config);
    RemoteJobPlanner planner = new RemoteJobPlanner(appDesc);
    List<JobConfig> jobConfigs = planner.prepareJobs();
    if (jobConfigs.size() != 1) {
        throw new SamzaException("Only support single remote job is supported.");
    }
    Config fullConfig = jobConfigs.get(0);
    // Create coordinator stream if does not exist before fetching launch config from it.
    CoordinatorStreamUtil.createCoordinatorStream(fullConfig);
    MetricsRegistryMap metrics = new MetricsRegistryMap();
    MetadataStore metadataStore = new CoordinatorStreamStore(CoordinatorStreamUtil.buildCoordinatorStreamConfig(fullConfig), metrics);
    // MetadataStore will be closed in ClusterBasedJobCoordinator#onShutDown
    // initialization of MetadataStore can be moved to ClusterBasedJobCoordinator after we clean up
    // ClusterBasedJobCoordinator#createFromMetadataStore
    metadataStore.init();
    // Reads extra launch config from metadata store.
    Config launchConfig = CoordinatorStreamUtil.readLaunchConfigFromCoordinatorStream(fullConfig, metadataStore);
    Config finalConfig = new MapConfig(launchConfig, fullConfig);
    // This needs to be consistent with RemoteApplicationRunner#run where JobRunner#submit to be called instead of JobRunner#run
    CoordinatorStreamUtil.writeConfigToCoordinatorStream(finalConfig, true);
    DiagnosticsUtil.createDiagnosticsStream(finalConfig);
    Optional<String> jobCoordinatorFactoryClassName = new JobCoordinatorConfig(config).getOptionalJobCoordinatorFactoryClassName();
    if (jobCoordinatorFactoryClassName.isPresent()) {
        runJobCoordinator(jobCoordinatorFactoryClassName.get(), metrics, metadataStore, finalConfig);
    } else {
        ClusterBasedJobCoordinator jc = new ClusterBasedJobCoordinator(metrics, metadataStore, finalConfig);
        jc.run();
    }
}
Also used : MetricsConfig(org.apache.samza.config.MetricsConfig) JobConfig(org.apache.samza.config.JobConfig) MapConfig(org.apache.samza.config.MapConfig) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) Config(org.apache.samza.config.Config) SamzaException(org.apache.samza.SamzaException) JobConfig(org.apache.samza.config.JobConfig) MetadataStore(org.apache.samza.metadatastore.MetadataStore) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) MapConfig(org.apache.samza.config.MapConfig) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) RemoteJobPlanner(org.apache.samza.execution.RemoteJobPlanner)

Aggregations

MetadataStore (org.apache.samza.metadatastore.MetadataStore)7 SamzaException (org.apache.samza.SamzaException)4 JobConfig (org.apache.samza.config.JobConfig)3 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)3 MapConfig (org.apache.samza.config.MapConfig)2 CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)2 ZkMetadataStore (org.apache.samza.zk.ZkMetadataStore)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 ApplicationConfig (org.apache.samza.config.ApplicationConfig)1 Config (org.apache.samza.config.Config)1 ConfigException (org.apache.samza.config.ConfigException)1 JobCoordinatorConfig (org.apache.samza.config.JobCoordinatorConfig)1 MetricsConfig (org.apache.samza.config.MetricsConfig)1 DistributedLock (org.apache.samza.coordinator.DistributedLock)1 RunIdGenerator (org.apache.samza.coordinator.RunIdGenerator)1 CoordinatorStreamMetadataStoreFactory (org.apache.samza.coordinator.metadatastore.CoordinatorStreamMetadataStoreFactory)1 CoordinatorStreamValueSerde (org.apache.samza.coordinator.stream.CoordinatorStreamValueSerde)1