Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vdk-jupyter: Pick up REST API URL from the env #2142

Merged
merged 5 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ describe('#onTeamChange', () => {
});
});

describe('#onRestApiUrlChange', () => {
it('should change the rest api url in jobData', () => {
const component = render(new CreateJobDialog(defaultProps).render());
const input = component.getByPlaceholderText('http://my_vdk_instance');
fireEvent.change(input, { target: { value: 'random-url' } });
expect(jobData.get(VdkOption.REST_API_URL)).toEqual('random-url');
});
});

describe('#onPathChange', () => {
it('should change the path in jobData', () => {
const component = render(new CreateJobDialog(defaultProps).render());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,3 @@ describe('#onTeamChange', () => {
expect(jobData.get(VdkOption.TEAM)).toEqual('second-team');
});
});

describe('#onRestApiUrlChange', () => {
it('should change the rest api url in jobData', () => {
const component = render(new DeleteJobDialog(defaultProps).render());
const input = component.getByPlaceholderText('http://my_vdk_instance');
fireEvent.change(input, { target: { value: 'random-url' } });
expect(jobData.get(VdkOption.REST_API_URL)).toEqual('random-url');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ describe('#onTeamChange', () => {
});
});

describe('#onRestApiUrlChange', () => {
it('should change the rest api url in jobData', () => {
const component = render(new DeployJobDialog(defaultProps).render());
const input = component.getByPlaceholderText('http://my_vdk_instance');
fireEvent.change(input, { target: { value: 'random-url' } });
expect(jobData.get(VdkOption.REST_API_URL)).toEqual('random-url');
});
});

describe('#onPathChange', () => {
it('should change the path in jobData', () => {
const component = render(new DeployJobDialog(defaultProps).render());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,6 @@ describe('#onTeamChange', () => {
});
});

describe('#onRestApiUrlChange', () => {
it('should change the rest api url in jobData', () => {
const component = render(new DownloadJobDialog(defaultProps).render());
const input = component.getByPlaceholderText('http://my_vdk_instance');
fireEvent.change(input, { target: { value: 'random-url' } });
expect(jobData.get(VdkOption.REST_API_URL)).toEqual('random-url');
});
});

describe('#onPathChange', () => {
it('should change the path in jobData', () => {
const component = render(new DownloadJobDialog(defaultProps).render());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ export default class CreateJobDialog extends Component<(IJobFullProps)> {
value={this.props.jobTeam}
label="Job Team:"
></VDKTextInput>
<VDKTextInput
option={VdkOption.REST_API_URL}
value="http://my_vdk_instance"
label="Rest API URL:"
></VDKTextInput>
<VDKTextInput
option={VdkOption.PATH}
value={this.props.jobPath}
Expand All @@ -79,26 +74,24 @@ export default class CreateJobDialog extends Component<(IJobFullProps)> {
*/
private _onLocalClick() {
return (event: React.MouseEvent) => {
this.setJobFlags('Local', 'jobPath');
this.setJobFlags('Local');
};
}
/**
* Callback invoked upon choosing cloud checkbox
*/
private _onCloudClick() {
return (event: React.MouseEvent) => {
this.setJobFlags('Cloud', 'jobRestApiUrl');
this.setJobFlags('Cloud');
};
}
/**
* Function that sets job's cloud/local flags
*/
private setJobFlags(flag: string, inputId: string) {
private setJobFlags(flag: string) {
let checkbox = document.getElementById(flag);
let input = document.getElementById(inputId);
if (checkbox?.classList.contains('checked')) {
checkbox.classList.remove('checked');
input?.parentElement?.classList.add('hidden');
if (flag === 'Cloud') {
jobData.set(VdkOption.CLOUD, '');
} else {
Expand All @@ -111,7 +104,6 @@ export default class CreateJobDialog extends Component<(IJobFullProps)> {
} else {
jobData.set(VdkOption.LOCAL, '1');
}
input?.parentElement?.classList.remove('hidden');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export default class DeleteJobDialog extends Component<IJobNameAndTeamProps> {
value={this.props.jobTeam}
label="Job Team:"
></VDKTextInput>
<VDKTextInput
option={VdkOption.REST_API_URL}
value="http://my_vdk_instance"
label="Rest API URL:"
></VDKTextInput>
</>
);
}
Expand All @@ -63,8 +58,6 @@ export async function showDeleteJobDialog() {
body:
'Do you really want to delete the job with name ' +
jobData.get(VdkOption.NAME) +
' from ' +
jobData.get(VdkOption.REST_API_URL) +
'?',
buttons: [
Dialog.cancelButton({ label: 'Cancel' }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export default class DeployJobDialog extends Component<(IJobFullProps)> {
value={this.props.jobTeam}
label="Job Team:"
></VDKTextInput>
<VDKTextInput
option={VdkOption.REST_API_URL}
value="http://my_vdk_instance"
label="Rest API URL:"
></VDKTextInput>
<VDKTextInput
option={VdkOption.PATH}
value={this.props.jobPath}
Expand Down Expand Up @@ -113,7 +108,7 @@ export async function showCreateDeploymentDialog() {
}
} else {
showErrorMessage(
'Encauntered an error while running the job!',
'Encоuntered an error while running the job!',
message,
[Dialog.okButton()]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export default class DownloadJobDialog extends Component<IJobPathProp> {
value="default-team"
label="Job Team:"
></VDKTextInput>
<VDKTextInput
option={VdkOption.REST_API_URL}
value="http://my_vdk_instance"
label="Rest API URL:"
></VDKTextInput>
<VDKTextInput
option={VdkOption.PATH}
value={this.props.jobPath}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export function getJobDataJsonObject() {
const jsObj = {
jobName: jobData.get(VdkOption.NAME),
jobTeam: jobData.get(VdkOption.TEAM),
restApiUrl: jobData.get(VdkOption.REST_API_URL),
jobPath: jobData.get(VdkOption.PATH),
cloud: jobData.get(VdkOption.CLOUD),
local: jobData.get(VdkOption.LOCAL),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
export enum VdkOption {
NAME = 'jobName',
TEAM = 'jobTeam',
REST_API_URL = 'restApiUrl',
PATH = 'jobPath',
CLOUD = 'cloud',
LOCAL = 'local',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2021-2023 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
import json
import os

import tornado
from jupyter_server.base.handlers import APIHandler
Expand All @@ -11,6 +12,24 @@
from .vdk_ui import VdkUI


class HandlerConfiguration:
def __init__(self):
self._rest_api_url = os.environ["REST_API_URL"]
if not self._rest_api_url:
raise Exception(
"What happened: Missing environment variable REST_API_URL.\n"
"Why it happened: This is probably caused by a corrupt environment.\n"
"Consequences: The current environment cannot work as it cannot connect to the VDK Control Service.\n"
"Countermeasures: Please alert your support team; alternatively, try restarting your environment."
)

def get_rest_api_url(self):
return self._rest_api_url


handler_config = HandlerConfiguration()


class LoadJobDataHandler(APIHandler):
"""
Class responsible for handling POST request for retrieving data(full path, job's name and team)
Expand Down Expand Up @@ -66,7 +85,7 @@ def post(self):
status = VdkUI.delete_job(
input_data[VdkOption.NAME.value],
input_data[VdkOption.TEAM.value],
input_data[VdkOption.REST_API_URL.value],
handler_config.get_rest_api_url(),
)
self.finish(json.dumps({"message": f"{status}", "error": ""}))
except Exception as e:
Expand All @@ -89,7 +108,7 @@ def post(self):
status = VdkUI.download_job(
input_data[VdkOption.NAME.value],
input_data[VdkOption.TEAM.value],
input_data[VdkOption.REST_API_URL.value],
handler_config.get_rest_api_url(),
input_data[VdkOption.PATH.value],
)
self.finish(json.dumps({"message": f"{status}", "error": ""}))
Expand All @@ -114,7 +133,7 @@ def post(self):
status = VdkUI.create_job(
input_data[VdkOption.NAME.value],
input_data[VdkOption.TEAM.value],
input_data[VdkOption.REST_API_URL.value],
handler_config.get_rest_api_url(),
input_data[VdkOption.PATH.value],
bool(input_data[VdkOption.LOCAL.value]),
bool(input_data[VdkOption.CLOUD.value]),
Expand All @@ -140,7 +159,7 @@ def post(self):
status = VdkUI.create_deployment(
input_data[VdkOption.NAME.value],
input_data[VdkOption.TEAM.value],
input_data[VdkOption.REST_API_URL.value],
handler_config.get_rest_api_url(),
input_data[VdkOption.PATH.value],
input_data[VdkOption.DEPLOYMENT_REASON.value],
input_data[VdkOption.DEPLOY_ENABLE.value],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
class VdkOption(Enum):
NAME = "jobName"
TEAM = "jobTeam"
REST_API_URL = "restApiUrl"
PATH = "jobPath"
CLOUD = "cloud"
LOCAL = "local"
Expand Down