You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@gobblin.apache.org by GitBox <gi...@apache.org> on 2021/06/08 16:39:58 UTC

[GitHub] [gobblin] sv2000 commented on a change in pull request #3281: [GOBBLIN-1444] Use Guice as DI framework in Gobblin service

sv2000 commented on a change in pull request #3281:
URL: https://github.com/apache/gobblin/pull/3281#discussion_r647607226



##########
File path: gobblin-service/src/main/java/org/apache/gobblin/service/modules/scheduler/GobblinServiceJobScheduler.java
##########
@@ -105,9 +111,10 @@
    */
   public static final String DR_FILTER_TAG = "dr";
 
-  public GobblinServiceJobScheduler(String serviceName, Config config, Optional<HelixManager> helixManager,
-      Optional<FlowCatalog> flowCatalog, Optional<TopologyCatalog> topologyCatalog, Orchestrator orchestrator,
-      SchedulerService schedulerService, Optional<Logger> log) throws Exception {
+  @Inject

Review comment:
       Should this be a singleton too?

##########
File path: gobblin-service/src/main/java/org/apache/gobblin/service/modules/core/GobblinServiceGuiceModule.java
##########
@@ -0,0 +1,253 @@
+/*
+ * 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.gobblin.service.modules.core;
+
+import java.util.Objects;
+
+import org.apache.helix.HelixManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Binder;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+import com.google.inject.Provider;
+import com.google.inject.multibindings.OptionalBinder;
+import com.google.inject.name.Names;
+import com.typesafe.config.Config;
+
+import javax.inject.Singleton;
+
+import org.apache.gobblin.restli.EmbeddedRestliServer;
+import org.apache.gobblin.runtime.api.GobblinInstanceEnvironment;
+import org.apache.gobblin.runtime.instance.StandardGobblinInstanceLauncher;
+import org.apache.gobblin.runtime.spec_catalog.FlowCatalog;
+import org.apache.gobblin.runtime.spec_catalog.TopologyCatalog;
+import org.apache.gobblin.scheduler.SchedulerService;
+import org.apache.gobblin.service.FlowConfigResourceLocalHandler;
+import org.apache.gobblin.service.FlowConfigV2ResourceLocalHandler;
+import org.apache.gobblin.service.FlowConfigsResource;
+import org.apache.gobblin.service.FlowConfigsResourceHandler;
+import org.apache.gobblin.service.FlowConfigsV2Resource;
+import org.apache.gobblin.service.FlowConfigsV2ResourceHandler;
+import org.apache.gobblin.service.FlowExecutionResource;
+import org.apache.gobblin.service.FlowExecutionResourceHandler;
+import org.apache.gobblin.service.FlowExecutionResourceLocalHandler;
+import org.apache.gobblin.service.FlowStatusResource;
+import org.apache.gobblin.service.GroupOwnershipService;
+import org.apache.gobblin.service.NoopRequesterService;
+import org.apache.gobblin.service.RequesterService;
+import org.apache.gobblin.service.ServiceConfigKeys;
+import org.apache.gobblin.service.modules.orchestration.DagManager;
+import org.apache.gobblin.service.modules.orchestration.Orchestrator;
+import org.apache.gobblin.service.modules.restli.GobblinServiceFlowConfigResourceHandler;
+import org.apache.gobblin.service.modules.restli.GobblinServiceFlowConfigV2ResourceHandler;
+import org.apache.gobblin.service.modules.restli.GobblinServiceFlowExecutionResourceHandler;
+import org.apache.gobblin.service.modules.scheduler.GobblinServiceJobScheduler;
+import org.apache.gobblin.service.modules.topology.TopologySpecFactory;
+import org.apache.gobblin.service.modules.utils.HelixUtils;
+import org.apache.gobblin.service.modules.utils.InjectionNames;
+import org.apache.gobblin.service.monitoring.FlowStatusGenerator;
+import org.apache.gobblin.service.monitoring.FsJobStatusRetriever;
+import org.apache.gobblin.service.monitoring.JobStatusRetriever;
+import org.apache.gobblin.service.monitoring.KafkaJobStatusMonitor;
+import org.apache.gobblin.service.monitoring.KafkaJobStatusMonitorFactory;
+import org.apache.gobblin.util.ClassAliasResolver;
+import org.apache.gobblin.util.ConfigUtils;
+
+
+public class GobblinServiceGuiceModule implements Module {
+  private static final Logger LOGGER = LoggerFactory.getLogger(GobblinServiceGuiceModule.class);
+  private static final String JOB_STATUS_RETRIEVER_CLASS_KEY = "jobStatusRetriever.class";
+
+  GobblinServiceConfiguration serviceConfig;
+
+  public GobblinServiceGuiceModule(GobblinServiceConfiguration serviceConfig) {
+    this.serviceConfig = Objects.requireNonNull(serviceConfig);
+  }
+
+  @Override
+  public void configure(Binder binder) {
+    LOGGER.info("Configuring bindings for the following service settings: {}", serviceConfig);
+
+    // In the current code base, we frequently inject classes instead of interfaces
+    // As a result, even when the binding is missing, Guice will create an instance of the
+    // the class and inject it. This interferes with disabling of different services and
+    // components, because without explicit bindings they will get instantiated anyway.
+    binder.requireExplicitBindings();
+
+    // Optional binder will find the existing binding for T and create additional binding for Optional<T>.
+    // If none of the specific class binding exist, optional will be "absent".
+    OptionalBinder.newOptionalBinder(binder, Logger.class);
+
+    binder.bind(Logger.class).toInstance(LoggerFactory.getLogger(GobblinServiceManager.class));
+
+    binder.bind(Config.class).toInstance(serviceConfig.getInnerConfig());
+
+    binder.bind(GobblinServiceConfiguration.class).toInstance(serviceConfig);
+
+    // Used by TopologyCatalog and FlowCatalog
+    GobblinInstanceEnvironment gobblinInstanceEnvironment = StandardGobblinInstanceLauncher.builder()
+        .withLog(LoggerFactory.getLogger(GobblinServiceManager.class))
+        .setInstrumentationEnabled(true)
+        .withSysConfig(serviceConfig.getInnerConfig())
+        .build();
+
+    binder.bind(GobblinInstanceEnvironment.class).toInstance(gobblinInstanceEnvironment);
+
+    binder.bind(EventBus.class)
+        .annotatedWith(Names.named(GobblinServiceManager.SERVICE_EVENT_BUS_NAME))
+        .toInstance(new EventBus(GobblinServiceManager.class.getSimpleName()));
+
+    binder.bindConstant().annotatedWith(Names.named(InjectionNames.SERVICE_NAME)).to(serviceConfig.getServiceName());
+
+    binder.bindConstant()

Review comment:
       Is the general recommendation then that all service wide constants which were getting passed around in config objects or as arguments use DI instead? 

##########
File path: gobblin-service/src/main/java/org/apache/gobblin/service/modules/orchestration/DagManager.java
##########
@@ -193,7 +194,7 @@ public String toString() {
 
   private volatile boolean isActive = false;
 
-  public DagManager(Config config, boolean instrumentationEnabled) {
+  public DagManager(Config config, JobStatusRetriever jobStatusRetriever, boolean instrumentationEnabled) {

Review comment:
       @Singleton? 




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org