Skip to content

Commit

Permalink
refactor(core): rename ActionHelper to ActionRouter
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Oct 25, 2019
1 parent 8ae8434 commit ac48a66
Show file tree
Hide file tree
Showing 33 changed files with 99 additions and 99 deletions.
68 changes: 34 additions & 34 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ export interface DeployServicesParams {
}

/**
* The ActionHelper takes care of choosing which plugin should be responsible for handling an action,
* The ActionRouter takes care of choosing which plugin should be responsible for handling an action,
* and preparing common parameters (so as to reduce boilerplate on the usage side).
*
* Each plugin and module action has a corresponding method on this class (aside from configureProvider, which
* is handled especially elsewhere).
*/
export class ActionHelper implements TypeGuard {
export class ActionRouter implements TypeGuard {
private readonly actionHandlers: WrappedPluginActionMap
private readonly moduleActionHandlers: WrappedModuleActionMap
private readonly loadedPlugins: PluginMap
Expand All @@ -124,7 +124,7 @@ export class ActionHelper implements TypeGuard {
this.moduleActionHandlers = <WrappedModuleActionMap>fromPairs(moduleActionNames.map(n => [n, {}]))
this.loadedPlugins = keyBy(loadedPlugins, "name")

garden.log.silly(`Creating ActionHelper with ${configuredPlugins.length} configured plugins`)
garden.log.silly(`Creating ActionRouter with ${configuredPlugins.length} configured plugins`)

for (const plugin of configuredPlugins) {
const handlers = plugin.handlers || {}
Expand Down Expand Up @@ -180,7 +180,7 @@ export class ActionHelper implements TypeGuard {
}

async getEnvironmentStatus(
params: RequirePluginName<ActionHelperParams<GetEnvironmentStatusParams>>,
params: RequirePluginName<ActionRouterParams<GetEnvironmentStatusParams>>,
): Promise<EnvironmentStatus> {
const { pluginName } = params

Expand All @@ -193,7 +193,7 @@ export class ActionHelper implements TypeGuard {
}

async prepareEnvironment(
params: RequirePluginName<ActionHelperParams<PrepareEnvironmentParams>>,
params: RequirePluginName<ActionRouterParams<PrepareEnvironmentParams>>,
): Promise<PrepareEnvironmentResult> {
const { pluginName } = params

Expand All @@ -206,7 +206,7 @@ export class ActionHelper implements TypeGuard {
}

async cleanupEnvironment(
params: RequirePluginName<ActionHelperParams<CleanupEnvironmentParams>>,
params: RequirePluginName<ActionRouterParams<CleanupEnvironmentParams>>,
) {
const { pluginName } = params
return this.callActionHandler({
Expand All @@ -217,17 +217,17 @@ export class ActionHelper implements TypeGuard {
})
}

async getSecret(params: RequirePluginName<ActionHelperParams<GetSecretParams>>): Promise<GetSecretResult> {
async getSecret(params: RequirePluginName<ActionRouterParams<GetSecretParams>>): Promise<GetSecretResult> {
const { pluginName } = params
return this.callActionHandler({ actionType: "getSecret", pluginName, params: omit(params, ["pluginName"]) })
}

async setSecret(params: RequirePluginName<ActionHelperParams<SetSecretParams>>): Promise<SetSecretResult> {
async setSecret(params: RequirePluginName<ActionRouterParams<SetSecretParams>>): Promise<SetSecretResult> {
const { pluginName } = params
return this.callActionHandler({ actionType: "setSecret", pluginName, params: omit(params, ["pluginName"]) })
}

async deleteSecret(params: RequirePluginName<ActionHelperParams<DeleteSecretParams>>): Promise<DeleteSecretResult> {
async deleteSecret(params: RequirePluginName<ActionRouterParams<DeleteSecretParams>>): Promise<DeleteSecretResult> {
const { pluginName } = params
return this.callActionHandler({ actionType: "deleteSecret", pluginName, params: omit(params, ["pluginName"]) })
}
Expand All @@ -239,7 +239,7 @@ export class ActionHelper implements TypeGuard {
//===========================================================================

async getBuildStatus<T extends Module>(
params: ModuleActionHelperParams<GetBuildStatusParams<T>>,
params: ModuleActionRouterParams<GetBuildStatusParams<T>>,
): Promise<BuildStatus> {
return this.callModuleHandler({
params,
Expand All @@ -248,26 +248,26 @@ export class ActionHelper implements TypeGuard {
})
}

async build<T extends Module>(params: ModuleActionHelperParams<BuildModuleParams<T>>): Promise<BuildResult> {
async build<T extends Module>(params: ModuleActionRouterParams<BuildModuleParams<T>>): Promise<BuildResult> {
return this.callModuleHandler({ params, actionType: "build" })
}

async publishModule<T extends Module>(
params: ModuleActionHelperParams<PublishModuleParams<T>>,
params: ModuleActionRouterParams<PublishModuleParams<T>>,
): Promise<PublishResult> {
return this.callModuleHandler({ params, actionType: "publish", defaultHandler: dummyPublishHandler })
}

async runModule<T extends Module>(params: ModuleActionHelperParams<RunModuleParams<T>>): Promise<RunResult> {
async runModule<T extends Module>(params: ModuleActionRouterParams<RunModuleParams<T>>): Promise<RunResult> {
return this.callModuleHandler({ params, actionType: "runModule" })
}

async testModule<T extends Module>(params: ModuleActionHelperParams<TestModuleParams<T>>): Promise<TestResult> {
async testModule<T extends Module>(params: ModuleActionRouterParams<TestModuleParams<T>>): Promise<TestResult> {
return this.callModuleHandler({ params, actionType: "testModule" })
}

async getTestResult<T extends Module>(
params: ModuleActionHelperParams<GetTestResultParams<T>>,
params: ModuleActionRouterParams<GetTestResultParams<T>>,
): Promise<TestResult | null> {
return this.callModuleHandler({
params,
Expand All @@ -282,20 +282,20 @@ export class ActionHelper implements TypeGuard {
//region Service Actions
//===========================================================================

async getServiceStatus(params: ServiceActionHelperParams<GetServiceStatusParams>): Promise<ServiceStatus> {
async getServiceStatus(params: ServiceActionRouterParams<GetServiceStatusParams>): Promise<ServiceStatus> {
return this.callServiceHandler({ params, actionType: "getServiceStatus" })
}

async deployService(params: ServiceActionHelperParams<DeployServiceParams>): Promise<ServiceStatus> {
async deployService(params: ServiceActionRouterParams<DeployServiceParams>): Promise<ServiceStatus> {
return this.callServiceHandler({ params, actionType: "deployService" })
}

async hotReloadService(params: ServiceActionHelperParams<HotReloadServiceParams>)
async hotReloadService(params: ServiceActionRouterParams<HotReloadServiceParams>)
: Promise<HotReloadServiceResult> {
return this.callServiceHandler(({ params, actionType: "hotReloadService" }))
}

async deleteService(params: ServiceActionHelperParams<DeleteServiceParams>): Promise<ServiceStatus> {
async deleteService(params: ServiceActionRouterParams<DeleteServiceParams>): Promise<ServiceStatus> {
const log = params.log.info({
section: params.service.name,
msg: "Deleting...",
Expand Down Expand Up @@ -324,23 +324,23 @@ export class ActionHelper implements TypeGuard {
return result
}

async execInService(params: ServiceActionHelperParams<ExecInServiceParams>): Promise<ExecInServiceResult> {
async execInService(params: ServiceActionRouterParams<ExecInServiceParams>): Promise<ExecInServiceResult> {
return this.callServiceHandler({ params, actionType: "execInService" })
}

async getServiceLogs(params: ServiceActionHelperParams<GetServiceLogsParams>): Promise<GetServiceLogsResult> {
async getServiceLogs(params: ServiceActionRouterParams<GetServiceLogsParams>): Promise<GetServiceLogsResult> {
return this.callServiceHandler({ params, actionType: "getServiceLogs", defaultHandler: dummyLogStreamer })
}

async runService(params: ServiceActionHelperParams<RunServiceParams>): Promise<RunResult> {
async runService(params: ServiceActionRouterParams<RunServiceParams>): Promise<RunResult> {
return this.callServiceHandler({ params, actionType: "runService" })
}

async getPortForward(params: ServiceActionHelperParams<GetPortForwardParams>) {
async getPortForward(params: ServiceActionRouterParams<GetPortForwardParams>) {
return this.callServiceHandler({ params, actionType: "getPortForward" })
}

async stopPortForward(params: ServiceActionHelperParams<StopPortForwardParams>) {
async stopPortForward(params: ServiceActionRouterParams<StopPortForwardParams>) {
return this.callServiceHandler({ params, actionType: "stopPortForward" })
}

Expand All @@ -350,11 +350,11 @@ export class ActionHelper implements TypeGuard {
//region Task Methods
//===========================================================================

async runTask(params: TaskActionHelperParams<RunTaskParams>): Promise<RunTaskResult> {
async runTask(params: TaskActionRouterParams<RunTaskParams>): Promise<RunTaskResult> {
return this.callTaskHandler({ params, actionType: "runTask" })
}

async getTaskResult(params: TaskActionHelperParams<GetTaskResultParams>): Promise<RunTaskResult | null> {
async getTaskResult(params: TaskActionRouterParams<GetTaskResultParams>): Promise<RunTaskResult | null> {
return this.callTaskHandler({
params,
actionType: "getTaskResult",
Expand Down Expand Up @@ -479,7 +479,7 @@ export class ActionHelper implements TypeGuard {
private async callActionHandler<T extends keyof Omit<WrappedPluginActionHandlers, "configureProvider">>(
{ params, actionType, pluginName, defaultHandler }:
{
params: ActionHelperParams<PluginActionParams[T]>,
params: ActionRouterParams<PluginActionParams[T]>,
actionType: T,
pluginName: string,
defaultHandler?: PluginActionHandlers[T],
Expand Down Expand Up @@ -508,7 +508,7 @@ export class ActionHelper implements TypeGuard {
private async callModuleHandler<T extends keyof Omit<ModuleActionHandlers, "configure">>(
{ params, actionType, defaultHandler }:
{
params: ModuleActionHelperParams<ModuleActionParams[T]>,
params: ModuleActionRouterParams<ModuleActionParams[T]>,
actionType: T,
defaultHandler?: ModuleActionHandlers[T],
},
Expand Down Expand Up @@ -539,7 +539,7 @@ export class ActionHelper implements TypeGuard {
private async callServiceHandler<T extends keyof ServiceActionHandlers>(
{ params, actionType, defaultHandler }:
{
params: ServiceActionHelperParams<ServiceActionParams[T]>,
params: ServiceActionRouterParams<ServiceActionParams[T]>,
actionType: T,
defaultHandler?: ServiceActionHandlers[T],
},
Expand Down Expand Up @@ -590,7 +590,7 @@ export class ActionHelper implements TypeGuard {
private async callTaskHandler<T extends keyof TaskActionHandlers>(
{ params, actionType, defaultHandler }:
{
params: TaskActionHelperParams<TaskActionParams[T]>, actionType: T,
params: TaskActionRouterParams<TaskActionParams[T]>, actionType: T,
defaultHandler?: TaskActionHandlers[T],
},
): Promise<TaskActionOutputs[T]> {
Expand Down Expand Up @@ -934,18 +934,18 @@ type WrappedModuleActionMap = {
}

// avoid having to specify common params on each action helper call
type ActionHelperParams<T extends PluginActionParamsBase> =
type ActionRouterParams<T extends PluginActionParamsBase> =
Omit<T, CommonParams> & { pluginName?: string }

type ModuleActionHelperParams<T extends PluginModuleActionParamsBase> =
type ModuleActionRouterParams<T extends PluginModuleActionParamsBase> =
Omit<T, CommonParams> & { pluginName?: string }
// additionally make runtimeContext param optional

type ServiceActionHelperParams<T extends PluginServiceActionParamsBase> =
type ServiceActionRouterParams<T extends PluginServiceActionParamsBase> =
Omit<T, "module" | CommonParams>
& { pluginName?: string }

type TaskActionHelperParams<T extends PluginTaskActionParamsBase> =
type TaskActionRouterParams<T extends PluginTaskActionParamsBase> =
Omit<T, "module" | CommonParams>
& { pluginName?: string }

Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class CallCommand extends Command<Args> {
const service = await graph.getService(serviceName)
// No need for full context, since we're just checking if the service is running.
const runtimeContext = emptyRuntimeContext
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const status = await actions.getServiceStatus({ service, log, hotReload: false, runtimeContext })

if (!includes(["ready", "outdated"], status.state)) {
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/commands/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class DeleteSecretCommand extends Command<typeof deleteSecretArgs> {
{ garden, log, args }: CommandParams<DeleteSecretArgs>,
): Promise<CommandResult<DeleteSecretResult>> {
const key = args.key!
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const result = await actions.deleteSecret({ log, pluginName: args.provider!, key })

if (result.found) {
Expand Down Expand Up @@ -101,7 +101,7 @@ export class DeleteEnvironmentCommand extends Command {
async action({ garden, log, headerLog }: CommandParams): Promise<CommandResult<DeleteEnvironmentResult>> {
printHeader(headerLog, `Deleting ${garden.environmentName} environment`, "skull_and_crossbones")

const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const result = await actions.deleteEnvironment(log)

return { result }
Expand Down Expand Up @@ -145,7 +145,7 @@ export class DeleteServiceCommand extends Command {

const result: { [key: string]: ServiceStatus } = {}

const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()

await Bluebird.map(services, async service => {
result[service.name] = await actions.deleteService({ log, service })
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class ExecCommand extends Command<Args> {

const graph = await garden.getConfigGraph()
const service = await graph.getService(serviceName)
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const result = await actions.execInService({
log,
service,
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/get/get-debug-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export async function collectProviderDebugInfo(garden: Garden, log: LogEntry, fo
const tempPath = join(garden.gardenDirPath, TEMP_DEBUG_ROOT)
await ensureDir(tempPath)
// Collect debug info from providers
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const providersDebugInfo = await actions.getDebugInfo({ log, includeProject })

// Create a provider folder and report for each provider.
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/get/get-secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class GetSecretCommand extends Command<GetArgs> {

async action({ garden, log, args }: CommandParams<GetArgs>): Promise<CommandResult> {
const key = args.key
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const { value } = await actions.getSecret({
pluginName: args.provider,
key,
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/commands/get/get-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class GetStatusCommand extends Command {
help = "Outputs the status of your environment."

async action({ garden, log, opts }: CommandParams): Promise<CommandResult<AllEnvironmentStatus>> {
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const status = await actions.getStatus({ log })

let result: AllEnvironmentStatus
Expand Down Expand Up @@ -68,7 +68,7 @@ export class GetStatusCommand extends Command {

async function getTestStatuses(garden: Garden, configGraph: ConfigGraph, log: LogEntry) {
const modules = await configGraph.getModules()
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()

return fromPairs(flatten(await Bluebird.map(modules, async (module) => {
return Bluebird.map(module.testConfigs, async (testConfig) => {
Expand All @@ -83,7 +83,7 @@ async function getTestStatuses(garden: Garden, configGraph: ConfigGraph, log: Lo

async function getTaskStatuses(garden: Garden, configGraph: ConfigGraph, log: LogEntry): Promise<TaskStatuses> {
const tasks = await configGraph.getTasks()
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()

return fromPairs(await Bluebird.map(tasks, async (task) => {
const taskVersion = await getTaskVersion(garden, configGraph, task)
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/get/get-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class GetTaskResultCommand extends Command<Args> {
const graph: ConfigGraph = await garden.getConfigGraph()
const task = await graph.getTask(taskName)

const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()

const result = await actions.getTaskResult(
{
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/get/get-test-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class GetTestResultCommand extends Command<Args> {
)

const graph = await garden.getConfigGraph()
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()

const module = await graph.getModule(moduleName)

Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class LogsCommand extends Command<Args, Opts> {
}
})

const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const voidLog = log.placeholder(LogLevel.silly, true)

await Bluebird.map(services, async (service: Service<any>) => {
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/run/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class RunModuleCommand extends Command<Args, Opts> {

printHeader(headerLog, msg, "runner")

const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()

const buildTask = new BuildTask({ garden, log, module, force: opts["force-build"] })
await garden.processTasks([buildTask])
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/run/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class RunServiceCommand extends Command<Args, Opts> {
"runner",
)

const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()

// Make sure all dependencies are ready and collect their outputs for the runtime context
const deployTask = new DeployTask({
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/run/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class RunTestCommand extends Command<Args, Opts> {
"runner",
)

const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const version = await getTestVersion(garden, graph, module, testConfig)

// Make sure all dependencies are ready and collect their outputs for the runtime context
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class SetSecretCommand extends Command<typeof setSecretArgs> {

async action({ garden, log, args }: CommandParams<SetArgs>): Promise<CommandResult<SetSecretResult>> {
const key = args.key
const actions = await garden.getActionHelper()
const actions = await garden.getActionRouter()
const result = await actions.setSecret({
pluginName: args.provider,
key,
Expand Down
Loading

0 comments on commit ac48a66

Please sign in to comment.