mynameborat commented on a change in pull request #1529: URL: https://github.com/apache/samza/pull/1529#discussion_r712272025
########## File path: samza-core/src/main/java/org/apache/samza/coordinator/StaticResourceJobCoordinator.java ########## @@ -0,0 +1,299 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.samza.coordinator; + +import java.io.IOException; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import com.google.common.annotations.VisibleForTesting; +import org.apache.samza.SamzaException; +import org.apache.samza.config.Config; +import org.apache.samza.config.JobConfig; +import org.apache.samza.config.JobCoordinatorConfig; +import org.apache.samza.container.LocalityManager; +import org.apache.samza.container.grouper.task.TaskAssignmentManager; +import org.apache.samza.container.grouper.task.TaskPartitionAssignmentManager; +import org.apache.samza.coordinator.communication.CoordinatorCommunication; +import org.apache.samza.coordinator.communication.CoordinatorCommunicationContext; +import org.apache.samza.coordinator.communication.HttpCoordinatorToWorkerCommunicationFactory; +import org.apache.samza.coordinator.communication.JobModelServingContext; +import org.apache.samza.coordinator.lifecycle.JobRestartSignal; +import org.apache.samza.coordinator.lifecycle.JobRestartSignalFactory; +import org.apache.samza.coordinator.lifecycle.JobRestartSignalFactoryContext; +import org.apache.samza.coordinator.metadatastore.NamespaceAwareCoordinatorStreamStore; +import org.apache.samza.coordinator.stream.messages.SetChangelogMapping; +import org.apache.samza.coordinator.stream.messages.SetContainerHostMapping; +import org.apache.samza.coordinator.stream.messages.SetJobCoordinatorMetadataMessage; +import org.apache.samza.coordinator.stream.messages.SetTaskContainerMapping; +import org.apache.samza.coordinator.stream.messages.SetTaskModeMapping; +import org.apache.samza.coordinator.stream.messages.SetTaskPartitionMapping; +import org.apache.samza.job.JobCoordinatorMetadata; +import org.apache.samza.job.JobMetadataChange; +import org.apache.samza.job.metadata.JobCoordinatorMetadataManager; +import org.apache.samza.job.model.JobModel; +import org.apache.samza.job.model.JobModelUtil; +import org.apache.samza.metadatastore.MetadataStore; +import org.apache.samza.metrics.MetricsRegistry; +import org.apache.samza.startpoint.StartpointManager; +import org.apache.samza.storage.ChangelogStreamManager; +import org.apache.samza.system.StreamMetadataCache; +import org.apache.samza.system.SystemAdmins; +import org.apache.samza.util.ReflectionUtil; +import org.apache.samza.util.SystemClock; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Handles coordination with the workers for a Samza job. This includes generating the job model, managing metadata, + * and coordinating with the workers when the job model changes. + * This does certain similar things as the older ClusterBasedJobCoordinator, but one notable difference is that this + * coordinator does no management of execution resources. It relies on an external component to manage those resources + * for a Samza job. + */ +public class StaticResourceJobCoordinator { + private static final Logger LOG = LoggerFactory.getLogger(StaticResourceJobCoordinator.class); + + private final JobModelHelper jobModelHelper; + private final JobModelServingContext jobModelServingContext; + private final CoordinatorCommunication coordinatorCommunication; + private final JobCoordinatorMetadataManager jobCoordinatorMetadataManager; + private final StreamPartitionCountMonitorFactory streamPartitionCountMonitorFactory; + private final StreamRegexMonitorFactory streamRegexMonitorFactory; + /** + * This can be null if startpoints are not enabled. + */ + private final StartpointManager startpointManager; + private final ChangelogStreamManager changelogStreamManager; + private final JobRestartSignal jobRestartSignal; + private final MetricsRegistry metrics; + private final SystemAdmins systemAdmins; + private final Config config; + + private final AtomicBoolean isStarted = new AtomicBoolean(false); + private final AtomicBoolean shouldShutdown = new AtomicBoolean(false); + private final CountDownLatch shutdownLatch = new CountDownLatch(1); + + public static StaticResourceJobCoordinator build(MetricsRegistry metrics, MetadataStore metadataStore, + Config config) { + JobModelServingContext jobModelServingContext = new JobModelServingContext(); + JobConfig jobConfig = new JobConfig(config); + CoordinatorCommunicationContext context = + new CoordinatorCommunicationContext(jobModelServingContext, config, metrics); + CoordinatorCommunication coordinatorCommunication = + new HttpCoordinatorToWorkerCommunicationFactory().coordinatorCommunication(context); + JobCoordinatorMetadataManager jobCoordinatorMetadataManager = new JobCoordinatorMetadataManager( + new NamespaceAwareCoordinatorStreamStore(metadataStore, SetJobCoordinatorMetadataMessage.TYPE), + JobCoordinatorMetadataManager.ClusterType.NON_YARN, metrics); Review comment: Fair enough. Although, it seems we need this distinction in config rewriting/expansion. Wouldn't it be better to have implementation consistency in having on common ClusterType and then make `JobCoordinatorMetadataManager` treat different types as one with the exception of YARN? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
