experimentStartupInfo.ts 2.02 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Deshui Yu's avatar
Deshui Yu committed
3

liuzhe-lz's avatar
liuzhe-lz committed
4
import assert from 'assert/strict';
5
import path from 'path';
6

liuzhe-lz's avatar
liuzhe-lz committed
7
import type { NniManagerArgs } from 'common/globals/arguments';
8
9
10
11
12

let singleton: ExperimentStartupInfo | null = null;

export class ExperimentStartupInfo {

liuzhe-lz's avatar
liuzhe-lz committed
13
14
15
    public experimentId: string;
    public newExperiment: boolean;
    public basePort: number;
16
    public logDir: string = '';
liuzhe-lz's avatar
liuzhe-lz committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    public logLevel: string;
    public readonly: boolean;
    public dispatcherPipe: string | null;
    public platform: string;
    public urlprefix: string;

    constructor(args: NniManagerArgs) {
        this.experimentId = args.experimentId;
        this.newExperiment = (args.action === 'create');
        this.basePort = args.port;
        this.logDir = path.join(args.experimentsDirectory, args.experimentId);  // TODO: handle in globals
        this.logLevel = args.logLevel;
        this.readonly = (args.action === 'view');
        this.dispatcherPipe = args.dispatcherPipe ?? null;
        this.platform = args.mode as string;
        this.urlprefix = args.urlPrefix;
33
34
    }

35
    public static getInstance(): ExperimentStartupInfo {
liuzhe-lz's avatar
liuzhe-lz committed
36
        assert.notEqual(singleton, null);
37
        return singleton!;
38
    }
Deshui Yu's avatar
Deshui Yu committed
39
40
}

41
42
export function getExperimentStartupInfo(): ExperimentStartupInfo {
    return ExperimentStartupInfo.getInstance();
Deshui Yu's avatar
Deshui Yu committed
43
44
}

liuzhe-lz's avatar
liuzhe-lz committed
45
46
export function setExperimentStartupInfo(args: NniManagerArgs): void {
    singleton = new ExperimentStartupInfo(args);
47
48
}

49
50
export function getExperimentId(): string {
    return getExperimentStartupInfo().experimentId;
Deshui Yu's avatar
Deshui Yu committed
51
52
}

53
54
export function getBasePort(): number {
    return getExperimentStartupInfo().basePort;
55
56
}

57
58
export function isNewExperiment(): boolean {
    return getExperimentStartupInfo().newExperiment;
59
60
}

61
62
export function getPlatform(): string {
    return getExperimentStartupInfo().platform;
SparkSnail's avatar
SparkSnail committed
63
64
}

65
66
export function isReadonly(): boolean {
    return getExperimentStartupInfo().readonly;
Deshui Yu's avatar
Deshui Yu committed
67
68
}

69
70
export function getDispatcherPipe(): string | null {
    return getExperimentStartupInfo().dispatcherPipe;
71
}