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

Commit

Permalink
Webportal update k8s proxy api
Browse files Browse the repository at this point in the history
  • Loading branch information
yiyione committed Aug 6, 2020
1 parent 30aa629 commit 80a19c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/webportal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@hapi/joi": "~15.1.0",
"@loadable/component": "^5.10.3",
"@microsoft/openpai-js-sdk": "^0.1.3",
"@microsoft/openpai-js-sdk": "^0.1.4",
"@svgr/webpack": "^4.3.3",
"@webcomponents/custom-elements": "^1.2.1",
"admin-lte": "~2.4.2",
Expand Down
56 changes: 21 additions & 35 deletions src/webportal/src/app/cluster-view/services/service-info.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,22 @@
// 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 { PAIV2 } = require('@microsoft/openpai-js-sdk');
const userAuth = require('../../user/user-auth/user-auth.component');
const loading = require('../../job/loading/loading.component');
const webportalConfig = require('../../config/webportal.config.js');
const { clearToken } = require('../../user/user-logout/user-logout.component');

const fetchWrapper = async url => {
const token = userAuth.checkToken();
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (res.ok) {
const data = await res.json();
const wrapper = async func => {
try {
const data = await func();
return data.items;
} else {
} catch (err) {
loading.hideLoading();
if (res.status === 401) {
if (err.data.code === 'UnauthorizedUserError') {
clearToken();
} else {
const data = await res.json();
alert(data.message);
alert(err.data.message);
}
}
};
Expand All @@ -49,13 +29,19 @@ export const getServiceView = async callback => {
if (!restServerUrl.pathname.endsWith('/')) {
restServerUrl.pathname += '/';
}
const nodeUrl = new URL('api/v1/kubernetes/nodes', restServerUrl);
const podUrl = new URL('api/v1/kubernetes/pods', restServerUrl);
podUrl.searchParams.set('namespace', 'default');
podUrl.searchParams.set('labelSelector', 'app');
const client = new PAIV2.OpenPAIClient({
token: userAuth.checkToken(),
rest_server_uri: restServerUrl.href,
https: window.location.protocol === 'https:',
});
const [nodes, pods] = await Promise.all([
fetchWrapper(nodeUrl),
fetchWrapper(podUrl),
wrapper(async () => client.kubernetes.getK8sNodes()),
wrapper(async () =>
client.kubernetes.getK8sPods({
namespace: 'default',
labelSelector: 'app',
}),
),
]);
const resultDict = {};
for (const node of nodes) {
Expand Down
8 changes: 4 additions & 4 deletions src/webportal/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1527,10 +1527,10 @@
resolved "https://registry.yarnpkg.com/@microsoft/load-themed-styles/-/load-themed-styles-1.9.7.tgz#4f28d7097802317d2a491888ba65fac617c56dd4"
integrity sha512-8Iua4vPmffV2tT1nR/E55GSbUkYRPD9xFfa6v8zJ89EiiDrlyO2OGuXAtC6/nWxLTeVRA3GhtQuU2SApD2sQAA==

"@microsoft/openpai-js-sdk@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@microsoft/openpai-js-sdk/-/openpai-js-sdk-0.1.3.tgz#9aefccbce928c248e28c03a7a2dc6b8f70877183"
integrity sha512-++9KUVqPFTO/IP9Fnm973oM9KcTCaqCSg/Ug9WluXVL2CmUK/fg+H4Icn/8DHGql7SFeOJxW1Le49SJN+pxcZQ==
"@microsoft/openpai-js-sdk@^0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@microsoft/openpai-js-sdk/-/openpai-js-sdk-0.1.4.tgz#99084c2e984dcdf171f9ea1901c750b48c390827"
integrity sha512-QD0QdeC4JWvRG5r3BqcX3WMQB5Xq3ENsh1iFfj32N7nloQIVo3iDJAHzQaGNr5vvMPaW08HY36OYTHO2OcfG6g==
dependencies:
"@apidevtools/swagger-parser" "^9.0.1"
"@azure/storage-blob" "^12.1.0"
Expand Down

0 comments on commit 80a19c6

Please sign in to comment.