You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/12/18 22:32:44 UTC
[36/50] incubator-slider git commit: SLIDER-724 don't serve web
content until AM is fully configured: AM-side
SLIDER-724 don't serve web content until AM is fully configured: AM-side
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/bfc20d75
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/bfc20d75
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/bfc20d75
Branch: refs/heads/feature/SLIDER-151_REST_API
Commit: bfc20d7597faf3dcb9cac6f2853bdb6db7727de5
Parents: 47ca9e6
Author: Steve Loughran <st...@apache.org>
Authored: Tue Dec 16 20:23:56 2014 +0000
Committer: Steve Loughran <st...@apache.org>
Committed: Tue Dec 16 20:25:40 2014 +0000
----------------------------------------------------------------------
.../apache/slider/common/tools/PortScanner.java | 23 +++++++++-
.../server/appmaster/SliderAppMaster.java | 47 ++++++++++++--------
2 files changed, 49 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/bfc20d75/slider-core/src/main/java/org/apache/slider/common/tools/PortScanner.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/tools/PortScanner.java b/slider-core/src/main/java/org/apache/slider/common/tools/PortScanner.java
index 0f4cfbc..60fd008 100644
--- a/slider-core/src/main/java/org/apache/slider/common/tools/PortScanner.java
+++ b/slider-core/src/main/java/org/apache/slider/common/tools/PortScanner.java
@@ -28,7 +28,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- *
+ * a scanner which can take an input string for a range or scan the lot.
*/
public class PortScanner {
private static Pattern NUMBER_RANGE = Pattern.compile("^(\\d+)\\s*-\\s*(\\d+)$");
@@ -39,6 +39,8 @@ public class PortScanner {
public PortScanner() {
}
+ int nextPort = 1024;
+
public void setPortRange(String input) {
// first split based on commas
Set<Integer> inputPorts= new TreeSet<Integer>();
@@ -66,7 +68,24 @@ public class PortScanner {
return remainingPortsToCheck;
}
- public int getAvailablePort () throws SliderException{
+ public int getAvailablePort() throws SliderException {
+ if (remainingPortsToCheck!=null) {
+ return getAvailablePortViaPortArray();
+ } else {
+ return getAvailablePortViaCounter();
+ }
+ }
+
+ private int getAvailablePortViaCounter() throws SliderException {
+ int port;
+ do {
+ port = nextPort;
+ nextPort++;
+ } while (!SliderUtils.isPortAvailable(port));
+ return port;
+ }
+
+ private int getAvailablePortViaPortArray() throws SliderException {
boolean found = false;
int availablePort = -1;
Iterator<Integer> portsToCheck = this.remainingPortsToCheck.iterator();
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/bfc20d75/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java b/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
index 429dc95..67e050a 100644
--- a/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
+++ b/slider-core/src/main/java/org/apache/slider/server/appmaster/SliderAppMaster.java
@@ -378,6 +378,10 @@ public class SliderAppMaster extends AbstractSliderLaunchedService
private RegisterApplicationMasterResponse amRegistrationData;
private PortScanner portScanner;
private SecurityConfiguration securityConfiguration;
+
+ /**
+ * The port for the web application
+ */
private int webAppPort;
/**
@@ -679,6 +683,8 @@ public class SliderAppMaster extends AbstractSliderLaunchedService
}
}
//bring up the Slider RPC service
+
+ buildPortScanner(instanceDefinition);
startSliderRPCServer(instanceDefinition);
rpcServiceAddress = rpcService.getConnectAddress();
@@ -705,7 +711,7 @@ public class SliderAppMaster extends AbstractSliderLaunchedService
.getComponent(SliderKeys.COMPONENT_AM);
certificateManager.initialize(component);
certificateManager.setPassphrase(instanceDefinition.getPassphrase());
-
+
if (component.getOptionBool(
AgentKeys.KEY_AGENT_TWO_WAY_SSL_ENABLED, false)) {
uploadServerCertForLocalization(clustername, fs);
@@ -713,7 +719,11 @@ public class SliderAppMaster extends AbstractSliderLaunchedService
startAgentWebApp(appInformation, serviceConf);
- webAppPort = getPortToRequest(instanceDefinition);
+ webAppPort = getPortToRequest();
+ if (webAppPort == 0) {
+ // failure to find a port
+ throw new BadConfigException("Failed to fix a web application port");
+ }
String scheme = WebAppUtils.HTTP_PREFIX;
appMasterTrackingUrl = scheme + appMasterHostname + ":" + webAppPort;
@@ -965,32 +975,31 @@ public class SliderAppMaster extends AbstractSliderLaunchedService
}
/**
+ * Build up the port scanner. This may include setting a port range.
+ */
+ private void buildPortScanner(AggregateConf instanceDefinition) {
+ portScanner = new PortScanner();
+ String portRange = instanceDefinition.
+ getAppConfOperations().getGlobalOptions().
+ getOption(SliderKeys.KEY_ALLOWED_PORT_RANGE, "0");
+ if (!"0".equals(portRange)) {
+ portScanner.setPortRange(portRange);
+ }
+ }
+
+ /**
* Locate a port to request for a service such as RPC or web/REST.
* This uses port range definitions in the <code>instanceDefinition</code>
* to fix the port range —if one is set.
* <p>
* The port returned is available at the time of the request; there are
* no guarantees as to how long that situation will last.
- * @param instanceDefinition instance definition containing port range
- * restrictions in in the application configuration
* @return the port to request.
* @throws SliderException
*/
- private int getPortToRequest(AggregateConf instanceDefinition)
+ private int getPortToRequest()
throws SliderException {
- int portToRequest = 0;
- String portRange = instanceDefinition.
- getAppConfOperations().getGlobalOptions().
- getOption(SliderKeys.KEY_ALLOWED_PORT_RANGE, "0");
- if (!"0".equals(portRange)) {
- if (portScanner == null) {
- portScanner = new PortScanner();
- portScanner.setPortRange(portRange);
- }
- portToRequest = portScanner.getAvailablePort();
- }
-
- return portToRequest;
+ return portScanner.getAvailablePort();
}
private void uploadServerCertForLocalization(String clustername,
@@ -1427,7 +1436,7 @@ the registry with/without the new record format
.newReflectiveBlockingService(
protobufRelay);
- int port = getPortToRequest(instanceDefinition);
+ int port = getPortToRequest();
rpcService =
new WorkflowRpcService("SliderRPC", RpcBinder.createProtobufServer(
new InetSocketAddress("0.0.0.0", port),