From de1a1da31345074ce51c488d0310ea589c44bc00 Mon Sep 17 00:00:00 2001 From: Duygu Hasan Date: Thu, 27 Jul 2023 17:38:44 +0300 Subject: [PATCH 1/7] automate create and remove cloud and local from vdkOptions in pytrhon --- .../vdk_jupyterlab_extension/handlers.py | 2 -- .../vdk_options/vdk_options.py | 2 -- .../vdk_jupyterlab_extension/vdk_ui.py | 33 +++++++++++-------- 3 files changed, 19 insertions(+), 18 deletions(-) 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..fdd528d081 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 @@ -118,30 +118,35 @@ 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): """ 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") ) - - cmd.create_job(name, team, path, cloud, local, jupyter_job_dir) - - return f"Job with name {name} was created." + try: + cmd = JobCreate(RestApiUrlConfiguration.get_rest_api_url()) + cli_utils.check_rest_api_url(RestApiUrlConfiguration.get_rest_api_url()) + cmd.validate_job_path(path, name) + cmd.create_job(name, team, path, True, True, pathlib.Path(jupyter_job_dir)) + result = f"Job with name {name} was created locally and in the cloud." + except ValueError as e: + cmd = JobCreate("") + cmd.validate_job_path(path, name) + cmd.create_job(name, team, path, False, True, pathlib.Path(jupyter_job_dir)) + 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!" + f"We tried to create it in the cloud but come up to:" + f"{e}" + f"" + ) + return result @staticmethod def create_deployment(name: str, team: str, path: str, reason: str): From 3e9954927d2b933a69cb55374de6f03a0d506056 Mon Sep 17 00:00:00 2001 From: Duygu Hasan Date: Mon, 31 Jul 2023 13:55:39 +0300 Subject: [PATCH 2/7] remove cloud and local flags from front end components --- .../src/components/CreateJob.tsx | 63 ------------------- .../vdk-jupyterlab-extension/src/jobData.ts | 2 - .../src/vdkOptions/vdk_options.ts | 2 - 3 files changed, 67 deletions(-) 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 bfc0f5247b..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 @@ -25,32 +25,6 @@ export default class CreateJobDialog extends Component<(IJobFullProps)> { 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) { - let 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() { 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' } From eaaf4b72db01b07c4246b9df7401fec5ed4ca699 Mon Sep 17 00:00:00 2001 From: Duygu Hasan Date: Mon, 31 Jul 2023 13:59:17 +0300 Subject: [PATCH 3/7] remove cloud and local flags from tests --- .../__tests__/create-job-component.spec.ts | 26 ------------------- 1 file changed, 26 deletions(-) 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()); From 6730d38551ead2908d4e67abdfee87f7e0586ec8 Mon Sep 17 00:00:00 2001 From: Duygu Hasan Date: Mon, 31 Jul 2023 15:49:16 +0300 Subject: [PATCH 4/7] remove cloud and local flags from ui-tests --- .../ui-tests/tests/vdk-jupyterlab-extension.spec.ts | 1 - 1 file changed, 1 deletion(-) 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 4f43272e1d..e9a19c8fde 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 @@ -81,7 +81,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(); From 1d4842fbfca7c267c5862ae6d9213592b61f0041 Mon Sep 17 00:00:00 2001 From: Duygu Hasan Date: Tue, 8 Aug 2023 14:47:08 +0300 Subject: [PATCH 5/7] address comments --- .../vdk_jupyterlab_extension/vdk_ui.py | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) 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 fdd528d081..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,7 +118,7 @@ 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): + 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 @@ -129,23 +129,28 @@ def create_job(name: str, team: str, path: str): jupyter_job_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), "jupyter_sample_job") ) + rest_api_url = "" + cloud = False + error = "" try: - cmd = JobCreate(RestApiUrlConfiguration.get_rest_api_url()) - cli_utils.check_rest_api_url(RestApiUrlConfiguration.get_rest_api_url()) - cmd.validate_job_path(path, name) - cmd.create_job(name, team, path, True, True, pathlib.Path(jupyter_job_dir)) - result = f"Job with name {name} was created locally and in the cloud." + rest_api_url = RestApiUrlConfiguration.get_rest_api_url() + cli_utils.check_rest_api_url(rest_api_url) + cloud = True except ValueError as e: - cmd = JobCreate("") - cmd.validate_job_path(path, name) - cmd.create_job(name, team, path, False, True, pathlib.Path(jupyter_job_dir)) + 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!" + 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"{e}" + f"{error}" f"" ) + return result @staticmethod From 81b90e6e486e3d825117e8c2e517ae405cfc7a9c Mon Sep 17 00:00:00 2001 From: Duygu Hasan Date: Wed, 9 Aug 2023 13:35:16 +0300 Subject: [PATCH 6/7] add e2e test --- .../tests/vdk-jupyterlab-extension.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 6fed29b20b..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 @@ -93,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 }) => { From bda79c0e16c971dc177d3908d6a6160d742d78c6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 10:39:24 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../vdk-jupyterlab-extension/src/components/CreateJob.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fe7c801a67..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 @@ -60,4 +60,4 @@ export async function showCreateJobDialog() { if (result.button.accept) { await jobRequest('create'); } -} \ No newline at end of file +}