tons of cursor-shit cleaning, finished implementing cnxId in observer
This commit is contained in:
@@ -9,7 +9,7 @@ export const dispatchMessage = createDispatchMessage({
|
||||
eventHandlers,
|
||||
actionRules(redisCnx) {
|
||||
const maestro = redisCnx.config.maestro ?? {}
|
||||
const arenaChannel = maestro.bus?.arena?.actionsChannel
|
||||
const arenaChannel = maestro.arenaActionsChannel
|
||||
return({
|
||||
channels: arenaChannel ? [arenaChannel] : [],
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
export const eventHandlers = {
|
||||
'arena:gods:ready': {
|
||||
readyToStart(msg, chan) {
|
||||
readyToStart(msg, chan, sender, cnxId) {
|
||||
if(!this.maestroSrv) return
|
||||
this.maestroSrv.handlePrepareAck(msg, chan)
|
||||
},
|
||||
|
||||
@@ -11,7 +11,7 @@ export const dispatchMessage = createDispatchMessage({
|
||||
actionRules(redisCnx) {
|
||||
const maestro = redisCnx.config.maestro ?? {}
|
||||
return({
|
||||
channels: [maestro.maestroActionsChannel].filter(Boolean),
|
||||
channels: [maestro.ActionsChannel].filter(Boolean),
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -3,20 +3,20 @@ import { isValidUuid } from '../../simRepository.js'
|
||||
|
||||
export const actions = {
|
||||
|
||||
async action_STARTSIMULATION(action, payload, reqid, sender, roles) {
|
||||
async action_STARTSIMULATION(action, payload, reqid, sender, cnxId, roles) {
|
||||
if(!isValidUuid(sender)) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
return
|
||||
}
|
||||
|
||||
if(!payload?.simulationUuid) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing simulationUuid' })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing simulationUuid' })
|
||||
return
|
||||
}
|
||||
|
||||
const result = await this.maestroSrv.startSimulation(sender, payload)
|
||||
if(!result.ok) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: result.err })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ export const actions = {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
cnxId,
|
||||
success: true,
|
||||
payload: {
|
||||
simulationId: result.simulationId,
|
||||
@@ -36,20 +37,20 @@ export const actions = {
|
||||
})
|
||||
},
|
||||
|
||||
async action_PAUSESIMULATION(action, payload, reqid, sender, roles) {
|
||||
async action_PAUSESIMULATION(action, payload, reqid, sender, cnxId, roles) {
|
||||
if(!isValidUuid(sender)) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
return
|
||||
}
|
||||
|
||||
if(!payload?.simulationUuid) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing simulationUuid' })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing simulationUuid' })
|
||||
return
|
||||
}
|
||||
|
||||
const result = await this.maestroSrv.pauseSimulation(sender, payload)
|
||||
if(!result.ok) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: result.err })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -57,6 +58,7 @@ export const actions = {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
cnxId,
|
||||
success: true,
|
||||
payload: {
|
||||
simulationId: result.simulationId,
|
||||
@@ -65,20 +67,20 @@ export const actions = {
|
||||
})
|
||||
},
|
||||
|
||||
async action_STOPSIMULATION(action, payload, reqid, sender, roles) {
|
||||
async action_STOPSIMULATION(action, payload, reqid, sender, cnxId, roles) {
|
||||
if(!isValidUuid(sender)) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
return
|
||||
}
|
||||
|
||||
if(!payload?.simulationUuid) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing simulationUuid' })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing simulationUuid' })
|
||||
return
|
||||
}
|
||||
|
||||
const result = await this.maestroSrv.stopSimulation(sender, payload)
|
||||
if(!result.ok) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: result.err })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -86,20 +88,21 @@ export const actions = {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
cnxId,
|
||||
success: true,
|
||||
payload: { simulationId: result.simulationId },
|
||||
})
|
||||
},
|
||||
|
||||
async action_GETSIMULATIONSSTATUS(action, payload, reqid, sender, roles) {
|
||||
async action_GETSIMULATIONSSTATUS(action, payload, reqid, sender, cnxId, roles) {
|
||||
if(!isValidUuid(sender)) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: 'Missing or invalid sender (user UUID)' })
|
||||
return
|
||||
}
|
||||
|
||||
const result = await this.maestroSrv.getSimulationsStatus(sender)
|
||||
if(!result.ok) {
|
||||
replyToAction(this, { action, reqid, sender, success: false, err: result.err })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: false, err: result.err })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -107,6 +110,7 @@ export const actions = {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
cnxId,
|
||||
success: true,
|
||||
payload: result.simulations,
|
||||
})
|
||||
|
||||
@@ -2,16 +2,17 @@ import { replyToAction } from '../../../bus/publishActionReply.js'
|
||||
|
||||
export const actions = {
|
||||
|
||||
async action_RELOADCONFIG(action, payload, reqid, sender, roles) {
|
||||
async action_RELOADCONFIG(action, payload, reqid, sender, cnxId, roles) {
|
||||
this.reloadAccessRights()
|
||||
replyToAction(this, { action, reqid, sender, success: true })
|
||||
replyToAction(this, { action, reqid, sender, cnxId, success: true })
|
||||
},
|
||||
|
||||
async action_GETCONFIG(action, payload, reqid, sender, roles) {
|
||||
async action_GETCONFIG(action, payload, reqid, sender, cnxId, roles) {
|
||||
replyToAction(this, {
|
||||
action,
|
||||
reqid,
|
||||
sender,
|
||||
cnxId,
|
||||
success: true,
|
||||
payload: this.getAccessRights(),
|
||||
})
|
||||
|
||||
+18
-38
@@ -10,10 +10,12 @@ export class maestroServer {
|
||||
|
||||
constructor(configHelper, allRediscnx, debug) {
|
||||
this.configHelper = configHelper
|
||||
this.maestroConfig = configHelper.config
|
||||
this.rootConfig = configHelper.config
|
||||
this.maestroConfig = configHelper.config.maestro ?? {}
|
||||
this.gpsConfig = configHelper.config.gps ?? {}
|
||||
this.allRediscnx = allRediscnx
|
||||
this.debug = debug
|
||||
this.accessRights = new AccesRights(this.maestroConfig, debug)
|
||||
this.accessRights = new AccesRights(this.rootConfig, debug)
|
||||
this.arenaCnx = null
|
||||
this.arenaCnxs = []
|
||||
this.systemCnx = null
|
||||
@@ -31,26 +33,6 @@ export class maestroServer {
|
||||
this.pausedAt = null
|
||||
}
|
||||
|
||||
getMaestroSettings() {
|
||||
const maestro = this.maestroConfig.maestro ?? {}
|
||||
return({
|
||||
senderId: maestro.senderId ?? 'maestro',
|
||||
lifecycle: {
|
||||
arenaChannel: maestro.lifecycle?.arenaChannel ?? 'arena:lifecycle',
|
||||
prepareAckChannel: maestro.lifecycle?.godsReadyChannel ?? 'arena:gods:ready',
|
||||
},
|
||||
readyTimeoutMs: maestro.readyTimeoutMs ?? 30000,
|
||||
})
|
||||
}
|
||||
|
||||
getArenaStorageSettings() {
|
||||
const gps = this.maestroConfig.gps ?? {}
|
||||
return({
|
||||
agentHashKey: gps.arenaStorage?.agentHashKey ?? 'arena:agents:[UID]',
|
||||
agentsIndexKey: gps.arenaStorage?.agentsIndexKey ?? 'arena:agents',
|
||||
})
|
||||
}
|
||||
|
||||
isIdle() {
|
||||
return(this.orchestrationState === MaestroState.IDLE)
|
||||
}
|
||||
@@ -72,7 +54,7 @@ export class maestroServer {
|
||||
}
|
||||
|
||||
async init() {
|
||||
const mysqlCfg = this.maestroConfig.mysql
|
||||
const mysqlCfg = this.rootConfig.mysql
|
||||
if(!mysqlCfg) {
|
||||
console.error('[Maestro] Missing mysql config')
|
||||
return(false)
|
||||
@@ -84,10 +66,11 @@ export class maestroServer {
|
||||
}
|
||||
|
||||
refreshArenaGroom() {
|
||||
if(this.arenaCnx) {
|
||||
const arenaStorage = this.gpsConfig.arenaStorage
|
||||
if(this.arenaCnx && arenaStorage) {
|
||||
this.arenaGroom = new ArenaGroom(
|
||||
this.arenaCnx,
|
||||
this.getArenaStorageSettings(),
|
||||
arenaStorage,
|
||||
this.debug
|
||||
)
|
||||
}
|
||||
@@ -95,10 +78,9 @@ export class maestroServer {
|
||||
|
||||
refreshPrepareQuorum() {
|
||||
if(!this.arenaCnx) return
|
||||
const { lifecycle, readyTimeoutMs } = this.getMaestroSettings()
|
||||
this.prepareQuorum = new PrepareQuorum({
|
||||
ackChannel: lifecycle.prepareAckChannel,
|
||||
timeoutMs: readyTimeoutMs,
|
||||
ackChannel: this.maestroConfig.lifecycle.godsReadyChannel,
|
||||
timeoutMs: this.maestroConfig.readyTimeoutMs,
|
||||
matchesChan: this.arenaCnx.matchesChan.bind(this.arenaCnx),
|
||||
debug: this.debug,
|
||||
})
|
||||
@@ -144,11 +126,10 @@ export class maestroServer {
|
||||
|
||||
async publishLifecycle(eventType, payload, state = null) {
|
||||
if(!this.arenaCnx) throw(new Error('No arena Redis connection'))
|
||||
const { arenaChannel, senderId } = this.getMaestroSettings().lifecycle
|
||||
const resolvedState = state ?? this.orchestrationStateFor(payload?.simulationId ?? this.simulationId)
|
||||
await this.arenaCnx.redisPublish(arenaChannel, {
|
||||
await this.arenaCnx.redisPublish(this.maestroConfig.lifecycle.arenaChannel, {
|
||||
eventType,
|
||||
sender: senderId,
|
||||
sender: this.maestroConfig.senderId,
|
||||
payload,
|
||||
})
|
||||
await this.publishSystemLifecycle(eventType, payload, resolvedState)
|
||||
@@ -164,9 +145,8 @@ export class maestroServer {
|
||||
const ownersResult = await this.simRepo.listSimulationOwnerUuids(simulationId)
|
||||
if(!ownersResult.ok || !ownersResult.ownerUuids.length) return
|
||||
|
||||
const maestro = this.maestroConfig.maestro ?? {}
|
||||
const channelTemplate = maestro.systemLifecycleChannel ?? 'system:maestro:lifecycle:[UID]'
|
||||
const senderId = maestro.senderId ?? 'maestro'
|
||||
const channelTemplate = this.maestroConfig.systemLifecycleChannel
|
||||
const senderId = this.maestroConfig.senderId
|
||||
const msg = {
|
||||
eventType,
|
||||
sender: senderId,
|
||||
@@ -219,7 +199,7 @@ export class maestroServer {
|
||||
infraId,
|
||||
}
|
||||
|
||||
const expectedParticipants = buildPrepareQuorum(this.agentIds, this.maestroConfig)
|
||||
const expectedParticipants = buildPrepareQuorum(this.agentIds, this.rootConfig)
|
||||
const readyWait = this.prepareQuorum.begin(expectedParticipants, this.simulationId)
|
||||
|
||||
await this.publishLifecycle('onYourMarks', lifecyclePayload)
|
||||
@@ -410,12 +390,12 @@ export class maestroServer {
|
||||
|
||||
async reloadAccessRights() {
|
||||
await this.configHelper.refreshAccessRights()
|
||||
this.maestroConfig.accessRights = this.configHelper.config.accessRights
|
||||
this.accessRights.refreshAccessRights(this.maestroConfig)
|
||||
this.rootConfig.accessRights = this.configHelper.config.accessRights
|
||||
this.accessRights.refreshAccessRights(this.rootConfig)
|
||||
}
|
||||
|
||||
getAccessRights() {
|
||||
return(this.maestroConfig.accessRights)
|
||||
return(this.rootConfig.accessRights)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user