WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 139fadd

Browse files
DeviceInfracopybara-github
authored andcommitted
Internal change
PiperOrigin-RevId: 840553980
1 parent 999f274 commit 139fadd

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.devtools.mobileharness.service.deviceconfig;
18+
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import javax.inject.Qualifier;
22+
23+
/** Annotations for the config server. */
24+
public final class Annotations {
25+
26+
/** Annotation for binding the server port. */
27+
@Qualifier
28+
@Retention(RetentionPolicy.RUNTIME)
29+
public @interface ServerPort {}
30+
31+
private Annotations() {}
32+
}

src/java/com/google/devtools/mobileharness/service/deviceconfig/BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,30 @@ java_library(
2424
name = "device_config_module",
2525
srcs = ["DeviceConfigModule.java"],
2626
deps = [
27+
":annotations",
2728
"//src/java/com/google/devtools/mobileharness/service/deviceconfig/storage:local_file_storage_client",
2829
"//src/java/com/google/devtools/mobileharness/service/deviceconfig/storage:storage_client",
30+
"//src/java/com/google/devtools/mobileharness/shared/util/flags",
2931
"@maven//:com_google_inject_guice",
32+
"@maven//:javax_inject_jsr330_api",
3033
],
3134
)
3235

36+
java_library(
37+
name = "annotations",
38+
srcs = ["Annotations.java"],
39+
deps = ["@maven//:javax_inject_jsr330_api"],
40+
)
41+
3342
java_library(
3443
name = "device_config_server_lib",
3544
srcs = ["DeviceConfigServer.java"],
3645
runtime_deps = ["@grpc-java//netty"],
3746
deps = [
47+
":annotations",
3848
":device_config_module",
3949
"//src/java/com/google/devtools/mobileharness/service/deviceconfig/rpc/service/grpc:device_config_grpc_impl",
50+
"//src/java/com/google/devtools/mobileharness/shared/util/flags",
4051
"//src/java/com/google/devtools/mobileharness/shared/util/logging:google_logger",
4152
"@grpc-java//core",
4253
"@grpc-java//services:reflection",

src/java/com/google/devtools/mobileharness/service/deviceconfig/DeviceConfigModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818

1919
import com.google.devtools.mobileharness.service.deviceconfig.storage.LocalFileStorageClient;
2020
import com.google.devtools.mobileharness.service.deviceconfig.storage.StorageClient;
21+
import com.google.devtools.mobileharness.shared.util.flags.Flags;
2122
import com.google.inject.AbstractModule;
23+
import com.google.inject.Provides;
24+
import javax.inject.Singleton;
2225

2326
/** The Guice module for device config service. */
2427
public class DeviceConfigModule extends AbstractModule {
@@ -28,4 +31,11 @@ protected void configure() {
2831
// TODO: b/460296020 - Add a flag to control which storage client to use.
2932
bind(StorageClient.class).to(LocalFileStorageClient.class);
3033
}
34+
35+
@Provides
36+
@Singleton
37+
@Annotations.ServerPort
38+
int provideServerPort() {
39+
return Flags.instance().configServiceGrpcPort.getNonNull();
40+
}
3141
}

src/java/com/google/devtools/mobileharness/service/deviceconfig/DeviceConfigServer.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.common.flogger.FluentLogger;
2020
import com.google.devtools.mobileharness.service.deviceconfig.rpc.service.grpc.DeviceConfigGrpcImpl;
21+
import com.google.devtools.mobileharness.shared.util.flags.Flags;
2122
import com.google.inject.Guice;
2223
import io.grpc.Server;
2324
import io.grpc.ServerBuilder;
@@ -27,28 +28,27 @@
2728

2829
/** The starter of the DeviceConfigServer. */
2930
final class DeviceConfigServer {
30-
// TODO: b/460296020 - use a flag to specify the port.
31-
private static final Integer CONFIG_SERVER_GRPC_PORT = 10000;
32-
3331
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
3432

33+
private final int port;
3534
private final DeviceConfigGrpcImpl deviceConfigService;
3635
private volatile Server grpcServer;
3736

3837
@Inject
39-
DeviceConfigServer(DeviceConfigGrpcImpl deviceConfigService) {
38+
DeviceConfigServer(DeviceConfigGrpcImpl deviceConfigService, @Annotations.ServerPort int port) {
4039
this.deviceConfigService = deviceConfigService;
40+
this.port = port;
4141
}
4242

4343
/** Starts the device config server and blocks until it's terminated. */
4444
public void start() throws IOException {
4545
grpcServer =
46-
ServerBuilder.forPort(CONFIG_SERVER_GRPC_PORT)
46+
ServerBuilder.forPort(port)
4747
.addService(deviceConfigService)
4848
.addService(ProtoReflectionService.newInstance())
4949
.build();
5050
grpcServer.start();
51-
logger.atInfo().log("Device config server started on port %d", CONFIG_SERVER_GRPC_PORT);
51+
logger.atInfo().log("Device config server started on port %d", port);
5252

5353
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
5454
}
@@ -69,6 +69,8 @@ private void blockUntilShutdown() throws InterruptedException {
6969
}
7070

7171
public static void main(String[] args) throws InterruptedException, IOException {
72+
Flags.parse(args);
73+
7274
DeviceConfigServer deviceConfigServer =
7375
Guice.createInjector(new DeviceConfigModule()).getInstance(DeviceConfigServer.class);
7476
deviceConfigServer.start();

src/java/com/google/devtools/mobileharness/shared/util/flags/Flags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,14 @@ public class Flags {
626626
converter = Flag.IntegerConverter.class)
627627
public Flag<Integer> commandPort = commandPortDefault;
628628

629+
private static final Flag<Integer> configServiceGrpcPortDefault = Flag.value(8081);
630+
631+
@com.beust.jcommander.Parameter(
632+
names = "--config_service_grpc_port",
633+
description = "gRPC port of the config service.",
634+
converter = Flag.IntegerConverter.class)
635+
public Flag<Integer> configServiceGrpcPort = configServiceGrpcPortDefault;
636+
629637
private static final Flag<Boolean> connectToLabServerUsingIpDefault = Flag.value(false);
630638

631639
@com.beust.jcommander.Parameter(

0 commit comments

Comments
 (0)