Search in sources :

Example 21 with CoordinatorStreamStore

use of org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore in project samza by apache.

the class TestContainerAllocatorWithoutHostAffinity method setup.

@Before
public void setup() throws Exception {
    LocalityManager mockLocalityManager = mock(LocalityManager.class);
    when(mockLocalityManager.readLocality()).thenReturn(new LocalityModel(new HashMap<>()));
    CoordinatorStreamStoreTestUtil coordinatorStreamStoreTestUtil = new CoordinatorStreamStoreTestUtil(config);
    CoordinatorStreamStore coordinatorStreamStore = coordinatorStreamStoreTestUtil.getCoordinatorStreamStore();
    coordinatorStreamStore.init();
    containerPlacementMetadataStore = new ContainerPlacementMetadataStore(coordinatorStreamStore);
    containerPlacementMetadataStore.start();
    containerAllocator = new ContainerAllocator(manager, config, state, false, new ContainerManager(containerPlacementMetadataStore, state, manager, false, false, mockLocalityManager, faultDomainManager, config));
    requestState = new MockContainerRequestState(manager, false);
    Field requestStateField = containerAllocator.getClass().getDeclaredField("resourceRequestState");
    requestStateField.setAccessible(true);
    requestStateField.set(containerAllocator, requestState);
    allocatorThread = new Thread(containerAllocator);
}
Also used : Field(java.lang.reflect.Field) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) HashMap(java.util.HashMap) ContainerPlacementMetadataStore(org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadataStore) LocalityManager(org.apache.samza.container.LocalityManager) LocalityModel(org.apache.samza.job.model.LocalityModel) CoordinatorStreamStoreTestUtil(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStoreTestUtil) Before(org.junit.Before)

Example 22 with CoordinatorStreamStore

use of org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore in project samza by apache.

the class TestContainerProcessManager method setup.

@Before
public void setup() throws Exception {
    server = new MockHttpServer("/", 7777, null, new ServletHolder(DefaultServlet.class));
    CoordinatorStreamStoreTestUtil coordinatorStreamStoreTestUtil = new CoordinatorStreamStoreTestUtil(config);
    CoordinatorStreamStore coordinatorStreamStore = coordinatorStreamStoreTestUtil.getCoordinatorStreamStore();
    coordinatorStreamStore.init();
    containerPlacementMetadataStore = new ContainerPlacementMetadataStore(coordinatorStreamStore);
    containerPlacementMetadataStore.start();
}
Also used : CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) MockHttpServer(org.apache.samza.testUtils.MockHttpServer) ContainerPlacementMetadataStore(org.apache.samza.clustermanager.container.placement.ContainerPlacementMetadataStore) CoordinatorStreamStoreTestUtil(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStoreTestUtil) Before(org.junit.Before)

Example 23 with CoordinatorStreamStore

use of org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore 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)

Example 24 with CoordinatorStreamStore

use of org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore in project samza by apache.

the class SamzaTaskProxy method readTasksFromCoordinatorStream.

/**
 * Builds list of {@link Task} from job model in coordinator stream.
 * @param consumer system consumer associated with a job's coordinator stream.
 * @return list of {@link Task} constructed from job model in coordinator stream.
 */
protected List<Task> readTasksFromCoordinatorStream(CoordinatorStreamSystemConsumer consumer) {
    CoordinatorStreamStore coordinatorStreamStore = new CoordinatorStreamStore(consumer.getConfig(), new MetricsRegistryMap());
    LocalityManager localityManager = new LocalityManager(coordinatorStreamStore);
    Map<String, ProcessorLocality> containerLocalities = localityManager.readLocality().getProcessorLocalities();
    TaskAssignmentManager taskAssignmentManager = new TaskAssignmentManager(new NamespaceAwareCoordinatorStreamStore(coordinatorStreamStore, SetTaskContainerMapping.TYPE), new NamespaceAwareCoordinatorStreamStore(coordinatorStreamStore, SetTaskModeMapping.TYPE));
    Map<String, String> taskNameToContainerIdMapping = taskAssignmentManager.readTaskAssignment();
    StorageConfig storageConfig = new StorageConfig(consumer.getConfig());
    List<String> storeNames = storageConfig.getStoreNames();
    return taskNameToContainerIdMapping.entrySet().stream().map(entry -> {
        String hostName = Optional.ofNullable(containerLocalities.get(entry.getValue())).map(ProcessorLocality::host).orElse(null);
        return new Task(hostName, entry.getKey(), entry.getValue(), new ArrayList<>(), storeNames);
    }).collect(Collectors.toList());
}
Also used : CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) SetTaskModeMapping(org.apache.samza.coordinator.stream.messages.SetTaskModeMapping) Task(org.apache.samza.rest.model.Task) LoggerFactory(org.slf4j.LoggerFactory) JobConfig(org.apache.samza.config.JobConfig) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) TaskAssignmentManager(org.apache.samza.container.grouper.task.TaskAssignmentManager) JobInstance(org.apache.samza.rest.proxy.job.JobInstance) URI(java.net.URI) MapConfig(org.apache.samza.config.MapConfig) NamespaceAwareCoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.NamespaceAwareCoordinatorStreamStore) StorageConfig(org.apache.samza.config.StorageConfig) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) InstallationFinder(org.apache.samza.rest.proxy.installation.InstallationFinder) ConfigFactory(org.apache.samza.config.ConfigFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SamzaException(org.apache.samza.SamzaException) LocalityManager(org.apache.samza.container.LocalityManager) CoordinatorStreamSystemConsumer(org.apache.samza.coordinator.stream.CoordinatorStreamSystemConsumer) List(java.util.List) ReflectionUtil(org.apache.samza.util.ReflectionUtil) ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) Optional(java.util.Optional) InstallationRecord(org.apache.samza.rest.proxy.installation.InstallationRecord) Preconditions(com.google.common.base.Preconditions) Config(org.apache.samza.config.Config) SetTaskContainerMapping(org.apache.samza.coordinator.stream.messages.SetTaskContainerMapping) CoordinatorStreamUtil(org.apache.samza.util.CoordinatorStreamUtil) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Task(org.apache.samza.rest.model.Task) StorageConfig(org.apache.samza.config.StorageConfig) ArrayList(java.util.ArrayList) ProcessorLocality(org.apache.samza.job.model.ProcessorLocality) NamespaceAwareCoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.NamespaceAwareCoordinatorStreamStore) CoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore) NamespaceAwareCoordinatorStreamStore(org.apache.samza.coordinator.metadatastore.NamespaceAwareCoordinatorStreamStore) TaskAssignmentManager(org.apache.samza.container.grouper.task.TaskAssignmentManager) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) LocalityManager(org.apache.samza.container.LocalityManager)

Aggregations

CoordinatorStreamStore (org.apache.samza.coordinator.metadatastore.CoordinatorStreamStore)24 Config (org.apache.samza.config.Config)13 JobConfig (org.apache.samza.config.JobConfig)12 MapConfig (org.apache.samza.config.MapConfig)12 Test (org.junit.Test)12 JobCoordinatorConfig (org.apache.samza.config.JobCoordinatorConfig)10 ApplicationConfig (org.apache.samza.config.ApplicationConfig)8 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 HashMap (java.util.HashMap)7 Before (org.junit.Before)7 SamzaException (org.apache.samza.SamzaException)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Map (java.util.Map)5 StreamProcessor (org.apache.samza.processor.StreamProcessor)5 SystemAdmins (org.apache.samza.system.SystemAdmins)5 Optional (java.util.Optional)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 LegacyTaskApplication (org.apache.samza.application.LegacyTaskApplication)4