Skip to content

Commit

Permalink
Merge pull request #247 from fortizpenaloza/update-launchpad
Browse files Browse the repository at this point in the history
First iteration
  • Loading branch information
fortizpenaloza authored Aug 19, 2023
2 parents c94dee5 + e67a072 commit 956a0bb
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 136 deletions.
6 changes: 4 additions & 2 deletions .smalltalkci/.loading.development.ston
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ SmalltalkCISpec {
#baseline : 'Cosmos',
#directory : '../source',
#load : [ 'Development' ],
#platforms : [ #pharo ]
#platforms : [ #pharo ],
#onConflict : #useIncoming,
#onUpgrade : #useIncoming
}
],
#testing : {
Expand All @@ -13,4 +15,4 @@ SmalltalkCISpec {
#format: #lcov
}
}
}
}
6 changes: 3 additions & 3 deletions source/BaselineOfCosmos/BaselineOfCosmos.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,22 @@ BaselineOfCosmos >> setUpDependeciesOn: aSpec [
aSpec
baseline: 'Kepler'
with: [ aSpec
repository: 'github://ba-st/Kepler:v4/source';
repository: 'github://ba-st/Kepler:v5/source';
loads: #('Deployment') ];
project: 'Kepler-SUnit' copyFrom: 'Kepler' with: [ aSpec loads: 'Dependent-SUnit-Extensions' ];
project: 'Kepler-Tools' copyFrom: 'Kepler' with: [ aSpec loads: 'Tools' ].

aSpec
baseline: 'Stargate'
with: [ aSpec
repository: 'github://ba-st/Stargate:v3/source';
repository: 'github://ba-st/Stargate:v8/source';
loads: 'Deployment' ];
project: 'Stargate-Tools' copyFrom: 'Stargate' with: [ aSpec loads: 'Tools' ].

aSpec
baseline: 'Launchpad'
with: [ aSpec
repository: 'github://ba-st/Launchpad:v3/source';
repository: 'github://ba-st/Launchpad:v4/source';
loads: 'Deployment' ]
]

Expand Down
164 changes: 164 additions & 0 deletions source/Cosmos-CommandLineHandler/CosmosApplication.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
Class {
#name : #CosmosApplication,
#superclass : #LaunchpadApplication,
#instVars : [
'pendingActionsQueue',
'actionEvaluationsQueue',
'cosmos'
],
#category : #'Cosmos-CommandLineHandler'
}

