"vscode:/vscode.git/clone" did not exist on "9a3fc32d6a6994932fd5bb37102a3e7c83606649"
experimentStartupInfo.ts 3.46 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
4
5
6

'use strict';

import * as assert from 'assert';
7
8
import * as os from 'os';
import * as path from 'path';
Deshui Yu's avatar
Deshui Yu committed
9
10
11
12
13
14
import * as component from '../common/component';

@component.Singleton
class ExperimentStartupInfo {
    private experimentId: string = '';
    private newExperiment: boolean = true;
15
    private basePort: number = -1;
Deshui Yu's avatar
Deshui Yu committed
16
    private initialized: boolean = false;
17
18
    private logDir: string = '';
    private logLevel: string = '';
SparkSnail's avatar
SparkSnail committed
19
    private readonly: boolean = false;
20
    private platform: string = '';
Deshui Yu's avatar
Deshui Yu committed
21

22
    public setStartupInfo(newExperiment: boolean, experimentId: string, basePort: number, platform: string, logDir?: string, logLevel?: string, readonly?: boolean): void {
Deshui Yu's avatar
Deshui Yu committed
23
24
25
26
        assert(!this.initialized);
        assert(experimentId.trim().length > 0);
        this.newExperiment = newExperiment;
        this.experimentId = experimentId;
27
        this.basePort = basePort;
Deshui Yu's avatar
Deshui Yu committed
28
        this.initialized = true;
29
        this.platform = platform;
30
31

        if (logDir !== undefined && logDir.length > 0) {
chicm-ms's avatar
chicm-ms committed
32
            this.logDir = path.join(path.normalize(logDir), this.getExperimentId());
33
        } else {
chicm-ms's avatar
chicm-ms committed
34
            this.logDir = path.join(os.homedir(), 'nni', 'experiments', this.getExperimentId());
35
36
37
38
39
        }

        if (logLevel !== undefined && logLevel.length > 1) {
            this.logLevel = logLevel;
        }
SparkSnail's avatar
SparkSnail committed
40
41
42
43

        if (readonly !== undefined) {
            this.readonly = readonly;
        }
Deshui Yu's avatar
Deshui Yu committed
44
45
46
47
48
49
50
51
    }

    public getExperimentId(): string {
        assert(this.initialized);

        return this.experimentId;
    }

52
53
54
55
56
57
    public getBasePort(): number {
        assert(this.initialized);

        return this.basePort;
    }

Deshui Yu's avatar
Deshui Yu committed
58
59
60
61
62
    public isNewExperiment(): boolean {
        assert(this.initialized);

        return this.newExperiment;
    }
63

64
65
66
67
68
69
    public getPlatform(): string {
        assert(this.initialized);

        return this.platform;
    }

70
71
72
73
74
75
76
77
78
79
80
81
    public getLogDir(): string {
        assert(this.initialized);

        return this.logDir;
    }

    public getLogLevel(): string {
        assert(this.initialized);

        return this.logLevel;
    }

SparkSnail's avatar
SparkSnail committed
82
83
84
85
86
    public isReadonly(): boolean {
        assert(this.initialized);

        return this.readonly;
    }
Deshui Yu's avatar
Deshui Yu committed
87
88
89
90
91
92
}

function getExperimentId(): string {
    return component.get<ExperimentStartupInfo>(ExperimentStartupInfo).getExperimentId();
}

93
94
95
96
function getBasePort(): number {
    return component.get<ExperimentStartupInfo>(ExperimentStartupInfo).getBasePort();
}

Deshui Yu's avatar
Deshui Yu committed
97
98
99
100
function isNewExperiment(): boolean {
    return component.get<ExperimentStartupInfo>(ExperimentStartupInfo).isNewExperiment();
}

101
102
103
104
function getPlatform(): string {
    return component.get<ExperimentStartupInfo>(ExperimentStartupInfo).getPlatform();
}

105
106
107
108
109
function getExperimentStartupInfo(): ExperimentStartupInfo {
    return component.get<ExperimentStartupInfo>(ExperimentStartupInfo);
}

function setExperimentStartupInfo(
110
    newExperiment: boolean, experimentId: string, basePort: number, platform: string, logDir?: string, logLevel?: string, readonly?: boolean): void {
111
    component.get<ExperimentStartupInfo>(ExperimentStartupInfo)
112
        .setStartupInfo(newExperiment, experimentId, basePort, platform, logDir, logLevel, readonly);
SparkSnail's avatar
SparkSnail committed
113
114
115
116
}

function isReadonly(): boolean {
    return component.get<ExperimentStartupInfo>(ExperimentStartupInfo).isReadonly();
Deshui Yu's avatar
Deshui Yu committed
117
118
}

119
120
121
122
export {
    ExperimentStartupInfo, getBasePort, getExperimentId, isNewExperiment, getPlatform, getExperimentStartupInfo,
    setExperimentStartupInfo, isReadonly
};