Skip to content

Commit

Permalink
Issue 2793: Ability to enable/disable REST server for standalone Prav…
Browse files Browse the repository at this point in the history
…ega (pravega#2794)

Add the ability to enable or disable the REST server for standalone Pravega based on the InProcPravegaCluster.startRestServer build option.

Signed-off-by: Andrei Paduroiu <[email protected]>
  • Loading branch information
adrianmo authored and andreipaduroiu committed Aug 1, 2018
1 parent 977a49b commit 126db9b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
3 changes: 3 additions & 0 deletions config/standalone-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# Port on which the controller server grpc is started.
#singlenode.controllerPort=9090

# Enable REST server.
#singlenode.enableRestServer=true

# Port on which the controller REST service is started.
#singlenode.restServerPort=9091

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class InProcPravegaCluster implements AutoCloseable {
private String zkUrl;

@Builder.Default
private boolean startRestServer = true;
private boolean enableRestServer = true;
private String userName;
private String passwd;
private String certFile;
Expand Down Expand Up @@ -139,7 +139,7 @@ public InProcPravegaCluster build() {
isInProcController, controllerCount, controllerPorts, controllerURI,
restServerPort, isInProcSegmentStore, segmentStoreCount, segmentStorePorts, isInProcZK, zkPort, zkHost,
zkService, isInProcHDFS, hdfsUrl, containerCount, nodeServiceStarter, localHdfs, controllerServers, zkUrl,
startRestServer, userName, passwd, certFile, keyFile, passwdFile);
enableRestServer, userName, passwd, certFile, keyFile, passwdFile);
}
}

Expand Down Expand Up @@ -332,10 +332,13 @@ private ControllerServiceMain startLocalController(int controllerId) {
.tokenSigningKey("secret")
.build();

RESTServerConfig restServerConfig = RESTServerConfigImpl.builder()
.host("0.0.0.0")
.port(this.restServerPort)
.build();
RESTServerConfig restServerConfig = null;
if (this.enableRestServer) {
restServerConfig = RESTServerConfigImpl.builder()
.host("0.0.0.0")
.port(this.restServerPort)
.build();
}

ControllerServiceConfig serviceConfig = ControllerServiceConfigImpl.builder()
.threadPoolSize(Config.ASYNC_TASK_POOL_SIZE)
Expand All @@ -345,7 +348,7 @@ private ControllerServiceMain startLocalController(int controllerId) {
.timeoutServiceConfig(timeoutServiceConfig)
.eventProcessorConfig(Optional.of(eventProcessorConfig))
.grpcServerConfig(Optional.of(grpcServerConfig))
.restServerConfig(Optional.of(restServerConfig))
.restServerConfig(Optional.ofNullable(restServerConfig))
.build();

ControllerServiceMain controllerService = new ControllerServiceMain(serviceConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LocalPravegaEmulator implements AutoCloseable {
private int controllerPort;
private int segmentStorePort;
private int restServerPort;
private boolean enableRestServer;
private boolean enableAuth;
private boolean enableTls;
private String certFile;
Expand All @@ -46,8 +47,8 @@ public LocalPravegaEmulator build() {
.isInProcSegmentStore(true)
.segmentStoreCount(1)
.containerCount(4)
.startRestServer(true)
.restServerPort(restServerPort)
.enableRestServer(enableRestServer)
.enableMetrics(false)
.enableAuth(enableAuth)
.enableTls(enableTls)
Expand All @@ -59,8 +60,8 @@ public LocalPravegaEmulator build() {
.build();
this.inProcPravegaCluster.setControllerPorts(new int[]{controllerPort});
this.inProcPravegaCluster.setSegmentStorePorts(new int[]{segmentStorePort});
return new LocalPravegaEmulator(zkPort, controllerPort, segmentStorePort, restServerPort, enableAuth, enableTls,
certFile, passwd, userName, passwdFile, keyFile, inProcPravegaCluster);
return new LocalPravegaEmulator(zkPort, controllerPort, segmentStorePort, restServerPort, enableRestServer,
enableAuth, enableTls, certFile, passwd, userName, passwdFile, keyFile, inProcPravegaCluster);
}
}

Expand All @@ -78,6 +79,7 @@ public static void main(String[] args) {
.segmentStorePort(conf.getSegmentStorePort())
.zkPort(conf.getZkPort())
.restServerPort(conf.getRestServerPort())
.enableRestServer(conf.isEnableRestServer())
.enableAuth(conf.isEnableAuth())
.enableTls(conf.isEnableTls())
.certFile(conf.getCertFile())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class SingleNodeConfig {
public final static Property<String> PASSWD_FILE = Property.named("passwdFile", "");
public final static Property<String> USER_NAME = Property.named("userName", "");
public final static Property<String> PASSWD = Property.named("passwd", "");
public final static Property<Boolean> ENABLE_REST_SERVER = Property.named("enableRestServer", true);
public final static Property<Boolean> ENABLE_TLS = Property.named("enableTls", false);
public final static Property<Boolean> ENABLE_AUTH = Property.named("enableAuth", false);
public final static String PROPERTY_FILE = "singlenode.configurationFile";
Expand Down Expand Up @@ -88,6 +89,12 @@ public class SingleNodeConfig {
@Getter
private String passwd;

/**
* Flag to enable REST server.
*/
@Getter
private boolean enableRestServer;

/**
* Flag to enable TLS.
*/
Expand All @@ -113,6 +120,7 @@ private SingleNodeConfig(TypedProperties properties) {
this.passwdFile = properties.get(PASSWD_FILE);
this.userName = properties.get(USER_NAME);
this.passwd = properties.get(PASSWD);
this.enableRestServer = properties.getBoolean(ENABLE_REST_SERVER);
this.enableTls = properties.getBoolean(ENABLE_TLS);
this.enableAuth = properties.getBoolean(ENABLE_AUTH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/
@Slf4j
public class InProcPravegaClusterTest {
boolean restEnabled = false;
boolean authEnabled = false;
boolean tlsEnabled = false;
LocalPravegaEmulator localPravega;
Expand All @@ -50,6 +51,7 @@ public void setUp() throws Exception {
.segmentStorePort(TestUtils.getAvailableListenPort())
.zkPort(TestUtils.getAvailableListenPort())
.restServerPort(TestUtils.getAvailableListenPort())
.enableRestServer(restEnabled)
.enableAuth(authEnabled)
.enableTls(tlsEnabled)
.certFile("../config/cert.pem")
Expand Down

0 comments on commit 126db9b

Please sign in to comment.