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

multiregion config files #96

Merged
merged 1 commit into from
Feb 26, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void launchServer(String[] args) throws Exception {
protected void infrastructureInit() {
MainClassUtils.setupJbossLoggingToUseSlf4j();

Pair<String, String> appIdAndEnvironmentPair = MainClassUtils.getAppIdAndEnvironmentFromSystemProperties();
Pair<String, String> appIdAndEnvironmentPair = getAppIdAndEnvironmentPair();
Config appConfig = TypesafeConfigUtil
.loadConfigForAppIdAndEnvironment(appIdAndEnvironmentPair.getLeft(), appIdAndEnvironmentPair.getRight());

Expand All @@ -97,6 +97,19 @@ protected void infrastructureInit() {
setAppConfig(appConfig);
}

/**
* Allow the appId and Environment to be overridden when loading TypesafeConfig files.
* This will support resolution of different TypesafeConfig files without globally modifying the
* appId or environment. This would allow region specific property files
* while still maintaining the same appId or environment variables.
*
* @return {@code Pair<String,String>} with the {@code Left} the appId of the TypesafeConfig to load
* and the {@code Right} the Environment.
*/
protected Pair<String,String> getAppIdAndEnvironmentPair(){
return MainClassUtils.getAppIdAndEnvironmentFromSystemProperties();
}

/**
* Creates the {@link Server} instance using {@link #getServerConfig(Config)} and {@link #getAppConfig()}, then
* calls {@link Server#startup()}. DO NOT CALL THIS DIRECTLY. Use {@link #launchServer(String[])} when you're ready
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nike.riposte.typesafeconfig;

import com.nike.internal.util.Pair;
import com.nike.riposte.server.config.ServerConfig;
import com.nike.riposte.server.http.Endpoint;
import com.nike.riposte.server.http.RequestInfo;
Expand All @@ -21,6 +22,7 @@
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;

import io.netty.channel.ChannelHandlerContext;
import io.netty.util.ResourceLeakDetector;
Expand Down Expand Up @@ -115,6 +117,30 @@ public void verify_essential_behavior() throws Exception {
assertThat(ResourceLeakDetector.getLevel()).isEqualTo(ResourceLeakDetector.Level.PARANOID);
}

@Test
public void getAppIdAndEnvironmentPair(){
// given
setAppAndEnvironment("typesafeconfigserver", "compiletimetest");

AtomicBoolean called = new AtomicBoolean(false);
// when
TypesafeConfigServer server = new TypesafeConfigServer(){
protected ServerConfig getServerConfig(Config appConfig){
return null;
}

@Override
protected Pair<String, String> getAppIdAndEnvironmentPair() {
called.set(true);
return super.getAppIdAndEnvironmentPair();
}
};
server.infrastructureInit();

// then (verify that getAppIdAndEnvironmentPair was called from infrastructureInit)
assertThat(called.get()).isTrue();
}

private static class SomeEndpoint extends StandardEndpoint<Void, String> {

public static final String MATCHING_PATH = "/typesafeConfigValue";
Expand Down