1717package 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 ;
2023import org .opencb .opencga .server .RestServer ;
24+ import org .opencb .opencga .server .grpc .AdminServiceGrpc ;
2125import org .opencb .opencga .server .grpc .GrpcServer ;
2226
2327import 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