forked from redhat-developer/vscode-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just a POC for now See: Provide a "Deploy to OpenShift" command redhat-developer#313 Signed-off-by: David Thompson <davthomp@redhat.com>
- Loading branch information
Showing
6 changed files
with
154 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { commands, Extension, extensions } from "vscode"; | ||
|
||
export const OPENSHIFT_CONNECTOR_EXTENSION_ID: string = 'redhat.vscode-openshift-connector'; | ||
|
||
/** | ||
* Returns true if the OpenShift connector extension is installed, and false otherwise | ||
* | ||
* @returns true if the OpenShift connector extension is installed, and false otherwise | ||
*/ | ||
export function isOpenShiftConnectorInstalled(): boolean { | ||
return !!extensions.getExtension(OPENSHIFT_CONNECTOR_EXTENSION_ID); | ||
} | ||
|
||
/** | ||
* Returns the OpenShift Connector extension API | ||
* | ||
* @throws Error if the extension is not installed | ||
* @returns the OpenShift Connector extension API | ||
*/ | ||
export async function getOpenShiftConnector(): Promise<any> { | ||
if (!isOpenShiftConnectorInstalled) { | ||
throw new Error('The OpenShift Connector extension is not installed'); | ||
} | ||
const openShiftConnector: Extension<any> = extensions.getExtension(OPENSHIFT_CONNECTOR_EXTENSION_ID); | ||
if (openShiftConnector.isActive) { | ||
return openShiftConnector.exports; | ||
} | ||
return extensions.getExtension(OPENSHIFT_CONNECTOR_EXTENSION_ID).activate(); | ||
} | ||
|
||
/** | ||
* Install the OpenShift Connector extension | ||
* | ||
* Resolves when the extension is installed | ||
*/ | ||
export async function installOpenShiftConnector(): Promise<any> { | ||
commands.executeCommand("workbench.extensions.installExtension", OPENSHIFT_CONNECTOR_EXTENSION_ID); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { window } from "vscode"; | ||
import { ProjectLabelInfo } from "../../definitions/ProjectLabelInfo"; | ||
import { getOpenShiftConnector, installOpenShiftConnector, isOpenShiftConnectorInstalled } from "../../utils/openShiftConnectorUtils"; | ||
import { getQuarkusProject } from "../getQuarkusProject"; | ||
|
||
/** | ||
* Attempts to select a Quarkus project, then deploy it to OpenShift using OpenShift Connector | ||
*/ | ||
export async function deployToOpenShift() { | ||
try { | ||
const openShiftConnectorExtension: any = await installOpenShiftConnectorIfNeeded(); | ||
const quarkusProject: ProjectLabelInfo = await getQuarkusProject(); | ||
// openShiftConnectorExtension.Component.createFromFolder(quarkusProject.uri); | ||
window.showInformationMessage('Successfully deployed extension is deployed'); | ||
} catch (error) { | ||
return window.showErrorMessage(`Failed to deploy to OpenShift: ${error}`); | ||
} | ||
} | ||
|
||
/** | ||
* Installs the OpenShift Connector extension if its missing, then returns the extension API | ||
* | ||
* @throws Error if the extension is not installed and something prevents installation | ||
* @returns the OpenShift Connector extension API | ||
*/ | ||
async function installOpenShiftConnectorIfNeeded(): Promise<any> { | ||
if (isOpenShiftConnectorInstalled()) { | ||
return getOpenShiftConnector(); | ||
} | ||
return askToInstallOpenShiftConnector(); | ||
} | ||
|
||
/** | ||
* Resolves to the OpenShift connector extension API, or rejects if the extension is missing and the user doesn't want to install it | ||
* | ||
* @throws Error if the extension is missing and the user can't or doesn't want to install it | ||
* @returns the OpenShift connector extension API | ||
*/ | ||
async function askToInstallOpenShiftConnector(): Promise<any> { | ||
const YES: string = 'Yes'; | ||
const NO: string = 'No'; | ||
const response: string = await window.showInformationMessage('The OpenShift Connector extension is needed to deploy to OpenShift. Install it now?', YES, NO); | ||
if (response === YES) { | ||
await installOpenShiftConnector(); | ||
if (isOpenShiftConnectorInstalled()) { | ||
return getOpenShiftConnector(); | ||
} | ||
throw new Error('The OpenShift Connector installation failed'); | ||
} | ||
throw new Error('The OpenShift Connector extension needs to be installed to deploy to OpenShift'); | ||
} |