Skip to content

Commit

Permalink
consistent configurations across modules #108
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed Feb 23, 2024
1 parent a680545 commit 9780ff2
Show file tree
Hide file tree
Showing 31 changed files with 434 additions and 298 deletions.
137 changes: 93 additions & 44 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,58 +1,107 @@
#!/bin/bash

echo "==============================================================================="
echo "Building Oasis..."
echo "==============================================================================="
mvn clean install -DskipTests

echo "==============================================================================="
echo "Build the base java image"
echo "==============================================================================="
docker build -t oasis/base-java -f ./buildscripts/docker/base-java.dockerfile .
do_log() {
echo "==============================================================================="
echo "$1"
echo "==============================================================================="
}

proj_build_status() {
case $1 in
'events-api') echo 'true';;
'stats-api') echo 'true';;
'engine') echo 'true';;
'feeder') echo 'true';;
*) echo 'true'
esac
}
skip_build_project=false
do_clean=true
skip_tests=true
build_base_java_image=true
compose_hide_logs="kafka,zookeeper"

# ///////////////////// BUILD PROJECT ////////////////////////////////////

if [ "$skip_build_project" != "true" ]; then
MVN_ARGS=""
if [ "$do_clean" == "true" ]; then
MVN_ARGS+="clean"
fi
MVN_ARGS+=" install "
if [ "$skip_tests" == "true" ]; then
MVN_ARGS+=" -DskipTests "
fi

do_log "⚙️ Building Oasis..."
mvn $MVN_ARGS
else
echo "🔸 Skipped: Building maven project"
fi

# ///////////////////// BUILD DOCKER IMAGES ////////////////////////////////////

do_log "🚢 Creating Containers..."

if [ "$build_base_java_image" == "true" ]; then
do_log "🛠️ Build the base java image"
docker build -t oasis/base-java -f ./buildscripts/docker/base-java.dockerfile .
else
echo "🔸 Skipped: Building base java image"
fi

