remoteMachineJobRestServer.ts 1.33 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
SparkSnail's avatar
SparkSnail committed
3
4
5
6

'use strict';

import { Inject } from 'typescript-ioc';
7
8
import * as component from '../../common/component';
import { ClusterJobRestServer } from '../common/clusterJobRestServer';
SparkSnail's avatar
SparkSnail committed
9
10
11
12
import { RemoteMachineTrainingService } from './remoteMachineTrainingService';

/**
 * RemoteMachine Training service Rest server, provides rest RemoteMachine to support remotemachine job metrics update
13
 *
SparkSnail's avatar
SparkSnail committed
14
15
 */
@component.Singleton
16
export class RemoteMachineJobRestServer extends ClusterJobRestServer {
SparkSnail's avatar
SparkSnail committed
17
    @Inject
chicm-ms's avatar
chicm-ms committed
18
    private readonly remoteMachineTrainingService: RemoteMachineTrainingService;
SparkSnail's avatar
SparkSnail committed
19
20
21
22
23
24
25
26
27

    /**
     * constructor to provide NNIRestServer's own rest property, e.g. port
     */
    constructor() {
        super();
        this.remoteMachineTrainingService = component.get(RemoteMachineTrainingService);
    }

28
    // tslint:disable-next-line:no-any
chicm-ms's avatar
chicm-ms committed
29
    protected handleTrialMetrics(jobId: string, metrics: any[]): void {
SparkSnail's avatar
SparkSnail committed
30
31
32
33
34
35
36
37
38
        // Split metrics array into single metric, then emit
        // Warning: If not split metrics into single ones, the behavior will be UNKNOWNls
        for (const singleMetric of metrics) {
            this.remoteMachineTrainingService.MetricsEmitter.emit('metric', {
                id : jobId,
                data : singleMetric
            });
        }
    }
39
}