Skip to content

Commit

Permalink
feat: add test/task statuses to get status command
Browse files Browse the repository at this point in the history
When the get status command is called with json or yaml as the output
option, test and task statuses for the latest test/task versions are
included in the command result.
  • Loading branch information
thsig committed May 16, 2019
1 parent 073df1c commit a1e2122
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
4 changes: 0 additions & 4 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ export interface EnvironmentStatus {
services: { [name: string]: ServiceStatus }
}

export interface EnvironmentOverview {
modules: { [name: string]: ServiceStatus }[]
}

export interface DeployServicesParams {
log: LogEntry
serviceNames?: string[]
Expand Down
2 changes: 2 additions & 0 deletions garden-service/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export class GardenCli {
await command.prepare({
log,
logFooter,
output,
args: parsedArgs,
opts: parsedOpts,
})
Expand All @@ -292,6 +293,7 @@ export class GardenCli {
garden,
log,
logFooter,
output,
args: parsedArgs,
opts: parsedOpts,
})
Expand Down
1 change: 1 addition & 0 deletions garden-service/src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export interface PrepareParams<T extends Parameters = {}, U extends Parameters =
opts: ParameterValues<U>
log: LogEntry
logFooter: LogEntry
output?: string
}

export interface CommandParams<T extends Parameters = {}, U extends Parameters = {}> extends PrepareParams<T, U> {
Expand Down
56 changes: 54 additions & 2 deletions garden-service/src/commands/get/get-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,79 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import * as Bluebird from "bluebird"
import { flatten, fromPairs } from "lodash"
import { deepFilter } from "../../util/util"
import {
Command,
CommandResult,
CommandParams,
} from "../base"
import { EnvironmentStatus } from "../../actions"
import { Garden } from "../../garden"
import { ConfigGraph } from "../../config-graph"
import { getTaskVersion } from "../../tasks/task"
import { LogEntry } from "../../logger/log-entry"
import { getTestVersion } from "../../tasks/test"

type RunStatus = "not-completed" | "completed"

interface TestStatuses { [testKey: string]: RunStatus }
interface TaskStatuses { [taskKey: string]: RunStatus }

// Value is "completed" if the test/task has been run for the current version.
export interface StatusCommandResult extends EnvironmentStatus {
testStatuses: TestStatuses
taskStatuses: TaskStatuses
}

export class GetStatusCommand extends Command {
name = "status"
help = "Outputs the status of your environment."

async action({ garden, log }: CommandParams): Promise<CommandResult<EnvironmentStatus>> {
async action({ garden, log, output }: CommandParams): Promise<CommandResult<EnvironmentStatus>> {
const status = await garden.actions.getStatus({ log })

let result
if (output) {
const graph = await garden.getConfigGraph()
result = await Bluebird.props({
...status,
testStatuses: getTestStatuses(garden, graph, log),
taskStatuses: getTaskStatuses(garden, graph, log),
})
} else {
result = status
}

// TODO: we should change the status format because this will remove services called "detail"
const withoutDetail = deepFilter(status, (_, key) => key !== "detail")

// TODO: do a nicer print of this by default
log.info({ data: withoutDetail })

return { result: status }
return { result }
}
}

async function getTestStatuses(garden: Garden, configGraph: ConfigGraph, log: LogEntry) {
const modules = await configGraph.getModules()
return fromPairs(flatten(await Bluebird.map(modules, async (module) => {
return Bluebird.map(module.testConfigs, async (testConfig) => {
const testVersion = await getTestVersion(garden, configGraph, module, testConfig)
const done = !!(await garden.actions.getTestResult({
module, log, testVersion, testName: testConfig.name,
}))
return [`${module.name}.${testConfig.name}`, done ? "completed" : "not-completed"]
})
})))
}

async function getTaskStatuses(garden: Garden, configGraph: ConfigGraph, log: LogEntry): Promise<TaskStatuses> {
const tasks = await configGraph.getTasks()
return fromPairs(await Bluebird.map(tasks, async (task) => {
const taskVersion = await getTaskVersion(garden, configGraph, task)
const done = !!(await garden.actions.getTaskResult({ task, taskVersion, log }))
return [task.name, done ? "completed" : "not-completed"]
}))
}

0 comments on commit a1e2122

Please sign in to comment.