Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,6 @@ describe('#render()', () => {
});
});

describe('#onLocalClick', () => {
it('should put a flag for local in jobData', () => {
const component = render(new CreateJobDialog(defaultProps).render());
const localCheckbox = component.getAllByLabelText(
'Local'
)[0] as HTMLInputElement;
expect(localCheckbox.checked).toEqual(false);
fireEvent.click(localCheckbox);
expect(localCheckbox.checked).toEqual(true);
expect(jobData.get(VdkOption.LOCAL)).toEqual('1');
});
});

describe('#onCloudClick', () => {
it('should put a flag for cloud in jobData', () => {
const component = render(new CreateJobDialog(defaultProps).render());
const cloudCheckbox = component.getAllByLabelText(
'Cloud'
)[0] as HTMLInputElement;
expect(cloudCheckbox.checked).toEqual(false);
fireEvent.click(cloudCheckbox);
expect(cloudCheckbox.checked).toEqual(true);
expect(jobData.get(VdkOption.CLOUD)).toEqual('1');
});
});

describe('#onNameChange', () => {
it('should change the job name in jobData', () => {
const component = render(new CreateJobDialog(defaultProps).render());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { Dialog, showDialog } from '@jupyterlab/apputils';
import { jobRequest } from '../serverRequests';
import { IJobFullProps } from './props';
import { CREATE_JOB_BUTTON_LABEL } from '../utils';
import { StatusButton } from './StatusButton';

export default class CreateJobDialog extends Component<IJobFullProps> {
export default class CreateJobDialog extends Component<(IJobFullProps)> {
/**
* Returns a React component for rendering a create menu.
*
Expand All @@ -26,32 +25,6 @@ export default class CreateJobDialog extends Component<IJobFullProps> {
render(): React.ReactElement {
return (
<>
<div className="jp-vdk-checkbox-wrappers">
<div>
<input
type="checkbox"
name="Local"
id="Local"
className="jp-vdk-checkbox"
onClick={this._onLocalClick()}
/>
<label className="checkboxLabel" htmlFor="Local">
Local
</label>
</div>
<div>
<input
type="checkbox"
name="Cloud"
id="Cloud"
className="jp-vdk-checkbox"
onClick={this._onCloudClick()}
/>
<label className="checkboxLabel" htmlFor="Cloud">
Cloud
</label>
</div>
</div>
<VDKTextInput
option={VdkOption.NAME}
value={this.props.jobName}
Expand All @@ -70,46 +43,9 @@ export default class CreateJobDialog extends Component<IJobFullProps> {
</>
);
}
/**
* Callback invoked upon choosing local checkbox
*/
private _onLocalClick() {
return (event: React.MouseEvent) => {
this.setJobFlags('Local');
};
}
/**
* Callback invoked upon choosing cloud checkbox
*/
private _onCloudClick() {
return (event: React.MouseEvent) => {
this.setJobFlags('Cloud');
};
}
/**
* Function that sets job's cloud/local flags
*/
private setJobFlags(flag: string) {
const checkbox = document.getElementById(flag);
if (checkbox?.classList.contains('checked')) {
checkbox.classList.remove('checked');
if (flag === 'Cloud') {
jobData.set(VdkOption.CLOUD, '');
} else {
jobData.set(VdkOption.LOCAL, '');
}
} else {
checkbox?.classList.add('checked');
if (flag === 'Cloud') {
jobData.set(VdkOption.CLOUD, '1');
} else {
jobData.set(VdkOption.LOCAL, '1');
}
}
}
}

export async function showCreateJobDialog(statusButton?: StatusButton) {
export async function showCreateJobDialog() {
const result = await showDialog({
title: CREATE_JOB_BUTTON_LABEL,
body: (
Expand All @@ -122,7 +58,6 @@ export async function showCreateJobDialog(statusButton?: StatusButton) {
buttons: [Dialog.okButton(), Dialog.cancelButton()]
});
if (result.button.accept) {
statusButton?.show('Create', jobData.get(VdkOption.PATH)!);
await jobRequest('create');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export function getJobDataJsonObject() {
jobName: jobData.get(VdkOption.NAME),
jobTeam: jobData.get(VdkOption.TEAM),
jobPath: jobData.get(VdkOption.PATH),
cloud: jobData.get(VdkOption.CLOUD),
local: jobData.get(VdkOption.LOCAL),
jobArguments: jobData.get(VdkOption.ARGUMENTS),
deploymentReason: jobData.get(VdkOption.DEPLOYMENT_REASON)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export enum VdkOption {
NAME = 'jobName',
TEAM = 'jobTeam',
PATH = 'jobPath',
CLOUD = 'cloud',
LOCAL = 'local',
ARGUMENTS = 'jobArguments',
DEPLOYMENT_REASON = 'deploymentReason'
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ test('should try to create a job with incorrect input and get error', async ({
await page.goto('');
await page.menu.open('VDK');
await page.locator('#jp-vdk-menu').getByText('Create').click();
await page.getByLabel('Local').check();
await page.getByLabel('Job name:').click();
await page.getByLabel('Job name:').fill('first-job');
await page.getByLabel('Job team:').click();
Expand All @@ -94,6 +93,25 @@ test('should try to create a job with incorrect input and get error', async ({
await page.getByRole('button', { name: 'OK' }).click();
});

test('should try to create a job successfully', async ({ page }) => {
await page.goto('');
await page.menu.open('VDK');
await page.locator('#jp-vdk-menu').getByText('Create').click();
await page.getByLabel('Job name:').click();
await page.getByLabel('Job name:').fill('first-job');
await page.getByLabel('Job team:').click();
await page.getByLabel('Job team:').fill('my-team');
await page.getByRole('button', { name: 'OK' }).click();
page.on('dialog', async dialog => {
expect(dialog.type()).toContain('alert');
expect(dialog.message()).toContain(
'Job with name first-job was created successfully!'
);
await dialog.accept();
});
await page.getByRole('button', { name: 'OK' }).click();
});

test('should open download job pop up and then cancel the operation', async ({
page
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ def post(self):
input_data[VdkOption.NAME.value],
input_data[VdkOption.TEAM.value],
input_data[VdkOption.PATH.value],
bool(input_data[VdkOption.LOCAL.value]),
bool(input_data[VdkOption.CLOUD.value]),
)
self.finish(json.dumps({"message": f"{status}", "error": ""}))
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ class VdkOption(Enum):
NAME = "jobName"
TEAM = "jobTeam"
PATH = "jobPath"
CLOUD = "cloud"
LOCAL = "local"
ARGUMENTS = "jobArguments"
DEPLOYMENT_REASON = "deploymentReason"
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def run_job(path, arguments=None):
return {"message": process.returncode}

@staticmethod
def delete_job(name: str, team: str):
def delete_job(name: str, team: str) -> str:
"""
Execute `delete job`.
:param name: the name of the data job that will be deleted
Expand All @@ -105,7 +105,7 @@ def delete_job(name: str, team: str):
return f"Deleted the job with name {name} from {team} team. "

@staticmethod
def download_job(name: str, team: str, path: str):
def download_job(name: str, team: str, path: str) -> str:
"""
Execute `download job`.
:param name: the name of the data job that will be downloaded
Expand All @@ -118,30 +118,40 @@ def download_job(name: str, team: str, path: str):
return f"Downloaded the job with name {name} to {path}. "

@staticmethod
def create_job(name: str, team: str, path: str, local: bool, cloud: bool):
def create_job(name: str, team: str, path: str) -> str:
"""
Execute `create job`.
:param name: the name of the data job that will be created
:param team: the team of the data job that will be created
:param path: the path to the directory where the job will be created
:param local: create sample job on local file system
:param cloud: create job in the cloud
:return: message that the job is created
"""
cmd = JobCreate(RestApiUrlConfiguration.get_rest_api_url())
if cloud:
cli_utils.check_rest_api_url(RestApiUrlConfiguration.get_rest_api_url())

if local:
cmd.validate_job_path(path, name)

jupyter_job_dir = os.path.abspath(
os.path.join(os.path.dirname(__file__), "jupyter_sample_job")
)
rest_api_url = ""
cloud = False
error = ""
try:
rest_api_url = RestApiUrlConfiguration.get_rest_api_url()
cli_utils.check_rest_api_url(rest_api_url)
cloud = True
except ValueError as e:
Comment thread
duyguHsnHsn marked this conversation as resolved.
error = str(e)
cmd = JobCreate(rest_api_url)
cmd.create_job(name, team, path, cloud, True, pathlib.Path(jupyter_job_dir))
if cloud:
result = f"Job with name {name} was created successfully!"
else:
result = (
f"Job with name {name} was created only locally. "
f"If you are not using the Control Service the next lines should not concern you! \n"
f"We tried to create it in the cloud but come up to:"
f"{error}"
f""
)

cmd.create_job(name, team, path, cloud, local, jupyter_job_dir)

return f"Job with name {name} was created."
return result

@staticmethod
def create_deployment(name: str, team: str, path: str, reason: str):
Expand Down