Cluster Director API v1的TypeScript类型
Cluster Director API允许您部署、管理和监控运行人工智能(AI)、机器学习(ML)或高性能计算(HPC)工作负载的集群。 详细说明请查看 文档.
安装
安装Cluster Director API的类型:
npm install @types/gapi.client.hypercomputecluster-v1 --save-dev
打印稿6.0 +
TypeScript 6.0更改 types 默认为 []. 中显式列出类型包 tsconfig.json:
{
"compilerOptions": {
"types": [
"gapi",
"gapi.auth2",
"gapi.client",
"gapi.client.hypercomputecluster-v1"
]
}
}
使用
你需要在你的代码中初始化谷歌API客户端:
gapi.load('client', () => {
// now we can use gapi.client
// ...
});
然后加载api客户端包装器:
gapi.client.load(
'https://hypercomputecluster.googleapis.com/$discovery/rest?version=v1',
() => {
// now we can use:
// gapi.client.hypercomputecluster
},
);
// Deprecated, use discovery document URL, see https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md#----gapiclientloadname----version----callback--
gapi.client.load('hypercomputecluster', 'v1', () => {
// now we can use:
// gapi.client.hypercomputecluster
});
在向资源发送任何请求之前,不要忘记验证您的客户端:
// declare client_id registered in Google Developers Console
var client_id = '',
scope = [
// See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account.
'https://www.googleapis.com/auth/cloud-platform',
],
immediate = true;
// ...
gapi.auth.authorize(
{client_id: client_id, scope: scope, immediate: immediate},
authResult => {
if (authResult && !authResult.error) {
/* handle successful authorization */
} else {
/* handle authorization error */
}
},
);
之后就可以使用Cluster Director API资源了:
有关来源信息,请参见 NPM的出处部分