cp externals/kafka-stream/target/libs/* buildscripts/modules
cp externals/kafka-stream/target/oasis-ext-kafkastream.jar buildscripts/modules

echo "==============================================================================="
echo "Building Events API Docker Image..."
echo "==============================================================================="
cd services/events-api
docker build -t oasis/events-api .

cd ../..

echo "==============================================================================="
echo "Building Admin/Stats API Docker Image..."
echo "==============================================================================="
cd services/stats-api
docker build -t oasis/stats-api .

cd ../..

echo "==============================================================================="
echo "Building Feeder Docker Image..."
echo "==============================================================================="
cd services/feeder
docker build -t oasis/feeder .

cd ../..

echo "==============================================================================="
echo "Building Engine Docker Image..."
echo "==============================================================================="
cd engine
docker build -t oasis/engine .

cd ..
if [ "$(proj_build_status events-api)" == "true" ]; then
do_log "🛠️ Building Events API Docker Image..."
cd services/events-api || exit 1
docker build -t oasis/events-api .
cd ../..
else
echo "🔸 Skipped: Building events-api"
fi

if [ "$(proj_build_status stats-api)" == "true" ]; then
do_log "🛠 Building Admin/Stats API Docker Image..."
cd services/stats-api || exit 1
docker build -t oasis/stats-api .
cd ../..
else
echo "🔸 Skipped: Building stats-api"
fi

if [ "$(proj_build_status feeder)" == "true" ]; then
do_log "🛠️ Building Feeder Docker Image..."
cd services/feeder || exit 1
docker build -t oasis/feeder .
cd ../..
else
echo "🔸 Skipped: Building feeder"
fi

if [ "$(proj_build_status engine)" == "true" ]; then
do_log "🛠️ Building Engine Docker Image..."
cd engine || exit 1
docker build -t oasis/engine .
cd ..
else
echo "🔸 Skipped: Building engine"
fi

mkdir -p .tmpdata/enginedb
mkdir -p .tmpdata/cache


echo "==============================================================================="
echo "Starting Oasis..."
echo "==============================================================================="
docker compose up --no-attach kafka --no-attach zookeeper --no-attach stats-api
do_log "📣 Starting Oasis..."

IFS=',' read -ra LOGS <<< "$compose_hide_logs"
args_logs=""
for log in "${LOGS[@]}"; do
args_logs+="--no-attach $log "
done

docker compose up $args_logs



16 changes: 8 additions & 8 deletions buildscripts/engine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ oasis:
eventstream:
impl: "io.github.oasis.ext.kafkastream.KafkaStreamFactory"
configs:
brokerUrls: "kafka:9092"
brokerUrls: "localhost:9092"

maxConsumerThreadPoolSize: 4

Expand All @@ -18,11 +18,11 @@ oasis:
engineEventConsumer:
props:

redis:
host: enginedb
port: 6379
enginedb:
configs:
url: "redis://localhost:6379"

pool:
max: 16
maxIdle: 8
minIdle: 4
pool:
max: 16
maxIdle: 8
minIdle: 4
8 changes: 4 additions & 4 deletions buildscripts/events-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ http:
oasis:

adminApi:
baseUrl: "http://stats-api:8010/api"
baseUrl: "http://localhost:8010/api"

eventSourceGet: "/admin/event-source"
playerGet: "/players"
Expand All @@ -23,10 +23,10 @@ oasis:
secretKey: "eventapi"


dispatcher:
eventstream:
impl: "oasis:io.github.oasis.ext.kafkastream.KafkaStreamFactory"
configs:
brokerUrls: "kafka:9092"
brokerUrls: "localhost:9092"

maxConsumerThreadPoolSize: 4

Expand Down Expand Up @@ -58,7 +58,7 @@ oasis:
cache:
impl: "oasis:io.github.oasis.services.events.db.RedisVerticle"
configs:
connectionString: "redis://apicache:6381"
connectionString: "redis://localhost:6379"
maxPoolSize: 16
maxWaitingHandlers: 16

Expand Down
4 changes: 2 additions & 2 deletions buildscripts/feeder.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
oasis:
adminApi:
baseUrl: "http://stats-api:8010/api"
baseUrl: "http://localhost:8010/api"

eventSourceGet: "/admin/event-sources/"
playerGet: "/players/"
Expand All @@ -21,7 +21,7 @@ oasis:
eventstream:
impl: "io.github.oasis.ext.kafkastream.KafkaStreamFactory"
configs:
brokerUrls: "kafka:9092"
brokerUrls: "localhost:9092"

feedStreamConsumer:
groupId: feed-consumer-group
Expand Down
26 changes: 12 additions & 14 deletions buildscripts/stats-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ oasis:
defaultApiKey: "root:root,eventapi:eventapi,feeder:feeder:7"

cache:
host: "apicache"
port: 6379
url: "redis://localhost:6381"

connectionRetries: 5
connectionRetryDelay: 5000
Expand All @@ -24,8 +23,7 @@ oasis:
minIdle: 4

enginedb:
host: "enginedb"
port: 6379
url: "redis://localhost:6379"

connectionRetries: 5
connectionRetryDelay: 5000
Expand All @@ -35,24 +33,24 @@ oasis:
maxIdle: 16
minIdle: 4

dispatcher:
eventstream:
impl: "io.github.oasis.ext.kafkastream.KafkaStreamFactory"
configs:
brokerUrls: "kafka:9092"
brokerUrls: "localhost:9092"

maxConsumerThreadPoolSize: 4

gameEventsConsumer:
# groupId: ""
# groupId: ""

# If not specified, this will take engine id
# instanceId: ""
# If not specified, this will take engine id
# instanceId: ""

# These props will directly feed to Kafka property configs
# Check kafka consumer documentation for supported props.
# props:
#"max.poll.records": 10,
#"session.timeout.ms": 86400000
# These props will directly feed to Kafka property configs
# Check kafka consumer documentation for supported props.
# props:
#"max.poll.records": 10,
#"session.timeout.ms": 86400000

broadcastConsumer:
# groupId: ""
Expand Down
22 changes: 18 additions & 4 deletions core/src/main/java/io/github/oasis/core/configs/OasisConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
public class OasisConfigs implements Serializable {

private static final String DEFAULT_ENV_PREFIX = "OASIS_";
private static final String DEFAULT_ENV_PREFIX = "O_";

public static final String GAME_SUPERVISOR_COUNT = "oasis.supervisors.game";
public static final String RULE_SUPERVISOR_COUNT = "oasis.supervisors.rule";
Expand All @@ -62,14 +62,22 @@ public class OasisConfigs implements Serializable {

private DocumentContext ctx;

private OasisConfigs(Map<String, Object> configValues, String envVarPrefix, Supplier<Map<String, String>> envVarSupplier) {
this.envVarPrefix = Objects.toString(envVarPrefix, DEFAULT_ENV_PREFIX);
private OasisConfigs(Map<String, Object> configValues, String theEnvVarPrefix, Supplier<Map<String, String>> envVarSupplier) {
this.envVarPrefix = deriveEnvVarPrefix(theEnvVarPrefix);
this.configValues = configValues;

this.loadEnvVariables(Objects.requireNonNullElse(envVarSupplier, defaultEnvVarSupplier));
this.createConfigContext(configValues);
}

private String deriveEnvVarPrefix(String theEnvVarPrefix) {
if (theEnvVarPrefix != null) {
return theEnvVarPrefix;
}

return System.getProperty("oasis.config.env.prefix", DEFAULT_ENV_PREFIX);
}

private void createConfigContext(Map<String, Object> configValues) {
var jsonObject = new JsonObject(configValues);
ctx = JsonPath.parse(jsonObject.toJson(), jsonPathConf);
Expand All @@ -92,7 +100,7 @@ private Optional<String> readFromEnvVar(String prop) {
}

public Map<String, Object> getAll() {
return Collections.unmodifiableMap(configValues);
return Collections.unmodifiableMap(resolveWithEnvVars(configValues, null));
}

public boolean hasProperty(String property) {
Expand Down Expand Up @@ -150,6 +158,7 @@ public Map<String, Object> getObject(String property) {
return resolveWithEnvVars(value, property);
}

@SuppressWarnings("unchecked")
private Map<String, Object> resolveWithEnvVars(Map<String, Object> configs, String baseProperty) {
var result = new HashMap<String, Object>();

Expand All @@ -166,6 +175,8 @@ private Map<String, Object> resolveWithEnvVars(Map<String, Object> configs, Stri
result.put(k, getFloat(concat(baseProperty, k), (Float) v));
} else if (v instanceof Double) {
result.put(k, getDouble(concat(baseProperty, k), (Double) v));
} else if (v instanceof Map<?,?>) {
result.put(k, resolveWithEnvVars((Map<String, Object>) v, concat(baseProperty, k)));
} else {
result.put(k, v);
}
Expand All @@ -182,6 +193,9 @@ private String concat(String base, String property) {
if (base == null) {
return "$." + property;
} else {
if (base.startsWith("$.")) {
return base.substring(2) + "." + property;
}
return base + "." + property;
}
}
Expand Down
Loading

0 comments on commit 9780ff2

Please sign in to comment.