Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

concord-server: remove more @Named #828

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<module>runtime-v1</module>
<module>runtime-v2</module>
<module>compat</module>

<module>testing-server</module>
</modules>

<properties>
Expand Down
49 changes: 49 additions & 0 deletions it/testing-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.walmartlabs.concord.it</groupId>
<artifactId>parent</artifactId>
<version>2.1.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>testing-concord-server</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>com.walmartlabs.concord.server</groupId>
<artifactId>concord-server</artifactId>
<exclusions>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins.ansible</groupId>
<artifactId>concord-ansible-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins</groupId>
<artifactId>concord-oneops-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins.noderoster</groupId>
<artifactId>concord-noderoster-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>com.walmartlabs.concord.server.plugins</groupId>
<artifactId>pfed-sso</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.walmartlabs.concord.it.testingserver;

/*-
* *****
* 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.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigParseOptions;
import com.typesafe.config.ConfigResolveOptions;
import com.walmartlabs.concord.server.ConcordServer;
import com.walmartlabs.concord.server.ConcordServerModule;
import org.testcontainers.containers.PostgreSQLContainer;

import java.security.SecureRandom;
import java.util.Base64;
import java.util.Map;

public class TestingConcordServer implements AutoCloseable {

private PostgreSQLContainer<?> db;
private ConcordServer server;

public TestingConcordServer start() throws Exception {
db = new PostgreSQLContainer<>("postgres:15-alpine");
db.start();

server = ConcordServer.withModules(new ConcordServerModule(prepareConfig(db)))
.start();

return this;
}

@Override
public void close() throws Exception {
this.stop();
}

public void stop() throws Exception {
if (server != null) {
server.stop();
server = null;
}

if (db != null) {
db.stop();
db = null;
}
}

private static Config prepareConfig(PostgreSQLContainer<?> db) {
Config testConfig = ConfigFactory.parseMap(Map.of(
"db.url", db.getJdbcUrl(),
"db.appUsername", db.getUsername(),
"db.appPassword", db.getPassword(),
"db.inventoryUsername", db.getUsername(),
"db.inventoryPassword", db.getPassword(),
"db.changeLogParameters.defaultAdminToken", "foobar",
"secretStore.serverPassword", randomString(),
"secretStore.secretStoreSalt", randomString(),
"secretStore.projectSecretSalt", randomString()
));

Config defaultConfig = ConfigFactory.load("concord-server.conf", ConfigParseOptions.defaults(), ConfigResolveOptions.defaults().setAllowUnresolved(true))
.getConfig("concord-server");

return testConfig.withFallback(defaultConfig).resolve();
}

private static String randomString() {
byte[] ab = new byte[64];
new SecureRandom().nextBytes(ab);
return Base64.getEncoder().encodeToString(ab);
}

public static void main(String[] args) throws Exception {
TestingConcordServer server = new TestingConcordServer().start();
Thread.sleep(100000);
server.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public final class ConcordServer {
*/
public static ConcordServer withAutoWiring() throws Exception {
ClassLoader cl = ConcordServer.class.getClassLoader();
return withModules(new WireModule(new SpaceModule(new URLClassSpace(cl), BeanScanning.GLOBAL_INDEX)));
return withModules(
new WireModule(new SpaceModule(new URLClassSpace(cl), BeanScanning.GLOBAL_INDEX)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* 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.
Expand All @@ -22,22 +22,30 @@

import com.google.inject.Binder;
import com.google.inject.Module;
import com.typesafe.config.Config;
import com.walmartlabs.concord.db.DatabaseModule;
import com.walmartlabs.concord.dependencymanager.DependencyManagerConfiguration;
import com.walmartlabs.concord.server.agent.AgentModule;
import com.walmartlabs.concord.server.audit.AuditLogModule;
import com.walmartlabs.concord.server.boot.BackgroundTasks;
import com.walmartlabs.concord.server.cfg.ConfigurationModule;
import com.walmartlabs.concord.server.cfg.DatabaseConfigurationModule;
import com.walmartlabs.concord.server.console.ConsoleModule;
import com.walmartlabs.concord.server.events.EventModule;
import com.walmartlabs.concord.server.metrics.MetricModule;
import com.walmartlabs.concord.server.org.secret.SecretModule;
import com.walmartlabs.concord.server.org.triggers.TriggersModule;
import com.walmartlabs.concord.server.policy.PolicyModule;
import com.walmartlabs.concord.server.process.ProcessModule;
import com.walmartlabs.concord.server.repository.RepositoryModule;
import com.walmartlabs.concord.server.role.RoleModule;
import com.walmartlabs.concord.server.security.SecurityModule;
import com.walmartlabs.concord.server.security.apikey.ApiKeyModule;
import com.walmartlabs.concord.server.task.TaskSchedulerModule;
import com.walmartlabs.concord.server.template.TemplateModule;
import com.walmartlabs.ollie.config.ConfigurationProcessor;
import com.walmartlabs.ollie.config.Environment;
import com.walmartlabs.ollie.config.EnvironmentSelector;

import javax.inject.Named;

Expand All @@ -50,9 +58,19 @@
@Named
public class ConcordServerModule implements Module {

private final Config config;

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

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

@Override
public void configure(Binder binder) {
binder.install(new ConfigurationModule());
binder.install(new ConfigurationModule(config));
binder.install(new MetricModule());

binder.install(new DatabaseConfigurationModule());
Expand All @@ -61,18 +79,28 @@ public void configure(Binder binder) {
binder.install(new TaskSchedulerModule());
binder.bind(BackgroundTasks.class).in(SINGLETON);

binder.bind(DependencyManagerConfiguration.class).toProvider(DependencyManagerConfigurationProvider.class);

binder.install(new AgentModule());
binder.install(new ApiKeyModule());
binder.install(new ConsoleModule());
binder.install(new ApiServerModule());
binder.install(new AuditLogModule());
binder.install(new ConsoleModule());
binder.install(new EventModule());
binder.install(new PolicyModule());
binder.install(new ProcessModule());
binder.install(new RepositoryModule());
binder.install(new RoleModule());
binder.install(new SecretModule());
binder.install(new SecurityModule());
binder.install(new TemplateModule());
binder.install(new TriggersModule());

bindJaxRsResource(binder, ServerResource.class);
}

private static Config loadDefaultConfig() {
Environment env = new EnvironmentSelector().select();
return new ConfigurationProcessor("concord-server", env, null, null).process();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@
import com.walmartlabs.concord.server.cfg.DependenciesConfiguration;

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

@Named
@Singleton
public class DependencyManagerConfigurationProvider implements Provider<DependencyManagerConfiguration> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@

import com.google.inject.Binder;
import com.google.inject.Module;
import com.walmartlabs.concord.server.sdk.audit.AuditLogListener;

import static com.google.inject.multibindings.Multibinder.newSetBinder;
import static com.walmartlabs.concord.server.Utils.bindJaxRsResource;
import static com.walmartlabs.concord.server.Utils.bindSingletonScheduledTask;

public class AuditLogModule implements Module {

@Override
public void configure(Binder binder) {
newSetBinder(binder, AuditLogListener.class);
bindSingletonScheduledTask(binder, AuditLogCleaner.class);
bindJaxRsResource(binder, AuditLogResource.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@

import com.google.inject.Binder;
import com.google.inject.Module;
import com.walmartlabs.ollie.config.ConfigurationProcessor;
import com.walmartlabs.ollie.config.Environment;
import com.walmartlabs.ollie.config.EnvironmentSelector;
import com.walmartlabs.ollie.config.OllieConfigurationModule;
import com.typesafe.config.Config;

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

public class ConfigurationModule implements Module {

private final Config config;

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

@Override
public void configure(Binder binder) {
Environment env = new EnvironmentSelector().select();
com.typesafe.config.Config config = new ConfigurationProcessor("concord-server", env, null, null).process();
binder.install(new OllieConfigurationModule("com.walmartlabs.concord.server", config));
binder.install(new com.walmartlabs.ollie.config.OllieConfigurationModule("com.walmartlabs.concord.server", config));

binder.bind(AgentConfiguration.class).in(SINGLETON);
binder.bind(ApiKeyConfiguration.class).in(SINGLETON);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.walmartlabs.concord.server.events;

/*-
* *****
* 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.google.inject.Binder;
import com.google.inject.Module;
import com.walmartlabs.concord.server.sdk.events.ProcessEventListener;

import static com.google.inject.multibindings.Multibinder.newSetBinder;

public class EventModule implements Module {

@Override
public void configure(Binder binder) {
newSetBinder(binder, ProcessEventListener.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.matcher.Matchers;
import com.walmartlabs.concord.server.sdk.metrics.GaugeProvider;
import com.walmartlabs.concord.server.sdk.metrics.WithTimer;

import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.multibindings.Multibinder.newSetBinder;
import static com.walmartlabs.concord.server.Utils.bindServletHolder;
import static com.walmartlabs.concord.server.Utils.bindSingletonBackgroundTask;
import static com.walmartlabs.concord.server.metrics.NoSyntheticMethodMatcher.INSTANCE;
Expand All @@ -35,6 +37,10 @@ public class MetricModule implements Module {

@Override
public void configure(Binder binder) {
// common

newSetBinder(binder, GaugeProvider.class);

// registry

binder.bind(MetricRegistry.class).toProvider(MetricRegistryProvider.class).in(SINGLETON);
Expand All @@ -50,9 +56,9 @@ public void configure(Binder binder) {

// tasks

bindSingletonBackgroundTask(binder, MetricsRegistrator.class);
bindSingletonBackgroundTask(binder, FailedTaskMetrics.class);
bindSingletonBackgroundTask(binder, WorkerMetrics.class);
bindSingletonBackgroundTask(binder, MetricsRegistrator.class);

// the /metrics endpoint

Expand Down
Loading
Loading