utEnvironmentService.ts 2.2 KB
Newer Older
1
2
3
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

liuzhe-lz's avatar
liuzhe-lz committed
4
import { Channel, EnvironmentInformation, EnvironmentService, EnvironmentStatus } from "../../../training_service/reusable/environment";
5
import { EventEmitter } from 'events';
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { UtCommandChannel } from "./utCommandChannel";

export class UtEnvironmentService extends EnvironmentService {
    private allEnvironments = new Map<string, EnvironmentInformation>();
    private hasMoreEnvironmentsInternal = true;

    constructor() {
        super();
    }

    public get hasStorageService(): boolean {
        // storage service is tested by integration testing.
        return false;
    }
20
21
22
23
24

    public get useSharedStorage(): boolean {
        return false;
    }

25
26
27
28
    public get environmentMaintenceLoopInterval(): number {
        return 1;
    }

29
30
31
32
33
34
35
36
    public get getName(): string {
        return 'ut';
    }

    public initCommandChannel(eventEmitter: EventEmitter): void {
        this.commandChannel = new UtCommandChannel(eventEmitter);
    }

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    public testSetEnvironmentStatus(environment: EnvironmentInformation, newStatus: EnvironmentStatus): void {
        environment.status = newStatus;
    }

    public testReset(): void {
        this.allEnvironments.clear();
    }

    public testGetEnvironments(): Map<string, EnvironmentInformation> {
        return this.allEnvironments;
    }

    public testSetNoMoreEnvironment(hasMore: boolean): void {
        this.hasMoreEnvironmentsInternal = hasMore;
    }

    public get hasMoreEnvironments(): boolean {
        return this.hasMoreEnvironmentsInternal;
    }

    public async config(_key: string, _value: string): Promise<void> {
        // do nothing
    }

61
    public async refreshEnvironmentsStatus(_environments: EnvironmentInformation[]): Promise<void> {
62
63
64
65
66
67
68
69
70
71
72
73
74
75
        // do nothing
    }

    public async startEnvironment(environment: EnvironmentInformation): Promise<void> {
        if (!this.allEnvironments.has(environment.id)) {
            this.allEnvironments.set(environment.id, environment);
            environment.status = "WAITING";
        }
    }

    public async stopEnvironment(environment: EnvironmentInformation): Promise<void> {
        environment.status = "USER_CANCELED";
    }
}