Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Use JS SDK in submit-job-v2 plugin #4613

Merged
merged 3 commits into from
Jun 12, 2020
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
5 changes: 3 additions & 2 deletions contrib/submit-job-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
"homepage": "https://github.com/Microsoft/pai#readme",
"license": "MIT",
"dependencies": {
"@microsoft/openpai-js-sdk": "^0.1.0",
"classnames": "^2.2.6",
"core-js": "^3.0.1",
"immutability-helper": "^3.0.0",
"js-cookie": "^2.2.0",
"js-yaml": "^3.13.1",
"monaco-editor": "^0.16.2",
"monaco-editor": "^0.20.0",
"office-ui-fabric-react": "^6.162.1",
"react": "^16.8.4",
"react-dom": "^16.8.4",
Expand All @@ -40,7 +41,7 @@
"css-loader": "^2.1.1",
"file-loader": "^3.0.1",
"monaco-editor-webpack-plugin": "^1.7.0",
"node-sass": "^4.11.0",
"node-sass": "^4.14.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.23.1",
"ts-loader": "^6.2.1",
Expand Down
49 changes: 15 additions & 34 deletions contrib/submit-job-v2/src/App/ProtocolForm.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import React, { Suspense, lazy } from "react";
import {
Expand All @@ -25,6 +11,7 @@ import Cookies from "js-cookie";
import classNames from "classnames/bind";
import update from "immutability-helper";
import yaml from "js-yaml";
import { PAIV2 } from "@microsoft/openpai-js-sdk";

import monacoStyles from "./monaco.scss";
import MarketplaceForm from "./MarketplaceForm";
Expand Down Expand Up @@ -173,6 +160,12 @@ export default class ProtocolForm extends React.Component<IProtocolProps, IProto
showEditor: false,
};

private client = new PAIV2.OpenPAIClient({
username: this.props.user,
token: this.props.token,
rest_server_uri: this.props.api,
});

public componentDidMount() {
this.fetchConfig();
}
Expand Down Expand Up @@ -359,13 +352,9 @@ export default class ProtocolForm extends React.Component<IProtocolProps, IProto
marketplaceOption: source.protocolItemKey,
});
} else if (source && source.jobName && source.user && pluginId) {
const res = await fetch(
`${this.props.api}/api/v1/user/${source.user}/jobs/${source.jobName}/config`,
);
const body = await res.text();
protocol = yaml.safeLoad(body);
if (protocol.extras.submitFrom !== pluginId) {
throw new Error(`Unknown plugin id ${protocol.extras.submitFrom}`);
protocol = await this.client.job.getJobConfig(source.user, source.jobName);
if (protocol!.extras!.submitFrom !== pluginId) {
throw new Error(`Unknown plugin id ${protocol!.extras!.submitFrom}`);
}
protocol.name = this.getCloneJobName(source.jobName);
}
Expand Down Expand Up @@ -555,17 +544,9 @@ export default class ProtocolForm extends React.Component<IProtocolProps, IProto
protocol.extras = { submitFrom: this.props.pluginId };
}
try {
const res = await fetch(`${this.props.api}/api/v2/jobs`, {
body: yaml.safeDump(protocol),
headers: {
"Authorization": `Bearer ${this.props.token}`,
"Content-Type": "text/yaml",
},
method: "POST",
});
const body = await res.json();
if (Number(res.status) >= 400) {
alert(body.message);
const res = await this.client.job.createJob(protocol);
if (res.code) {
alert(res.message);
} else {
window.location.href = `/job-detail.html?username=${this.props.user}&jobName=${this.state.jobName}`;
}
Expand Down
18 changes: 2 additions & 16 deletions contrib/submit-job-v2/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import "core-js/stable";
import "whatwg-fetch";
Expand Down
23 changes: 7 additions & 16 deletions contrib/submit-job-v2/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

const { resolve } = require("path");
const webpack = require("webpack");
Expand Down Expand Up @@ -95,6 +81,11 @@ const configuration = {
},
disableHostCheck: true,
},
node: {
fs: 'empty',
net: 'empty',
tls: 'empty',
}
};

module.exports = configuration;
Loading