[
https://issues.apache.org/jira/browse/GOBBLIN-1444?focusedWorklogId=608628&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-608628
]
ASF GitHub Bot logged work on GOBBLIN-1444:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 08/Jun/21 17:13
Start Date: 08/Jun/21 17:13
Worklog Time Spent: 10m
Work Description: aplex commented on a change in pull request #3281:
URL: https://github.com/apache/gobblin/pull/3281#discussion_r647638477
##########
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:
If the class has many configuration settings, than it's better to have a
config object and inject it. That's what we do for GobblinServiceManager that
gets GobblinServiceConfiguration injected into it.
Service name is injected into a couple of classes that don't have much in
common, and those classes don't have a lot of configuration of their own. In
future PRs we can consider adding something like ServiceEnvironment class that
will hold the service name, id and other properties that can be useful for the
classes that run inside Gobblin service.
There are still a bunch of places in the code that needs to be refactored
for better DI support, but I left them out at the moment to reduce the PR size.
--
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 608628)
Time Spent: 5h 20m (was: 5h 10m)
> Use Guice as DI framework in Gobblin service
> --------------------------------------------
>
> Key: GOBBLIN-1444
> URL: https://issues.apache.org/jira/browse/GOBBLIN-1444
> Project: Apache Gobblin
> Issue Type: Improvement
> Components: gobblin-service
> Reporter: Alex Prokofiev
> Assignee: Abhishek Tiwari
> Priority: Major
> Time Spent: 5h 20m
> Remaining Estimate: 0h
>
> Currently, to initialize Gobblin service, we used a mixture of dependency
> injection, direct class creation and config-based class creation. In this
> change, we unify the service initialization by moving towards using
> dependency injection(DI) with Guice everywhere.
> Using DI will help with (1) unit testing; (2) overriding classes in the
> middle of the dependency with company-specific implementations, and (3) will
> improve code readability, as dependencies between classes become visible from
> the outside and explicit.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)