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

Commit

Permalink
[Webportal] Support dynamic sku types for different vc (#4900)
Browse files Browse the repository at this point in the history
Support dynamic sku types for different virtual clusters on webportal.
  • Loading branch information
abuccts authored Sep 21, 2020
1 parent f5552de commit d31eb2a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
35 changes: 32 additions & 3 deletions src/rest-server/src/controllers/v2/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,40 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// module dependencies
const axios = require('axios');
const status = require('statuses');
const createError = require('@pai/utils/error');
const { resourceUnits } = require('@pai/config/vc');
const { hivedWebserviceUri } = require('@pai/config/launcher');
const asyncHandler = require('@pai/middlewares/v2/asyncHandler');

const getSkuTypes = (req, res) => {
res.status(status('OK')).json(resourceUnits);
};
const getSkuTypes = asyncHandler(async (req, res) => {
if (req.query.vc) {
let vcStatus;
try {
vcStatus = (
await axios.get(
`${hivedWebserviceUri}/v1/inspect/clusterstatus/virtualclusters/${req.query.vc}`,
)
).data;
} catch (error) {
throw createError(
'Not Found',
'NoVirtualClusterError',
`Cannot get sku types for virtual clyster ${req.query.vc}.`,
);
}
const leafCellTypes = new Set(vcStatus.map((cell) => cell.leafCellType));
const skuTypes = Object.keys(resourceUnits)
.filter((key) => leafCellTypes.has(key))
.reduce((obj, key) => {
obj[key] = resourceUnits[key];
return obj;
}, {});
res.status(status('OK')).json(skuTypes);
} else {
res.status(status('OK')).json(resourceUnits);
}
});

module.exports = { getSkuTypes };
4 changes: 2 additions & 2 deletions src/webportal/src/app/job-submission/job-submission-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@ export const JobSubmissionPage = ({
}, []);

useEffect(() => {
listHivedSkuTypes()
listHivedSkuTypes(jobInformation.virtualCluster)
.then(hivedSkuTypes => {
setHivedSkuTypes(hivedSkuTypes);
})
.catch(alert);
}, []);
}, [jobInformation.virtualCluster]);

const onToggleAdvanceFlag = useCallback(() => {
setAdvanceFlag(!advanceFlag);
Expand Down
17 changes: 12 additions & 5 deletions src/webportal/src/app/job-submission/utils/conn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { clearToken } from '../../user/user-logout/user-logout.component.js';
import config from '../../config/webportal.config';
import yaml from 'js-yaml';
import { get } from 'lodash';
import urljoin from 'url-join';

const token = cookies.get('token');

Expand Down Expand Up @@ -52,16 +53,22 @@ export async function listUserVirtualClusters(user) {
return get(userInfo, 'virtualCluster', []);
}

export async function listHivedSkuTypes() {
export async function listHivedSkuTypes(virtualCluster) {
if (config.launcherScheduler !== 'hivedscheduler') {
return {};
}
return wrapper(async () =>
(await fetch(`${config.restServerUri}/api/v2/cluster/sku-types`, {
headers: {
Authorization: `Bearer ${token}`,
(await fetch(
urljoin(
config.restServerUri,
`/api/v2/cluster/sku-types?vc=${virtualCluster}`,
),
{
headers: {
Authorization: `Bearer ${token}`,
},
},
})).json(),
)).json(),
);
}

Expand Down

0 comments on commit d31eb2a

Please sign in to comment.