"test/gtest-1.7.0/README" did not exist on "32125697f271ed03209f686186c67eee2075856c"
kubernetesConfig.ts 5.73 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
3
4
5

'use strict';

6
7
export type KubernetesStorageKind = 'nfs' | 'azureStorage';
import { MethodNotImplementedError } from '../../common/errors';
8

9
// tslint:disable: completed-docs function-name
10
11
12
export abstract class KubernetesClusterConfig {
    public readonly storage?: KubernetesStorageKind;
    public readonly apiVersion: string;
13

14
15
    constructor(apiVersion: string, storage?: KubernetesStorageKind) {
        this.storage = storage;
16
        this.apiVersion = apiVersion;
17
18
    }

19
    public get storageType(): KubernetesStorageKind {
20
21
22
23
24
25
26
27
        throw new MethodNotImplementedError();
    }
}

export class StorageConfig {
    public readonly storage?: KubernetesStorageKind;

    constructor(storage?: KubernetesStorageKind) {
28
29
30
31
        this.storage = storage;
    }
}

32
export class KubernetesClusterConfigNFS extends KubernetesClusterConfig {
33
    public readonly nfs: NFSConfig;
34
35

    constructor(
36
            apiVersion: string,
37
38
39
40
            nfs: NFSConfig,
            storage?: KubernetesStorageKind
        ) {
        super(apiVersion, storage);
41
42
        this.nfs = nfs;
    }
43

44
    public get storageType(): KubernetesStorageKind {
45
46
47
48
        return 'nfs';
    }

    public static getInstance(jsonObject: object): KubernetesClusterConfigNFS {
49
50
        const kubernetesClusterConfigObjectNFS: KubernetesClusterConfigNFS = <KubernetesClusterConfigNFS>jsonObject;

51
52
53
54
55
56
        return new KubernetesClusterConfigNFS(
            kubernetesClusterConfigObjectNFS.apiVersion,
            kubernetesClusterConfigObjectNFS.nfs,
            kubernetesClusterConfigObjectNFS.storage
        );
    }
57
58
}

59
export class KubernetesClusterConfigAzure extends KubernetesClusterConfig {
60
    public readonly keyVault: KeyVaultConfig;
61
    public readonly azureStorage: AzureStorage;
62
    public readonly uploadRetryCount: number | undefined;
63

64
    constructor(
65
            apiVersion: string,
66
            keyVault: KeyVaultConfig,
67
            azureStorage: AzureStorage,
68
69
            storage?: KubernetesStorageKind,
            uploadRetryCount?: number
70
71
        ) {
        super(apiVersion, storage);
SparkSnail's avatar
SparkSnail committed
72
73
        this.keyVault = keyVault;
        this.azureStorage = azureStorage;
74
        this.uploadRetryCount = uploadRetryCount;
75
    }
76

77
    public get storageType(): KubernetesStorageKind {
78
79
80
81
        return 'azureStorage';
    }

    public static getInstance(jsonObject: object): KubernetesClusterConfigAzure {
82
83
        const kubernetesClusterConfigObjectAzure: KubernetesClusterConfigAzure = <KubernetesClusterConfigAzure>jsonObject;

84
85
86
87
        return new KubernetesClusterConfigAzure(
            kubernetesClusterConfigObjectAzure.apiVersion,
            kubernetesClusterConfigObjectAzure.keyVault,
            kubernetesClusterConfigObjectAzure.azureStorage,
88
89
            kubernetesClusterConfigObjectAzure.storage,
            kubernetesClusterConfigObjectAzure.uploadRetryCount
90
91
92
93
        );
    }
}

94
// tslint:disable-next-line:no-unnecessary-class
95
96
97
export class KubernetesClusterConfigFactory {

    public static generateKubernetesClusterConfig(jsonObject: object): KubernetesClusterConfig {
98
99
         const storageConfig: StorageConfig = <StorageConfig>jsonObject;
         switch (storageConfig.storage) {
100
101
            case 'azureStorage':
                return KubernetesClusterConfigAzure.getInstance(jsonObject);
102
103
            case 'nfs':
            case undefined:
104
                return KubernetesClusterConfigNFS.getInstance(jsonObject);
105
106
            default:
                throw new Error(`Invalid json object ${jsonObject}`);
107
108
         }
    }
109
110
111
112
113
114
}

/**
 * NFS configuration to store Kubeflow job related files
 */
export class NFSConfig {
115
    // IP Adress of NFS server
116
    public readonly server : string;
117
    // exported NFS path on NFS server
118
119
120
121
122
123
124
125
    public readonly path : string;

    constructor(server : string, path : string) {
        this.server = server;
        this.path = path;
    }
}

SparkSnail's avatar
SparkSnail committed
126
127
128
129
/**
 * KeyVault configuration to store the key of Azure Storage Service
 * Refer https://docs.microsoft.com/en-us/azure/key-vault/key-vault-manage-with-cli2
 */
130
131
export class KeyVaultConfig {
    // The vault-name to specify vault
SparkSnail's avatar
SparkSnail committed
132
    public readonly vaultName : string;
133
    // The name to specify private key
SparkSnail's avatar
SparkSnail committed
134
135
    public readonly name : string;

136
    constructor(vaultName : string, name : string) {
SparkSnail's avatar
SparkSnail committed
137
138
139
140
141
142
143
144
145
        this.vaultName = vaultName;
        this.name = name;
    }
}

/**
 * Azure Storage Service
 */
export class AzureStorage {
146
    // The azure share to storage files
SparkSnail's avatar
SparkSnail committed
147
    public readonly azureShare : string;
148

149
    // The account name of sotrage service
SparkSnail's avatar
SparkSnail committed
150
    public readonly accountName: string;
151
    constructor(azureShare : string, accountName: string) {
SparkSnail's avatar
SparkSnail committed
152
153
154
155
156
        this.azureShare = azureShare;
        this.accountName = accountName;
    }
}

157
/**
158
 * Trial job configuration for Kubernetes
159
 */
160
export class KubernetesTrialConfigTemplate {
161
    // CPU number
162
    public readonly cpuNum: number;
163

164
    // Memory
165
    public readonly memoryMB: number;
166

167
    // Docker image
168
    public readonly image: string;
169

170
171
172
    // Private registry config file path to download docker iamge
    public readonly privateRegistryAuthPath?: string;

173
    // Trail command
174
175
    public readonly command : string;

176
    // Required GPU number for trial job. The number should be in [0,100]
177
    public readonly gpuNum : number;
178
179

    constructor(command : string, gpuNum : number,
180
                cpuNum: number, memoryMB: number, image: string, privateRegistryAuthPath?: string) {
181
182
        this.command = command;
        this.gpuNum = gpuNum;
183
184
185
        this.cpuNum = cpuNum;
        this.memoryMB = memoryMB;
        this.image = image;
186
        this.privateRegistryAuthPath = privateRegistryAuthPath;
187
    }
188
189
}

190
export class KubernetesTrialConfig {
191
    public readonly codeDir: string;
192
193
194
195

    constructor(codeDir: string) {
        this.codeDir = codeDir;
    }
196
}