You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/03/01 16:16:46 UTC
stratos git commit: Synchronize generateKubernetesServicePorts()
method to avoid port collisions
Repository: stratos
Updated Branches:
refs/heads/master bc2e71653 -> 960e4240f
Synchronize generateKubernetesServicePorts() method to avoid port collisions
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/960e4240
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/960e4240
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/960e4240
Branch: refs/heads/master
Commit: 960e4240f2eeed2a2a14a10783f1c9aea97ed2eb
Parents: bc2e716
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sun Mar 1 20:46:35 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sun Mar 1 20:46:35 2015 +0530
----------------------------------------------------------------------
.../iaases/kubernetes/KubernetesIaas.java | 60 +++++++++++---------
1 file changed, 34 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/960e4240/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
index 07da283..d8b06fc 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/kubernetes/KubernetesIaas.java
@@ -516,40 +516,48 @@ public class KubernetesIaas extends Iaas {
return false;
}
+ /**
+ * Generate kubernetes service ports for cluster.
+ * @param kubernetesClusterContext
+ * @param clusterId
+ * @param cartridge
+ */
private void generateKubernetesServicePorts(KubernetesClusterContext kubernetesClusterContext, String clusterId,
Cartridge cartridge) {
- if(cartridge != null) {
- StringBuilder portMappingStrBuilder = new StringBuilder();
- for (PortMapping portMapping : cartridge.getPortMappings()) {
- if(portMapping.getKubernetesServicePort() == 0) {
- int nextServicePort = kubernetesClusterContext.getNextServicePort();
- if (nextServicePort == -1) {
- throw new RuntimeException(String.format("Could not generate service port: [cluster-id] %s " +
- "[port] %d", clusterId, portMapping.getPort()));
- }
- portMapping.setKubernetesServicePort(nextServicePort);
- portMapping.setKubernetesServicePortMapping(true);
+ synchronized (KubernetesIaas.class) {
+ if (cartridge != null) {
+ StringBuilder portMappingStrBuilder = new StringBuilder();
+ for (PortMapping portMapping : cartridge.getPortMappings()) {
+ if (portMapping.getKubernetesServicePort() == 0) {
+ int nextServicePort = kubernetesClusterContext.getNextServicePort();
+ if (nextServicePort == -1) {
+ throw new RuntimeException(String.format("Could not generate service port: [cluster-id] %s " +
+ "[port] %d", clusterId, portMapping.getPort()));
+ }
+ portMapping.setKubernetesServicePort(nextServicePort);
+ portMapping.setKubernetesServicePortMapping(true);
- // Add port mappings to payload
- if(portMappingStrBuilder.toString().length() > 0) {
- portMappingStrBuilder.append(":");
- }
- portMappingStrBuilder.append(String.format("PROTOCOL=%s|PORT=%d|PROXY_PORT=%d",
- portMapping.getProtocol(), portMapping.getPort(), portMapping.getProxyPort()));
+ // Add port mappings to payload
+ if (portMappingStrBuilder.toString().length() > 0) {
+ portMappingStrBuilder.append(":");
+ }
+ portMappingStrBuilder.append(String.format("PROTOCOL=%s|PORT=%d|PROXY_PORT=%d",
+ portMapping.getProtocol(), portMapping.getPort(), portMapping.getProxyPort()));
- if (log.isInfoEnabled()) {
- log.info(String.format("Kubernetes service port generated: [cluster-id] %s [port] %d " +
- "[service-port] %d", clusterId, portMapping.getPort(), nextServicePort));
+ if (log.isInfoEnabled()) {
+ log.info(String.format("Kubernetes service port generated: [cluster-id] %s [port] %d " +
+ "[service-port] %d", clusterId, portMapping.getPort(), nextServicePort));
+ }
}
}
- }
- NameValuePair nameValuePair = new NameValuePair(PORT_MAPPINGS, portMappingStrBuilder.toString());
- payload.add(nameValuePair);
+ NameValuePair nameValuePair = new NameValuePair(PORT_MAPPINGS, portMappingStrBuilder.toString());
+ payload.add(nameValuePair);
- // Persist service ports added to port mappings
- CloudControllerContext.getInstance().updateKubernetesClusterContext(kubernetesClusterContext);
- CloudControllerContext.getInstance().persist();
+ // Persist service ports added to port mappings
+ CloudControllerContext.getInstance().updateKubernetesClusterContext(kubernetesClusterContext);
+ CloudControllerContext.getInstance().persist();
+ }
}
}