diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/__tests__/create-job-component.spec.ts b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/__tests__/create-job-component.spec.ts index 3f1098c116..dd8d52d898 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/__tests__/create-job-component.spec.ts +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/__tests__/create-job-component.spec.ts @@ -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()); diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/components/CreateJob.tsx b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/components/CreateJob.tsx index 3e5595c7e7..902bffdd9c 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/components/CreateJob.tsx +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/components/CreateJob.tsx @@ -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 { +export default class CreateJobDialog extends Component<(IJobFullProps)> { /** * Returns a React component for rendering a create menu. * @@ -26,32 +25,6 @@ export default class CreateJobDialog extends Component { render(): React.ReactElement { return ( <> -
-
- - -
-
- - -
-
{ ); } - /** - * 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: ( @@ -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'); } } diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/jobData.ts b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/jobData.ts index 23f513b083..b52bdc3b08 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/jobData.ts +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/jobData.ts @@ -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) }; diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/vdkOptions/vdk_options.ts b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/vdkOptions/vdk_options.ts index 9bc08fa6c4..4b8a24ebb1 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/vdkOptions/vdk_options.ts +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/src/vdkOptions/vdk_options.ts @@ -7,8 +7,6 @@ export enum VdkOption { NAME = 'jobName', TEAM = 'jobTeam', PATH = 'jobPath', - CLOUD = 'cloud', - LOCAL = 'local', ARGUMENTS = 'jobArguments', DEPLOYMENT_REASON = 'deploymentReason' } diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/ui-tests/tests/vdk-jupyterlab-extension.spec.ts b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/ui-tests/tests/vdk-jupyterlab-extension.spec.ts index 6ee04279cd..92698cbde8 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/ui-tests/tests/vdk-jupyterlab-extension.spec.ts +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/ui-tests/tests/vdk-jupyterlab-extension.spec.ts @@ -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(); @@ -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 }) => { diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/handlers.py b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/handlers.py index ba051cb2ed..2acca39a8c 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/handlers.py +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/handlers.py @@ -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: diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_options/vdk_options.py b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_options/vdk_options.py index 393ab96b90..4389fc9dda 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_options/vdk_options.py +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_options/vdk_options.py @@ -7,7 +7,5 @@ class VdkOption(Enum): NAME = "jobName" TEAM = "jobTeam" PATH = "jobPath" - CLOUD = "cloud" - LOCAL = "local" ARGUMENTS = "jobArguments" DEPLOYMENT_REASON = "deploymentReason" diff --git a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_ui.py b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_ui.py index b9b4f24502..190820be85 100644 --- a/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_ui.py +++ b/projects/vdk-plugins/vdk-jupyter/vdk-jupyterlab-extension/vdk_jupyterlab_extension/vdk_ui.py @@ -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 @@ -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 @@ -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: + 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):