health.dart 1.39 KB
Newer Older
1 2 3 4
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'enum_util.dart';
6 7 8 9
import 'message.dart';

/// Requests an application health check.
class GetHealth implements Command {
10
  @override
11 12
  final String kind = 'get_health';

13
  /// Deserializes the command from JSON generated by [serialize].
14
  static GetHealth deserialize(Map<String, String> json) => new GetHealth();
15

16
  @override
pq's avatar
pq committed
17
  Map<String, String> serialize() => const <String, String>{};
18 19 20 21 22 23 24 25 26 27 28
}

/// Application health status.
enum HealthStatus {
  /// Application is known to be in a good shape and should be able to respond.
  ok,

  /// Application is not known to be in a good shape and may be unresponsive.
  bad,
}

29 30 31
final EnumIndex<HealthStatus> _healthStatusIndex =
    new EnumIndex<HealthStatus>(HealthStatus.values);

32 33
/// Application health status.
class Health extends Result {
34
  /// Creates a [Health] object with the given [status].
35 36 37 38
  Health(this.status) {
    assert(status != null);
  }

39
  /// Deserializes the result from JSON.
40
  static Health fromJson(Map<String, dynamic> json) {
41
    return new Health(_healthStatusIndex.lookupBySimpleName(json['status']));
42 43 44 45 46
  }

  /// Health status
  final HealthStatus status;

47
  @override
pq's avatar
pq committed
48
  Map<String, dynamic> toJson() => <String, dynamic>{
49
    'status': _healthStatusIndex.toSimpleName(status)
50 51
  };
}