Skip to content

Commit d18ac29

Browse files
committed
app: fix gRPC server stop. Add new parameter to run in servers in background
1 parent 1b0590e commit d18ac29

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/AdminCliOptionsParser.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,6 @@ public class DaemonCatalogCommandOptions extends CatalogDatabaseCommandOptions {
401401
/*
402402
* AUDIT SUB-COMMANDS
403403
*/
404-
405-
406404
@Parameters(commandNames = {"query"}, commandDescription = "Query audit data from Catalog database")
407405
public class QueryAuditCommandOptions extends CatalogDatabaseCommandOptions {
408406

@@ -424,7 +422,6 @@ public class StatsAuditCommandOptions extends CatalogDatabaseCommandOptions {
424422
/*
425423
* USER SUB-COMMANDS
426424
*/
427-
428425
@Parameters(commandNames = {"create"}, commandDescription = "Create a new user")
429426
public class CreateUserCommandOptions extends CatalogDatabaseCommandOptions {
430427

@@ -616,6 +613,9 @@ public class RestServerCommandOptions extends CatalogDatabaseCommandOptions {
616613

617614
@Parameter(names = {"--stop"}, description = "File with the new tool to be installed", arity = 0)
618615
public boolean stop;
616+
617+
@Parameter(names = {"--bg", "--background"}, description = "Run the server in background as a daemon", arity = 0)
618+
public boolean background;
619619
}
620620

621621
@Parameters(commandNames = {"grpc"}, commandDescription = "Print a summary list of all tools")
@@ -629,6 +629,9 @@ public class GrpcServerCommandOptions extends CatalogDatabaseCommandOptions {
629629

630630
@Parameter(names = {"--stop"}, description = "File with the new tool to be installed", arity = 0)
631631
public boolean stop;
632+
633+
@Parameter(names = {"--bg", "--background"}, description = "Run the server in background as a daemon", arity = 0)
634+
public boolean background;
632635
}
633636

634637

opencga-app/src/main/java/org/opencb/opencga/app/cli/admin/ServerCommandExecutor.java

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
package org.opencb.opencga.app.cli.admin;
1818

1919

20+
import io.grpc.ManagedChannel;
21+
import io.grpc.ManagedChannelBuilder;
22+
import org.opencb.biodata.models.common.protobuf.service.ServiceTypesModel;
2023
import org.opencb.opencga.server.RestServer;
24+
import org.opencb.opencga.server.grpc.AdminServiceGrpc;
2125
import org.opencb.opencga.server.grpc.GrpcServer;
2226

2327
import javax.ws.rs.client.Client;
@@ -59,31 +63,15 @@ public void execute() throws Exception {
5963

6064
private void rest() throws Exception {
6165
if (serverCommandOptions.restServerCommandOptions.start) {
62-
// StorageConfiguration storageConfiguration = configuration;
63-
// if (StringUtils.isNotEmpty(restCommandOptions.restStartCommandOptions.commonOptions.conf)) {
64-
// Path path = Paths.get(restCommandOptions.restStartCommandOptions.commonOptions.conf);
65-
// if (Files.exists(path)) {
66-
// storageConfiguration = StorageConfiguration.load(Files.newInputStream(path));
67-
// }
68-
// }
69-
70-
// if (StringUtils.isNotEmpty(restCommandOptions.restStartCommandOptions.commonOptions.storageEngine)) {
71-
// storageConfiguration.setDefaultStorageEngineId(restCommandOptions.restStartCommandOptions.commonOptions.storageEngine);
72-
// }
73-
74-
// Server crated and started
7566
RestServer server = new RestServer(Paths.get(this.conf));
7667
server.start();
77-
server.blockUntilShutdown();
68+
if (!serverCommandOptions.restServerCommandOptions.background) {
69+
server.blockUntilShutdown();
70+
}
7871
logger.info("Shutting down OpenCGA Storage REST server");
7972
}
8073

8174
if (serverCommandOptions.restServerCommandOptions.stop) {
82-
// if (serverCommandOptions.restStopCommandOptions.port > 0) {
83-
// port = restCommandOptions.restStopCommandOptions.port;
84-
// }
85-
86-
// GeneralConfiguration openCGAGeneralConfiguration = getOpenCGAConfiguration();catalogConfiguration
8775
Client client = ClientBuilder.newClient();
8876
WebTarget target = client.target("http://localhost:" + configuration.getServer().getRest().getPort())
8977
.path("opencga")
@@ -98,30 +86,21 @@ private void rest() throws Exception {
9886

9987
private void grpc() throws Exception {
10088
if (serverCommandOptions.grpcServerCommandOptions.start) {
101-
102-
// Server crated and started
103-
// FileInputStream fileInputStream = new FileInputStream(Paths.get(this.conf).resolve("storage-configuration.yml").toFile());
104-
// StorageConfiguration load = StorageConfiguration.load(fileInputStream);
10589
GrpcServer server = new GrpcServer(Paths.get(this.conf));
10690
server.start();
107-
server.blockUntilShutdown();
91+
if (!serverCommandOptions.grpcServerCommandOptions.background) {
92+
server.blockUntilShutdown();
93+
}
10894
logger.info("Shutting down OpenCGA Storage GRPC server");
10995
}
11096

11197
if (serverCommandOptions.grpcServerCommandOptions.stop) {
112-
// if (serverCommandOptions.restStopCommandOptions.port > 0) {
113-
// port = restCommandOptions.restStopCommandOptions.port;
114-
// }
115-
// GeneralConfiguration openCGAGeneralConfiguration = getOpenCGAConfiguration();
116-
Client client = ClientBuilder.newClient();
117-
WebTarget target = client.target("http://localhost" + configuration.getServer().getGrpc().getPort())
118-
.path("opencga")
119-
.path("webservices")
120-
.path("rest")
121-
.path("admin")
122-
.path("stop");
123-
Response response = target.request().get();
124-
logger.info(response.toString());
98+
ManagedChannel channel = ManagedChannelBuilder.forTarget("localhost:" + configuration.getServer().getGrpc().getPort())
99+
.usePlaintext(true)
100+
.build();
101+
AdminServiceGrpc.AdminServiceBlockingStub stub = AdminServiceGrpc.newBlockingStub(channel);
102+
ServiceTypesModel.MapResponse stopResponse = stub.stop(null);
103+
System.out.println(stopResponse.toString());
125104
}
126105
}
127106

0 commit comments

Comments
 (0)