diff --git a/api-tests/Dockerfile b/api-tests/Dockerfile index 3422d01..b65c185 100644 --- a/api-tests/Dockerfile +++ b/api-tests/Dockerfile @@ -11,7 +11,7 @@ FROM basmalltalk/pharo:8.0 USER root -WORKDIR /opt/Superluminal-Service-Discovery-Example +WORKDIR /opt/app COPY start.sh ./ COPY --from=loader /opt/pharo/Pharo.image ./ COPY --from=loader /opt/pharo/Pharo.changes ./ @@ -19,7 +19,7 @@ COPY --from=loader /opt/pharo/Pharo*.sources ./ RUN mkdir logs \ && chmod a+x start.sh \ - && chown --recursive pharo:users /opt/Superluminal-Service-Discovery-Example + && chown --recursive pharo:users /opt/app USER pharo diff --git a/api-tests/start.sh b/api-tests/start.sh index 675fe95..5f7bca8 100644 --- a/api-tests/start.sh +++ b/api-tests/start.sh @@ -1,8 +1,6 @@ #!/usr/bin/env bash exec /opt/pharo/pharo \ - /opt/Superluminal-Service-Discovery-Example/Pharo.image \ - super-luminal-service-discovery \ - --message="${MESSAGE}" \ - --consul-agent-location="${CONSUL_AGENT_LOCATION}" \ - --retry-delay-in-ms=10000 + /opt/app/Pharo.image \ + launchpad start superluminal-service-discovery \ + --retry-delay-in-ms=10000 diff --git a/source/BaselineOfSuperluminal/BaselineOfSuperluminal.class.st b/source/BaselineOfSuperluminal/BaselineOfSuperluminal.class.st index 9d8f7f5..b38c1ed 100644 --- a/source/BaselineOfSuperluminal/BaselineOfSuperluminal.class.st +++ b/source/BaselineOfSuperluminal/BaselineOfSuperluminal.class.st @@ -37,7 +37,7 @@ BaselineOfSuperluminal >> setUpDependencies: spec [ with: [ spec loads: 'Dependent-SUnit-Extensions' ]. spec - baseline: 'Launchpad' with: [ spec repository: 'github://ba-st/Launchpad:v3' ]; + baseline: 'Launchpad' with: [ spec repository: 'github://ba-st/Launchpad:v4' ]; project: 'Launchpad-Deployment' copyFrom: 'Launchpad' with: [ spec loads: 'Deployment' ]. spec diff --git a/source/Superluminal-Service-Discovery-Examples-Tests/SuperluminalServiceDiscoveryExampleLauncherTest.class.st b/source/Superluminal-Service-Discovery-Examples-Tests/SuperluminalServiceDiscoveryExampleLauncherTest.class.st index 0ae7c3f..c4ece97 100644 --- a/source/Superluminal-Service-Discovery-Examples-Tests/SuperluminalServiceDiscoveryExampleLauncherTest.class.st +++ b/source/Superluminal-Service-Discovery-Examples-Tests/SuperluminalServiceDiscoveryExampleLauncherTest.class.st @@ -10,52 +10,67 @@ Class { { #category : #tests } SuperluminalServiceDiscoveryExampleLauncherTest >> testActivate [ - self - should: [ - | launcher | - - launcher := SuperluminalServiceDiscoveryExampleLauncher new. - launcher - commandLine: ( CommandLineArguments withArguments: - #( '--consul-agent-location=http://consul:8500' - '--message=Hello' '--retry-delay-in-ms=1' '--debug-mode' ) ); - activate - ] - raise: NameLookupFailure + | commandLine | + + commandLine := CommandLineArguments withArguments: + #( 'launchpad' 'start' '--debug-mode' 'superluminal-service-discovery' + '--consul-agent-location=http://consul:8500' + '--message=Hello' '--retry-delay-in-ms=1' ). + + self should: [ LaunchpadCommandLineHandler activateWith: commandLine ] raise: NameLookupFailure ] { #category : #tests } -SuperluminalServiceDiscoveryExampleLauncherTest >> testArguments [ +SuperluminalServiceDiscoveryExampleLauncherTest >> testActivateInReleaseMode [ - | launcher | + | commandLine | - launcher := SuperluminalServiceDiscoveryExampleLauncher new. - launcher commandLine: ( CommandLineArguments withArguments: - #( '--consul-agent-location=http://consul:8500' '--message=Hello' '--retry-delay-in-ms=1' - '--debug-mode' ) ). + commandLine := CommandLineArguments withArguments: + #( 'launchpad' 'start' 'superluminal-service-discovery' + '--consul-agent-location=http://consul:8500' + '--message=Hello' '--retry-delay-in-ms=1' ). - self - assert: launcher message equals: 'Hello'; - assertUrl: launcher consulAgentLocation equals: 'http://consul:8500' + self should: [ LaunchpadCommandLineHandler activateWith: commandLine ] + raise: Exit + withExceptionDo: [ :exit | self deny: exit isSuccess ] ] { #category : #tests } SuperluminalServiceDiscoveryExampleLauncherTest >> testCommandName [ - self assert: SuperluminalServiceDiscoveryExampleLauncher commandName - equals: 'super-luminal-service-discovery' + self assert: SuperluminalServiceDiscoveryExample commandName + equals: 'superluminal-service-discovery' ] { #category : #tests } SuperluminalServiceDiscoveryExampleLauncherTest >> testDescription [ - self assert: SuperluminalServiceDiscoveryExampleLauncher description + self assert: SuperluminalServiceDiscoveryExample description equals: 'I''m a command line example using as dependency an echo API' ] { #category : #tests } -SuperluminalServiceDiscoveryExampleLauncherTest >> testLogPrefix [ +SuperluminalServiceDiscoveryExampleLauncherTest >> testHelp [ - self assert: SuperluminalServiceDiscoveryExampleLauncher logPrefix - equals: 'Superluminal-Service-Discovery' + self assert: + ( String streamContents: [ :stream | SuperluminalServiceDiscoveryExample printHelpOn: stream ] ) + equals: 'NAME + superluminal-service-discovery [3.0.0] - I''m a command line example using as dependency an echo API +SYNOPSYS + superluminal-service-discovery --message= --consul-agent-location= [--retry-delay-in-ms=] +PARAMETERS + --message= + Message to echo. + --consul-agent-location= + Location of the Consul agent. + --retry-delay-in-ms= + Milliseconds to wait between retries. Defaults to 0:00:00:00.2. +ENVIRONMENT + MESSAGE + Message to echo. + CONSUL_AGENT_LOCATION + Location of the Consul agent. + RETRY_DELAY_IN_MS + Milliseconds to wait between retries. Defaults to 0:00:00:00.2. +' ] diff --git a/source/Superluminal-Service-Discovery-Examples/SuperluminalServiceDiscoveryExample.class.st b/source/Superluminal-Service-Discovery-Examples/SuperluminalServiceDiscoveryExample.class.st new file mode 100644 index 0000000..31e8ebe --- /dev/null +++ b/source/Superluminal-Service-Discovery-Examples/SuperluminalServiceDiscoveryExample.class.st @@ -0,0 +1,81 @@ +Class { + #name : #SuperluminalServiceDiscoveryExample, + #superclass : #LaunchpadApplication, + #category : #'Superluminal-Service-Discovery-Examples' +} + +{ #category : #accessing } +SuperluminalServiceDiscoveryExample class >> commandName [ + + ^ 'superluminal-service-discovery' +] + +{ #category : #accessing } +SuperluminalServiceDiscoveryExample class >> configurationParameters [ + + ^ Array + with: ( MandatoryConfigurationParameter named: 'Message' describedBy: 'Message to echo' ) + with: ( MandatoryConfigurationParameter named: 'Consul Agent Location' + describedBy: 'Location of the Consul agent' + convertingWith: #asUrl ) + with: ( OptionalConfigurationParameter named: 'Retry Delay in ms' + describedBy: 'Milliseconds to wait between retries' + defaultingTo: 200 milliSeconds + convertingWith: [ :parameter | parameter asNumber milliSeconds ] ) +] + +{ #category : #accessing } +SuperluminalServiceDiscoveryExample class >> description [ + + ^ 'I''m a command line example using as dependency an echo API' +] + +{ #category : #accessing } +SuperluminalServiceDiscoveryExample class >> version [ + + ^ '3.0.0' +] + +{ #category : #'private - activation' } +SuperluminalServiceDiscoveryExample >> basicStartWithin: context [ + + | consulAgentLocation echoServiceLocation | + + consulAgentLocation := self configuration consulAgentLocation. + LaunchpadLogRecord emitInfo: 'Discovering dependencies' during: [ + echoServiceLocation := Retry + value: [ + ( ConsulAgentHttpAPIBasedDiscoveryClient queryingAgentOn: + consulAgentLocation ) withLocationOfService: #echo + do: [ :location | location ] + ifUnable: [ Error signal: 'Cannot discover #echo service' ] + ] + configuredBy: [ :retry | + retry + upTo: 3 timesEvery: self configuration retryDelayInMs; + on: Error evaluating: [ :attemptNumber :exception | + LaunchpadLogRecord emitWarning: + ( 'Attempt #<1p> failed with error: <2s>' expandMacrosWith: + attemptNumber + with: exception messageText ) + ] + ] + ]. + + RESTfulAPIClient cachingOnLocalMemory + get: ( echoServiceLocation + scheme: #http; + addPathSegment: 'echo'; + addPathSegment: self configuration message; + yourself ) + withSuccessfulResponseDo: [ :response | + response = self configuration message asUppercase ifFalse: [ Error signal: 'Invalid response received' ] ]. + + self exitSuccess +] + +{ #category : #'error handling' } +SuperluminalServiceDiscoveryExample >> stackTraceDumper [ + + ^ NullStackTraceDumper new +] diff --git a/source/Superluminal-Service-Discovery-Examples/SuperluminalServiceDiscoveryExampleLauncher.class.st b/source/Superluminal-Service-Discovery-Examples/SuperluminalServiceDiscoveryExampleLauncher.class.st deleted file mode 100644 index cb0f5d7..0000000 --- a/source/Superluminal-Service-Discovery-Examples/SuperluminalServiceDiscoveryExampleLauncher.class.st +++ /dev/null @@ -1,82 +0,0 @@ -Class { - #name : #SuperluminalServiceDiscoveryExampleLauncher, - #superclass : #LaunchpadCommandLineHandler, - #category : #'Superluminal-Service-Discovery-Examples' -} - -{ #category : #accessing } -SuperluminalServiceDiscoveryExampleLauncher class >> commandName [ - - ^'super-luminal-service-discovery' -] - -{ #category : #accessing } -SuperluminalServiceDiscoveryExampleLauncher class >> description [ - - ^ 'I''m a command line example using as dependency an echo API' -] - -{ #category : #'private - accessing' } -SuperluminalServiceDiscoveryExampleLauncher class >> logPrefix [ - - ^ 'Superluminal-Service-Discovery' -] - -{ #category : #'private - activation' } -SuperluminalServiceDiscoveryExampleLauncher >> basicActivate [ - - | consulAgentLocation echoServiceLocation | - - consulAgentLocation := self consulAgentLocation. - CurrentLogger value logAsInfo: 'Discovering dependencies' during: [ - echoServiceLocation := Retry - value: [ - ( ConsulAgentHttpAPIBasedDiscoveryClient queryingAgentOn: - consulAgentLocation ) withLocationOfService: #echo - do: [ :location | location ] - ifUnable: [ Error signal: 'Cannot discover #echo service' ] - ] - configuredBy: [ :retry | - retry - upTo: 3 timesEvery: ( self configuration at: 'retry-delay-in-ms' ); - on: Error evaluating: [ :attemptNumber :exception | - CurrentLogger value logAsWarning: - ( 'Attempt #<1p> failed with error: <2s>' expandMacrosWith: - attemptNumber - with: exception messageText ) - ] - ] - ]. - - RESTfulAPIClient cachingOnLocalMemory - get: ( echoServiceLocation - scheme: #http; - addPathSegment: 'echo'; - addPathSegment: self message; - yourself ) - withSuccessfulResponseDo: [ :response | - response = self message asUppercase ifFalse: [ Error signal: 'Invalid response received' ] ]. - - self exitSuccess -] - -{ #category : #'private - accessing' } -SuperluminalServiceDiscoveryExampleLauncher >> configurationDefinition [ - - ^ Array - with: ( MandatoryArgument named: 'message' ) - with: ( MandatoryArgument named: 'consul-agent-location' convertingWith: #asUrl ) - with: ( OptionalArgument named: 'retry-delay-in-ms' defaultingTo: 200 convertingWith: [:parameter | parameter asNumber milliSeconds ]) -] - -{ #category : #'private - accessing' } -SuperluminalServiceDiscoveryExampleLauncher >> consulAgentLocation [ - - ^ self configuration at: 'consul-agent-location' -] - -{ #category : #'private - accessing' } -SuperluminalServiceDiscoveryExampleLauncher >> message [ - - ^ self configuration at: 'message' -]