Skip to content

Commit

Permalink
concord-agent: bind classes explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
ibodrov committed Nov 21, 2023
1 parent 96f82e0 commit 254b3b5
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 101 deletions.
4 changes: 4 additions & 0 deletions agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions agent/src/main/java/com/walmartlabs/concord/agent/Agent.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,13 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean;

@Named
@Singleton
public class Agent {

private static final Logger log = LoggerFactory.getLogger(Agent.class);
Expand Down
81 changes: 81 additions & 0 deletions agent/src/main/java/com/walmartlabs/concord/agent/AgentModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.walmartlabs.concord.agent;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2023 Walmart Inc.
* -----
* Licensed 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.
* =====
*/

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.typesafe.config.Config;
import com.walmartlabs.concord.agent.cfg.*;
import com.walmartlabs.concord.agent.executors.runner.DefaultDependencies;
import com.walmartlabs.concord.agent.executors.runner.ProcessPool;
import com.walmartlabs.concord.agent.remote.ApiClientFactory;
import com.walmartlabs.concord.agent.remote.QueueClientProvider;
import com.walmartlabs.concord.server.queueclient.QueueClient;
import com.walmartlabs.ollie.config.ConfigurationProcessor;
import com.walmartlabs.ollie.config.Environment;
import com.walmartlabs.ollie.config.EnvironmentSelector;

import javax.inject.Named;

import static com.google.inject.Scopes.SINGLETON;

@Named
public class AgentModule implements Module {

private final Config config;

public AgentModule() {
this(loadDefaultConfig());
}

public AgentModule(Config config) {
this.config = config;
}

@Override
public void configure(Binder binder) {
binder.bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class);
binder.bind(Config.class).toInstance(config);

binder.bind(AgentConfiguration.class).in(SINGLETON);
binder.bind(DockerConfiguration.class).in(SINGLETON);
binder.bind(GitConfiguration.class).in(SINGLETON);
binder.bind(ImportConfiguration.class).in(SINGLETON);
binder.bind(PreForkConfiguration.class).in(SINGLETON);
binder.bind(RepositoryCacheConfiguration.class).in(SINGLETON);
binder.bind(RunnerV1Configuration.class).in(SINGLETON);
binder.bind(RunnerV2Configuration.class).in(SINGLETON);
binder.bind(ServerConfiguration.class).in(SINGLETON);

binder.bind(DefaultDependencies.class).in(SINGLETON);
binder.bind(ProcessPool.class).in(SINGLETON);
binder.bind(ApiClientFactory.class).in(SINGLETON);
binder.bind(QueueClient.class).toProvider(QueueClientProvider.class).in(SINGLETON);

binder.bind(Agent.class).in(SINGLETON);
}

private static Config loadDefaultConfig() {
Environment env = new EnvironmentSelector().select();
return new ConfigurationProcessor("concord-agent", env, null, null).process();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,34 @@
* =====
*/

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.guava.GuavaModule;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

@Named
@Singleton
public class ObjectMapperProvider implements Provider<ObjectMapper> {

@Override
public ObjectMapper get() {
return new ObjectMapper();
ObjectMapper mapper = new ObjectMapper()
.registerModule(new Jdk8Module())
.registerModule(new GuavaModule())
.registerModule(new JavaTimeModule());

// Write dates as ISO-8601
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);

// Ignore unknown properties
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);

// Ignore nulls
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

return mapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.nio.file.Path;
import java.time.Duration;
import java.util.List;
Expand All @@ -37,8 +35,6 @@
import static com.walmartlabs.concord.agent.cfg.Utils.getOrCreatePath;
import static com.walmartlabs.concord.agent.cfg.Utils.getStringOrDefault;

@Named
@Singleton
public class AgentConfiguration {

private static final Logger log = LoggerFactory.getLogger(AgentConfiguration.class);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,9 @@
import com.typesafe.config.Config;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Named
@Singleton
public class DockerConfiguration {

private final String dockerHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

import static com.walmartlabs.concord.agent.cfg.Utils.getStringOrDefault;

@Named
@Singleton
public class GitConfiguration {

private final String token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
import com.typesafe.config.Config;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

@Named
@Singleton
public class ImportConfiguration {

private final Set<String> disabledProcessors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,8 @@
import com.typesafe.config.Config;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.concurrent.TimeUnit;

@Named
@Singleton
public class PreForkConfiguration {

private final boolean enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@
import com.typesafe.config.Config;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.nio.file.Path;
import java.time.Duration;

import static com.walmartlabs.concord.agent.cfg.Utils.getOrCreatePath;

@Named
@Singleton
public class RepositoryCacheConfiguration {

private final Path cacheDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
import com.typesafe.config.Config;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

@Named
@Singleton
public class RunnerV1Configuration extends AbstractRunnerConfiguration {

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
import com.typesafe.config.Config;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

@Named
@Singleton
public class RunnerV2Configuration extends AbstractRunnerConfiguration {

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.concurrent.TimeUnit;

import static com.walmartlabs.concord.agent.cfg.Utils.getStringOrDefault;

@Named
@Singleton
public class ServerConfiguration {

private static final Logger log = LoggerFactory.getLogger(ServerConfiguration.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Named;
import javax.inject.Singleton;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -37,8 +35,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Named
@Singleton
public class DefaultDependencies {

private static final Logger log = LoggerFactory.getLogger(DefaultDependencies.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Named
@Singleton
public class ProcessPool {

private static final Logger log = LoggerFactory.getLogger(ProcessPool.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@
import com.walmartlabs.concord.common.IOUtils;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Named
@Singleton
public class ApiClientFactory {

private static final String SESSION_COOKIE_NAME = "JSESSIONID";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@
import com.walmartlabs.concord.server.queueclient.QueueClientConfiguration;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import java.net.URISyntaxException;

@Named
@Singleton
public class QueueClientProvider implements Provider<QueueClient> {

private final AgentConfiguration agentCfg;
Expand Down

0 comments on commit 254b3b5

Please sign in to comment.