diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..0ea857e119 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,205 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Sep Server: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunSepServer", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Platform Server: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunPlatformServer", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Custody Server: custody", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunCustodyServer", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Event Processing Server: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunEventProcessingServer", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Horizon Observer: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunStellarObserver", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Soroban Observer: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunStellarObserver", + "envFile": "${workspaceFolder}/.env", + "env": { + "stellar_network.rpc_url": "https://soroban-testnet.stellar.org" + } + }, + { + "type": "java", + "name": "Reference Server: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunKotlinReferenceServer", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "default" + } + }, + { + "type": "java", + "name": "Wallet Reference Server: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunWalletServer", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Docker - Run Dev Stack - Kafka, Postgres, SEP24 Reference UI", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunDockerDevStack", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Test Profile: default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Test Profile: default - horizon", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "default-horizon" + } + }, + { + "type": "java", + "name": "Test Profile: auth-apikey-custody", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "auth-apikey-custody" + } + }, + { + "type": "java", + "name": "Test Profile: auth-apikey-platform", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "auth-apikey-platform" + } + }, + { + "type": "java", + "name": "Test Profile: auth-jwt-custody", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "auth-jwt-custody" + } + }, + { + "type": "java", + "name": "Test Profile: auth-jwt-platform", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "auth-jwt-platform" + } + }, + { + "type": "java", + "name": "Test Profile: custody", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "custody" + } + }, + { + "type": "java", + "name": "Test Profile: deployment", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "deployment" + } + }, + { + "type": "java", + "name": "Test Profile: host.docker.internal", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "console": "internalConsole", + "internalConsoleOptions": "openOnSessionStart" + }, + { + "type": "java", + "name": "Test Profile: kafka-sasl-ssl", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "kafka-sasl-ssl" + } + }, + { + "type": "java", + "name": "Test Profile: rpc", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "rpc" + } + }, + { + "type": "java", + "name": "Test Profile: soroban-rpc-default", + "request": "launch", + "mainClass": "org.stellar.anchor.platform.run_profiles.RunTestProfile", + "envFile": "${workspaceFolder}/.env", + "env": { + "TEST_PROFILE_NAME": "soroban-rpc-default" + } + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..6e2074b379 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic", + "java.debug.settings.enableRunDebugCodeLens": true, + "java.debug.settings.hotCodeReplace": "auto", + "java.debug.settings.vmArgs": "", + "java.compile.nullAnalysis.mode": "automatic", + "java.configuration.runtimes": [], + "java.jdt.ls.java.home": "", + "java.import.gradle.enabled": true, + "java.import.gradle.wrapper.enabled": true +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/scripts/docker-start.sh b/scripts/docker-start.sh old mode 100644 new mode 100755 diff --git a/service-runner/src/main/java/org/stellar/anchor/platform/ServiceRunner.java b/service-runner/src/main/java/org/stellar/anchor/platform/ServiceRunner.java deleted file mode 100644 index 3e04c2adec..0000000000 --- a/service-runner/src/main/java/org/stellar/anchor/platform/ServiceRunner.java +++ /dev/null @@ -1,159 +0,0 @@ -package org.stellar.anchor.platform; - -import static org.stellar.anchor.util.Log.*; - -import java.util.Map; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.jetbrains.annotations.NotNull; -import org.springframework.context.ConfigurableApplicationContext; -import org.stellar.anchor.api.shared.Metadata; -import org.stellar.reference.ReferenceServerStartKt; -import org.stellar.reference.wallet.WalletServerStartKt; - -public class ServiceRunner { - public static void main(String[] args) { - printBanner(); - startServers(args); - } - - private static void startServers(String[] args) { - Options options = getOptions(); - try { - CommandLine cmd = new DefaultParser().parse(options, args); - boolean anyServerStarted = false; - if (cmd.hasOption("sep-server") || cmd.hasOption("all")) { - startSepServer(null); - anyServerStarted = true; - } - - if (cmd.hasOption("custody-server") || cmd.hasOption("all")) { - startCustodyServer(null); - anyServerStarted = true; - } - - if (cmd.hasOption("platform-server") || cmd.hasOption("all")) { - startPlatformServer(null); - anyServerStarted = true; - } - - if (cmd.hasOption("stellar-observer") || cmd.hasOption("all")) { - startStellarObserver(null); - anyServerStarted = true; - } - - if (cmd.hasOption("event-processor") || cmd.hasOption("all")) { - startEventProcessingServer(null); - anyServerStarted = true; - } - - if (cmd.hasOption("kotlin-reference-server") || cmd.hasOption("all")) { - startKotlinReferenceServer(null, true); - anyServerStarted = true; - } - - if (cmd.hasOption("wallet-reference-server") || cmd.hasOption("all")) { - startWalletServer(null, true); - anyServerStarted = true; - } - - if (cmd.hasOption("test-profile-runner")) { - startTestProfileRunner(); - anyServerStarted = true; - } - - if (!anyServerStarted) { - printUsage(options); - } - } catch (ParseException e) { - printUsage(options); - } - } - - private static void printBanner() { - System.out.println("****************************************"); - System.out.println(" Anchor Platform "); - System.out.println(" Version " + getVersion()); - System.out.println("****************************************"); - } - - @NotNull - private static Options getOptions() { - Options options = new Options(); - options.addOption("h", "help", false, "Print this message."); - options.addOption("a", "all", false, "Start all servers."); - options.addOption("s", "sep-server", false, "Start SEP endpoint server."); - options.addOption("c", "custody-server", false, "Start Custody server."); - options.addOption("p", "platform-server", false, "Start Platform API endpoint server."); - options.addOption( - "o", "stellar-observer", false, "Start Observer that streams from the Stellar blockchain."); - options.addOption("e", "event-processor", false, "Start the event processor."); - options.addOption("k", "kotlin-reference-server", false, "Start Kotlin reference server."); - options.addOption("w", "wallet-reference-server", false, "Start wallet reference server."); - options.addOption("t", "test-profile-runner", false, "Run the stack with test profile."); - return options; - } - - public static ConfigurableApplicationContext startSepServer(Map env) { - info("Starting SEP server..."); - return new SepServer().start(env); - } - - public static ConfigurableApplicationContext startPlatformServer(Map env) { - info("Starting platform server..."); - return new PlatformServer().start(env); - } - - public static ConfigurableApplicationContext startCustodyServer(Map env) { - info("Starting custody server..."); - return new CustodyServer().start(env); - } - - public static ConfigurableApplicationContext startStellarObserver(Map env) { - info("Starting observer..."); - return new StellarObservingServer().start(env); - } - - public static ConfigurableApplicationContext startEventProcessingServer(Map env) { - info("Starting event processing server..."); - return new EventProcessingServer().start(env); - } - - public static void startKotlinReferenceServer(Map envMap, boolean wait) { - try { - info("Starting Kotlin reference server..."); - ReferenceServerStartKt.start(envMap, wait); - } catch (Exception e) { - errorEx("Error starting reference server", e); - throw e; - } - } - - public static void startWalletServer(Map envMap, boolean wait) { - try { - info("Starting wallet server..."); - WalletServerStartKt.start(envMap, wait); - } catch (Exception e) { - errorEx("Error starting wallet server", e); - throw e; - } - } - - public static void startTestProfileRunner() { - info("Running test profile runner"); - TestProfileRunner.main(); - } - - static void printUsage(Options options) { - HelpFormatter helper = new HelpFormatter(); - helper.setOptionComparator(null); - helper.printHelp("java -jar anchor-platform.jar", options); - } - - static String getVersion() { - return Metadata.getVersion(); - } -} diff --git a/service-runner/src/main/kotlin/org/stellar/anchor/platform/ServiceRunner.kt b/service-runner/src/main/kotlin/org/stellar/anchor/platform/ServiceRunner.kt new file mode 100644 index 0000000000..a3111b113b --- /dev/null +++ b/service-runner/src/main/kotlin/org/stellar/anchor/platform/ServiceRunner.kt @@ -0,0 +1,174 @@ +package org.stellar.anchor.platform + +import org.apache.commons.cli.DefaultParser +import org.apache.commons.cli.HelpFormatter +import org.apache.commons.cli.Options +import org.apache.commons.cli.ParseException +import org.jetbrains.annotations.NotNull +import org.springframework.context.ConfigurableApplicationContext +import org.stellar.anchor.api.shared.Metadata +import org.stellar.anchor.platform.main as testProfileRunnerMain +import org.stellar.anchor.util.Log.errorEx +import org.stellar.anchor.util.Log.info +import org.stellar.reference.start as startReferenceServer +import org.stellar.reference.wallet.start as startWalletServerFunction + +object ServiceRunner { + @JvmStatic + fun main(args: Array) { + printBanner() + startServers(args) + } + + private fun startServers(args: Array) { + val options = getOptions() + try { + val cmd = DefaultParser().parse(options, args) + var anyServerStarted = false + + if (cmd.hasOption("sep-server") || cmd.hasOption("all")) { + startSepServer(null) + anyServerStarted = true + } + + if (cmd.hasOption("custody-server") || cmd.hasOption("all")) { + startCustodyServer(null) + anyServerStarted = true + } + + if (cmd.hasOption("platform-server") || cmd.hasOption("all")) { + startPlatformServer(null) + anyServerStarted = true + } + + if (cmd.hasOption("stellar-observer") || cmd.hasOption("all")) { + startStellarObserver(null) + anyServerStarted = true + } + + if (cmd.hasOption("event-processor") || cmd.hasOption("all")) { + startEventProcessingServer(null) + anyServerStarted = true + } + + if (cmd.hasOption("kotlin-reference-server") || cmd.hasOption("all")) { + startKotlinReferenceServer(null, true) + anyServerStarted = true + } + + if (cmd.hasOption("wallet-reference-server") || cmd.hasOption("all")) { + startWalletServer(null, true) + anyServerStarted = true + } + + if (cmd.hasOption("test-profile-runner")) { + startTestProfileRunner() + anyServerStarted = true + } + + if (!anyServerStarted) { + printUsage(options) + } + } catch (e: ParseException) { + printUsage(options) + } + } + + private fun printBanner() { + println("****************************************") + println(" Anchor Platform ") + println(" Version ${getVersion()}") + println("****************************************") + } + + @NotNull + private fun getOptions(): Options { + val options = Options() + options.addOption("h", "help", false, "Print this message.") + options.addOption("a", "all", false, "Start all servers.") + options.addOption("s", "sep-server", false, "Start SEP endpoint server.") + options.addOption("c", "custody-server", false, "Start Custody server.") + options.addOption("p", "platform-server", false, "Start Platform API endpoint server.") + options.addOption( + "o", + "stellar-observer", + false, + "Start Observer that streams from the Stellar blockchain." + ) + options.addOption("e", "event-processor", false, "Start the event processor.") + options.addOption("k", "kotlin-reference-server", false, "Start Kotlin reference server.") + options.addOption("w", "wallet-reference-server", false, "Start wallet reference server.") + options.addOption("t", "test-profile-runner", false, "Run the stack with test profile.") + return options + } + + @JvmStatic + fun startSepServer(env: Map?): ConfigurableApplicationContext { + info("Starting SEP server...") + return SepServer().start(env) + } + + @JvmStatic + fun startPlatformServer(env: Map?): ConfigurableApplicationContext { + info("Starting platform server...") + return PlatformServer().start(env) + } + + @JvmStatic + fun startCustodyServer(env: Map?): ConfigurableApplicationContext { + info("Starting custody server...") + return CustodyServer().start(env) + } + + @JvmStatic + fun startStellarObserver(env: Map?): ConfigurableApplicationContext { + info("Starting observer...") + return StellarObservingServer().start(env) + } + + @JvmStatic + fun startEventProcessingServer(env: Map?): ConfigurableApplicationContext { + info("Starting event processing server...") + return EventProcessingServer().start(env) + } + + @JvmStatic + fun startKotlinReferenceServer(envMap: Map?, wait: Boolean) { + try { + info("Starting Kotlin reference server...") + startReferenceServer(envMap, wait) + } catch (e: Exception) { + errorEx("Error starting reference server", e) + throw e + } + } + + @JvmStatic + fun startWalletServer(envMap: Map?, wait: Boolean) { + try { + info("Starting wallet server...") + startWalletServerFunction(envMap, wait) + } catch (e: Exception) { + errorEx("Error starting wallet server", e) + throw e + } + } + + @JvmStatic + fun startTestProfileRunner() { + info("Running test profile runner") + testProfileRunnerMain() + } + + @JvmStatic + fun printUsage(options: Options) { + val helper = HelpFormatter() + helper.optionComparator = null + helper.printHelp("java -jar anchor-platform.jar", options) + } + + @JvmStatic + fun getVersion(): String { + return Metadata.getVersion() + } +}