{ #category : #accessing }
CosmosApplication class >> commandName [

^ 'cosmos'
]

{ #category : #accessing }
CosmosApplication class >> configurationParameters [

^ Array
with: ( OptionalConfigurationParameter
named: 'hostname'
describedBy: 'The host where the cosmos RESTful API will be available'
defaultingTo: 'localhost' )
with: ( OptionalConfigurationParameter
named: 'port'
describedBy: 'The port where the cosmos RESTful API will be available'
defaultingTo: 57001
convertingWith: #asNumber )
with: ( MandatoryConfigurationParameter
named: 'allowed-origins'
describedBy: 'The allowed origins'
convertingWith: [ :string | ( ( string substrings: ',' ) collect: #trim ) collect: #asUrl ] )
]

{ #category : #accessing }
CosmosApplication class >> description [

^ 'Cosmos application'
]

{ #category : #accessing }
CosmosApplication class >> version [

^ 'v1.0.0'
]

{ #category : #'private - activation/deactivation' }
CosmosApplication >> basicStartWithin: context [

LogRecord emitInfo: 'Creating pending evaluation actions queue' during: [ pendingActionsQueue := AtomicSharedQueue new ].
LogRecord emitInfo: 'Creating action evaluation queue' during: [ actionEvaluationsQueue := AtomicSharedQueue new ].
LogRecord emitInfo: 'Building and starting cosmos' during: [ self buildAndStartCosmos ].
LogRecord emitInfo: 'Building and starting RESTful API' during: [ self buildAndStartCosmosAPI ].
LogRecord emitInfo: 'Building and starting the periodical scheduler' during: [ self buildAndStartScheduler ].
LogRecord emitInfo: 'Building and starting the action evaluator' during: [ self buildAndStartActionEvaluator ].

]

{ #category : #'private - building evaluator' }
CosmosApplication >> buildAndStartActionEvaluator [

| evaluator |

evaluator := ActionEvaluator
evaluatingActionsFrom: pendingActionsQueue
using: (ActionEvaluatorConfiguration workingWith: SystemTimeSource new)
registeringEvaluationsInto: actionEvaluationsQueue.

evaluator start


]

{ #category : #'private - building cosmos system' }
CosmosApplication >> buildAndStartCosmos [

cosmos := CompositeSystem new.

cosmos
register: (TimeSystem using: SystemTimeSource new);
register: EventNotificationSystem new;
register: MetadataSystem new;
register: (IdentifierSystem using: UUIDProvider new);
register: TimestampingSystem new;
register: DataStreamManagementSystem new;
register: (TriggerManagementSystem enqueuingActionsInto: pendingActionsQueue);
register: ActionManagementSystem new;
register: (ActionEvaluationSystem registeringFrom: actionEvaluationsQueue);
register: CommandManagementSystem new.

cosmos startUp
]

{ #category : #'private - building cosmos API' }
CosmosApplication >> buildAndStartCosmosAPI [

| api |

api := HTTPBasedRESTfulAPI
configuredBy:
{(#port -> self port).
(#debugMode -> self isDebugModeEnabled).
(#serverUrl -> self baseUrl)}
installing:
{(DataStreamsRESTfulController workingWith: cosmos).
(DataPointsRESTfulController workingWith: cosmos).
(CommandsRESTfulController workingWith: cosmos).
(ActionsRESTfulController workingWith: cosmos).
(ActionEvaluationsRESTfulController workingWith: cosmos).
(TriggersRESTfulController workingWith: cosmos)}..

api
on: self exceptionsToHandle
addErrorHandler: [ :signal :request | self class dumpStackAndReport: signal ].

api beCORSAwareAllowing: self allowedOrigins.

api
install;
start
]

{ #category : #'private - building scheduler' }
CosmosApplication >> buildAndStartScheduler [

| scheduler |

scheduler := self periodicalScheduler.

self timePeriodsToSchedule
do: [ :timePeriod | | task |

task := Task
named: ('Notify every <1p>' expandMacrosWith: timePeriod)
do: [ (cosmos systemImplementing: #EventNotificationSystemInterface)
notifySubscribersTo: (TickEvent of: timePeriod) ].

scheduler schedule: task toBeExecutedEvery: timePeriod ].

scheduler start
]

{ #category : #'private - building scheduler' }
CosmosApplication >> periodicalScheduler [

^ PeriodicalScheduler usingDefaultScheduler
]

{ #category : #'error handling' }
CosmosApplication >> stackTraceDumper [

^ NullStackTraceDumper new
]

{ #category : #'private - building scheduler' }
CosmosApplication >> timePeriodsToSchedule [

^ {(TimeUnits second with: 10).
(TimeUnits minute with: 1).
(TimeUnits minute with: 10).
(TimeUnits hour with: 1)}
]
132 changes: 1 addition & 131 deletions source/Cosmos-CommandLineHandler/CosmosCommandLineHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Examples:
"
Class {
#name : #CosmosCommandLineHandler,
#superclass : #LaunchpadCommandLineHandler,
#superclass : #AnObsoleteLaunchpadCommandLineHandler,
#instVars : [
'cosmos',
'pendingActionsQueue',
Expand Down Expand Up @@ -64,121 +64,6 @@ CosmosCommandLineHandler >> baseUrl [
^ ('http://' , self hostname) asUrl port: self port
]

{ #category : #activation }
CosmosCommandLineHandler >> basicActivate [

self
logAsInfo: 'Creating pending evaluation actions queue'
during: [ pendingActionsQueue := AtomicSharedQueue new ];
logAsInfo: 'Creating action evaluation queue'
during: [ actionEvaluationsQueue := AtomicSharedQueue new ];
logAsInfo: 'Building and starting cosmos'
during: [ self buildAndStartCosmos ];
logAsInfo: 'Building and starting RESTful API'
during: [ self buildAndStartCosmosAPI ];
logAsInfo: 'Building and starting the periodical scheduler'
during: [ self buildAndStartScheduler ];
logAsInfo: 'Building and starting the action evaluator'
during: [ self buildAndStartActionEvaluator ]
]

{ #category : #activation }
CosmosCommandLineHandler >> buildAndStartActionEvaluator [

| evaluator |

evaluator := ActionEvaluator
evaluatingActionsFrom: pendingActionsQueue
using: (ActionEvaluatorConfiguration workingWith: SystemTimeSource new)
registeringEvaluationsInto: actionEvaluationsQueue.

evaluator start


]

{ #category : #'private - building cosmos system' }
CosmosCommandLineHandler >> buildAndStartCosmos [

cosmos := CompositeSystem new.

cosmos
register: (TimeSystem using: SystemTimeSource new);
register: EventNotificationSystem new;
register: MetadataSystem new;
register: (IdentifierSystem using: UUIDProvider new);
register: TimestampingSystem new;
register: DataStreamManagementSystem new;
register: (TriggerManagementSystem enqueuingActionsInto: pendingActionsQueue);
register: ActionManagementSystem new;
register: (ActionEvaluationSystem registeringFrom: actionEvaluationsQueue);
register: CommandManagementSystem new.

cosmos startUp
]

{ #category : #'private - building cosmos API' }
CosmosCommandLineHandler >> buildAndStartCosmosAPI [

| api |

api := HTTPBasedRESTfulAPI
configuredBy:
{(#port -> self port).
(#debugMode -> self isDebugModeEnabled).
(#serverUrl -> self baseUrl)}
installing:
{(DataStreamsRESTfulController workingWith: cosmos).
(DataPointsRESTfulController workingWith: cosmos).
(CommandsRESTfulController workingWith: cosmos).
(ActionsRESTfulController workingWith: cosmos).
(ActionEvaluationsRESTfulController workingWith: cosmos).
(TriggersRESTfulController workingWith: cosmos)}..

api
on: self exceptionsToHandle
addErrorHandler: [ :signal :request | self class dumpStackAndReport: signal ].

api beCORSAwareAllowing: self allowedOrigins.

api
install;
start
]

{ #category : #'private - building scheduler' }
CosmosCommandLineHandler >> buildAndStartScheduler [

| scheduler |

scheduler := self periodicalScheduler.

self timePeriodsToSchedule
do: [ :timePeriod | | task |

task := Task
named: ('Notify every <1p>' expandMacrosWith: timePeriod)
do: [ (cosmos systemImplementing: #EventNotificationSystemInterface)
notifySubscribersTo: (TickEvent of: timePeriod) ].

scheduler schedule: task toBeExecutedEvery: timePeriod ].

scheduler start
]

{ #category : #'private - accessing' }
CosmosCommandLineHandler >> configurationDefinition [

^ OrderedCollection new
add: (OptionalArgument named: 'hostname' defaultingTo: 'localhost');
add: (OptionalArgument named: 'port' defaultingTo: 57001 convertingWith: #asNumber);
add:
(MandatoryArgument
named: 'allowed-origins'
convertingWith: [ :string | ((string substrings: ',') collect: #trim) collect: #asUrl ]);
asArray
]

{ #category : #'private - accessing' }
CosmosCommandLineHandler >> hostname [

Expand All @@ -191,23 +76,8 @@ CosmosCommandLineHandler >> logAsInfo: aMessage during: aBlock [
CurrentLogger value logAsInfo: aMessage during: aBlock
]

{ #category : #'private - accessing' }
CosmosCommandLineHandler >> periodicalScheduler [

^ PeriodicalScheduler usingDefaultScheduler
]

{ #category : #'private - accessing' }
CosmosCommandLineHandler >> port [

^ self configuration at: 'port'
]

{ #category : #'private - accessing' }
CosmosCommandLineHandler >> timePeriodsToSchedule [

^ {(TimeUnits second with: 10).
(TimeUnits minute with: 1).
(TimeUnits minute with: 10).
(TimeUnits hour with: 1)}
]

0 comments on commit 956a0bb

Please sign in to comment.