Unverified Commit 1725a26e authored by Naud Ghebre's avatar Naud Ghebre Committed by GitHub

Switch the way we retrieve the vm_service_port from /hub to iquery, on device. (#114834)

parent a84e369b
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -506,32 +507,55 @@ class FuchsiaRemoteConnection { ...@@ -506,32 +507,55 @@ class FuchsiaRemoteConnection {
_pollDartVms = true; _pollDartVms = true;
} }
/// Gets the open Dart VM service ports on a remote Fuchsia device. /// Helper for getDeviceServicePorts() to extract the vm_service_port from
/// /// json response.
/// The method attempts to get service ports through an SSH connection. Upon List<int> getVmServicePortFromInspectSnapshot(dynamic inspectSnapshot) {
/// successfully getting the VM service ports, returns them as a list of final List<Map<String, dynamic>> snapshot =
/// integers. If an empty list is returned, then no Dart VM instances could be List<Map<String, dynamic>>.from(inspectSnapshot as List<dynamic>);
/// found. An exception is thrown in the event of an actual error when
/// attempting to acquire the ports.
Future<List<int>> getDeviceServicePorts() async {
final List<String> portPaths = await _sshCommandRunner
.run('/bin/find /hub -name vmservice-port');
final List<int> ports = <int>[]; final List<int> ports = <int>[];
for (final String path in portPaths) {
if (path == '') { for (final Map<String, dynamic> item in snapshot) {
if (!item.containsKey('payload') || item['payload'] == null) {
continue;
}
final Map<String, dynamic> payload =
Map<String, dynamic>.from(item['payload'] as Map<String, dynamic>);
if (!payload.containsKey('root') || payload['root'] == null) {
continue; continue;
} }
final List<String> lsOutput = final Map<String, dynamic> root =
await _sshCommandRunner.run('/bin/ls $path'); Map<String, dynamic>.from(payload['root'] as Map<String, dynamic>);
for (final String line in lsOutput) {
if (line == '') { if (!root.containsKey('vm_service_port') ||
root['vm_service_port'] == null) {
continue; continue;
} }
final int? port = int.tryParse(line);
final int? port = int.tryParse(root['vm_service_port'] as String);
if (port != null) { if (port != null) {
ports.add(port); ports.add(port);
} }
} }
return ports;
}
/// Gets the open Dart VM service ports on a remote Fuchsia device.
///
/// The method attempts to get service ports through an SSH connection. Upon
/// successfully getting the VM service ports, returns them as a list of
/// integers. If an empty list is returned, then no Dart VM instances could be
/// found. An exception is thrown in the event of an actual error when
/// attempting to acquire the ports.
Future<List<int>> getDeviceServicePorts() async {
final List<String> inspectResult = await _sshCommandRunner
.run("iquery --format json show '**:root:vm_service_port'");
final dynamic inspectOutputJson = jsonDecode(inspectResult.join('\n'));
final List<int> ports =
getVmServicePortFromInspectSnapshot(inspectOutputJson);
if (ports.length > 1) {
throw StateError('More than one Flutter observatory port found');
} }
return ports; return ports;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment