Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -1,6 +1,7 @@
# Copyright 2023-2023 VMware, Inc.
# SPDX-License-Identifier: Apache-2.0
import abc
import io
import json
from enum import Enum
from enum import unique
Expand Down Expand Up @@ -107,6 +108,36 @@ def print_dict(self, data: Dict[str, Any]) -> None:
click.echo("{}")


@printer("memory")
class _MemoryPrinter(Printer):
output_buffer = io.StringIO()

def print_table(self, table: Optional[List[Dict[str, Any]]]) -> None:
if table and len(table) > 0:
print(
tabulate(table, headers="keys", tablefmt="fancy_grid"),
file=_MemoryPrinter.output_buffer,
)
else:
print("No Data.", file=_MemoryPrinter.output_buffer)

def print_dict(self, data: Optional[Dict[str, Any]]) -> None:
if data:
print(
tabulate(
[[k, v] for k, v in data.items()],
headers=("key", "value"),
),
file=_MemoryPrinter.output_buffer,
)
else:
print("No Data.", file=_MemoryPrinter.output_buffer)

@classmethod
def get_memory(cls):
return cls.output_buffer.getvalue()


def create_printer(output_format: str) -> Printer:
"""
Creates a printer instance for the given output format.
Expand All @@ -130,3 +161,4 @@ class OutputFormat(str, Enum):

TEXT = "TEXT"
JSON = "JSON"
FILE = "MEMORY"
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ describe('#render()', () => {
});
});

describe('#onEnableClick', () => {
it('should put a flag for enabled in jobData', () => {
const component = render(new DeployJobDialog(defaultProps).render());
const enableCheckbox = component.getAllByLabelText(
'Enable'
)[0] as HTMLInputElement;
expect(enableCheckbox.checked).toEqual(false);
fireEvent.click(enableCheckbox);
expect(enableCheckbox.checked).toEqual(true);
expect(jobData.get(VdkOption.DEPLOY_ENABLE)).toEqual('1');
});
});

describe('#onNameChange', () => {
it('should change the job name in jobData', () => {
const component = render(new DeployJobDialog(defaultProps).render());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,9 @@ export default class DeployJobDialog extends Component<IJobFullProps> {
value="reason"
label="Deployment reason:"
></VDKTextInput>
<div>
<input
type="checkbox"
name="enable"
id="enable"
className="jp-vdk-checkbox"
onClick={this.onEnableClick()}
/>
<label className="checkboxLabel" htmlFor="enable">
Enable
</label>
</div>
</>
);
}
/**
* Callback invoked upon choosing Enable checkbox
*/
private onEnableClick() {
return (event: React.MouseEvent) => {
const checkbox = document.getElementById('enable');
if (checkbox?.classList.contains('checked')) {
checkbox.classList.remove('checked');
jobData.set(VdkOption.DEPLOY_ENABLE, '');
} else {
checkbox?.classList.add('checked');
jobData.set(VdkOption.DEPLOY_ENABLE, '1');
}
};
}
}

export async function showCreateDeploymentDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export function getJobDataJsonObject() {
cloud: jobData.get(VdkOption.CLOUD),
local: jobData.get(VdkOption.LOCAL),
jobArguments: jobData.get(VdkOption.ARGUMENTS),
deploymentReason: jobData.get(VdkOption.DEPLOYMENT_REASON),
enableDeploy: jobData.get(VdkOption.DEPLOY_ENABLE)
deploymentReason: jobData.get(VdkOption.DEPLOYMENT_REASON)
};
return jsObj;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export enum VdkOption {
CLOUD = 'cloud',
LOCAL = 'local',
ARGUMENTS = 'jobArguments',
DEPLOYMENT_REASON = 'deploymentReason',
DEPLOY_ENABLE = 'enableDeploy'
DEPLOYMENT_REASON = 'deploymentReason'
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def post(self):
input_data[VdkOption.TEAM.value],
input_data[VdkOption.PATH.value],
input_data[VdkOption.DEPLOYMENT_REASON.value],
input_data[VdkOption.DEPLOY_ENABLE.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 @@ -11,4 +11,3 @@ class VdkOption(Enum):
LOCAL = "local"
ARGUMENTS = "jobArguments"
DEPLOYMENT_REASON = "deploymentReason"
DEPLOY_ENABLE = "enableDeploy"
Original file line number Diff line number Diff line change
Expand Up @@ -143,37 +143,30 @@ def create_job(name: str, team: str, path: str, local: bool, cloud: bool):
return f"Job with name {name} was created."

@staticmethod
def create_deployment(name: str, team: str, path: str, reason: str, enabled: bool):
def create_deployment(name: str, team: str, path: str, reason: str):
"""
Execute `Deploy job`.
:param name: the name of the data job that will be deployed
:param team: the team of the data job that will be deployed
:param path: the path to the job's directory
:param reason: the reason of deployment
:param enabled: flag whether the job is enabled (that will basically un-pause the job)
:return: output string of the operation
"""
output = "text"
output = "memory"
cmd = JobDeploy(RestApiUrlConfiguration.get_rest_api_url(), output)
if enabled:
cmd.create(
name=name,
team=team,
job_path=path,
reason=reason,
vdk_version=None,
enabled=True,
)
else:
cmd.create(
name=name,
team=team,
job_path=path,
reason=reason,
vdk_version=None,
enabled=False,
)
return f"Job with name {name} and team {team} is deployed successfully!"
cmd.create(
name=name,
team=team,
job_path=path,
reason=reason,
vdk_version=None,
enabled=True,
)
result = cmd._JobDeploy__printer.get_memory()
return (
f"Job with name {name} and team {team} is deployed successfully! "
f"Deployment information:\n {result}"
)

@staticmethod
def get_notebook_info(cell_id: str, pr_path: str):
Expand Down