Skip to content

Commit

Permalink
Split server:deploy and server:start commands
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Nov 17, 2020
1 parent 300e892 commit fea4a61
Showing 1 changed file with 105 additions and 0 deletions.
105 changes: 105 additions & 0 deletions src/commands/server/start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*********************************************************************
* Copyright (c) 2019 Red Hat, Inc.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/

import { Command, flags } from '@oclif/command'
import { string } from '@oclif/parser/lib/flags'
import { cli } from 'cli-ux'
import * as Listr from 'listr'
import * as notifier from 'node-notifier'

import { DEFAULT_K8S_POD_ERROR_RECHECK_TIMEOUT, DEFAULT_K8S_POD_TIMEOUT } from '../../api/kube'
import { cheDeployment, cheNamespace, listrRenderer, skipKubeHealthzCheck as skipK8sHealthCheck } from '../../common-flags'
import { CheTasks } from '../../tasks/che'
import { getPrintHighlightedMessagesTask } from '../../tasks/installers/common-tasks'
import { ApiTasks } from '../../tasks/platforms/api'
import { getCommandFailMessage, getCommandSuccessMessage, initializeContext } from '../../util'

export default class Start extends Command {
static description = 'start Eclipse Che server'

static flags: flags.Input<any> = {
help: flags.help({ char: 'h' }),
chenamespace: cheNamespace,
'listr-renderer': listrRenderer,
'deployment-name': cheDeployment,
k8spodwaittimeout: string({
description: 'Waiting time for Pod scheduled condition (in milliseconds)',
default: `${DEFAULT_K8S_POD_TIMEOUT}`
}),
k8spoddownloadimagetimeout: string({
description: 'Waiting time for Pod downloading image (in milliseconds)',
default: `${DEFAULT_K8S_POD_TIMEOUT}`
}),
k8spodreadytimeout: string({
description: 'Waiting time for Pod Ready condition (in milliseconds)',
default: `${DEFAULT_K8S_POD_TIMEOUT}`
}),
k8spoderrorrechecktimeout: string({
description: 'Waiting time for Pod rechecking error (in milliseconds)',
default: `${DEFAULT_K8S_POD_ERROR_RECHECK_TIMEOUT}`
}),
directory: string({
char: 'd',
description: 'Directory to store logs into',
env: 'CHE_LOGS'
}),
'skip-kubernetes-health-check': skipK8sHealthCheck,
}

async run() {
const { flags } = this.parse(Start)
const ctx = await initializeContext(flags)

const cheTasks = new CheTasks(flags)
const apiTasks = new ApiTasks()

// Checks if Eclipse Che is already deployed
const preInstallTasks = new Listr([
apiTasks.testApiTasks(flags, this),
{
title: '👀 Looking for an already existing Eclipse Che instance',
task: () => new Listr(cheTasks.checkIfCheIsInstalledTasks(flags, this))
}], ctx.listrOptions)

const logsTasks = new Listr([{
title: 'Start following Eclipse Che logs',
task: () => new Listr(cheTasks.serverLogsTasks(flags, true))
}], ctx.listrOptions)

const startDeployedCheTasks = new Listr([{
title: 'Starting already deployed Eclipse Che',
task: () => new Listr(cheTasks.scaleCheUpTasks())
}], ctx.listrOptions)

try {
await preInstallTasks.run(ctx)

if (!ctx.isCheDeployed) {
cli.warn('Eclipse Che has not been deployed yet. Use server:deploy command to deploy a new Eclipse Che instance.')
} else if (ctx.isCheReady) {
cli.info('Eclipse Che has been already started.')
} else {
await logsTasks.run(ctx)
await startDeployedCheTasks.run(ctx)
this.log(getCommandSuccessMessage(this, ctx))
}
} catch (err) {
this.error(`${err}\n${getCommandFailMessage(this, ctx)}`)
}

notifier.notify({
title: 'chectl',
message: getCommandSuccessMessage(this, ctx)
})

this.exit(0)
}

}

0 comments on commit fea4a61

Please sign in to comment.