From c8ea6faf30ebc0708670a86e422c0541ed063dfe Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 4 Jun 2015 09:12:59 +0000 Subject: [PATCH 001/217] adding gce-extension files --- .../load-balancer/gce-extension/pom.xml | 129 ++++++++++++++++++ .../gce-extension/src/main/assembly/bin.xml | 69 ++++++++++ .../src/main/bin/gce-extension.sh | 46 +++++++ .../src/main/conf/jndi.properties | 22 +++ .../src/main/conf/log4j.properties | 40 ++++++ .../src/main/conf/thrift-client-config.xml | 27 ++++ .../gce/extension/GCELoadBalancer.java | 62 +++++++++ .../stratos/gce/extension/GCEOperations.java | 77 +++++++++++ .../gce/extension/GCEStatisticsReader.java | 37 +++++ .../apache/stratos/gce/extension/Main.java | 88 ++++++++++++ extensions/load-balancer/pom.xml | 1 + 11 files changed, 598 insertions(+) create mode 100644 extensions/load-balancer/gce-extension/pom.xml create mode 100644 extensions/load-balancer/gce-extension/src/main/assembly/bin.xml create mode 100644 extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh create mode 100644 extensions/load-balancer/gce-extension/src/main/conf/jndi.properties create mode 100644 extensions/load-balancer/gce-extension/src/main/conf/log4j.properties create mode 100644 extensions/load-balancer/gce-extension/src/main/conf/thrift-client-config.xml create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml new file mode 100644 index 0000000000..230d27add7 --- /dev/null +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -0,0 +1,129 @@ + + + + + 4.0.0 + + + org.apache.stratos + stratos-load-balancer-extensions + 4.1.0-SNAPSHOT + + + org.apache.stratos.gce.extension + Apache Stratos - GCE Extension + Apache Stratos GCE Extension for Load Balancing + + + + org.slf4j + slf4j-log4j12 + 1.7.5 + + + org.apache.stratos + org.apache.stratos.common + ${project.version} + + + org.apache.stratos + org.apache.stratos.messaging + ${project.version} + + + org.apache.stratos + org.apache.stratos.load.balancer.extension.api + ${project.version} + + + commons-io + commons-io + 2.0 + + + org.apache.velocity + velocity + 1.7 + + + org.wso2.andes.wso2 + andes-client + 0.13.wso2v8 + + + org.apache.jclouds.driver + jclouds-sshj + ${jclouds.version} + + + org.apache.jclouds.driver + jclouds-slf4j + ${jclouds.version} + + + org.apache.jclouds.labs + google-compute-engine + 1.8.1 + + + com.google.api-client + google-api-client + 1.18.0-rc + + + + + + maven-assembly-plugin + + + src/main/assembly/bin.xml + + + 420 + 493 + 493 + + false + + + + package + + attached + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + org.apache.stratos.gce.extension.Main + + + + + + + \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/assembly/bin.xml b/extensions/load-balancer/gce-extension/src/main/assembly/bin.xml new file mode 100644 index 0000000000..42e0761b74 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/assembly/bin.xml @@ -0,0 +1,69 @@ + + + + bin + + zip + + + + ${project.basedir}/src/main/bin + /bin + 0755 + + gce-extension.sh + + + + ${project.basedir}/src/main/conf + /conf + 0600 + + jndi.properties + log4j.properties + thrift-client-config.xml + + + + ${project.basedir}/src/main/security + /security + 0600 + + client-truststore.jks + + + + + + /lib + + *:icu4j* + *:jaxen* + *:jboss-transaction-api* + *:wrapper* + *:xom* + + true + runtime + + + \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh new file mode 100644 index 0000000000..2c208cbb95 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# -------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# -------------------------------------------------------------- + +echo "Starting gce load balancer extension..." +script_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )/`dirname $0`" +echo ${script_path} +lib_path=${script_path}/../lib/ +class_path=`echo ${lib_path}/*.jar | tr ' ' ':'` + + + +properties="-Djndi.properties.dir=${script_path}/../conf + -Dstats.socket.file.path=/tmp/haproxy-stats.socket + -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties + -Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks + -Djavax.net.ssl.trustStorePassword=wso2carbon + -Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml + -Dcep.stats.publisher.enabled=false + -Dthrift.receiver.ip=127.0.0.1 + -Dthrift.receiver.port=7615 + -Dnetwork.partition.id=network-partition-1" + + +# Uncomment below line to enable remote debugging +debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" + +java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $* \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/conf/jndi.properties b/extensions/load-balancer/gce-extension/src/main/conf/jndi.properties new file mode 100644 index 0000000000..21d74207b9 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/conf/jndi.properties @@ -0,0 +1,22 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +connectionfactoryName=TopicConnectionFactory +java.naming.provider.url=tcp://localhost:61616 +java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory diff --git a/extensions/load-balancer/gce-extension/src/main/conf/log4j.properties b/extensions/load-balancer/gce-extension/src/main/conf/log4j.properties new file mode 100644 index 0000000000..40f9c47efb --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/conf/log4j.properties @@ -0,0 +1,40 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Set root logger level and appenders +log4j.rootLogger=INFO, CONSOLE_APPENDER, FILE_APPENDER + +# CONSOLE_APPENDER is set to be a ConsoleAppender. +log4j.appender.CONSOLE_APPENDER=org.apache.log4j.ConsoleAppender + +# The standard error log where all the warnings, errors and fatal errors will be logged +log4j.appender.FILE_APPENDER=org.apache.log4j.FileAppender +log4j.appender.FILE_APPENDER.File=logs/gce-extension.log +log4j.appender.FILE_APPENDER.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE_APPENDER.layout.ConversionPattern=%d{ISO8601} [%X{ip}-%X{host}] [%t] %5p %c{1} %m%n +log4j.appender.FILE_APPENDER.threshold=DEBUG + +# CONSOLE_APPENDER uses PatternLayout. +log4j.appender.CONSOLE_APPENDER.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE_APPENDER.layout.ConversionPattern=[%d{ISO8601}] %5p - [%c{1}] %m%n + +log4j.logger.org.apache.stratos.gce.extension=INFO +log4j.logger.org.apache.stratos.load.balancer.extension.api=INFO +log4j.logger.org.apache.stratos.messaging=INFO +log4j.logger.org.wso2.andes.client=ERROR \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/conf/thrift-client-config.xml b/extensions/load-balancer/gce-extension/src/main/conf/thrift-client-config.xml new file mode 100644 index 0000000000..5cacada428 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/conf/thrift-client-config.xml @@ -0,0 +1,27 @@ + + + + + + admin + admin + localhost + 7611 + \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java new file mode 100644 index 0000000000..44a8f17c2f --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -0,0 +1,62 @@ +package org.apache.stratos.gce.extension; + +import org.apache.stratos.load.balancer.common.domain.Topology; +import org.apache.stratos.load.balancer.extension.api.LoadBalancer; +import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class GCELoadBalancer implements LoadBalancer { + + private static final Log log = LogFactory.getLog(GCELoadBalancer.class); + + private GCEOperations gceOperations; + + public GCELoadBalancer() { + try { + gceOperations = new GCEOperations(); + } catch (LoadBalancerExtensionException e) { + log.error(e); + } + } + + @Override + public void start() throws LoadBalancerExtensionException { + log.info("Starting GCE instance..."); + + } + + @Override + public void stop() throws LoadBalancerExtensionException { + + } + + @Override + public boolean configure(Topology topology) throws LoadBalancerExtensionException { + return false; + } + + @Override + public void reload() throws LoadBalancerExtensionException { + + } +} \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java new file mode 100644 index 0000000000..d02ed56d71 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -0,0 +1,77 @@ +package org.apache.stratos.gce.extension; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; +import org.jclouds.ContextBuilder; +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.sshj.config.SshjSshClientModule; +import org.jclouds.util.Strings2; + +import java.io.FileInputStream; +import java.io.IOException; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +public class GCEOperations { + + private static final Log log = LogFactory.getLog(GCELoadBalancer.class); + + public GCEOperations() throws LoadBalancerExtensionException { + + //TODO: remove hard coded values + String provider = "google-compute-engine"; + String identity = "969955727877-3q53n9vgjajebj9g7tigdosekedfviat@developer.gserviceaccount.com"; + String credential = "/home/sanjaya/key.pem"; + String groupName = "instance-group-1"; + credential = getPrivateKeyFromFile(credential); + + ComputeService compute = initComputeService(provider, identity, credential); + + + } + + private static ComputeService initComputeService(String provider, String identity, String credential) { + + //initialize compute service + + Iterable modules = ImmutableSet. of(new SshjSshClientModule()); + + ContextBuilder builder = ContextBuilder.newBuilder(provider) + .credentials(identity, credential) + .modules(modules); + + log.info("initializing " + builder.getApiMetadata()); + + return builder.buildView(ComputeServiceContext.class).getComputeService(); + } + + private static String getPrivateKeyFromFile(String filename) throws LoadBalancerExtensionException { + try { + return Strings2.toStringAndClose(new FileInputStream(filename)); + } catch (IOException e) { + log.error("Exception : " + e); + throw new LoadBalancerExtensionException(e); + } + } + +} \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java new file mode 100644 index 0000000000..2ae2a99c0f --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -0,0 +1,37 @@ +package org.apache.stratos.gce.extension; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.stratos.load.balancer.common.statistics.LoadBalancerStatisticsReader; + +/** + * GCE extension statistics reader class. + */ +public class GCEStatisticsReader implements LoadBalancerStatisticsReader { + @Override + public String getClusterInstanceId() { + return null; + } + + @Override + public int getInFlightRequestCount(String clusterId) { + return 0; + } +} \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java new file mode 100644 index 0000000000..6fb7a53282 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.gce.extension; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.PropertyConfigurator; +import org.apache.stratos.common.threading.StratosThreadPool; +import org.apache.stratos.load.balancer.common.topology.TopologyProvider; +import org.apache.stratos.load.balancer.extension.api.LoadBalancerExtension; + +import java.util.concurrent.ExecutorService; + +/** + * GCE extension main class. + */ +public class Main { + private static final Log log = LogFactory.getLog(Main.class); + private static ExecutorService executorService; + + public static void main(String[] args) { + + LoadBalancerExtension extension = null; + try { + // Configure log4j properties + PropertyConfigurator.configure(System.getProperty("log4j.properties.file.path")); + + if (log.isInfoEnabled()) { + log.info("GCE extension started"); + } + + // Add shutdown hook + final Thread mainThread = Thread.currentThread(); + final LoadBalancerExtension finalExtension = extension; + Runtime.getRuntime().addShutdownHook(new Thread() { + public void run() { + try { + if(finalExtension != null) { + log.info("GCE gce instance..."); + finalExtension.stop(); + } + mainThread.join(); + } catch (Exception e) { + log.error(e); + } + } + }); + + executorService = StratosThreadPool.getExecutorService("gce.extension.thread.pool", 10); + + // Validate runtime parameters + + TopologyProvider topologyProvider = new TopologyProvider(); + //ToDo: pass topology provider inside the statsReader. Look line 70 in HAProxy.java + GCEStatisticsReader statisticsReader = new GCEStatisticsReader(); + extension = new LoadBalancerExtension(new GCELoadBalancer(), statisticsReader, topologyProvider); + extension.setExecutorService(executorService); + extension.execute(); + + + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error(e); + } + if (extension != null) { + log.info("Shutting GCE instance..."); + extension.stop(); + } + } + } +} \ No newline at end of file diff --git a/extensions/load-balancer/pom.xml b/extensions/load-balancer/pom.xml index ff89360c71..5b27928988 100644 --- a/extensions/load-balancer/pom.xml +++ b/extensions/load-balancer/pom.xml @@ -36,6 +36,7 @@ haproxy-extension nginx-extension + gce-extension From 14676ec1fb0eb47ac27b505112e9bc01493103b2 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 4 Jun 2015 09:57:34 +0000 Subject: [PATCH 002/217] adding gce-extension files --- .../load-balancer/gce-extension/pom.xml | 27 +++--- .../stratos/gce/extension/GCEOperations.java | 93 ++++++++++++------- 2 files changed, 74 insertions(+), 46 deletions(-) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index 230d27add7..b08cfc6caf 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -68,26 +68,25 @@ 0.13.wso2v8 - org.apache.jclouds.driver - jclouds-sshj - ${jclouds.version} + com.google.http-client + google-http-client-jackson2 + ${project.http.version} - org.apache.jclouds.driver - jclouds-slf4j - ${jclouds.version} + com.google.oauth-client + google-oauth-client-jetty + ${project.oauth.version} - org.apache.jclouds.labs - google-compute-engine - 1.8.1 - - - com.google.api-client - google-api-client - 1.18.0-rc + com.google.apis + google-api-services-compute + v1-rev27-1.19.0 + + 1.19.0 + 1.19.0 + diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index d02ed56d71..0529f743ed 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -1,18 +1,24 @@ package org.apache.stratos.gce.extension; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; +import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; +import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.store.DataStoreFactory; +import com.google.api.client.util.store.FileDataStoreFactory; +import com.google.api.services.compute.Compute; +import com.google.api.services.compute.ComputeScopes; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; -import org.jclouds.ContextBuilder; -import org.jclouds.compute.ComputeService; -import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.jclouds.util.Strings2; -import java.io.FileInputStream; +import java.io.File; import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -36,42 +42,65 @@ public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); - public GCEOperations() throws LoadBalancerExtensionException { + //TODO: remove hardcoded values + private static final String PROJECT_NAME = "GCE-test"; + private static final String projectId = "oceanic-depth-89120"; + private static final String zoneName = "europe-west1-d"; + private static final String regionName = "europe-west1"; - //TODO: remove hard coded values - String provider = "google-compute-engine"; - String identity = "969955727877-3q53n9vgjajebj9g7tigdosekedfviat@developer.gserviceaccount.com"; - String credential = "/home/sanjaya/key.pem"; - String groupName = "instance-group-1"; - credential = getPrivateKeyFromFile(credential); + //auth + private static final String keyFile = "/home/sanjaya/keys/p12key-donwloaded.p12"; + private static final String accountId = "164588286821-a517i85433f83e0nthc4qjmoupri" + + "394q@developer.gserviceaccount.com"; - ComputeService compute = initComputeService(provider, identity, credential); + /** + * Directory to store user credentials. + */ + private static final String DATA_STORE_DIR = ".store/gce-extension"; + /** + * Global instance of the JSON factory. + */ - } + /** + * OAuth 2.0 scopes + */ + private static final List SCOPES = Arrays.asList(ComputeScopes.COMPUTE_READONLY); + + Compute compute; - private static ComputeService initComputeService(String provider, String identity, String credential) { - //initialize compute service + public GCEOperations() throws LoadBalancerExtensionException { + - Iterable modules = ImmutableSet. of(new SshjSshClientModule()); + } - ContextBuilder builder = ContextBuilder.newBuilder(provider) - .credentials(identity, credential) - .modules(modules); + private void createTargetPool(String targetPoolName) { - log.info("initializing " + builder.getApiMetadata()); - return builder.buildView(ComputeServiceContext.class).getComputeService(); } - private static String getPrivateKeyFromFile(String filename) throws LoadBalancerExtensionException { - try { - return Strings2.toStringAndClose(new FileInputStream(filename)); - } catch (IOException e) { - log.error("Exception : " + e); - throw new LoadBalancerExtensionException(e); - } + private Compute getComputeEngineObject() throws GeneralSecurityException, IOException { + + HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); + DataStoreFactory dataStoreFactory = new FileDataStoreFactory(new + File(System.getProperty("user.home"), DATA_STORE_DIR)); + JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); + + GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) + .setJsonFactory(jsonFactory) + .setServiceAccountId(accountId) + .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) + .setServiceAccountPrivateKeyFromP12File(new File(keyFile)) + .build(); + + // Create compute engine object for listing instances + compute = new Compute.Builder( + httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) + .setHttpRequestInitializer(credential).build(); + return compute; + } + } \ No newline at end of file From e2fa0567bced027ca7fb7eff1603a9ee7f769020 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 4 Jun 2015 10:00:15 +0000 Subject: [PATCH 003/217] adding gce-extension files --- .../org/apache/stratos/gce/extension/GCELoadBalancer.java | 7 +++++++ .../org/apache/stratos/gce/extension/GCEOperations.java | 7 ++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 44a8f17c2f..b0c95d82f4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -6,6 +6,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.io.IOException; +import java.security.GeneralSecurityException; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -36,6 +39,10 @@ public GCELoadBalancer() { gceOperations = new GCEOperations(); } catch (LoadBalancerExtensionException e) { log.error(e); + } catch (GeneralSecurityException e) { + log.error(e); + } catch (IOException e) { + log.error(e); } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 0529f743ed..8439edc1c0 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -70,8 +70,9 @@ public class GCEOperations { Compute compute; - public GCEOperations() throws LoadBalancerExtensionException { + public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityException, IOException { + buildComputeEngineObject(); } @@ -80,7 +81,7 @@ private void createTargetPool(String targetPoolName) { } - private Compute getComputeEngineObject() throws GeneralSecurityException, IOException { + private void buildComputeEngineObject() throws GeneralSecurityException, IOException { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); DataStoreFactory dataStoreFactory = new FileDataStoreFactory(new @@ -98,7 +99,7 @@ private Compute getComputeEngineObject() throws GeneralSecurityException, IOExce compute = new Compute.Builder( httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) .setHttpRequestInitializer(credential).build(); - return compute; + } From da86337582debfa74a90bcaa089093df07b54065 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 04:49:59 +0000 Subject: [PATCH 004/217] adding a test method --- .../stratos/gce/extension/GCEOperations.java | 25 ++++++++++++++++--- .../gce/extension/GCEStatisticsReader.java | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 8439edc1c0..49f1ff4c69 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -9,6 +9,8 @@ import com.google.api.client.util.store.FileDataStoreFactory; import com.google.api.services.compute.Compute; import com.google.api.services.compute.ComputeScopes; +import com.google.api.services.compute.model.Instance; +import com.google.api.services.compute.model.InstanceList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -43,8 +45,8 @@ public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); //TODO: remove hardcoded values - private static final String PROJECT_NAME = "GCE-test"; - private static final String projectId = "oceanic-depth-89120"; + private static final String PROJECT_NAME = "My First Project"; + private static final String projectId = "gold-access-96509"; private static final String zoneName = "europe-west1-d"; private static final String regionName = "europe-west1"; @@ -67,18 +69,20 @@ public class GCEOperations { */ private static final List SCOPES = Arrays.asList(ComputeScopes.COMPUTE_READONLY); - Compute compute; + static Compute compute; public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityException, IOException { buildComputeEngineObject(); + printInstances(); } private void createTargetPool(String targetPoolName) { + } private void buildComputeEngineObject() throws GeneralSecurityException, IOException { @@ -103,5 +107,20 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep } + //TODO: this is a testing method. Need to remove + public static void printInstances() throws IOException { + System.out.println("================== Listing Compute Engine Instances =================="); + Compute.Instances.List instances = compute.instances().list(projectId, zoneName); + InstanceList list = instances.execute(); + if (list.getItems() == null) { + System.out.println("No instances found. Sign in to the Google APIs Console and create " + + "an instance at: code.google.com/apis/console"); + } else { + for (Instance instance : list.getItems()) { + System.out.println(instance.toPrettyString()); + } + } + } + } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index 2ae2a99c0f..9058248535 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -32,6 +32,7 @@ public String getClusterInstanceId() { @Override public int getInFlightRequestCount(String clusterId) { + return 0; } } \ No newline at end of file From b536600da14f1c962bca2065349ab2872b88b6ce Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 06:00:02 +0000 Subject: [PATCH 005/217] fixing zone name error --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 49f1ff4c69..6b8f018371 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -47,7 +47,7 @@ public class GCEOperations { //TODO: remove hardcoded values private static final String PROJECT_NAME = "My First Project"; private static final String projectId = "gold-access-96509"; - private static final String zoneName = "europe-west1-d"; + private static final String zoneName = "europe-west1-b"; private static final String regionName = "europe-west1"; //auth From a109bc39081f3bcb077c421e48399174edf072f6 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 06:22:36 +0000 Subject: [PATCH 006/217] adding create target pool method --- .../apache/stratos/gce/extension/GCEOperations.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 6b8f018371..f473d01156 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -11,6 +11,7 @@ import com.google.api.services.compute.ComputeScopes; import com.google.api.services.compute.model.Instance; import com.google.api.services.compute.model.InstanceList; +import com.google.api.services.compute.model.TargetPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -75,12 +76,20 @@ public class GCEOperations { public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityException, IOException { buildComputeEngineObject(); - printInstances(); + createTargetPool("testing"); } private void createTargetPool(String targetPoolName) { + TargetPool targetPool = new TargetPool(); + targetPool.setName(targetPoolName); + + try { + compute.targetPools().insert(projectId,regionName,targetPool); + } catch (IOException e) { + e.printStackTrace(); + } } @@ -107,7 +116,7 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep } - //TODO: this is a testing method. Need to remove + //TODO: this is a testing method used for check authentication. Need to remove public static void printInstances() throws IOException { System.out.println("================== Listing Compute Engine Instances =================="); Compute.Instances.List instances = compute.instances().list(projectId, zoneName); From 410927b8ed77890c9311008c9831da4b23313873 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 07:00:56 +0000 Subject: [PATCH 007/217] adding create target pool method --- .../gce/extension/GCELoadBalancer.java | 1 + .../stratos/gce/extension/GCEOperations.java | 42 ++++++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index b0c95d82f4..e55c5e6e7e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -50,6 +50,7 @@ public GCELoadBalancer() { public void start() throws LoadBalancerExtensionException { log.info("Starting GCE instance..."); + } @Override diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index f473d01156..d7dd48e265 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -76,15 +76,32 @@ public class GCEOperations { public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityException, IOException { buildComputeEngineObject(); - createTargetPool("testing"); + //Calling this method from here only for testing purposes + createTargetPool("testtargetpool"); } - private void createTargetPool(String targetPoolName) { + public void createTargetPool(String targetPoolName) { TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); + //get instances in given region + try { + Compute.Instances.List instanceList = getInstanceList(""); + InstanceList list = instanceList.execute(); + if (list.getItems() == null) { + System.out.println("No instances found. Sign in to the Google APIs Console and create " + + "an instance at: code.google.com/apis/console"); + } else { + for (Instance instance : list.getItems()) { + System.out.println(instance.toPrettyString()); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + try { compute.targetPools().insert(projectId,regionName,targetPool); } catch (IOException e) { @@ -94,6 +111,14 @@ private void createTargetPool(String targetPoolName) { } + private void addInstancesToTargetPool(TargetPool targetPool,List instanceList){ + + log.info("=========adding instances to target pool========"); + + targetPool.setInstances(instanceList); + + } + private void buildComputeEngineObject() throws GeneralSecurityException, IOException { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); @@ -116,18 +141,15 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep } - //TODO: this is a testing method used for check authentication. Need to remove - public static void printInstances() throws IOException { + public static Compute.Instances.List getInstanceList(String filter) throws IOException { System.out.println("================== Listing Compute Engine Instances =================="); - Compute.Instances.List instances = compute.instances().list(projectId, zoneName); + Compute.Instances.List instances = compute.instances().list(projectId, zoneName).setFilter(filter); InstanceList list = instances.execute(); if (list.getItems() == null) { - System.out.println("No instances found. Sign in to the Google APIs Console and create " - + "an instance at: code.google.com/apis/console"); + System.out.println("No instances found for specified zone"); + return null; } else { - for (Instance instance : list.getItems()) { - System.out.println(instance.toPrettyString()); - } + return instances; } } From 3553eae7744ace49c31cc8b9b604865de3779a68 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 07:05:49 +0000 Subject: [PATCH 008/217] adding create target pool method --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index d7dd48e265..2bb0692f77 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -143,7 +143,7 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep public static Compute.Instances.List getInstanceList(String filter) throws IOException { System.out.println("================== Listing Compute Engine Instances =================="); - Compute.Instances.List instances = compute.instances().list(projectId, zoneName).setFilter(filter); + Compute.Instances.List instances = compute.instances().list(projectId, zoneName); InstanceList list = instances.execute(); if (list.getItems() == null) { System.out.println("No instances found for specified zone"); From 1b1d3133d9b43ef8b0a47af771f9f264aef07e09 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 07:46:25 +0000 Subject: [PATCH 009/217] adding create target pool method --- .../gce-extension/src/main/bin/gce-extension.sh | 2 +- .../org/apache/stratos/gce/extension/GCEOperations.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 2c208cbb95..905fce4f0e 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -41,6 +41,6 @@ properties="-Djndi.properties.dir=${script_path}/../conf # Uncomment below line to enable remote debugging -debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" +#debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $* \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 2bb0692f77..dcad337f62 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -88,7 +88,7 @@ public void createTargetPool(String targetPoolName) { //get instances in given region try { - Compute.Instances.List instanceList = getInstanceList(""); + Compute.Instances.List instanceList = getInstanceList("status=RUNNING"); InstanceList list = instanceList.execute(); if (list.getItems() == null) { System.out.println("No instances found. Sign in to the Google APIs Console and create " @@ -143,10 +143,10 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep public static Compute.Instances.List getInstanceList(String filter) throws IOException { System.out.println("================== Listing Compute Engine Instances =================="); - Compute.Instances.List instances = compute.instances().list(projectId, zoneName); + Compute.Instances.List instances = compute.instances().list(projectId, zoneName).setFilter(filter); InstanceList list = instances.execute(); if (list.getItems() == null) { - System.out.println("No instances found for specified zone"); + log.info("No instances found for specified zone"); return null; } else { return instances; From 4a296f5d8e23ca18f465e508cab1336aec860018 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 07:49:47 +0000 Subject: [PATCH 010/217] adding create target pool method --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index dcad337f62..7fb17fd06d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -88,7 +88,7 @@ public void createTargetPool(String targetPoolName) { //get instances in given region try { - Compute.Instances.List instanceList = getInstanceList("status=RUNNING"); + Compute.Instances.List instanceList = getInstanceList("status eq RUNNING"); InstanceList list = instanceList.execute(); if (list.getItems() == null) { System.out.println("No instances found. Sign in to the Google APIs Console and create " From 59713f6b040240b0c49be4296c42a49fb86a0aa4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 07:53:03 +0000 Subject: [PATCH 011/217] adding create target pool method --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 7fb17fd06d..c177f9e8ff 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -90,6 +90,7 @@ public void createTargetPool(String targetPoolName) { try { Compute.Instances.List instanceList = getInstanceList("status eq RUNNING"); InstanceList list = instanceList.execute(); + log.info("number of instances: "+ list.size()); if (list.getItems() == null) { System.out.println("No instances found. Sign in to the Google APIs Console and create " + "an instance at: code.google.com/apis/console"); From 6f036e0346c8b266d722fb44e07df57a3739e710 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:21:55 +0000 Subject: [PATCH 012/217] adding create target pool method --- .../stratos/gce/extension/GCEOperations.java | 45 ++++++++++--------- .../gce/extension/GCEStatisticsReader.java | 14 +++++- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index c177f9e8ff..8d73030c53 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -9,7 +9,6 @@ import com.google.api.client.util.store.FileDataStoreFactory; import com.google.api.services.compute.Compute; import com.google.api.services.compute.ComputeScopes; -import com.google.api.services.compute.model.Instance; import com.google.api.services.compute.model.InstanceList; import com.google.api.services.compute.model.TargetPool; import org.apache.commons.logging.Log; @@ -47,13 +46,15 @@ public class GCEOperations { //TODO: remove hardcoded values private static final String PROJECT_NAME = "My First Project"; - private static final String projectId = "gold-access-96509"; - private static final String zoneName = "europe-west1-b"; - private static final String regionName = "europe-west1"; + private static final String PROJECT_ID = "gold-access-96509"; + private static final String ZONE_NAME = "europe-west1-b"; + private static final String REGION_NAME = "europe-west1"; + private static final String RUNNING_FILTER="status eq RUNNING"; + //auth - private static final String keyFile = "/home/sanjaya/keys/p12key-donwloaded.p12"; - private static final String accountId = "164588286821-a517i85433f83e0nthc4qjmoupri" + + private static final String KEY_FILE = "/home/sanjaya/keys/p12key-donwloaded.p12"; + private static final String ACCOUNT_ID = "164588286821-a517i85433f83e0nthc4qjmoupri" + "394q@developer.gserviceaccount.com"; /** @@ -77,7 +78,7 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes - createTargetPool("testtargetpool"); + // createTargetPool("testtargetpool"); } @@ -88,23 +89,16 @@ public void createTargetPool(String targetPoolName) { //get instances in given region try { - Compute.Instances.List instanceList = getInstanceList("status eq RUNNING"); + Compute.Instances.List instanceList = getInstanceList(); InstanceList list = instanceList.execute(); log.info("number of instances: "+ list.size()); - if (list.getItems() == null) { - System.out.println("No instances found. Sign in to the Google APIs Console and create " - + "an instance at: code.google.com/apis/console"); - } else { - for (Instance instance : list.getItems()) { - System.out.println(instance.toPrettyString()); - } - } + } catch (IOException e) { e.printStackTrace(); } try { - compute.targetPools().insert(projectId,regionName,targetPool); + compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool); } catch (IOException e) { e.printStackTrace(); } @@ -120,6 +114,11 @@ private void addInstancesToTargetPool(TargetPool targetPool,List instanc } + /** + * Authorize and build compute engine object + * @throws GeneralSecurityException + * @throws IOException + */ private void buildComputeEngineObject() throws GeneralSecurityException, IOException { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); @@ -129,9 +128,9 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) .setJsonFactory(jsonFactory) - .setServiceAccountId(accountId) + .setServiceAccountId(ACCOUNT_ID) .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) - .setServiceAccountPrivateKeyFromP12File(new File(keyFile)) + .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE)) .build(); // Create compute engine object for listing instances @@ -142,9 +141,11 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep } - public static Compute.Instances.List getInstanceList(String filter) throws IOException { - System.out.println("================== Listing Compute Engine Instances =================="); - Compute.Instances.List instances = compute.instances().list(projectId, zoneName).setFilter(filter); + + public static Compute.Instances.List getInstanceList() throws IOException { + System.out.println("================== Listing running Compute Engine Instances =================="); + Compute.Instances.List instances = compute.instances(). + list(PROJECT_ID, ZONE_NAME).setFilter(RUNNING_FILTER); InstanceList list = instances.execute(); if (list.getItems() == null) { log.info("No instances found for specified zone"); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index 9058248535..42d235bfcb 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -19,15 +19,27 @@ * under the License. */ +import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.load.balancer.common.statistics.LoadBalancerStatisticsReader; +import org.apache.stratos.load.balancer.common.topology.TopologyProvider; /** * GCE extension statistics reader class. */ public class GCEStatisticsReader implements LoadBalancerStatisticsReader { + + private TopologyProvider topologyProvider; + private String clusterInstanceId; + + public GCEStatisticsReader(TopologyProvider topologyProvider){ + this.topologyProvider = topologyProvider; + this.clusterInstanceId = System.getProperty(StratosConstants.CLUSTER_INSTANCE_ID, StratosConstants.NOT_DEFINED); + + } + @Override public String getClusterInstanceId() { - return null; + return clusterInstanceId; } @Override From df21f52f9d57e927d8241e15f804dd7a2ddb7932 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:29:22 +0000 Subject: [PATCH 013/217] adding create target pool method --- .../stratos/gce/extension/GCEOperations.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 8d73030c53..06be588196 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -74,28 +75,45 @@ public class GCEOperations { static Compute compute; + /** + * Constructor for GCE Operations Class + * @throws LoadBalancerExtensionException + * @throws GeneralSecurityException + * @throws IOException + */ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityException, IOException { buildComputeEngineObject(); //Calling this method from here only for testing purposes - // createTargetPool("testtargetpool"); + createTargetPool("testtargetpool"); } + /** + * Creating a target pool by adding instances to the target pool. + * At least one instance should be available to create a target pool. + * @param targetPoolName + */ public void createTargetPool(String targetPoolName) { - TargetPool targetPool = new TargetPool(); - targetPool.setName(targetPoolName); - //get instances in given region - try { + /*try { Compute.Instances.List instanceList = getInstanceList(); InstanceList list = instanceList.execute(); log.info("number of instances: "+ list.size()); } catch (IOException e) { e.printStackTrace(); - } + }*/ + + TargetPool targetPool = new TargetPool(); + targetPool.setName(targetPoolName); + List instanceList = new ArrayList(); + //todo: remove hardcoded value and take all the instances created by stratos and add + instanceList.add("instance-2"); + targetPool.setInstances(instanceList); + + try { compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool); From 658aaf1267ee367d2c568a0adbb0324976208027 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:34:34 +0000 Subject: [PATCH 014/217] adding create target pool method --- .../src/main/java/org/apache/stratos/gce/extension/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 6fb7a53282..f03255f7d7 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -69,7 +69,7 @@ public void run() { TopologyProvider topologyProvider = new TopologyProvider(); //ToDo: pass topology provider inside the statsReader. Look line 70 in HAProxy.java - GCEStatisticsReader statisticsReader = new GCEStatisticsReader(); + GCEStatisticsReader statisticsReader = new GCEStatisticsReader(topologyProvider); extension = new LoadBalancerExtension(new GCELoadBalancer(), statisticsReader, topologyProvider); extension.setExecutorService(executorService); extension.execute(); From 41574cd4f1557365fd63a67cd763fcca5e0bbe76 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:43:03 +0000 Subject: [PATCH 015/217] adding create target pool method --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 06be588196..eed3cdb8b4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -117,6 +117,7 @@ public void createTargetPool(String targetPoolName) { try { compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool); + log.info("targetPool "+ targetPool+" added: " ); } catch (IOException e) { e.printStackTrace(); } From 5ce548c134ed89c13b9e4052bfaf669a54b2b2a6 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:47:36 +0000 Subject: [PATCH 016/217] adding create target pool method --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index eed3cdb8b4..a9e713f104 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -116,7 +116,7 @@ public void createTargetPool(String targetPoolName) { try { - compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool); + compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool).execute(); log.info("targetPool "+ targetPool+" added: " ); } catch (IOException e) { e.printStackTrace(); From 30ce224228cd8ca40ac07fa411dae1c6aac9e7d9 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:49:13 +0000 Subject: [PATCH 017/217] adding create target pool method --- .../org/apache/stratos/gce/extension/GCEOperations.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index a9e713f104..7b4cf1e53e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -108,10 +108,10 @@ public void createTargetPool(String targetPoolName) { TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); - List instanceList = new ArrayList(); + //List instanceList = new ArrayList(); //todo: remove hardcoded value and take all the instances created by stratos and add - instanceList.add("instance-2"); - targetPool.setInstances(instanceList); + //instanceList.add("instance-2"); + // targetPool.setInstances(instanceList); From b987c4545c4b9382883ce271afa8e7c6138454fe Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:51:35 +0000 Subject: [PATCH 018/217] adding create target pool method --- .../org/apache/stratos/gce/extension/GCEOperations.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 7b4cf1e53e..595e9c90a9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -90,8 +90,7 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc } /** - * Creating a target pool by adding instances to the target pool. - * At least one instance should be available to create a target pool. + * Creating a new target pool * @param targetPoolName */ public void createTargetPool(String targetPoolName) { @@ -108,11 +107,6 @@ public void createTargetPool(String targetPoolName) { TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); - //List instanceList = new ArrayList(); - //todo: remove hardcoded value and take all the instances created by stratos and add - //instanceList.add("instance-2"); - // targetPool.setInstances(instanceList); - try { From 4f0b334676b7f598014a904d02f6fae8e6b46939 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 08:53:33 +0000 Subject: [PATCH 019/217] adding create target pool method --- .../stratos/gce/extension/GCEOperations.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 595e9c90a9..37ef91eb33 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -95,23 +95,12 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc */ public void createTargetPool(String targetPoolName) { - //get instances in given region - /*try { - Compute.Instances.List instanceList = getInstanceList(); - InstanceList list = instanceList.execute(); - log.info("number of instances: "+ list.size()); - - } catch (IOException e) { - e.printStackTrace(); - }*/ - TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); - try { compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool).execute(); - log.info("targetPool "+ targetPool+" added: " ); + log.info("==========targetPool "+ targetPool+" added ============" ); } catch (IOException e) { e.printStackTrace(); } @@ -155,16 +144,16 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep } - public static Compute.Instances.List getInstanceList() throws IOException { + public static InstanceList getInstanceList() throws IOException { System.out.println("================== Listing running Compute Engine Instances =================="); Compute.Instances.List instances = compute.instances(). list(PROJECT_ID, ZONE_NAME).setFilter(RUNNING_FILTER); - InstanceList list = instances.execute(); - if (list.getItems() == null) { + InstanceList instanceList = instances.execute(); + if (instanceList.getItems() == null) { log.info("No instances found for specified zone"); return null; } else { - return instances; + return instanceList; } } From c3dc11bd69dfd89eb1d09fd5a8dc2beb6463c480 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:04:13 +0000 Subject: [PATCH 020/217] adding create target pool method --- .../src/main/bin/gce-extension.sh | 2 +- .../stratos/gce/extension/GCEOperations.java | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 905fce4f0e..2c208cbb95 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -41,6 +41,6 @@ properties="-Djndi.properties.dir=${script_path}/../conf # Uncomment below line to enable remote debugging -#debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" +debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $* \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 37ef91eb33..ebca7bba92 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -85,12 +85,13 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes - createTargetPool("testtargetpool"); + // createTargetPool("testtargetpool"); + isTargetPoolExists("testtargetpool"); } /** - * Creating a new target pool + * Creating a new target pool; name should be unique * @param targetPoolName */ public void createTargetPool(String targetPoolName) { @@ -98,9 +99,10 @@ public void createTargetPool(String targetPoolName) { TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); + //TODO:REMOVE try catch try { compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool).execute(); - log.info("==========targetPool "+ targetPool+" added ============" ); + log.info("==========targetPool "+ targetPoolName+" added ============" ); } catch (IOException e) { e.printStackTrace(); } @@ -108,6 +110,22 @@ public void createTargetPool(String targetPoolName) { } + /** + * Check whether the given target pool is already exists in the given project and region. + * Target pools are unique for regions, not for zones + * @param targetPoolName + */ + public void isTargetPoolExists(String targetPoolName){ + + try { + TargetPool targetPool = compute.targetPools().get(PROJECT_ID,REGION_NAME,targetPoolName).execute(); + log.info("==========targetpoolname===="+targetPool.getName()); + } catch (IOException e) { + e.printStackTrace(); + } + + } + private void addInstancesToTargetPool(TargetPool targetPool,List instanceList){ log.info("=========adding instances to target pool========"); From 88df9299b26ec6bfb9d6dea4a79e39680ce752da Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:07:06 +0000 Subject: [PATCH 021/217] adding create target pool method --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index ebca7bba92..e610dd4be2 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -86,7 +86,7 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes // createTargetPool("testtargetpool"); - isTargetPoolExists("testtargetpool"); + isTargetPoolExists("testtargetpool1"); } From 9cee960e8e3e221e227515247c8e628c1169ec3c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:21:47 +0000 Subject: [PATCH 022/217] adding create target pool method --- .../stratos/gce/extension/GCEOperations.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index e610dd4be2..f04daea9e7 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -11,6 +11,7 @@ import com.google.api.services.compute.ComputeScopes; import com.google.api.services.compute.model.InstanceList; import com.google.api.services.compute.model.TargetPool; +import com.google.api.services.compute.model.TargetPoolList; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -18,7 +19,6 @@ import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -50,7 +50,7 @@ public class GCEOperations { private static final String PROJECT_ID = "gold-access-96509"; private static final String ZONE_NAME = "europe-west1-b"; private static final String REGION_NAME = "europe-west1"; - private static final String RUNNING_FILTER="status eq RUNNING"; + private static final String RUNNING_FILTER = "status eq RUNNING"; //auth @@ -72,11 +72,12 @@ public class GCEOperations { */ private static final List SCOPES = Arrays.asList(ComputeScopes.COMPUTE_READONLY); - static Compute compute; + static Compute compute; /** * Constructor for GCE Operations Class + * * @throws LoadBalancerExtensionException * @throws GeneralSecurityException * @throws IOException @@ -85,13 +86,14 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes - // createTargetPool("testtargetpool"); - isTargetPoolExists("testtargetpool1"); + // createTargetPool("testtargetpool"); + System.out.println("==========="+isTargetPoolExists("testtargetpool1")+"============"); } /** * Creating a new target pool; name should be unique + * * @param targetPoolName */ public void createTargetPool(String targetPoolName) { @@ -101,8 +103,8 @@ public void createTargetPool(String targetPoolName) { //TODO:REMOVE try catch try { - compute.targetPools().insert(PROJECT_ID, REGION_NAME,targetPool).execute(); - log.info("==========targetPool "+ targetPoolName+" added ============" ); + compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); + log.info("==========targetPool " + targetPoolName + " added ============"); } catch (IOException e) { e.printStackTrace(); } @@ -113,20 +115,29 @@ public void createTargetPool(String targetPoolName) { /** * Check whether the given target pool is already exists in the given project and region. * Target pools are unique for regions, not for zones + * * @param targetPoolName */ - public void isTargetPoolExists(String targetPoolName){ + public boolean isTargetPoolExists(String targetPoolName) { try { - TargetPool targetPool = compute.targetPools().get(PROJECT_ID,REGION_NAME,targetPoolName).execute(); - log.info("==========targetpoolname===="+targetPool.getName()); + Compute.TargetPools.List targetPools = compute.targetPools().list(PROJECT_ID, REGION_NAME); + TargetPoolList targetPoolList = targetPools.execute(); + for (TargetPool targetPool : targetPoolList.getItems()) { + if (targetPool.getName().equals(targetPoolName)) { + return true; + } + + } + } catch (IOException e) { e.printStackTrace(); } + return false; } - private void addInstancesToTargetPool(TargetPool targetPool,List instanceList){ + private void addInstancesToTargetPool(TargetPool targetPool, List instanceList) { log.info("=========adding instances to target pool========"); @@ -136,6 +147,7 @@ private void addInstancesToTargetPool(TargetPool targetPool,List instanc /** * Authorize and build compute engine object + * * @throws GeneralSecurityException * @throws IOException */ @@ -171,7 +183,7 @@ public static InstanceList getInstanceList() throws IOException { log.info("No instances found for specified zone"); return null; } else { - return instanceList; + return instanceList; } } From e12036e460c31fd18d3b384006d382f40df05f00 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:23:24 +0000 Subject: [PATCH 023/217] adding create target pool method --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index f04daea9e7..5d10b3dd8a 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -87,7 +87,7 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes // createTargetPool("testtargetpool"); - System.out.println("==========="+isTargetPoolExists("testtargetpool1")+"============"); + System.out.println("==========="+isTargetPoolExists("testtargetpool")+"============"); } From 6457e31ffed3c24e65a4b4eb31dd21725a84bb07 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:41:29 +0000 Subject: [PATCH 024/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 5d10b3dd8a..2a5e07d50b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -86,8 +86,7 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes - // createTargetPool("testtargetpool"); - System.out.println("==========="+isTargetPoolExists("testtargetpool")+"============"); + System.out.println("=============targetpool name: "+ getTargetPool("testtargetpool")); } @@ -137,6 +136,26 @@ public boolean isTargetPoolExists(String targetPoolName) { } + /** + * Get a target pool already created in GCE + * @param targetPoolName + * @return + */ + public TargetPool getTargetPool(String targetPoolName){ + try { + if(isTargetPoolExists(targetPoolName)) + return compute.targetPools().get(PROJECT_ID, REGION_NAME, targetPoolName).execute(); + else + log.info("Requested Target Pool Is not Available"); + return null; + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } + private void addInstancesToTargetPool(TargetPool targetPool, List instanceList) { log.info("=========adding instances to target pool========"); From 8e248793642af0e3d09bdaed819131b7e55575d7 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:42:50 +0000 Subject: [PATCH 025/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 2a5e07d50b..15c72c8df1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -103,7 +103,6 @@ public void createTargetPool(String targetPoolName) { //TODO:REMOVE try catch try { compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); - log.info("==========targetPool " + targetPoolName + " added ============"); } catch (IOException e) { e.printStackTrace(); } From 8f11bf008a0301f4adf882aa8b5f670b7e68e67b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:49:37 +0000 Subject: [PATCH 026/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 15c72c8df1..e01c2332ad 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -45,14 +46,12 @@ public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); - //TODO: remove hardcoded values + //TODO: remove all hardcoded values private static final String PROJECT_NAME = "My First Project"; private static final String PROJECT_ID = "gold-access-96509"; private static final String ZONE_NAME = "europe-west1-b"; private static final String REGION_NAME = "europe-west1"; private static final String RUNNING_FILTER = "status eq RUNNING"; - - //auth private static final String KEY_FILE = "/home/sanjaya/keys/p12key-donwloaded.p12"; private static final String ACCOUNT_ID = "164588286821-a517i85433f83e0nthc4qjmoupri" + @@ -62,16 +61,6 @@ public class GCEOperations { * Directory to store user credentials. */ private static final String DATA_STORE_DIR = ".store/gce-extension"; - - /** - * Global instance of the JSON factory. - */ - - /** - * OAuth 2.0 scopes - */ - private static final List SCOPES = Arrays.asList(ComputeScopes.COMPUTE_READONLY); - static Compute compute; @@ -86,8 +75,9 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes - System.out.println("=============targetpool name: "+ getTargetPool("testtargetpool")); - + ArrayList instanceList = new ArrayList(); + instanceList.add("instance-2"); + addInstancesToTargetPool(getTargetPool("testtargetpool"), instanceList); } /** @@ -141,6 +131,7 @@ public boolean isTargetPoolExists(String targetPoolName) { * @return */ public TargetPool getTargetPool(String targetPoolName){ + //todo:remove try catch try { if(isTargetPoolExists(targetPoolName)) return compute.targetPools().get(PROJECT_ID, REGION_NAME, targetPoolName).execute(); From 7a4033da2eddb838b9f0b6e74725ffba232b62e1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 09:54:02 +0000 Subject: [PATCH 027/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index e01c2332ad..89a4907f38 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -152,6 +152,11 @@ private void addInstancesToTargetPool(TargetPool targetPool, List instan targetPool.setInstances(instanceList); + try { + compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); + } catch (IOException e) { + e.printStackTrace(); + } } /** From 0d345e7b686891cc6872dc9ff607715e25ea921f Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 10:09:54 +0000 Subject: [PATCH 028/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 89a4907f38..3c32fabd87 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -9,6 +9,7 @@ import com.google.api.client.util.store.FileDataStoreFactory; import com.google.api.services.compute.Compute; import com.google.api.services.compute.ComputeScopes; +import com.google.api.services.compute.model.Instance; import com.google.api.services.compute.model.InstanceList; import com.google.api.services.compute.model.TargetPool; import com.google.api.services.compute.model.TargetPoolList; @@ -20,7 +21,6 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -76,8 +76,9 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes ArrayList instanceList = new ArrayList(); - instanceList.add("instance-2"); - addInstancesToTargetPool(getTargetPool("testtargetpool"), instanceList); + //instanceList.add("instance-2"); + // addInstancesToTargetPool(getTargetPool("testtargetpool"), instanceList); + getInstanceURLFromName("instance-2"); } /** @@ -201,5 +202,29 @@ public static InstanceList getInstanceList() throws IOException { } } + public static String getInstanceURLFromName(String instanceName){ + + //check whether the given instance is available + //todo:remove try catch + String instanceURL; + try { + InstanceList instanceList = getInstanceList(); + for(Instance instance : instanceList.getItems()){ + if(instance.getName().equals(instanceName)){ + //instance is available + //getInstace URL + instanceURL = instance.getSelfLink(); + System.out.println("====instanceURL==== "+instanceURL); + return instanceURL; + } + } + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } + } \ No newline at end of file From 1dd8cd15af554ce56adcd80ae153396357736468 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 10:14:41 +0000 Subject: [PATCH 029/217] changes in gce operations class --- .../org/apache/stratos/gce/extension/GCEOperations.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 3c32fabd87..0ac97a5006 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -76,9 +76,9 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc buildComputeEngineObject(); //Calling this method from here only for testing purposes ArrayList instanceList = new ArrayList(); - //instanceList.add("instance-2"); - // addInstancesToTargetPool(getTargetPool("testtargetpool"), instanceList); - getInstanceURLFromName("instance-2"); + instanceList.add(getInstanceURLFromName("instance-2")); + addInstancesToTargetPool(getTargetPool("testtargetpool"), instanceList); + } /** @@ -214,7 +214,6 @@ public static String getInstanceURLFromName(String instanceName){ //instance is available //getInstace URL instanceURL = instance.getSelfLink(); - System.out.println("====instanceURL==== "+instanceURL); return instanceURL; } } From 8f6e2dc6944499818399986fde734e860a108769 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 10:21:13 +0000 Subject: [PATCH 030/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 0ac97a5006..7c7feb1a02 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -149,7 +149,7 @@ public TargetPool getTargetPool(String targetPoolName){ private void addInstancesToTargetPool(TargetPool targetPool, List instanceList) { - log.info("=========adding instances to target pool========"); + log.info("Adding instances to target pool"); targetPool.setInstances(instanceList); @@ -190,7 +190,7 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep public static InstanceList getInstanceList() throws IOException { - System.out.println("================== Listing running Compute Engine Instances =================="); + System.out.println("Listing running Compute Engine Instances"); Compute.Instances.List instances = compute.instances(). list(PROJECT_ID, ZONE_NAME).setFilter(RUNNING_FILTER); InstanceList instanceList = instances.execute(); From 6f1ba45072d8802cf41dede3c2931e1b3fa9479c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 10:38:12 +0000 Subject: [PATCH 031/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 7c7feb1a02..dbdb290a32 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -9,10 +9,7 @@ import com.google.api.client.util.store.FileDataStoreFactory; import com.google.api.services.compute.Compute; import com.google.api.services.compute.ComputeScopes; -import com.google.api.services.compute.model.Instance; -import com.google.api.services.compute.model.InstanceList; -import com.google.api.services.compute.model.TargetPool; -import com.google.api.services.compute.model.TargetPoolList; +import com.google.api.services.compute.model.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -74,10 +71,19 @@ public class GCEOperations { public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityException, IOException { buildComputeEngineObject(); - //Calling this method from here only for testing purposes - ArrayList instanceList = new ArrayList(); - instanceList.add(getInstanceURLFromName("instance-2")); - addInstancesToTargetPool(getTargetPool("testtargetpool"), instanceList); + + //Calling following methods from here only for testing purposes + + List instanceReferenceList = new ArrayList(); + //add instance to instance referencelist + + InstanceReference instanceReference1 = new InstanceReference(); + instanceReference1.setInstance("instance-2"); + + instanceReferenceList.add(instanceReference1); + + + addInstancesToTargetPool("testtargetpool", instanceReferenceList); } @@ -147,14 +153,18 @@ public TargetPool getTargetPool(String targetPoolName){ } - private void addInstancesToTargetPool(TargetPool targetPool, List instanceList) { + private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { log.info("Adding instances to target pool"); - targetPool.setInstances(instanceList); + //create target pools add instance request and set instance to it + TargetPoolsAddInstanceRequest targetPoolsAddInstanceRequest = new TargetPoolsAddInstanceRequest(); + targetPoolsAddInstanceRequest.setInstances(instanceReferenceList); + try { - compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); + //execute + compute.targetPools().addInstance(PROJECT_ID,REGION_NAME,targetPoolName,targetPoolsAddInstanceRequest).execute(); } catch (IOException e) { e.printStackTrace(); } From 6cdde95615ca815a5966dbe201c7dc39f19bef65 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 10:43:30 +0000 Subject: [PATCH 032/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index dbdb290a32..969f0dae37 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -78,7 +78,7 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc //add instance to instance referencelist InstanceReference instanceReference1 = new InstanceReference(); - instanceReference1.setInstance("instance-2"); + instanceReference1.setInstance(getInstanceURLFromName("instance-2")); instanceReferenceList.add(instanceReference1); From 0a543d05770253705f51a4de4cfa4a92c863db18 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 10:48:27 +0000 Subject: [PATCH 033/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 969f0dae37..b8ec95320a 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -74,18 +74,11 @@ public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityExc //Calling following methods from here only for testing purposes - List instanceReferenceList = new ArrayList(); - //add instance to instance referencelist - - InstanceReference instanceReference1 = new InstanceReference(); - instanceReference1.setInstance(getInstanceURLFromName("instance-2")); - instanceReferenceList.add(instanceReference1); + } - addInstancesToTargetPool("testtargetpool", instanceReferenceList); - } /** * Creating a new target pool; name should be unique @@ -235,5 +228,17 @@ public static String getInstanceURLFromName(String instanceName){ } + /** + * this is a sample method using for testing purposes + */ + public void sampleMethodForAddingInstancesToTargetPool(){ + List instanceReferenceList = new ArrayList(); + + //add instance to instance reference list, we should use the instance URL + InstanceReference instanceReference1 = new InstanceReference(); + instanceReference1.setInstance(getInstanceURLFromName("instance-2")); + instanceReferenceList.add(instanceReference1); + addInstancesToTargetPool("testtargetpool", instanceReferenceList); + } } \ No newline at end of file From a45c168e771a78c1ae7cb1ef6d9d70cfe092e23b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 10:58:24 +0000 Subject: [PATCH 034/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 104 +++++++++++------- 1 file changed, 65 insertions(+), 39 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index b8ec95320a..032f11a26f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -68,16 +68,43 @@ public class GCEOperations { * @throws GeneralSecurityException * @throws IOException */ - public GCEOperations() throws LoadBalancerExtensionException, GeneralSecurityException, IOException { + public GCEOperations() throws LoadBalancerExtensionException, + GeneralSecurityException, IOException { buildComputeEngineObject(); //Calling following methods from here only for testing purposes - } + /** + * Authorize and build compute engine object + * + * @throws GeneralSecurityException + * @throws IOException + */ + private void buildComputeEngineObject() throws GeneralSecurityException, IOException { + + HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); + DataStoreFactory dataStoreFactory = new FileDataStoreFactory(new + File(System.getProperty("user.home"), DATA_STORE_DIR)); + JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); + + GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) + .setJsonFactory(jsonFactory) + .setServiceAccountId(ACCOUNT_ID) + .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) + .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE)) + .build(); + + // Create compute engine object for listing instances + compute = new Compute.Builder( + httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) + .setHttpRequestInitializer(credential).build(); + + + } /** @@ -108,8 +135,10 @@ public void createTargetPool(String targetPoolName) { */ public boolean isTargetPoolExists(String targetPoolName) { + //TODO: remove try catch try { - Compute.TargetPools.List targetPools = compute.targetPools().list(PROJECT_ID, REGION_NAME); + Compute.TargetPools.List targetPools = compute.targetPools(). + list(PROJECT_ID, REGION_NAME); TargetPoolList targetPoolList = targetPools.execute(); for (TargetPool targetPool : targetPoolList.getItems()) { if (targetPool.getName().equals(targetPoolName)) { @@ -127,17 +156,18 @@ public boolean isTargetPoolExists(String targetPoolName) { /** * Get a target pool already created in GCE + * * @param targetPoolName * @return */ - public TargetPool getTargetPool(String targetPoolName){ + public TargetPool getTargetPool(String targetPoolName) { //todo:remove try catch try { - if(isTargetPoolExists(targetPoolName)) + if (isTargetPoolExists(targetPoolName)) return compute.targetPools().get(PROJECT_ID, REGION_NAME, targetPoolName).execute(); else log.info("Requested Target Pool Is not Available"); - return null; + return null; } catch (IOException e) { e.printStackTrace(); @@ -146,52 +176,42 @@ public TargetPool getTargetPool(String targetPoolName){ } - private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { + /** + * Add given set of instances to given target pool. + * + * @param targetPoolName + * @param instanceReferenceList + */ + + private void addInstancesToTargetPool(String targetPoolName, List + instanceReferenceList) { + //todo: target pool is must be validated before call this method. May be we can add a validation check here log.info("Adding instances to target pool"); //create target pools add instance request and set instance to it - TargetPoolsAddInstanceRequest targetPoolsAddInstanceRequest = new TargetPoolsAddInstanceRequest(); + TargetPoolsAddInstanceRequest targetPoolsAddInstanceRequest = new + TargetPoolsAddInstanceRequest(); targetPoolsAddInstanceRequest.setInstances(instanceReferenceList); - + //todo Remove try catch try { //execute - compute.targetPools().addInstance(PROJECT_ID,REGION_NAME,targetPoolName,targetPoolsAddInstanceRequest).execute(); + compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, + targetPoolName, targetPoolsAddInstanceRequest).execute(); } catch (IOException e) { e.printStackTrace(); } } /** - * Authorize and build compute engine object + * Get list of running instances in given project and zone.(This method can be used + * when we need to check whether a given instance is available or not in a given project + * and zone) * - * @throws GeneralSecurityException + * @return * @throws IOException */ - private void buildComputeEngineObject() throws GeneralSecurityException, IOException { - - HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); - DataStoreFactory dataStoreFactory = new FileDataStoreFactory(new - File(System.getProperty("user.home"), DATA_STORE_DIR)); - JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); - - GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) - .setJsonFactory(jsonFactory) - .setServiceAccountId(ACCOUNT_ID) - .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) - .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE)) - .build(); - - // Create compute engine object for listing instances - compute = new Compute.Builder( - httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) - .setHttpRequestInitializer(credential).build(); - - - } - - public static InstanceList getInstanceList() throws IOException { System.out.println("Listing running Compute Engine Instances"); Compute.Instances.List instances = compute.instances(). @@ -205,15 +225,21 @@ public static InstanceList getInstanceList() throws IOException { } } - public static String getInstanceURLFromName(String instanceName){ + /** + * Get instance resource URL from given instance name + * + * @param instanceName + * @return + */ + public static String getInstanceURLFromName(String instanceName) { //check whether the given instance is available //todo:remove try catch String instanceURL; try { InstanceList instanceList = getInstanceList(); - for(Instance instance : instanceList.getItems()){ - if(instance.getName().equals(instanceName)){ + for (Instance instance : instanceList.getItems()) { + if (instance.getName().equals(instanceName)) { //instance is available //getInstace URL instanceURL = instance.getSelfLink(); @@ -231,7 +257,7 @@ public static String getInstanceURLFromName(String instanceName){ /** * this is a sample method using for testing purposes */ - public void sampleMethodForAddingInstancesToTargetPool(){ + public void sampleMethodForAddingInstancesToTargetPool() { List instanceReferenceList = new ArrayList(); //add instance to instance reference list, we should use the instance URL From f01b6cece5c1684896dd9697d3a93579b1366f1d Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 11:17:03 +0000 Subject: [PATCH 035/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 032f11a26f..18136d8c47 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -74,7 +74,7 @@ public GCEOperations() throws LoadBalancerExtensionException, buildComputeEngineObject(); //Calling following methods from here only for testing purposes - + sampleMethodForRemovingInstancesToTargetPool(); } @@ -203,6 +203,20 @@ private void addInstancesToTargetPool(String targetPoolName, List + instanceReferenceList){ + TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest + = new TargetPoolsRemoveInstanceRequest(); + targetPoolsRemoveInstanceRequest.setInstances(instanceReferenceList); + //TODO: remove try catch + try { + compute.targetPools().removeInstance(PROJECT_ID, REGION_NAME, + targetPoolName, targetPoolsRemoveInstanceRequest).execute(); + } catch (IOException e) { + e.printStackTrace(); + } + + } /** * Get list of running instances in given project and zone.(This method can be used @@ -254,17 +268,31 @@ public static String getInstanceURLFromName(String instanceName) { } + /** * this is a sample method using for testing purposes */ public void sampleMethodForAddingInstancesToTargetPool() { List instanceReferenceList = new ArrayList(); - //add instance to instance reference list, we should use the instance URL + //remove instance to instance reference list, we should use the instance URL InstanceReference instanceReference1 = new InstanceReference(); instanceReference1.setInstance(getInstanceURLFromName("instance-2")); instanceReferenceList.add(instanceReference1); addInstancesToTargetPool("testtargetpool", instanceReferenceList); } + /** + * this is a sample method using for testing purposes + */ + public void sampleMethodForRemovingInstancesToTargetPool() { + List instanceReferenceList = new ArrayList(); + + //remove instances to instance reference list, we should use the instance URL + InstanceReference instanceReference1 = new InstanceReference(); + instanceReference1.setInstance(getInstanceURLFromName("instance-2")); + instanceReferenceList.add(instanceReference1); + removeInstancesFromTargetPool("testtargetpool", instanceReferenceList); + } + } \ No newline at end of file From dbe82ed5b3c7d5eba05016ffc36cc927ad22e2eb Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 11:39:16 +0000 Subject: [PATCH 036/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 18136d8c47..59b54e8815 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -74,7 +74,7 @@ public GCEOperations() throws LoadBalancerExtensionException, buildComputeEngineObject(); //Calling following methods from here only for testing purposes - sampleMethodForRemovingInstancesToTargetPool(); + createForwardingRule("fr1"); } @@ -121,6 +121,9 @@ public void createTargetPool(String targetPoolName) { try { compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("failed to create target pool: " + targetPoolName); + } e.printStackTrace(); } @@ -148,6 +151,9 @@ public boolean isTargetPoolExists(String targetPoolName) { } } catch (IOException e) { + if(log.isErrorEnabled()){ + log.error("Error caused when checking for target pools"); + } e.printStackTrace(); } return false; @@ -166,10 +172,15 @@ public TargetPool getTargetPool(String targetPoolName) { if (isTargetPoolExists(targetPoolName)) return compute.targetPools().get(PROJECT_ID, REGION_NAME, targetPoolName).execute(); else - log.info("Requested Target Pool Is not Available"); + if (log.isDebugEnabled()) + log.debug("Requested Target Pool Is not Available"); + return null; } catch (IOException e) { + if (log.isErrorEnabled()){ + log.error("Exception caused when try to get target pool"); + } e.printStackTrace(); } return null; @@ -203,8 +214,9 @@ private void addInstancesToTargetPool(String targetPoolName, List - instanceReferenceList){ + instanceReferenceList) { TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest = new TargetPoolsRemoveInstanceRequest(); targetPoolsRemoveInstanceRequest.setInstances(instanceReferenceList); @@ -255,7 +267,7 @@ public static String getInstanceURLFromName(String instanceName) { for (Instance instance : instanceList.getItems()) { if (instance.getName().equals(instanceName)) { //instance is available - //getInstace URL + //getInstance URL instanceURL = instance.getSelfLink(); return instanceURL; } @@ -268,6 +280,16 @@ public static String getInstanceURLFromName(String instanceName) { } + public void createForwardingRule(String forwardingRuleName){ + ForwardingRule forwardingRule = new ForwardingRule(); + forwardingRule.setName(forwardingRuleName); + try { + compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * this is a sample method using for testing purposes From 38f840f95a787f2c8294cb2b4575317fa7f1eeab Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 11:42:13 +0000 Subject: [PATCH 037/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 59b54e8815..f5491acfab 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -284,7 +284,7 @@ public void createForwardingRule(String forwardingRuleName){ ForwardingRule forwardingRule = new ForwardingRule(); forwardingRule.setName(forwardingRuleName); try { - compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule); + compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule).execute(); } catch (IOException e) { e.printStackTrace(); } From 3f05f405472209a9850541e1f067563f4290a8f4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 11:48:24 +0000 Subject: [PATCH 038/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index f5491acfab..0ec9926cdf 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -74,7 +74,7 @@ public GCEOperations() throws LoadBalancerExtensionException, buildComputeEngineObject(); //Calling following methods from here only for testing purposes - createForwardingRule("fr1"); + createForwardingRule("myfr"); } From 19d93c055af9014a7d05f77c93440c777fb3c569 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 12:02:19 +0000 Subject: [PATCH 039/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 0ec9926cdf..82d3fa0025 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -74,7 +74,7 @@ public GCEOperations() throws LoadBalancerExtensionException, buildComputeEngineObject(); //Calling following methods from here only for testing purposes - createForwardingRule("myfr"); + createForwardingRule("myfr","testtargetpool"); } @@ -259,10 +259,11 @@ public static InstanceList getInstanceList() throws IOException { */ public static String getInstanceURLFromName(String instanceName) { - //check whether the given instance is available + //todo:remove try catch String instanceURL; try { + //check whether the given instance is available InstanceList instanceList = getInstanceList(); for (Instance instance : instanceList.getItems()) { if (instance.getName().equals(instanceName)) { @@ -280,9 +281,16 @@ public static String getInstanceURLFromName(String instanceName) { } - public void createForwardingRule(String forwardingRuleName){ + + + public void createForwardingRule(String forwardingRuleName,String targetPoolName){ + + //Need to get target pool resource URL + TargetPool targetPool = getTargetPool(targetPoolName); + String targetPoolURL=targetPool.getSelfLink(); ForwardingRule forwardingRule = new ForwardingRule(); forwardingRule.setName(forwardingRuleName); + forwardingRule.setTarget(targetPoolURL); try { compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule).execute(); } catch (IOException e) { @@ -291,6 +299,8 @@ public void createForwardingRule(String forwardingRuleName){ } + + /** * this is a sample method using for testing purposes */ From 28e5d6b151b36675f66da72588163558a47a8c51 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 12:12:53 +0000 Subject: [PATCH 040/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 82d3fa0025..63fbf016c6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -74,7 +74,7 @@ public GCEOperations() throws LoadBalancerExtensionException, buildComputeEngineObject(); //Calling following methods from here only for testing purposes - createForwardingRule("myfr","testtargetpool"); + createForwardingRule("myfr1","testtargetpool","TCP"); } @@ -283,7 +283,7 @@ public static String getInstanceURLFromName(String instanceName) { - public void createForwardingRule(String forwardingRuleName,String targetPoolName){ + public void createForwardingRule(String forwardingRuleName,String targetPoolName,String protocol){ //Need to get target pool resource URL TargetPool targetPool = getTargetPool(targetPoolName); @@ -291,6 +291,7 @@ public void createForwardingRule(String forwardingRuleName,String targetPoolName ForwardingRule forwardingRule = new ForwardingRule(); forwardingRule.setName(forwardingRuleName); forwardingRule.setTarget(targetPoolURL); + forwardingRule.setIPProtocol(protocol); try { compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule).execute(); } catch (IOException e) { From f98ad9e331a1e6978481e6038e5b7418c8d69f78 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 12:26:43 +0000 Subject: [PATCH 041/217] changes in gce operations class --- .../stratos/gce/extension/GCEOperations.java | 66 +++++++++++++------ 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 63fbf016c6..22f90b95ba 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -130,6 +130,30 @@ public void createTargetPool(String targetPoolName) { } + /** + * create forwarding rule by using given target pool and protocol + * @param forwardingRuleName + * @param targetPoolName + * @param protocol + */ + + public void createForwardingRule(String forwardingRuleName,String targetPoolName,String protocol){ + + //Need to get target pool resource URL + TargetPool targetPool = getTargetPool(targetPoolName); + String targetPoolURL=targetPool.getSelfLink(); + ForwardingRule forwardingRule = new ForwardingRule(); + forwardingRule.setName(forwardingRuleName); + forwardingRule.setTarget(targetPoolURL); + forwardingRule.setIPProtocol(protocol); + try { + compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule).execute(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** * Check whether the given target pool is already exists in the given project and region. * Target pools are unique for regions, not for zones @@ -160,6 +184,21 @@ public boolean isTargetPoolExists(String targetPoolName) { } + public boolean isForwardingRuleExists(String forwardingRuleName){ + try { + Compute.ForwardingRules.List forwardingRules = compute.forwardingRules().list(PROJECT_ID,REGION_NAME); + ForwardingRuleList forwardingRuleList = forwardingRules.execute(); + for (ForwardingRule forwardingRule:forwardingRuleList.getItems()){ + if(forwardingRule.getName().equals(forwardingRuleName)){ + return true; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return false; + } + /** * Get a target pool already created in GCE * @@ -193,7 +232,6 @@ public TargetPool getTargetPool(String targetPoolName) { * @param targetPoolName * @param instanceReferenceList */ - private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { @@ -215,6 +253,12 @@ private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest @@ -282,26 +326,6 @@ public static String getInstanceURLFromName(String instanceName) { } - - public void createForwardingRule(String forwardingRuleName,String targetPoolName,String protocol){ - - //Need to get target pool resource URL - TargetPool targetPool = getTargetPool(targetPoolName); - String targetPoolURL=targetPool.getSelfLink(); - ForwardingRule forwardingRule = new ForwardingRule(); - forwardingRule.setName(forwardingRuleName); - forwardingRule.setTarget(targetPoolURL); - forwardingRule.setIPProtocol(protocol); - try { - compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule).execute(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - - - /** * this is a sample method using for testing purposes */ From d846b762f10f3837ba86df49d424ce316cf31eb1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 12:41:24 +0000 Subject: [PATCH 042/217] changes in gce operations class --- .../stratos/gce/extension/GCELoadBalancer.java | 15 ++++++++++++++- .../stratos/gce/extension/GCEOperations.java | 17 ++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index e55c5e6e7e..415388aee2 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -48,7 +48,11 @@ public GCELoadBalancer() { @Override public void start() throws LoadBalancerExtensionException { - log.info("Starting GCE instance..."); + log.info("Starting GCE Load balancer instance..."); + + //create a target pool by specifying the target pool name given by user + + log.info("GCE Load balancer instance started"); } @@ -56,15 +60,24 @@ public void start() throws LoadBalancerExtensionException { @Override public void stop() throws LoadBalancerExtensionException { + //remove instances from target pool + //delete forwarding rule } @Override public boolean configure(Topology topology) throws LoadBalancerExtensionException { + + //add members to target pool + //change port range in forwarding rule + return false; } @Override public void reload() throws LoadBalancerExtensionException { + //remove existing members in target pool + //add members to target pool + } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 22f90b95ba..2ca0408600 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -208,11 +208,14 @@ public boolean isForwardingRuleExists(String forwardingRuleName){ public TargetPool getTargetPool(String targetPoolName) { //todo:remove try catch try { - if (isTargetPoolExists(targetPoolName)) + if (isTargetPoolExists(targetPoolName)) { return compute.targetPools().get(PROJECT_ID, REGION_NAME, targetPoolName).execute(); - else - if (log.isDebugEnabled()) + } + else { + if (log.isDebugEnabled()) { log.debug("Requested Target Pool Is not Available"); + } + } return null; @@ -235,7 +238,8 @@ public TargetPool getTargetPool(String targetPoolName) { private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { - //todo: target pool is must be validated before call this method. May be we can add a validation check here + //todo: target pool is must be validated before call this method. May be we + // todo: can add a validation check here log.info("Adding instances to target pool"); //create target pools add instance request and set instance to it @@ -303,7 +307,6 @@ public static InstanceList getInstanceList() throws IOException { */ public static String getInstanceURLFromName(String instanceName) { - //todo:remove try catch String instanceURL; try { @@ -325,6 +328,10 @@ public static String getInstanceURLFromName(String instanceName) { } + public void setPortRangeToForwardingRule(){ + //todo:implement this method + } + /** * this is a sample method using for testing purposes From eb7aaa8405419b0a56f2189586c2bf976e5827b4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 14:08:33 +0000 Subject: [PATCH 043/217] changes in gce operations class --- .../gce/extension/GCELoadBalancer.java | 22 +++++----- .../stratos/gce/extension/GCEOperations.java | 41 +++++++++++-------- .../gce/extension/GCEStatisticsReader.java | 5 ++- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 415388aee2..6c0147b189 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -1,14 +1,3 @@ -package org.apache.stratos.gce.extension; - -import org.apache.stratos.load.balancer.common.domain.Topology; -import org.apache.stratos.load.balancer.extension.api.LoadBalancer; -import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.io.IOException; -import java.security.GeneralSecurityException; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -28,6 +17,17 @@ * under the License. */ +package org.apache.stratos.gce.extension; + +import org.apache.stratos.load.balancer.common.domain.Topology; +import org.apache.stratos.load.balancer.extension.api.LoadBalancer; +import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.IOException; +import java.security.GeneralSecurityException; + public class GCELoadBalancer implements LoadBalancer { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 2ca0408600..8da15911b2 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -1,3 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.stratos.gce.extension; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; @@ -21,24 +40,7 @@ import java.util.Collections; import java.util.List; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ + public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); @@ -328,6 +330,9 @@ public static String getInstanceURLFromName(String instanceName) { } + /** + * This method is used for set port rage for forwarding rule + */ public void setPortRangeToForwardingRule(){ //todo:implement this method } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index 42d235bfcb..08e26e454b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -1,5 +1,3 @@ -package org.apache.stratos.gce.extension; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -19,6 +17,9 @@ * under the License. */ +package org.apache.stratos.gce.extension; + + import org.apache.stratos.common.constants.StratosConstants; import org.apache.stratos.load.balancer.common.statistics.LoadBalancerStatisticsReader; import org.apache.stratos.load.balancer.common.topology.TopologyProvider; From 70d341118f68ec10aa2d6df1315924b4724b2481 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 6 Jun 2015 14:22:47 +0000 Subject: [PATCH 044/217] changes in gce operations class --- .../org/apache/stratos/gce/extension/GCEStatisticsReader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index 08e26e454b..70cc8915ac 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -34,7 +34,8 @@ public class GCEStatisticsReader implements LoadBalancerStatisticsReader { public GCEStatisticsReader(TopologyProvider topologyProvider){ this.topologyProvider = topologyProvider; - this.clusterInstanceId = System.getProperty(StratosConstants.CLUSTER_INSTANCE_ID, StratosConstants.NOT_DEFINED); + this.clusterInstanceId = System.getProperty(StratosConstants. + CLUSTER_INSTANCE_ID, StratosConstants.NOT_DEFINED); } From ad887600d255a9f280fa527199574e30eedbb330 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 06:08:44 +0000 Subject: [PATCH 045/217] changes in gce operations class --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 8da15911b2..299a7fde5e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -76,7 +76,6 @@ public GCEOperations() throws LoadBalancerExtensionException, buildComputeEngineObject(); //Calling following methods from here only for testing purposes - createForwardingRule("myfr1","testtargetpool","TCP"); } From 4c0556f7a106594f7a3efa659498239f50c8c229 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 08:37:57 +0000 Subject: [PATCH 046/217] Adding constance and context classes --- .../stratos/gce/extension/Constants.java | 29 +++++++ .../stratos/gce/extension/GCEContext.java | 87 +++++++++++++++++++ .../gce/extension/GCELoadBalancer.java | 3 + 3 files changed, 119 insertions(+) create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java new file mode 100644 index 0000000000..9459dbfe9c --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.gce.extension; + +/** + * GCE extension constants. + */ +public class Constants { + public static final String CEP_STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"; + public static final String THRIFT_RECEIVER_IP = "thrift.receiver.ip"; + public static final String THRIFT_RECEIVER_PORT = "thrift.receiver.port"; +} diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java new file mode 100644 index 0000000000..928839a140 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.gce.extension; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * This class is used to read and store system properties + */ +public class GCEContext { + private static final Log log = LogFactory.getLog(GCEContext.class); + + private static volatile GCEContext context; + + private boolean cepStatsPublisherEnabled; + private String thriftReceiverIp; + private String thriftReceiverPort; + + private GCEContext(){ + + this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); + this.thriftReceiverIp = System.getProperty(Constants.THRIFT_RECEIVER_IP); + this.thriftReceiverPort = System.getProperty(Constants.THRIFT_RECEIVER_PORT); + if (log.isDebugEnabled()) { + log.debug(Constants.CEP_STATS_PUBLISHER_ENABLED + " = " + cepStatsPublisherEnabled); + log.debug(Constants.THRIFT_RECEIVER_IP + " = " + thriftReceiverIp); + log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); + } + + } + + public static GCEContext getInstance() { + if (context == null) { + synchronized (GCEContext.class) { + if (context == null) { + context = new GCEContext(); + } + } + } + return context; + } + + public void validate() { + + validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED); + + + if (cepStatsPublisherEnabled) { + validateSystemProperty(Constants.THRIFT_RECEIVER_IP); + validateSystemProperty(Constants.THRIFT_RECEIVER_PORT); + + } + } + + private void validateSystemProperty(String propertyName) { + String value = System.getProperty(propertyName); + if (StringUtils.isEmpty(value)) { + throw new RuntimeException("System property was not found: " + propertyName); + } + } + + public boolean isCEPStatsPublisherEnabled() { + return cepStatsPublisherEnabled; + } + + + +} diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 6c0147b189..9eda1da24d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -52,6 +52,9 @@ public void start() throws LoadBalancerExtensionException { //create a target pool by specifying the target pool name given by user + //todo:remove hardcoded value + gceOperations.createTargetPool("targetpool-1"); + log.info("GCE Load balancer instance started"); From 8c3f0fdb7da493752caf1be478de1864a1e3b706 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 08:44:33 +0000 Subject: [PATCH 047/217] adding logic for if cepstatpublisher enabled --- .../main/java/org/apache/stratos/gce/extension/Main.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index f03255f7d7..6242ba5606 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -68,8 +68,10 @@ public void run() { // Validate runtime parameters TopologyProvider topologyProvider = new TopologyProvider(); - //ToDo: pass topology provider inside the statsReader. Look line 70 in HAProxy.java - GCEStatisticsReader statisticsReader = new GCEStatisticsReader(topologyProvider); + + //If user has enabled the cep stats publisher, create a stat publisher object. Else null + GCEStatisticsReader statisticsReader =GCEContext.getInstance().isCEPStatsPublisherEnabled() ? + new GCEStatisticsReader(topologyProvider) : null; extension = new LoadBalancerExtension(new GCELoadBalancer(), statisticsReader, topologyProvider); extension.setExecutorService(executorService); extension.execute(); From 5a60af63fb0303b5e2023e7f41d1aa2e0b3a0cb4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 10:19:04 +0000 Subject: [PATCH 048/217] adding logic for if cepstatpublisher enabled --- .../src/main/bin/gce-extension.sh | 5 ++-- .../stratos/gce/extension/Constants.java | 3 +++ .../stratos/gce/extension/GCEContext.java | 23 +++++++++++++++++++ .../gce/extension/GCELoadBalancer.java | 13 +++++++---- .../apache/stratos/gce/extension/Main.java | 1 - 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 2c208cbb95..9c358c31fd 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -37,8 +37,9 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dcep.stats.publisher.enabled=false -Dthrift.receiver.ip=127.0.0.1 -Dthrift.receiver.port=7615 - -Dnetwork.partition.id=network-partition-1" - + -Dnetwork.partition.id=network-partition-1 + -Dcluster.id=cluster-1 + -Dservice.name=php" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index 9459dbfe9c..74800df734 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -26,4 +26,7 @@ public class Constants { public static final String CEP_STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"; public static final String THRIFT_RECEIVER_IP = "thrift.receiver.ip"; public static final String THRIFT_RECEIVER_PORT = "thrift.receiver.port"; + public static final String NETWORK_PARTITION_ID = "network.partition.id"; + public static final String CLUSTER_ID = "cluster.id"; + public static final String SERVICE_NAME = "service.name"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 928839a140..2bdb6c5375 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -34,16 +34,26 @@ public class GCEContext { private boolean cepStatsPublisherEnabled; private String thriftReceiverIp; private String thriftReceiverPort; + private String networkPartitionId; + private String clusterId; + private String serviceName; + private GCEContext(){ this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); this.thriftReceiverIp = System.getProperty(Constants.THRIFT_RECEIVER_IP); this.thriftReceiverPort = System.getProperty(Constants.THRIFT_RECEIVER_PORT); + this.networkPartitionId = System.getProperty(Constants.NETWORK_PARTITION_ID); + this.clusterId = System.getProperty(Constants.CLUSTER_ID); + this.serviceName = System.getProperty(Constants.SERVICE_NAME); if (log.isDebugEnabled()) { log.debug(Constants.CEP_STATS_PUBLISHER_ENABLED + " = " + cepStatsPublisherEnabled); log.debug(Constants.THRIFT_RECEIVER_IP + " = " + thriftReceiverIp); log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); + log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); + log.debug(Constants.NETWORK_PARTITION_ID + " = " + networkPartitionId); + log.debug(Constants.CLUSTER_ID + " = " + clusterId); } } @@ -62,11 +72,13 @@ public static GCEContext getInstance() { public void validate() { validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED); + validateSystemProperty(Constants.CLUSTER_ID); if (cepStatsPublisherEnabled) { validateSystemProperty(Constants.THRIFT_RECEIVER_IP); validateSystemProperty(Constants.THRIFT_RECEIVER_PORT); + validateSystemProperty(Constants.NETWORK_PARTITION_ID); } } @@ -81,6 +93,17 @@ private void validateSystemProperty(String propertyName) { public boolean isCEPStatsPublisherEnabled() { return cepStatsPublisherEnabled; } + public String getNetworkPartitionId() { + return networkPartitionId; + } + + public String getClusterId() { + return clusterId; + } + + public String getServiceName() { + return serviceName; + } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 9eda1da24d..f02d861fac 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -48,14 +48,16 @@ public GCELoadBalancer() { @Override public void start() throws LoadBalancerExtensionException { - log.info("Starting GCE Load balancer instance..."); + log.info("===========Starting GCE Load balancer instance==========="); //create a target pool by specifying the target pool name given by user + //add members to target pool + //change port range in forwarding rule //todo:remove hardcoded value gceOperations.createTargetPool("targetpool-1"); - log.info("GCE Load balancer instance started"); + log.info("==========GCE Load balancer instance started============"); } @@ -63,6 +65,7 @@ public void start() throws LoadBalancerExtensionException { @Override public void stop() throws LoadBalancerExtensionException { + log.info("============stopped============"); //remove instances from target pool //delete forwarding rule } @@ -70,10 +73,10 @@ public void stop() throws LoadBalancerExtensionException { @Override public boolean configure(Topology topology) throws LoadBalancerExtensionException { - //add members to target pool - //change port range in forwarding rule - return false; + log.info("=======configured====="); + + return true; } @Override diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 6242ba5606..f70606844f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -66,7 +66,6 @@ public void run() { executorService = StratosThreadPool.getExecutorService("gce.extension.thread.pool", 10); // Validate runtime parameters - TopologyProvider topologyProvider = new TopologyProvider(); //If user has enabled the cep stats publisher, create a stat publisher object. Else null From 70cff79bc589c4b251ca2561da9f35caf8198a41 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 10:54:43 +0000 Subject: [PATCH 049/217] adding logic for if cepstatpublisher enabled --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index f02d861fac..872aa4e4b5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -74,7 +74,7 @@ public void stop() throws LoadBalancerExtensionException { public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("=======configured====="); + log.info("========topology====== "+ topology); return true; } From a0faaed467590ec6790342222b08d814f25b9583 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 10:59:21 +0000 Subject: [PATCH 050/217] adding logic for if cepstatpublisher enabled --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 872aa4e4b5..24db499559 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -74,7 +74,7 @@ public void stop() throws LoadBalancerExtensionException { public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("========topology====== "+ topology); + log.info("========Configuring====== "); return true; } From 2287952be8e3a2c74c5d651bbc63a6e4280243c4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 11:23:13 +0000 Subject: [PATCH 051/217] adding logic for if cepstatpublisher enabled --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 24db499559..a96de61da9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -74,7 +74,7 @@ public void stop() throws LoadBalancerExtensionException { public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("========Configuring====== "); + log.info("========Configuring====== "+ topology.toString()); return true; } From 9f01cfe92f5cdfd25a943ab9819fa607c878fb5b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 11:39:43 +0000 Subject: [PATCH 052/217] testing configure method --- .../stratos/gce/extension/GCELoadBalancer.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index a96de61da9..9fd3519f4a 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,6 +19,11 @@ package org.apache.stratos.gce.extension; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.reflection.FieldDictionary; +import com.thoughtworks.xstream.converters.reflection.ImmutableFieldKeySorter; +import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider; +import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.stratos.load.balancer.common.domain.Topology; import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -74,7 +79,13 @@ public void stop() throws LoadBalancerExtensionException { public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("========Configuring====== "+ topology.toString()); + log.info("========Configuring====== "); + + //printing topology value for testing purposes + XStream xstream = new XStream(new Sun14ReflectionProvider( + new FieldDictionary(new ImmutableFieldKeySorter())), + new DomDriver("utf-8")); + log.info(xstream.toXML(topology)); return true; } From 891716342f07b89027d35d47ec4d692738b33e91 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 7 Jun 2015 11:42:50 +0000 Subject: [PATCH 053/217] testing configure method --- extensions/load-balancer/gce-extension/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index b08cfc6caf..6f8456e7cb 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -82,6 +82,12 @@ google-api-services-compute v1-rev27-1.19.0 + + + com.thoughtworks.xstream + xstream + 1.4.8 + 1.19.0 From 503d5b9a6dd75134bb19439aef08c917d8167295 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 01:14:24 +0530 Subject: [PATCH 054/217] adding logic for load balancer configuration --- .../load-balancer/gce-extension/pom.xml | 2 + .../gce/extension/GCELoadBalancer.java | 84 +++++++++++++++---- .../stratos/gce/extension/GCEOperations.java | 2 +- .../extension/LoadBalancerConfiguration.java | 79 +++++++++++++++++ 4 files changed, 150 insertions(+), 17 deletions(-) create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index 6f8456e7cb..57cc3dbbd1 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -83,11 +83,13 @@ v1-rev27-1.19.0 + 1.19.0 diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 9fd3519f4a..8c019d391e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,11 +19,10 @@ package org.apache.stratos.gce.extension; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.reflection.FieldDictionary; -import com.thoughtworks.xstream.converters.reflection.ImmutableFieldKeySorter; -import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider; -import com.thoughtworks.xstream.io.xml.DomDriver; +import com.google.api.services.compute.model.TargetPool; +import org.apache.stratos.load.balancer.common.domain.Cluster; +import org.apache.stratos.load.balancer.common.domain.Member; +import org.apache.stratos.load.balancer.common.domain.Service; import org.apache.stratos.load.balancer.common.domain.Topology; import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -32,16 +31,26 @@ import java.io.IOException; import java.security.GeneralSecurityException; +import java.util.HashMap; public class GCELoadBalancer implements LoadBalancer { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); private GCEOperations gceOperations; + /** + * We create one load balancer per cluster(stratos side). + * A Load balancer has one target pool and set of forwarding rules + * This hash map is used to hold cluster IDs and corresponding Load balancer configuration + * So one cluster will have one loadBalancerConfiguration object + */ + private HashMap clusterToLoadBalancerConfigurationMap; public GCELoadBalancer() { try { gceOperations = new GCEOperations(); + clusterToLoadBalancerConfigurationMap = new HashMap(); + } catch (LoadBalancerExtensionException e) { log.error(e); } catch (GeneralSecurityException e) { @@ -55,12 +64,11 @@ public GCELoadBalancer() { public void start() throws LoadBalancerExtensionException { log.info("===========Starting GCE Load balancer instance==========="); - //create a target pool by specifying the target pool name given by user - //add members to target pool - //change port range in forwarding rule - - //todo:remove hardcoded value - gceOperations.createTargetPool("targetpool-1"); + //iterate through clusterToLoadBalancerConfigurationMap + //for each cluster{ + //if Load balancer status == not running --> + // execute commands through GCE API for start the load balancer + //} log.info("==========GCE Load balancer instance started============"); @@ -71,8 +79,7 @@ public void start() throws LoadBalancerExtensionException { public void stop() throws LoadBalancerExtensionException { log.info("============stopped============"); - //remove instances from target pool - //delete forwarding rule + //iterate through hashmap and remove all } @Override @@ -82,10 +89,54 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("========Configuring====== "); //printing topology value for testing purposes - XStream xstream = new XStream(new Sun14ReflectionProvider( + /* XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver("utf-8")); log.info(xstream.toXML(topology)); + */ + + for (Service service : topology.getServices()) { + for (Cluster cluster : service.getClusters()) { //for each cluster + //we create one load balancer per cluster + //Only create configuration object. Not execute. + + //check whether this cluster has a forwarding rule configuration or not + if(clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())){ + + //It has a loadBalancer configured. Take it and update it as the given topology. + + + } + else { + //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map + + TargetPool targetPool = new TargetPool(); + + + + for (Member member: cluster.getMembers()){ + + //set instances(members) to targetPool object + //add forwarding rules(Ports to be forwarded) + //for(Integer port :member.getPorts()){} + } + + LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( + cluster.getClusterId(),targetPool); + + //get forwarding rules from topology and set forwarding rules to + // LoadBalancerConfiguration object + + + + + + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), loadBalancerConfiguration); + + } + + } + } return true; } @@ -93,8 +144,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio @Override public void reload() throws LoadBalancerExtensionException { - //remove existing members in target pool - //add members to target pool + //iterate through hash map + //find what needs to be changed + //execute } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 299a7fde5e..0aab7be3d5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -99,7 +99,7 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE)) .build(); - // Create compute engine object for listing instances + // Create compute engine object compute = new Compute.Builder( httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) .setHttpRequestInitializer(credential).build(); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java new file mode 100644 index 0000000000..7ad775424f --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.stratos.gce.extension; + +import com.google.api.services.compute.model.TargetPool; + +import java.util.ArrayList; +import java.util.List; + +/** + * Since GCE have separate target pools and forwarding rules, we need + * a class to concatenate target pools and forwarding rules which belongs to + * one cluster in stratos. + * This class is used to hold the configuration for a load balancer + * Each cluster will have one object from this class + * + */ +public class LoadBalancerConfiguration { + + + + //A load balancer must have a target pool + private TargetPool targetPool; + //A load balancer can have one or more forwarding rules(set of ports to be forwarded) + private List forwardingRulesList; + //cluster ID from stratos side + private String clusterID; + //Whether we have executed this configuration in GCE or not + private boolean isRunning = false; + + + public LoadBalancerConfiguration(String clusterID, TargetPool targetPool) { + this.clusterID = clusterID; + this.targetPool = targetPool; + forwardingRulesList = new ArrayList(); + } + + public void addForwardingRule(Integer forwardingRule) { + forwardingRulesList.add(forwardingRule); + } + + public List getForwardingRulesList() { + return forwardingRulesList; + } + + public TargetPool getTargetPool() { + return targetPool; + } + + + public String getClusterID() { + return clusterID; + } + + public void setStatus(boolean status){ + isRunning = status; + } + public boolean getStatus(){ + return isRunning; + } + +} \ No newline at end of file From 03429b85c92f425fdb2a3f700b4e680428413a1c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 01:15:50 +0530 Subject: [PATCH 055/217] adding logic for load balancer configuration --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 0aab7be3d5..24001b7fa2 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -40,6 +40,9 @@ import java.util.Collections; import java.util.List; +/** + * All the GCE API calls will be done using this class + */ public class GCEOperations { From dc0beeac3392fd7c8736691f238ccc9ea90cbc5c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 01:16:41 +0530 Subject: [PATCH 056/217] adding logic for load balancer configuration --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 24001b7fa2..e5dfffd896 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -48,7 +48,7 @@ public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); - //TODO: remove all hardcoded values + //TODO: remove all hardcoded values and read from configuration parameters private static final String PROJECT_NAME = "My First Project"; private static final String PROJECT_ID = "gold-access-96509"; private static final String ZONE_NAME = "europe-west1-b"; From 14cb180eec0d6a21ea518dc98bf826f1d10ba344 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 01:17:46 +0530 Subject: [PATCH 057/217] adding logic for load balancer configuration --- .../stratos/gce/extension/GCELoadBalancer.java | 13 ++++--------- .../gce/extension/LoadBalancerConfiguration.java | 7 +++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 8c019d391e..f02609d589 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -101,20 +101,18 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //Only create configuration object. Not execute. //check whether this cluster has a forwarding rule configuration or not - if(clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())){ + if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { //It has a loadBalancer configured. Take it and update it as the given topology. - } - else { + } else { //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map TargetPool targetPool = new TargetPool(); - - for (Member member: cluster.getMembers()){ + for (Member member : cluster.getMembers()) { //set instances(members) to targetPool object //add forwarding rules(Ports to be forwarded) @@ -122,15 +120,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( - cluster.getClusterId(),targetPool); + cluster.getClusterId(), targetPool); //get forwarding rules from topology and set forwarding rules to // LoadBalancerConfiguration object - - - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), loadBalancerConfiguration); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java index 7ad775424f..a15870807f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -30,12 +30,10 @@ * one cluster in stratos. * This class is used to hold the configuration for a load balancer * Each cluster will have one object from this class - * */ public class LoadBalancerConfiguration { - //A load balancer must have a target pool private TargetPool targetPool; //A load balancer can have one or more forwarding rules(set of ports to be forwarded) @@ -69,10 +67,11 @@ public String getClusterID() { return clusterID; } - public void setStatus(boolean status){ + public void setStatus(boolean status) { isRunning = status; } - public boolean getStatus(){ + + public boolean getStatus() { return isRunning; } From fd33963d6c76fe0c973032b0e962d0fee4343c80 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 09:45:08 +0530 Subject: [PATCH 058/217] adding logic for load balancer configuration --- .../apache/stratos/gce/extension/GCELoadBalancer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index f02609d589..43b468c693 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -62,7 +62,7 @@ public GCELoadBalancer() { @Override public void start() throws LoadBalancerExtensionException { - log.info("===========Starting GCE Load balancer instance==========="); + log.info("Starting GCE Load balancer instance"); //iterate through clusterToLoadBalancerConfigurationMap //for each cluster{ @@ -70,7 +70,7 @@ public void start() throws LoadBalancerExtensionException { // execute commands through GCE API for start the load balancer //} - log.info("==========GCE Load balancer instance started============"); + log.info("GCE Load balancer instance started"); } @@ -78,7 +78,7 @@ public void start() throws LoadBalancerExtensionException { @Override public void stop() throws LoadBalancerExtensionException { - log.info("============stopped============"); + log.info("GCE Load Balancer is stopping"); //iterate through hashmap and remove all } @@ -86,9 +86,9 @@ public void stop() throws LoadBalancerExtensionException { public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("========Configuring====== "); + log.info("Configuring Load balancer "); - //printing topology value for testing purposes + //printing topology value as a xml for testing purposes /* XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver("utf-8")); From 939cde84a1f5c828d7abf594f2bac66154ce7c6f Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 09:47:14 +0530 Subject: [PATCH 059/217] adding logic for load balancer configuration --- .../stratos/gce/extension/GCEContext.java | 4 ++-- .../stratos/gce/extension/GCEOperations.java | 24 +++++++++---------- .../gce/extension/GCEStatisticsReader.java | 2 +- .../apache/stratos/gce/extension/Main.java | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 2bdb6c5375..78c47cb139 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -39,7 +39,7 @@ public class GCEContext { private String serviceName; - private GCEContext(){ + private GCEContext() { this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); this.thriftReceiverIp = System.getProperty(Constants.THRIFT_RECEIVER_IP); @@ -93,6 +93,7 @@ private void validateSystemProperty(String propertyName) { public boolean isCEPStatsPublisherEnabled() { return cepStatsPublisherEnabled; } + public String getNetworkPartitionId() { return networkPartitionId; } @@ -106,5 +107,4 @@ public String getServiceName() { } - } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index e5dfffd896..ab4a2f0102 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -136,22 +136,23 @@ public void createTargetPool(String targetPoolName) { /** * create forwarding rule by using given target pool and protocol + * * @param forwardingRuleName * @param targetPoolName * @param protocol */ - public void createForwardingRule(String forwardingRuleName,String targetPoolName,String protocol){ + public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol) { //Need to get target pool resource URL TargetPool targetPool = getTargetPool(targetPoolName); - String targetPoolURL=targetPool.getSelfLink(); + String targetPoolURL = targetPool.getSelfLink(); ForwardingRule forwardingRule = new ForwardingRule(); forwardingRule.setName(forwardingRuleName); forwardingRule.setTarget(targetPoolURL); forwardingRule.setIPProtocol(protocol); try { - compute.forwardingRules().insert(PROJECT_ID,REGION_NAME,forwardingRule).execute(); + compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); } catch (IOException e) { e.printStackTrace(); } @@ -179,7 +180,7 @@ public boolean isTargetPoolExists(String targetPoolName) { } } catch (IOException e) { - if(log.isErrorEnabled()){ + if (log.isErrorEnabled()) { log.error("Error caused when checking for target pools"); } e.printStackTrace(); @@ -188,12 +189,12 @@ public boolean isTargetPoolExists(String targetPoolName) { } - public boolean isForwardingRuleExists(String forwardingRuleName){ + public boolean isForwardingRuleExists(String forwardingRuleName) { try { - Compute.ForwardingRules.List forwardingRules = compute.forwardingRules().list(PROJECT_ID,REGION_NAME); + Compute.ForwardingRules.List forwardingRules = compute.forwardingRules().list(PROJECT_ID, REGION_NAME); ForwardingRuleList forwardingRuleList = forwardingRules.execute(); - for (ForwardingRule forwardingRule:forwardingRuleList.getItems()){ - if(forwardingRule.getName().equals(forwardingRuleName)){ + for (ForwardingRule forwardingRule : forwardingRuleList.getItems()) { + if (forwardingRule.getName().equals(forwardingRuleName)) { return true; } } @@ -214,8 +215,7 @@ public TargetPool getTargetPool(String targetPoolName) { try { if (isTargetPoolExists(targetPoolName)) { return compute.targetPools().get(PROJECT_ID, REGION_NAME, targetPoolName).execute(); - } - else { + } else { if (log.isDebugEnabled()) { log.debug("Requested Target Pool Is not Available"); } @@ -224,7 +224,7 @@ public TargetPool getTargetPool(String targetPoolName) { return null; } catch (IOException e) { - if (log.isErrorEnabled()){ + if (log.isErrorEnabled()) { log.error("Exception caused when try to get target pool"); } e.printStackTrace(); @@ -335,7 +335,7 @@ public static String getInstanceURLFromName(String instanceName) { /** * This method is used for set port rage for forwarding rule */ - public void setPortRangeToForwardingRule(){ + public void setPortRangeToForwardingRule() { //todo:implement this method } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index 70cc8915ac..6aa1de0fe1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -32,7 +32,7 @@ public class GCEStatisticsReader implements LoadBalancerStatisticsReader { private TopologyProvider topologyProvider; private String clusterInstanceId; - public GCEStatisticsReader(TopologyProvider topologyProvider){ + public GCEStatisticsReader(TopologyProvider topologyProvider) { this.topologyProvider = topologyProvider; this.clusterInstanceId = System.getProperty(StratosConstants. CLUSTER_INSTANCE_ID, StratosConstants.NOT_DEFINED); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index f70606844f..f8cf2b3916 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -52,7 +52,7 @@ public static void main(String[] args) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { - if(finalExtension != null) { + if (finalExtension != null) { log.info("GCE gce instance..."); finalExtension.stop(); } @@ -69,7 +69,7 @@ public void run() { TopologyProvider topologyProvider = new TopologyProvider(); //If user has enabled the cep stats publisher, create a stat publisher object. Else null - GCEStatisticsReader statisticsReader =GCEContext.getInstance().isCEPStatsPublisherEnabled() ? + GCEStatisticsReader statisticsReader = GCEContext.getInstance().isCEPStatsPublisherEnabled() ? new GCEStatisticsReader(topologyProvider) : null; extension = new LoadBalancerExtension(new GCELoadBalancer(), statisticsReader, topologyProvider); extension.setExecutorService(executorService); From 8ade3141b099fb57d351c87bc10ce949403171ea Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 11:34:09 +0530 Subject: [PATCH 060/217] adding logic for load balancer configuration --- .../gce/extension/GCELoadBalancer.java | 21 +++++++++++++------ .../extension/LoadBalancerConfiguration.java | 6 +++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 43b468c693..0f5716a81b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -20,10 +20,7 @@ package org.apache.stratos.gce.extension; import com.google.api.services.compute.model.TargetPool; -import org.apache.stratos.load.balancer.common.domain.Cluster; -import org.apache.stratos.load.balancer.common.domain.Member; -import org.apache.stratos.load.balancer.common.domain.Service; -import org.apache.stratos.load.balancer.common.domain.Topology; +import org.apache.stratos.load.balancer.common.domain.*; import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; import org.apache.commons.logging.Log; @@ -31,7 +28,10 @@ import java.io.IOException; import java.security.GeneralSecurityException; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; public class GCELoadBalancer implements LoadBalancer { @@ -111,12 +111,21 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio TargetPool targetPool = new TargetPool(); + List forwardingRulesList = new ArrayList(); for (Member member : cluster.getMembers()) { - //set instances(members) to targetPool object + //TODO:set instances(members) to targetPool + //add forwarding rules(Ports to be forwarded) - //for(Integer port :member.getPorts()){} + + //Iterator iterator = member.getPorts().iterator(); + + + for(Object port : member.getPorts()){ + log.info("=================port: "+ port.toString()); + } + } LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java index a15870807f..bf933d5b6f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -54,6 +54,10 @@ public void addForwardingRule(Integer forwardingRule) { forwardingRulesList.add(forwardingRule); } + public void setForwardingRulesList(List forwardingRulesList){ + this.forwardingRulesList = forwardingRulesList; + } + public List getForwardingRulesList() { return forwardingRulesList; } @@ -68,7 +72,7 @@ public String getClusterID() { } public void setStatus(boolean status) { - isRunning = status; + this.isRunning = status; } public boolean getStatus() { From d449739a6cc68c07f89aa24c2dc0b0ef771116c8 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 11:37:34 +0530 Subject: [PATCH 061/217] adding logic for load balancer configuration --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 0f5716a81b..1adaf80add 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -123,7 +123,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for(Object port : member.getPorts()){ - log.info("=================port: "+ port.toString()); + log.info("=================port: "+ ((Port) port).getValue()); } } From 57285d43c89eb010fe06c9cfc2d36d738d6dc57c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 11:41:05 +0530 Subject: [PATCH 062/217] adding logic for load balancer configuration --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 1adaf80add..0248c2d7e4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -124,6 +124,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for(Object port : member.getPorts()){ log.info("=================port: "+ ((Port) port).getValue()); + log.info("=================protocol: "+ ((Port) port).getProtocol()); } } From 64c4223b7c8244c466da2ecc3f50a23235f031a5 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 12:22:54 +0530 Subject: [PATCH 063/217] adding logic for load balancer configuration --- .../gce/extension/GCELoadBalancer.java | 44 +++++++++++++------ .../extension/LoadBalancerConfiguration.java | 28 ++++++------ 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 0248c2d7e4..215f8605e6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,18 +19,16 @@ package org.apache.stratos.gce.extension; -import com.google.api.services.compute.model.TargetPool; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.common.domain.*; import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import java.io.IOException; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; public class GCELoadBalancer implements LoadBalancer { @@ -105,11 +103,31 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //It has a loadBalancer configured. Take it and update it as the given topology. + //get load balancer configuration + LoadBalancerConfiguration loadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. + get(cluster.getClusterId()); + + //check and update + List instancesList = loadBalancerConfiguration.getInstancesList(); + + + for (Member member : cluster.getMembers()) { + + //TODO:check instances(members) in target pool and update + + //add forwarding rules(Ports to be forwarded) + + for (Object port : member.getPorts()) { + + + } + } + } else { //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map - TargetPool targetPool = new TargetPool(); + List instancesList = new ArrayList(); List forwardingRulesList = new ArrayList(); @@ -119,23 +137,23 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //add forwarding rules(Ports to be forwarded) - //Iterator iterator = member.getPorts().iterator(); - - - for(Object port : member.getPorts()){ - log.info("=================port: "+ ((Port) port).getValue()); - log.info("=================protocol: "+ ((Port) port).getProtocol()); + for (Object port : member.getPorts()) { + if (!forwardingRulesList.contains(((Port) port).getValue())) { //if port is not in list + forwardingRulesList.add(((Port) port).getValue()); + } } + } LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( - cluster.getClusterId(), targetPool); + cluster.getClusterId(), instancesList); + + loadBalancerConfiguration.setForwardingRulesList(forwardingRulesList); //get forwarding rules from topology and set forwarding rules to // LoadBalancerConfiguration object - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), loadBalancerConfiguration); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java index bf933d5b6f..16d694eadd 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -19,9 +19,6 @@ package org.apache.stratos.gce.extension; -import com.google.api.services.compute.model.TargetPool; - -import java.util.ArrayList; import java.util.List; /** @@ -34,8 +31,8 @@ public class LoadBalancerConfiguration { - //A load balancer must have a target pool - private TargetPool targetPool; + //A load balancer must have a target pool(set of instances) + private List instancesList; //A load balancer can have one or more forwarding rules(set of ports to be forwarded) private List forwardingRulesList; //cluster ID from stratos side @@ -44,17 +41,14 @@ public class LoadBalancerConfiguration { private boolean isRunning = false; - public LoadBalancerConfiguration(String clusterID, TargetPool targetPool) { + public LoadBalancerConfiguration(String clusterID, List instancesList, + List forwardingRulesList) { this.clusterID = clusterID; - this.targetPool = targetPool; - forwardingRulesList = new ArrayList(); - } - - public void addForwardingRule(Integer forwardingRule) { - forwardingRulesList.add(forwardingRule); + this.instancesList = instancesList; + this.forwardingRulesList = forwardingRulesList; } - public void setForwardingRulesList(List forwardingRulesList){ + public void setForwardingRulesList(List forwardingRulesList) { this.forwardingRulesList = forwardingRulesList; } @@ -62,8 +56,12 @@ public List getForwardingRulesList() { return forwardingRulesList; } - public TargetPool getTargetPool() { - return targetPool; + public List getInstancesList() { + return instancesList; + } + + public void setInstancesList(List instancesList) { + this.instancesList = instancesList; } From 3eeb1404b02e526ed891a0bbd24e054a6ebaa3c6 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 19:27:52 +0530 Subject: [PATCH 064/217] adding code for start method and configure method --- .../src/main/bin/gce-extension.sh | 3 +- .../stratos/gce/extension/Constants.java | 1 + .../stratos/gce/extension/GCEContext.java | 8 +- .../gce/extension/GCELoadBalancer.java | 105 +++++++++++++++--- .../stratos/gce/extension/GCEOperations.java | 14 ++- 5 files changed, 112 insertions(+), 19 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 9c358c31fd..736a113a6c 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -39,7 +39,8 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dthrift.receiver.port=7615 -Dnetwork.partition.id=network-partition-1 -Dcluster.id=cluster-1 - -Dservice.name=php" + -Dservice.name=php + -Dname.prefix=lb" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index 74800df734..a723f7cb6d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -29,4 +29,5 @@ public class Constants { public static final String NETWORK_PARTITION_ID = "network.partition.id"; public static final String CLUSTER_ID = "cluster.id"; public static final String SERVICE_NAME = "service.name"; + public static final String NAME_PREFIX = "name.prefix"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 78c47cb139..6b08a3035f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -37,6 +37,7 @@ public class GCEContext { private String networkPartitionId; private String clusterId; private String serviceName; + private String namePrefix; private GCEContext() { @@ -47,6 +48,8 @@ private GCEContext() { this.networkPartitionId = System.getProperty(Constants.NETWORK_PARTITION_ID); this.clusterId = System.getProperty(Constants.CLUSTER_ID); this.serviceName = System.getProperty(Constants.SERVICE_NAME); + this.namePrefix = System.getProperty(Constants.NAME_PREFIX); + if (log.isDebugEnabled()) { log.debug(Constants.CEP_STATS_PUBLISHER_ENABLED + " = " + cepStatsPublisherEnabled); log.debug(Constants.THRIFT_RECEIVER_IP + " = " + thriftReceiverIp); @@ -54,6 +57,7 @@ private GCEContext() { log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); log.debug(Constants.NETWORK_PARTITION_ID + " = " + networkPartitionId); log.debug(Constants.CLUSTER_ID + " = " + clusterId); + log.debug(Constants.NAME_PREFIX + " = "+ namePrefix); } } @@ -73,7 +77,7 @@ public void validate() { validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED); validateSystemProperty(Constants.CLUSTER_ID); - + validateSystemProperty(Constants.NAME_PREFIX); if (cepStatsPublisherEnabled) { validateSystemProperty(Constants.THRIFT_RECEIVER_IP); @@ -106,5 +110,7 @@ public String getServiceName() { return serviceName; } + public String getNamePrefix() { return namePrefix; } + } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 215f8605e6..d14c8b793f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,6 +19,7 @@ package org.apache.stratos.gce.extension; +import com.google.api.services.compute.model.TargetPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.common.domain.*; @@ -27,9 +28,7 @@ import java.io.IOException; import java.security.GeneralSecurityException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.util.*; public class GCELoadBalancer implements LoadBalancer { @@ -44,6 +43,9 @@ public class GCELoadBalancer implements LoadBalancer { */ private HashMap clusterToLoadBalancerConfigurationMap; + //protocol should be TCP or UDP + private String protocol = "TCP"; + public GCELoadBalancer() { try { gceOperations = new GCEOperations(); @@ -60,6 +62,8 @@ public GCELoadBalancer() { @Override public void start() throws LoadBalancerExtensionException { + //topology has completed + log.info("Starting GCE Load balancer instance"); //iterate through clusterToLoadBalancerConfigurationMap @@ -68,6 +72,39 @@ public void start() throws LoadBalancerExtensionException { // execute commands through GCE API for start the load balancer //} + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()){ //for each Load balancer configuration + + Map.Entry clusterIDForwardingRulesPair = (Map.Entry)iterator.next(); + + String clusterID = ((String) clusterIDForwardingRulesPair.getKey()); + + //set a valid target pool name + String targetPoolName = targetPoolNameCreator(clusterID); + + //crate a target pool in GCE + gceOperations.createTargetPool(targetPoolName); + + //add instances to target pool + gceOperations.addInstancesToTargetPool(((List) + clusterIDForwardingRulesPair.getValue()),targetPoolName); + + + //create forwarding rules in GCE + List forwardingRulesList = ((List) clusterIDForwardingRulesPair.getValue()); + + for (int forwardingRule : forwardingRulesList){ //for each port + + //set a valid forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(forwardingRule,clusterID); + + //create a forwarding rule in GCE + gceOperations.createForwardingRule(forwardingRuleName,targetPoolName,protocol); + } + + + } + log.info("GCE Load balancer instance started"); @@ -80,10 +117,16 @@ public void stop() throws LoadBalancerExtensionException { //iterate through hashmap and remove all } + /** + * Listen to latest topology and update load balancer configuration + * + * @param topology latest topology to be configured + * @return + * @throws LoadBalancerExtensionException + */ @Override public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("Configuring Load balancer "); //printing topology value as a xml for testing purposes @@ -108,32 +151,45 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio get(cluster.getClusterId()); //check and update - List instancesList = loadBalancerConfiguration.getInstancesList(); + List updatedInstancesList = new ArrayList(); + List updatedForwardingRulesList = new ArrayList(); for (Member member : cluster.getMembers()) { //TODO:check instances(members) in target pool and update + /* EX: + if(!updatedInstancesList.contains(member.getMemberName())){ + updatedInstancesList.add(member.getMemberName); + } + */ - //add forwarding rules(Ports to be forwarded) - + //checking for forwarding rules for (Object port : member.getPorts()) { + //if not present update it + if (!updatedForwardingRulesList.contains(((Port) port).getValue())) { //if port is not in list + updatedForwardingRulesList.add(((Port) port).getValue()); + } } } + //set new forwarding rules and instances list + loadBalancerConfiguration.setForwardingRulesList(updatedForwardingRulesList); + loadBalancerConfiguration.setInstancesList(updatedInstancesList); + } else { //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map List instancesList = new ArrayList(); - List forwardingRulesList = new ArrayList(); for (Member member : cluster.getMembers()) { - //TODO:set instances(members) to targetPool + //TODO:set instances(members) to instances list + //instancesList.add(member.getMemberName); //add forwarding rules(Ports to be forwarded) @@ -143,16 +199,10 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } - } LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( - cluster.getClusterId(), instancesList); - - loadBalancerConfiguration.setForwardingRulesList(forwardingRulesList); - - //get forwarding rules from topology and set forwarding rules to - // LoadBalancerConfiguration object + cluster.getClusterId(), instancesList, forwardingRulesList); clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), loadBalancerConfiguration); @@ -172,4 +222,27 @@ public void reload() throws LoadBalancerExtensionException { //execute } + + private String targetPoolNameCreator(String clusterID){ + //create a valid target pool name by using cluster ID + //remove spaces, make all to lower case, replace all "." --> "-" + //add name prefix + String targetPoolName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" + + clusterID.trim().toLowerCase().replace(".","-"); + //length should be les than 62 characters + if(targetPoolName.length()>=62){ + targetPoolName = targetPoolName.substring(0,62); + } + return targetPoolName; + } + + private String forwardingRuleNameCreator(int port,String clusterID){ + String forwardingRuleName = GCEContext.getInstance().getNamePrefix() + "-" + + Integer.toString(port) + "-" + clusterID; + //length should be les than 62 characters + if(forwardingRuleName.length()>=62){ + forwardingRuleName = forwardingRuleName.substring(0,62); + } + return forwardingRuleName; + } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index ab4a2f0102..6a859ab2b8 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -339,6 +339,18 @@ public void setPortRangeToForwardingRule() { //todo:implement this method } + public void addInstancesToTargetPool(List instancesNamesList, String targetPoolName){ + List instanceReferenceList = new ArrayList(); + + //add instance to instance reference list, we should use the instance URL + for(String instanceName : instancesNamesList ){ //for all instances + + instanceReferenceList.add(new InstanceReference(). + setInstance(getInstanceURLFromName(instanceName))); + + } + addInstancesToTargetPool(targetPoolName, instanceReferenceList); + } /** * this is a sample method using for testing purposes @@ -359,7 +371,7 @@ public void sampleMethodForAddingInstancesToTargetPool() { public void sampleMethodForRemovingInstancesToTargetPool() { List instanceReferenceList = new ArrayList(); - //remove instances to instance reference list, we should use the instance URL + //add instances to instance reference list, we should use the instance URL InstanceReference instanceReference1 = new InstanceReference(); instanceReference1.setInstance(getInstanceURLFromName("instance-2")); instanceReferenceList.add(instanceReference1); From 2373ffcf13766079c8399b3dae128f8432dde0cc Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 19:38:03 +0530 Subject: [PATCH 065/217] adding code for start method and configure method --- .../gce/extension/GCELoadBalancer.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index d14c8b793f..5c16155d93 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -75,34 +75,35 @@ public void start() throws LoadBalancerExtensionException { Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); while (iterator.hasNext()){ //for each Load balancer configuration - Map.Entry clusterIDForwardingRulesPair = (Map.Entry)iterator.next(); + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry)iterator.next(); - String clusterID = ((String) clusterIDForwardingRulesPair.getKey()); + String clusterID = ((String) clusterIDLoadBalancerConfigurationPair.getKey()); + LoadBalancerConfiguration loadBalancerConfiguration = + ((LoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - //set a valid target pool name - String targetPoolName = targetPoolNameCreator(clusterID); + if(!loadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running - //crate a target pool in GCE - gceOperations.createTargetPool(targetPoolName); + //set a valid target pool name + String targetPoolName = targetPoolNameCreator(clusterID); - //add instances to target pool - gceOperations.addInstancesToTargetPool(((List) - clusterIDForwardingRulesPair.getValue()),targetPoolName); + //crate a target pool in GCE + gceOperations.createTargetPool(targetPoolName); + //add instances to target pool + gceOperations.addInstancesToTargetPool(loadBalancerConfiguration.getInstancesList(),targetPoolName); - //create forwarding rules in GCE - List forwardingRulesList = ((List) clusterIDForwardingRulesPair.getValue()); - for (int forwardingRule : forwardingRulesList){ //for each port + //create forwarding rules in GCE + for (int forwardingRule : ((List) loadBalancerConfiguration.getForwardingRulesList())) { //for each port - //set a valid forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(forwardingRule,clusterID); + //set a valid forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(forwardingRule, clusterID); - //create a forwarding rule in GCE - gceOperations.createForwardingRule(forwardingRuleName,targetPoolName,protocol); + //create a forwarding rule in GCE + gceOperations.createForwardingRule(forwardingRuleName, targetPoolName, protocol); + } } - } log.info("GCE Load balancer instance started"); From 8d598e61323ac30da121048b83527c727a1f3532 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 21:35:34 +0530 Subject: [PATCH 066/217] adding code for start method and configure method --- .../gce/extension/GCELoadBalancer.java | 81 ++++++++++++++----- .../extension/LoadBalancerConfiguration.java | 35 ++++++-- 2 files changed, 90 insertions(+), 26 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 5c16155d93..892767f9a2 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -83,25 +83,24 @@ public void start() throws LoadBalancerExtensionException { if(!loadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running - //set a valid target pool name - String targetPoolName = targetPoolNameCreator(clusterID); //crate a target pool in GCE - gceOperations.createTargetPool(targetPoolName); + gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName()); //add instances to target pool - gceOperations.addInstancesToTargetPool(loadBalancerConfiguration.getInstancesList(),targetPoolName); + gceOperations.addInstancesToTargetPool(loadBalancerConfiguration.getInstancesList(), + loadBalancerConfiguration.getTargetPoolName()); //create forwarding rules in GCE - for (int forwardingRule : ((List) loadBalancerConfiguration.getForwardingRulesList())) { //for each port - - //set a valid forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(forwardingRule, clusterID); - + for (String forwardingRuleName : loadBalancerConfiguration.getForwardingRuleNames()) { //for each port //create a forwarding rule in GCE - gceOperations.createForwardingRule(forwardingRuleName, targetPoolName, protocol); + gceOperations.createForwardingRule(forwardingRuleName, + loadBalancerConfiguration.getTargetPoolName(), protocol); } + + //set status to running + loadBalancerConfiguration.setStatus(true); } } @@ -116,6 +115,24 @@ public void stop() throws LoadBalancerExtensionException { log.info("GCE Load Balancer is stopping"); //iterate through hashmap and remove all + + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()) { //for each Load balancer configuration + + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + + String clusterID = ((String) clusterIDLoadBalancerConfigurationPair.getKey()); + LoadBalancerConfiguration loadBalancerConfiguration = + ((LoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + + if (loadBalancerConfiguration.getStatus()) { //if the load balancer is already running + + //delete target pool from GCE + + //delete forwarding rules from GCE + } + } + } /** @@ -153,7 +170,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //check and update List updatedInstancesList = new ArrayList(); - List updatedForwardingRulesList = new ArrayList(); + HashMap updatedIpToForwardingRuleNameMap = new HashMap(); for (Member member : cluster.getMembers()) { @@ -168,24 +185,38 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //checking for forwarding rules for (Object port : member.getPorts()) { + int portValue = ((Port) port).getValue(); + //if not present update it - if (!updatedForwardingRulesList.contains(((Port) port).getValue())) { //if port is not in list - updatedForwardingRulesList.add(((Port) port).getValue()); + if (!updatedIpToForwardingRuleNameMap.containsKey(portValue)){ //if port is not in list + //create a new forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(portValue,cluster.getClusterId()); + //put the forwarding rule to map + updatedIpToForwardingRuleNameMap.put(portValue, forwardingRuleName); } } } //set new forwarding rules and instances list - loadBalancerConfiguration.setForwardingRulesList(updatedForwardingRulesList); + loadBalancerConfiguration.setipToForwardingRuleNameMap(updatedIpToForwardingRuleNameMap); loadBalancerConfiguration.setInstancesList(updatedInstancesList); + if(loadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name + //set target pool name + String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); + loadBalancerConfiguration.setTargetPoolName(targetPoolName); + } + } else { //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map List instancesList = new ArrayList(); - List forwardingRulesList = new ArrayList(); + HashMap ipToForwardingRuleNameMap = new HashMap(); + + + for (Member member : cluster.getMembers()) { @@ -193,17 +224,25 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //instancesList.add(member.getMemberName); //add forwarding rules(Ports to be forwarded) - for (Object port : member.getPorts()) { - if (!forwardingRulesList.contains(((Port) port).getValue())) { //if port is not in list - forwardingRulesList.add(((Port) port).getValue()); + int portValue = ((Port) port).getValue(); + if (!ipToForwardingRuleNameMap.containsKey(portValue)) { //if port is not in list + //create a new forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(portValue,cluster.getClusterId()); + //put the forwarding rule to map + ipToForwardingRuleNameMap.put(portValue,forwardingRuleName); } } } LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( - cluster.getClusterId(), instancesList, forwardingRulesList); + cluster.getClusterId(), instancesList, ipToForwardingRuleNameMap); + if(loadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name + //set target pool name + String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); + loadBalancerConfiguration.setTargetPoolName(targetPoolName); + } clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), loadBalancerConfiguration); @@ -215,6 +254,10 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio return true; } + /** + * + * @throws LoadBalancerExtensionException + */ @Override public void reload() throws LoadBalancerExtensionException { diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java index 16d694eadd..1d126d5c41 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -19,7 +19,10 @@ package org.apache.stratos.gce.extension; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Set; /** * Since GCE have separate target pools and forwarding rules, we need @@ -34,26 +37,36 @@ public class LoadBalancerConfiguration { //A load balancer must have a target pool(set of instances) private List instancesList; //A load balancer can have one or more forwarding rules(set of ports to be forwarded) - private List forwardingRulesList; + //we create a map to store the port IP and forwarding rule name + private HashMap ipToForwardingRuleNameMap; //cluster ID from stratos side private String clusterID; + private String targetPoolName; //Whether we have executed this configuration in GCE or not private boolean isRunning = false; public LoadBalancerConfiguration(String clusterID, List instancesList, - List forwardingRulesList) { + HashMap ipToForwardingRuleNameMap) { this.clusterID = clusterID; this.instancesList = instancesList; - this.forwardingRulesList = forwardingRulesList; + this.ipToForwardingRuleNameMap = ipToForwardingRuleNameMap; } - public void setForwardingRulesList(List forwardingRulesList) { - this.forwardingRulesList = forwardingRulesList; + public void setipToForwardingRuleNameMap(HashMap ipToForwardingRuleNameMap) { + this.ipToForwardingRuleNameMap = ipToForwardingRuleNameMap; } - public List getForwardingRulesList() { - return forwardingRulesList; + public void addForwardingRule(int ip, String forwardingRuleName){ + this.ipToForwardingRuleNameMap.put(ip,forwardingRuleName); + } + + public Set getPorts() { + return ipToForwardingRuleNameMap.keySet(); + } + + public Collection getForwardingRuleNames(){ + return ipToForwardingRuleNameMap.values(); } public List getInstancesList() { @@ -73,6 +86,14 @@ public void setStatus(boolean status) { this.isRunning = status; } + public void setTargetPoolName(String targetPoolName){ + this.targetPoolName = targetPoolName; + } + + public String getTargetPoolName(){ + return targetPoolName; + } + public boolean getStatus() { return isRunning; } From 18538cf04ef778d4ef93a1cc91f06ac2607e080e Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 21:50:49 +0530 Subject: [PATCH 067/217] adding code for stop method and configure method --- .../gce/extension/GCELoadBalancer.java | 20 +++++++++---------- .../stratos/gce/extension/GCEOperations.java | 17 ++++++++++++++++ .../extension/LoadBalancerConfiguration.java | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 892767f9a2..54ba762bf0 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,7 +19,6 @@ package org.apache.stratos.gce.extension; -import com.google.api.services.compute.model.TargetPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.common.domain.*; @@ -30,6 +29,7 @@ import java.security.GeneralSecurityException; import java.util.*; +//TODO: exception handling public class GCELoadBalancer implements LoadBalancer { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); @@ -120,16 +120,19 @@ public void stop() throws LoadBalancerExtensionException { while (iterator.hasNext()) { //for each Load balancer configuration Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - - String clusterID = ((String) clusterIDLoadBalancerConfigurationPair.getKey()); LoadBalancerConfiguration loadBalancerConfiguration = ((LoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); if (loadBalancerConfiguration.getStatus()) { //if the load balancer is already running + //delete forwarding rules from GCE + for(String forwardingRuleName : loadBalancerConfiguration.getForwardingRuleNames()){ + gceOperations.deleteForwardingRule(forwardingRuleName); + } + //delete target pool from GCE + gceOperations.deleteTargetPool(loadBalancerConfiguration.getTargetPoolName()); - //delete forwarding rules from GCE } } @@ -175,14 +178,14 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { - //TODO:check instances(members) in target pool and update + //TODO:check instances(members) in instance list and update /* EX: if(!updatedInstancesList.contains(member.getMemberName())){ updatedInstancesList.add(member.getMemberName); } */ - //checking for forwarding rules + //checking for forwarding rules and updating for (Object port : member.getPorts()) { int portValue = ((Port) port).getValue(); @@ -199,7 +202,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } //set new forwarding rules and instances list - loadBalancerConfiguration.setipToForwardingRuleNameMap(updatedIpToForwardingRuleNameMap); + loadBalancerConfiguration.setIPToForwardingRuleNameMap(updatedIpToForwardingRuleNameMap); loadBalancerConfiguration.setInstancesList(updatedInstancesList); if(loadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name @@ -215,9 +218,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio List instancesList = new ArrayList(); HashMap ipToForwardingRuleNameMap = new HashMap(); - - - for (Member member : cluster.getMembers()) { //TODO:set instances(members) to instances list diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 6a859ab2b8..60bff75c44 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -44,6 +44,7 @@ * All the GCE API calls will be done using this class */ +//TODO: exception handling public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); @@ -134,6 +135,14 @@ public void createTargetPool(String targetPoolName) { } + public void deleteTargetPool(String targetPoolName){ + try { + compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * create forwarding rule by using given target pool and protocol * @@ -158,6 +167,14 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } } + public void deleteForwardingRule(String forwardingRuleName){ + try { + compute.forwardingRules().delete(PROJECT_ID,REGION_NAME,forwardingRuleName).execute(); + } catch (IOException e) { + e.printStackTrace(); + } + } + /** * Check whether the given target pool is already exists in the given project and region. diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java index 1d126d5c41..bddeece3ef 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -53,7 +53,7 @@ public LoadBalancerConfiguration(String clusterID, List instancesList, this.ipToForwardingRuleNameMap = ipToForwardingRuleNameMap; } - public void setipToForwardingRuleNameMap(HashMap ipToForwardingRuleNameMap) { + public void setIPToForwardingRuleNameMap(HashMap ipToForwardingRuleNameMap) { this.ipToForwardingRuleNameMap = ipToForwardingRuleNameMap; } From 4e58e247b38a1232a0361e7f93bc3ea2bdd9b50b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 22:52:00 +0530 Subject: [PATCH 068/217] Remove hard-coded values and reading from configuration --- .../src/main/bin/gce-extension.sh | 9 ++- .../stratos/gce/extension/Constants.java | 7 +++ .../stratos/gce/extension/GCEContext.java | 62 ++++++++++++++++++- .../stratos/gce/extension/GCEOperations.java | 24 +++---- 4 files changed, 88 insertions(+), 14 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 736a113a6c..56dd2893c7 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -40,7 +40,14 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dnetwork.partition.id=network-partition-1 -Dcluster.id=cluster-1 -Dservice.name=php - -Dname.prefix=lb" + -Dname.prefix=lb + -Dproject.name=My First Project + -Dproject.id=gold-access-96509 + -Dzone.name=europe-west1-b + -Dregion.name=europe-west1 + -Dkey.file.path=/home/sanjaya/keys/p12key-donwloaded.p12 + -Dgce.account.id=164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com + -Ddata.store.directory=.store/gce-extension" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index a723f7cb6d..08ff794d64 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -30,4 +30,11 @@ public class Constants { public static final String CLUSTER_ID = "cluster.id"; public static final String SERVICE_NAME = "service.name"; public static final String NAME_PREFIX = "name.prefix"; + public static final String PROJECT_NAME = "project.name"; + public static final String PROJECT_ID = "project.id"; + public static final String ZONE_NAME = "zone.name"; + public static final String REGION_NAME = "region.name"; + public static final String KEY_FILE_PATH = "key.file.path"; + public static final String GCE_ACCOUNT_ID = "gce.account.id"; + public static final String DATA_STORE_DIRECTORY = ".store/gce-extension"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 6b08a3035f..31140cb5b6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -38,6 +38,13 @@ public class GCEContext { private String clusterId; private String serviceName; private String namePrefix; + private String projectName; + private String projectID; + private String zoneName; + private String regionName; + private String keyFilePath; + private String gceAccountID; + private String dataStoreDirectory; private GCEContext() { @@ -49,6 +56,14 @@ private GCEContext() { this.clusterId = System.getProperty(Constants.CLUSTER_ID); this.serviceName = System.getProperty(Constants.SERVICE_NAME); this.namePrefix = System.getProperty(Constants.NAME_PREFIX); + this.projectName = System.getProperty(Constants.PROJECT_NAME); + this.projectID = System.getProperty(Constants.PROJECT_ID); + this.zoneName = System.getProperty(Constants.ZONE_NAME); + this.regionName = System.getProperty(Constants.REGION_NAME); + this.keyFilePath = System.getProperty(Constants.KEY_FILE_PATH); + this.gceAccountID = System.getProperty(Constants.GCE_ACCOUNT_ID); + this.dataStoreDirectory = System.getProperty(Constants.DATA_STORE_DIRECTORY); + if (log.isDebugEnabled()) { log.debug(Constants.CEP_STATS_PUBLISHER_ENABLED + " = " + cepStatsPublisherEnabled); @@ -57,7 +72,14 @@ private GCEContext() { log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); log.debug(Constants.NETWORK_PARTITION_ID + " = " + networkPartitionId); log.debug(Constants.CLUSTER_ID + " = " + clusterId); - log.debug(Constants.NAME_PREFIX + " = "+ namePrefix); + log.debug(Constants.NAME_PREFIX + " = " + namePrefix); + log.debug(Constants.PROJECT_NAME + " = " + projectName); + log.debug(Constants.PROJECT_ID + " = " + projectID); + log.debug(Constants.ZONE_NAME + " = " + zoneName); + log.debug(Constants.REGION_NAME + " = " + regionName); + log.debug(Constants.KEY_FILE_PATH + " = " + keyFilePath); + log.debug(Constants.GCE_ACCOUNT_ID + " = " + gceAccountID); + log.debug(Constants.DATA_STORE_DIRECTORY + " = " + dataStoreDirectory); } } @@ -78,6 +100,14 @@ public void validate() { validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED); validateSystemProperty(Constants.CLUSTER_ID); validateSystemProperty(Constants.NAME_PREFIX); + validateSystemProperty(Constants.PROJECT_NAME); + validateSystemProperty(Constants.PROJECT_ID); + validateSystemProperty(Constants.ZONE_NAME); + validateSystemProperty(Constants.REGION_NAME); + validateSystemProperty(Constants.KEY_FILE_PATH); + validateSystemProperty(Constants.GCE_ACCOUNT_ID); + validateSystemProperty(Constants.DATA_STORE_DIRECTORY); + if (cepStatsPublisherEnabled) { validateSystemProperty(Constants.THRIFT_RECEIVER_IP); @@ -110,7 +140,35 @@ public String getServiceName() { return serviceName; } - public String getNamePrefix() { return namePrefix; } + public String getNamePrefix() { + return namePrefix; + } + + public String getProjectName() { + return projectName; + } + + public String getProjectID() { + return projectID; + } + public String getZoneName() { + return zoneName; + } + public String getRegionName() { + return regionName; + } + + public String getKeyFilePath() { + return keyFilePath; + } + + public String getGceAccountID() { + return gceAccountID; + } + + public String getDataStoreDirectory() { + return dataStoreDirectory; + } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 60bff75c44..2528687275 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -49,21 +49,23 @@ public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); - //TODO: remove all hardcoded values and read from configuration parameters - private static final String PROJECT_NAME = "My First Project"; - private static final String PROJECT_ID = "gold-access-96509"; - private static final String ZONE_NAME = "europe-west1-b"; - private static final String REGION_NAME = "europe-west1"; - private static final String RUNNING_FILTER = "status eq RUNNING"; + private static final String PROJECT_NAME = GCEContext.getInstance().getProjectName(); + private static final String PROJECT_ID = GCEContext.getInstance().getProjectID(); + private static final String ZONE_NAME = GCEContext.getInstance().getZoneName(); + private static final String REGION_NAME = GCEContext.getInstance().getRegionName(); + //auth - private static final String KEY_FILE = "/home/sanjaya/keys/p12key-donwloaded.p12"; - private static final String ACCOUNT_ID = "164588286821-a517i85433f83e0nthc4qjmoupri" + - "394q@developer.gserviceaccount.com"; + private static final String KEY_FILE_PATH = GCEContext.getInstance().getKeyFilePath(); + private static final String ACCOUNT_ID = GCEContext.getInstance().getGceAccountID(); /** * Directory to store user credentials. */ - private static final String DATA_STORE_DIR = ".store/gce-extension"; + private static final String DATA_STORE_DIR = GCEContext.getInstance().getDataStoreDirectory(); + + private static final String RUNNING_FILTER = "status eq RUNNING"; + + static Compute compute; @@ -100,7 +102,7 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep .setJsonFactory(jsonFactory) .setServiceAccountId(ACCOUNT_ID) .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) - .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE)) + .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_PATH)) .build(); // Create compute engine object From ce5bfc1228be1003538add54fd5f7075600ee933 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 23:15:35 +0530 Subject: [PATCH 069/217] fixing error in project name --- .../load-balancer/gce-extension/src/main/bin/gce-extension.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 56dd2893c7..94f323efbe 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -41,7 +41,7 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dcluster.id=cluster-1 -Dservice.name=php -Dname.prefix=lb - -Dproject.name=My First Project + -Dproject.name=MyFirstProject -Dproject.id=gold-access-96509 -Dzone.name=europe-west1-b -Dregion.name=europe-west1 From 230cc2f972f5c624fd38a36c3414d8bb36145060 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 23:26:54 +0530 Subject: [PATCH 070/217] fixing error in data store directory location --- .../gce-extension/src/main/bin/gce-extension.sh | 3 +-- .../java/org/apache/stratos/gce/extension/Constants.java | 1 - .../java/org/apache/stratos/gce/extension/GCEContext.java | 6 ------ .../org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 94f323efbe..6427e9dfc1 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -46,8 +46,7 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dzone.name=europe-west1-b -Dregion.name=europe-west1 -Dkey.file.path=/home/sanjaya/keys/p12key-donwloaded.p12 - -Dgce.account.id=164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com - -Ddata.store.directory=.store/gce-extension" + -Dgce.account.id=164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index 08ff794d64..f24d13f47f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -36,5 +36,4 @@ public class Constants { public static final String REGION_NAME = "region.name"; public static final String KEY_FILE_PATH = "key.file.path"; public static final String GCE_ACCOUNT_ID = "gce.account.id"; - public static final String DATA_STORE_DIRECTORY = ".store/gce-extension"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 31140cb5b6..5994d049f3 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -44,7 +44,6 @@ public class GCEContext { private String regionName; private String keyFilePath; private String gceAccountID; - private String dataStoreDirectory; private GCEContext() { @@ -62,7 +61,6 @@ private GCEContext() { this.regionName = System.getProperty(Constants.REGION_NAME); this.keyFilePath = System.getProperty(Constants.KEY_FILE_PATH); this.gceAccountID = System.getProperty(Constants.GCE_ACCOUNT_ID); - this.dataStoreDirectory = System.getProperty(Constants.DATA_STORE_DIRECTORY); if (log.isDebugEnabled()) { @@ -79,7 +77,6 @@ private GCEContext() { log.debug(Constants.REGION_NAME + " = " + regionName); log.debug(Constants.KEY_FILE_PATH + " = " + keyFilePath); log.debug(Constants.GCE_ACCOUNT_ID + " = " + gceAccountID); - log.debug(Constants.DATA_STORE_DIRECTORY + " = " + dataStoreDirectory); } } @@ -168,7 +165,4 @@ public String getGceAccountID() { return gceAccountID; } - public String getDataStoreDirectory() { - return dataStoreDirectory; - } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 2528687275..1fab21a8b3 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -61,7 +61,7 @@ public class GCEOperations { /** * Directory to store user credentials. */ - private static final String DATA_STORE_DIR = GCEContext.getInstance().getDataStoreDirectory(); + private static final String DATA_STORE_DIR = ".store/gce-extension"; private static final String RUNNING_FILTER = "status eq RUNNING"; From 66f83bb4f9986cfcfa7e0b5487f027cd4a43f48c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 23:27:34 +0530 Subject: [PATCH 071/217] fixing error in data store directory location --- .../main/java/org/apache/stratos/gce/extension/GCEContext.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 5994d049f3..f27e6279dd 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -103,8 +103,6 @@ public void validate() { validateSystemProperty(Constants.REGION_NAME); validateSystemProperty(Constants.KEY_FILE_PATH); validateSystemProperty(Constants.GCE_ACCOUNT_ID); - validateSystemProperty(Constants.DATA_STORE_DIRECTORY); - if (cepStatsPublisherEnabled) { validateSystemProperty(Constants.THRIFT_RECEIVER_IP); From d2daffc80aeb207745ad590d3569c7175602c4ae Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 8 Jun 2015 23:51:43 +0530 Subject: [PATCH 072/217] fixing bug --- .../gce/extension/GCELoadBalancer.java | 3 ++ .../stratos/gce/extension/GCEOperations.java | 47 ++++++++++++------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 54ba762bf0..89e451d1ca 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -84,6 +84,7 @@ public void start() throws LoadBalancerExtensionException { if(!loadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running + //todo: need to add validation checks here(Need to check whether the resources are created or not) //crate a target pool in GCE gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName()); @@ -92,6 +93,8 @@ public void start() throws LoadBalancerExtensionException { loadBalancerConfiguration.getTargetPoolName()); + + //create forwarding rules in GCE for (String forwardingRuleName : loadBalancerConfiguration.getForwardingRuleNames()) { //for each port //create a forwarding rule in GCE diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 1fab21a8b3..b1b27302da 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -21,6 +21,7 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; +import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.jackson2.JacksonFactory; @@ -126,12 +127,23 @@ public void createTargetPool(String targetPoolName) { //TODO:REMOVE try catch try { - compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); + Operation createTargetPoolOperation = + compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); + //wait until operation suceed + while (true){ + if(createTargetPoolOperation.getStatus().equals("DONE")){ + return; + } + Thread.sleep(100); + } + } catch (IOException e) { if (log.isErrorEnabled()) { log.error("failed to create target pool: " + targetPoolName); } e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } @@ -261,23 +273,8 @@ public TargetPool getTargetPool(String targetPoolName) { private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { - //todo: target pool is must be validated before call this method. May be we - // todo: can add a validation check here - log.info("Adding instances to target pool"); - //create target pools add instance request and set instance to it - TargetPoolsAddInstanceRequest targetPoolsAddInstanceRequest = new - TargetPoolsAddInstanceRequest(); - targetPoolsAddInstanceRequest.setInstances(instanceReferenceList); - //todo Remove try catch - try { - //execute - compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, - targetPoolName, targetPoolsAddInstanceRequest).execute(); - } catch (IOException e) { - e.printStackTrace(); - } } /** @@ -359,6 +356,9 @@ public void setPortRangeToForwardingRule() { } public void addInstancesToTargetPool(List instancesNamesList, String targetPoolName){ + + log.info("Adding instances to target pool"); + List instanceReferenceList = new ArrayList(); //add instance to instance reference list, we should use the instance URL @@ -368,7 +368,20 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar setInstance(getInstanceURLFromName(instanceName))); } - addInstancesToTargetPool(targetPoolName, instanceReferenceList); + + //create target pools add instance request and set instance to it + TargetPoolsAddInstanceRequest targetPoolsAddInstanceRequest = new + TargetPoolsAddInstanceRequest(); + targetPoolsAddInstanceRequest.setInstances(instanceReferenceList); + + //todo Remove try catch + try { + //execute + compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, + targetPoolName, targetPoolsAddInstanceRequest).execute(); + } catch (IOException e) { + e.printStackTrace(); + } } /** From e6859f5304ad1c2a77727f5d7710ba4977df728f Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 00:10:32 +0530 Subject: [PATCH 073/217] set waiting times for GCE api calls --- .../stratos/gce/extension/GCEOperations.java | 101 ++++++++++++++++-- 1 file changed, 94 insertions(+), 7 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index b1b27302da..94a8539480 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -21,7 +21,6 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; -import com.google.api.client.googleapis.services.AbstractGoogleClientRequest; import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.jackson2.JacksonFactory; @@ -41,6 +40,8 @@ import java.util.Collections; import java.util.List; +import com.google.api.services.compute.model.Operation.Error.Errors; + /** * All the GCE API calls will be done using this class */ @@ -127,13 +128,26 @@ public void createTargetPool(String targetPoolName) { //TODO:REMOVE try catch try { - Operation createTargetPoolOperation = + Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); - //wait until operation suceed + //wait until operation succeed while (true){ - if(createTargetPoolOperation.getStatus().equals("DONE")){ + if(operation.getStatus().equals("DONE")){ + + //log response + if(log.isDebugEnabled()){ + log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + } + if (log.isErrorEnabled()) { + for ( Errors errors : operation.getError().getErrors()) { + log.error("Target pool creation operation error: " + errors.getMessage()); + } + } return; } + if(log.isDebugEnabled()){ + log.debug("Waiting until the create target pool API call get succeeded"); + } Thread.sleep(100); } @@ -151,9 +165,32 @@ public void createTargetPool(String targetPoolName) { public void deleteTargetPool(String targetPoolName){ try { - compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); + Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); + //wait until operation succeed + while (true){ + if(operation.getStatus().equals("DONE")){ + + //log response + if(log.isDebugEnabled()){ + log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + } + if (log.isErrorEnabled()) { + for ( Errors errors : operation.getError().getErrors()) { + log.error("Target pool creation operation error: " + errors.getMessage()); + } + } + return; + } + if(log.isDebugEnabled()){ + log.debug("Waiting until the delete target pool API call get succeeded"); + } + Thread.sleep(100); + } + } catch (IOException e) { e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } } @@ -175,17 +212,65 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam forwardingRule.setTarget(targetPoolURL); forwardingRule.setIPProtocol(protocol); try { - compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); + Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); + + //wait until operation succeed + while (true){ + if(operation.getStatus().equals("DONE")){ + + //log response + if(log.isDebugEnabled()){ + log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + } + if (log.isErrorEnabled()) { + for ( Errors errors : operation.getError().getErrors()) { + log.error("Target pool creation operation error: " + errors.getMessage()); + } + } + return; + } + if(log.isDebugEnabled()){ + log.debug("Waiting until the create forwarding rule API call get succeeded"); + } + Thread.sleep(100); + } + } catch (IOException e) { e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } } public void deleteForwardingRule(String forwardingRuleName){ try { - compute.forwardingRules().delete(PROJECT_ID,REGION_NAME,forwardingRuleName).execute(); + Operation operation = compute.forwardingRules(). + delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); + //wait until operation succeed + while (true){ + if(operation.getStatus().equals("DONE")){ + + //log response + if(log.isDebugEnabled()){ + log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + } + if (log.isErrorEnabled()) { + for ( Errors errors : operation.getError().getErrors()) { + log.error("Target pool creation operation error: " + errors.getMessage()); + } + } + return; + } + if(log.isDebugEnabled()){ + log.debug("Waiting until the delete forwarding rule API call get succeeded"); + } + Thread.sleep(100); + } + } catch (IOException e) { e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } } @@ -379,6 +464,8 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar //execute compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); + + } catch (IOException e) { e.printStackTrace(); } From a553955b3f4b4039c4b32a54087cddf8ca91bbbe Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 00:11:50 +0530 Subject: [PATCH 074/217] set waiting times for GCE api calls --- .../gce/extension/GCELoadBalancer.java | 3 --- .../stratos/gce/extension/GCEOperations.java | 25 ++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 89e451d1ca..afa484bdaa 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -92,9 +92,6 @@ public void start() throws LoadBalancerExtensionException { gceOperations.addInstancesToTargetPool(loadBalancerConfiguration.getInstancesList(), loadBalancerConfiguration.getTargetPoolName()); - - - //create forwarding rules in GCE for (String forwardingRuleName : loadBalancerConfiguration.getForwardingRuleNames()) { //for each port //create a forwarding rule in GCE diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 94a8539480..4b04866e9d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -462,12 +462,35 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar //todo Remove try catch try { //execute - compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, + Operation operation = compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); + //wait until operation succeed + while (true){ + if(operation.getStatus().equals("DONE")){ + + //log response + if(log.isDebugEnabled()){ + log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + } + if (log.isErrorEnabled()) { + for ( Errors errors : operation.getError().getErrors()) { + log.error("Target pool creation operation error: " + errors.getMessage()); + } + } + return; + } + if(log.isDebugEnabled()){ + log.debug("Waiting until the Add instances to target pool API call get succeeded"); + } + Thread.sleep(100); + } + } catch (IOException e) { e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); } } From 4d6d1e71f5441f275d6cc1f02fadb8918db74a34 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 00:38:54 +0530 Subject: [PATCH 075/217] set waiting times for GCE api calls --- .../apache/stratos/gce/extension/GCEOperations.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 4b04866e9d..ec6325beae 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -132,6 +132,7 @@ public void createTargetPool(String targetPoolName) { compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); //wait until operation succeed while (true){ + //todo: correct this line if(operation.getStatus().equals("DONE")){ //log response @@ -167,7 +168,8 @@ public void deleteTargetPool(String targetPoolName){ try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); //wait until operation succeed - while (true){ + while (true){ //todo: correct this line + if(operation.getStatus().equals("DONE")){ //log response @@ -215,7 +217,8 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); //wait until operation succeed - while (true){ + while (true){ //todo: correct this line + if(operation.getStatus().equals("DONE")){ //log response @@ -248,7 +251,8 @@ public void deleteForwardingRule(String forwardingRuleName){ delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); //wait until operation succeed while (true){ - if(operation.getStatus().equals("DONE")){ + if(operation.getStatus().equals("DONE")){ //todo: correct this line + //log response if(log.isDebugEnabled()){ From 416e68834564248e07a157ce3f7cc4d833143cb1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 12:53:10 +0530 Subject: [PATCH 076/217] adding health check operations --- .../src/main/bin/gce-extension.sh | 6 +- .../stratos/gce/extension/Constants.java | 5 ++ .../stratos/gce/extension/GCEContext.java | 35 +++++++- .../stratos/gce/extension/GCEOperations.java | 87 ++++++++++++++++--- 4 files changed, 121 insertions(+), 12 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 6427e9dfc1..626e0efab4 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -46,7 +46,11 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dzone.name=europe-west1-b -Dregion.name=europe-west1 -Dkey.file.path=/home/sanjaya/keys/p12key-donwloaded.p12 - -Dgce.account.id=164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com" + -Dgce.account.id=164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com + -Dhealth.check.request.path=/ + -Dhealth.check.port=80 + -Dhealth.check.timeoutSec=5 + -Dhealth.check.unhealthyThreshold=2" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index f24d13f47f..3946cc8bcf 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -36,4 +36,9 @@ public class Constants { public static final String REGION_NAME = "region.name"; public static final String KEY_FILE_PATH = "key.file.path"; public static final String GCE_ACCOUNT_ID = "gce.account.id"; + public static final String HEALTH_CHECK_REQUEST_PATH = "health.check.request.path"; + public static final String HEALTH_CHECK_PORT = "health.check.port"; + public static final String HEALTH_CHECK_TIME_OUT_SEC = "health.check.time.out.sec"; + public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "health.check.unhealthy.threshold"; + } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index f27e6279dd..3b0d555dde 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -44,6 +44,11 @@ public class GCEContext { private String regionName; private String keyFilePath; private String gceAccountID; + private String healthCheckRequestPath; + private String healthCheckPort; + private String healthCheckTimeOutSec; + private String healthCheckUnhealthyThreshold; + private GCEContext() { @@ -61,6 +66,10 @@ private GCEContext() { this.regionName = System.getProperty(Constants.REGION_NAME); this.keyFilePath = System.getProperty(Constants.KEY_FILE_PATH); this.gceAccountID = System.getProperty(Constants.GCE_ACCOUNT_ID); + this.healthCheckRequestPath = System.getProperty(Constants.HEALTH_CHECK_REQUEST_PATH); + this.healthCheckPort = System.getProperty(Constants.HEALTH_CHECK_PORT); + this.healthCheckTimeOutSec = System.getProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); + this.healthCheckUnhealthyThreshold = System.getProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); if (log.isDebugEnabled()) { @@ -77,6 +86,11 @@ private GCEContext() { log.debug(Constants.REGION_NAME + " = " + regionName); log.debug(Constants.KEY_FILE_PATH + " = " + keyFilePath); log.debug(Constants.GCE_ACCOUNT_ID + " = " + gceAccountID); + log.debug(Constants.HEALTH_CHECK_REQUEST_PATH + " = " + healthCheckRequestPath); + log.debug(Constants.HEALTH_CHECK_PORT + " = " + healthCheckPort); + log.debug(Constants.HEALTH_CHECK_TIME_OUT_SEC + " = " + healthCheckTimeOutSec); + log.debug(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD + " = " + healthCheckUnhealthyThreshold); + } } @@ -103,12 +117,16 @@ public void validate() { validateSystemProperty(Constants.REGION_NAME); validateSystemProperty(Constants.KEY_FILE_PATH); validateSystemProperty(Constants.GCE_ACCOUNT_ID); + validateSystemProperty(Constants.HEALTH_CHECK_REQUEST_PATH); + validateSystemProperty(Constants.HEALTH_CHECK_PORT); + validateSystemProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); + validateSystemProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); + if (cepStatsPublisherEnabled) { validateSystemProperty(Constants.THRIFT_RECEIVER_IP); validateSystemProperty(Constants.THRIFT_RECEIVER_PORT); validateSystemProperty(Constants.NETWORK_PARTITION_ID); - } } @@ -163,4 +181,19 @@ public String getGceAccountID() { return gceAccountID; } + public String getHealthCheckRequestPath() { + return healthCheckRequestPath; + } + + public String getHealthCheckPort() { + return healthCheckPort; + } + + public String getHealthCheckTimeOutSec() { + return healthCheckTimeOutSec; + } + + public String getHealthCheckUnhealthyThreshold() { + return healthCheckUnhealthyThreshold; + } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index ec6325beae..6346331fe5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -51,6 +51,7 @@ public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); + //project related private static final String PROJECT_NAME = GCEContext.getInstance().getProjectName(); private static final String PROJECT_ID = GCEContext.getInstance().getProjectID(); private static final String ZONE_NAME = GCEContext.getInstance().getZoneName(); @@ -60,6 +61,12 @@ public class GCEOperations { private static final String KEY_FILE_PATH = GCEContext.getInstance().getKeyFilePath(); private static final String ACCOUNT_ID = GCEContext.getInstance().getGceAccountID(); + //health check + private static final String HEALTH_CHECK_REQUEST_PATH = GCEContext.getInstance().getHealthCheckRequestPath(); + private static final String HEALTH_CHECK_PORT = GCEContext.getInstance().getHealthCheckPort(); + private static final String HEALTH_CHECK_TIME_OUT_SEC =GCEContext.getInstance().getHealthCheckTimeOutSec(); + private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); + /** * Directory to store user credentials. */ @@ -174,11 +181,11 @@ public void deleteTargetPool(String targetPoolName){ //log response if(log.isDebugEnabled()){ - log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + log.debug("Delete target pool operation Status: "+operation.getStatusMessage()); } if (log.isErrorEnabled()) { for ( Errors errors : operation.getError().getErrors()) { - log.error("Target pool creation operation error: " + errors.getMessage()); + log.error("Delete target pool operation error: " + errors.getMessage()); } } return; @@ -223,11 +230,11 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam //log response if(log.isDebugEnabled()){ - log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + log.debug("Create forwarding rule operation Status: "+operation.getStatusMessage()); } if (log.isErrorEnabled()) { for ( Errors errors : operation.getError().getErrors()) { - log.error("Target pool creation operation error: " + errors.getMessage()); + log.error("Create forwarding rule operation error: " + errors.getMessage()); } } return; @@ -256,11 +263,11 @@ public void deleteForwardingRule(String forwardingRuleName){ //log response if(log.isDebugEnabled()){ - log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + log.debug("delete forwarding rule operation Status: "+operation.getStatusMessage()); } if (log.isErrorEnabled()) { for ( Errors errors : operation.getError().getErrors()) { - log.error("Target pool creation operation error: " + errors.getMessage()); + log.error("delete forwarding rule operation error: " + errors.getMessage()); } } return; @@ -474,11 +481,11 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar //log response if(log.isDebugEnabled()){ - log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + log.debug("Add instances to target pool operation Status: "+operation.getStatusMessage()); } if (log.isErrorEnabled()) { for ( Errors errors : operation.getError().getErrors()) { - log.error("Target pool creation operation error: " + errors.getMessage()); + log.error("Add instances to target pool operation error: " + errors.getMessage()); } } return; @@ -488,14 +495,74 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar } Thread.sleep(100); } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + public void createHealthCheck(String healthCheckName){ + if(!isHealthCheckExists(healthCheckName)){//if the health check is not present already + HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); + httpHealthCheck.setName(healthCheckName); + httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); + //TODO: read as integers + httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); + httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); + try { + Operation operation = compute.httpHealthChecks().insert(PROJECT_ID,httpHealthCheck).execute(); + + //wait until succeed + while (true){ + if(operation.getStatus().equals("DONE")){ + + //log response + if(log.isDebugEnabled()){ + log.debug("Create health check operation Status: "+operation.getStatusMessage()); + } + if (log.isErrorEnabled()) { + for ( Errors errors : operation.getError().getErrors()) { + log.error("Create create health check operation error: " + errors.getMessage()); + } + } + return; + } + if(log.isDebugEnabled()){ + log.debug("Waiting until the create health check API call get succeeded"); + } + Thread.sleep(100); + } + + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + else { + if(log.isDebugEnabled()) { + log.debug("Health check is already exist: " + healthCheckName); + } + } + } + + public boolean isHealthCheckExists(String healthCheckName){ + try { + HttpHealthCheckList httpHealthCheckList = compute.httpHealthChecks().list(PROJECT_ID).execute(); + for(HttpHealthCheck httpHealthCheck: httpHealthCheckList.getItems()){ + if(httpHealthCheck.getName().equals(healthCheckName)){ + return true; + } + } } catch (IOException e) { e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); } + return false; } /** From c0060fb17dccd9755923a9e3f0a55dea2aeca2aa Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 13:33:39 +0530 Subject: [PATCH 077/217] adding health check operations --- .../stratos/gce/extension/GCEContext.java | 2 ++ .../gce/extension/GCELoadBalancer.java | 29 ++++++++++++++++++- .../stratos/gce/extension/GCEOperations.java | 2 +- .../extension/LoadBalancerConfiguration.java | 8 +++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 3b0d555dde..b65c72ec81 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -181,6 +181,8 @@ public String getGceAccountID() { return gceAccountID; } + + public String getHealthCheckRequestPath() { return healthCheckRequestPath; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index afa484bdaa..76436b9ba6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,6 +19,7 @@ package org.apache.stratos.gce.extension; +import com.google.api.services.compute.model.TargetPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.common.domain.*; @@ -83,8 +84,9 @@ public void start() throws LoadBalancerExtensionException { if(!loadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running + //create a health check + gceOperations.createHealthCheck(loadBalancerConfiguration.getHealthCheckName()); - //todo: need to add validation checks here(Need to check whether the resources are created or not) //crate a target pool in GCE gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName()); @@ -211,6 +213,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio loadBalancerConfiguration.setTargetPoolName(targetPoolName); } + if(loadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name + //set health check name + String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); + loadBalancerConfiguration.setHealthCheckName(healthCheckName); + } + } else { //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map @@ -244,6 +252,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio loadBalancerConfiguration.setTargetPoolName(targetPoolName); } + if(loadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name + //set health check name + String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); + loadBalancerConfiguration.setHealthCheckName(healthCheckName); + } + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), loadBalancerConfiguration); } @@ -289,4 +303,17 @@ private String forwardingRuleNameCreator(int port,String clusterID){ } return forwardingRuleName; } + + private String healthCheckNameCreator(String clusterID){ + String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-hc-" + + clusterID.trim().toLowerCase().replace(".","-"); + + //length should be les than 62 characters + if(healthCheckName.length()>=62){ + healthCheckName = healthCheckName.substring(0,62); + } + + return healthCheckName; + + } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 6346331fe5..948910acdf 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -168,7 +168,6 @@ public void createTargetPool(String targetPoolName) { e.printStackTrace(); } - } public void deleteTargetPool(String targetPoolName){ @@ -512,6 +511,7 @@ public void createHealthCheck(String healthCheckName){ //TODO: read as integers httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); + httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID,httpHealthCheck).execute(); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java index bddeece3ef..e05611d6fe 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -42,6 +42,7 @@ public class LoadBalancerConfiguration { //cluster ID from stratos side private String clusterID; private String targetPoolName; + private String healthCheckName; //Whether we have executed this configuration in GCE or not private boolean isRunning = false; @@ -98,4 +99,11 @@ public boolean getStatus() { return isRunning; } + public String getHealthCheckName() { + return healthCheckName; + } + + public void setHealthCheckName(String healthCheckName) { + this.healthCheckName = healthCheckName; + } } \ No newline at end of file From a99ed706498de8a5247f27c7016674236288c4d6 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 13:34:42 +0530 Subject: [PATCH 078/217] adding health check operations --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 76436b9ba6..bf7cb8995b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -87,6 +87,8 @@ public void start() throws LoadBalancerExtensionException { //create a health check gceOperations.createHealthCheck(loadBalancerConfiguration.getHealthCheckName()); + //todo: add health check to target pool + //crate a target pool in GCE gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName()); From 33f63d71f3a3aaee4c867a2af738aba02c455866 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 13:43:11 +0530 Subject: [PATCH 079/217] adding health check operations --- .../load-balancer/gce-extension/src/main/bin/gce-extension.sh | 2 +- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 626e0efab4..5014da6287 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -49,7 +49,7 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dgce.account.id=164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com -Dhealth.check.request.path=/ -Dhealth.check.port=80 - -Dhealth.check.timeoutSec=5 + -Dhealth.check.timeout.sec=5 -Dhealth.check.unhealthyThreshold=2" # Uncomment below line to enable remote debugging diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index bf7cb8995b..ec6411e4f0 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -88,6 +88,7 @@ public void start() throws LoadBalancerExtensionException { gceOperations.createHealthCheck(loadBalancerConfiguration.getHealthCheckName()); //todo: add health check to target pool + //todo: set firewall rule for health check //crate a target pool in GCE gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName()); @@ -111,7 +112,6 @@ public void start() throws LoadBalancerExtensionException { log.info("GCE Load balancer instance started"); - } @Override From bffcb59a7ef0d4d70f0d3c5474e3da9d24d377d0 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 13:48:16 +0530 Subject: [PATCH 080/217] adding health check operations --- .../main/java/org/apache/stratos/gce/extension/Constants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index 3946cc8bcf..60cdf62de7 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -38,7 +38,7 @@ public class Constants { public static final String GCE_ACCOUNT_ID = "gce.account.id"; public static final String HEALTH_CHECK_REQUEST_PATH = "health.check.request.path"; public static final String HEALTH_CHECK_PORT = "health.check.port"; - public static final String HEALTH_CHECK_TIME_OUT_SEC = "health.check.time.out.sec"; + public static final String HEALTH_CHECK_TIME_OUT_SEC = "health.check.timeout.sec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "health.check.unhealthy.threshold"; } From e2ba1d8dcb495e4e354872a8b1bcb9b1d4da68e0 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 13:52:12 +0530 Subject: [PATCH 081/217] adding health check operations --- .../load-balancer/gce-extension/src/main/bin/gce-extension.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 5014da6287..a9e0b4ce20 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -50,7 +50,7 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dhealth.check.request.path=/ -Dhealth.check.port=80 -Dhealth.check.timeout.sec=5 - -Dhealth.check.unhealthyThreshold=2" + -Dhealth.check.unhealthy.threshold=2" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" From d440abe7d3f721b6f759c1c1044e289cf0f8047a Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 14:18:50 +0530 Subject: [PATCH 082/217] adding a time out for operations --- .../stratos/gce/extension/GCEOperations.java | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 948910acdf..00e67a15c8 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -71,8 +71,8 @@ public class GCEOperations { * Directory to store user credentials. */ private static final String DATA_STORE_DIR = ".store/gce-extension"; - private static final String RUNNING_FILTER = "status eq RUNNING"; + private static final int OPERATION_TIMEOUT_MSILEC = 10000; static Compute compute; @@ -138,6 +138,7 @@ public void createTargetPool(String targetPoolName) { Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); //wait until operation succeed + int timeout = 0; while (true){ //todo: correct this line if(operation.getStatus().equals("DONE")){ @@ -156,7 +157,13 @@ public void createTargetPool(String targetPoolName) { if(log.isDebugEnabled()){ log.debug("Waiting until the create target pool API call get succeeded"); } + if(OPERATION_TIMEOUT_MSILEC == timeout){ + if(log.isDebugEnabled()){ + log.debug("Operation timeout reached for create target pool operation"); + } + } Thread.sleep(100); + timeout+=100; } } catch (IOException e) { @@ -173,6 +180,8 @@ public void createTargetPool(String targetPoolName) { public void deleteTargetPool(String targetPoolName){ try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); + + int timeout = 0; //wait until operation succeed while (true){ //todo: correct this line @@ -192,7 +201,13 @@ public void deleteTargetPool(String targetPoolName){ if(log.isDebugEnabled()){ log.debug("Waiting until the delete target pool API call get succeeded"); } + if(OPERATION_TIMEOUT_MSILEC == timeout){ + if(log.isDebugEnabled()){ + log.debug("Operation timeout reached for delete target pool operation"); + } + } Thread.sleep(100); + timeout+=100; } } catch (IOException e) { @@ -222,6 +237,8 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam try { Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); + int timeout = 0; + //wait until operation succeed while (true){ //todo: correct this line @@ -241,7 +258,13 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam if(log.isDebugEnabled()){ log.debug("Waiting until the create forwarding rule API call get succeeded"); } + if(OPERATION_TIMEOUT_MSILEC == timeout){ + if(log.isDebugEnabled()){ + log.debug("Operation timeout reached for delete target pool operation"); + } + } Thread.sleep(100); + timeout+=100; } } catch (IOException e) { @@ -255,6 +278,8 @@ public void deleteForwardingRule(String forwardingRuleName){ try { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); + + int timeout = 0; //wait until operation succeed while (true){ if(operation.getStatus().equals("DONE")){ //todo: correct this line @@ -274,7 +299,13 @@ public void deleteForwardingRule(String forwardingRuleName){ if(log.isDebugEnabled()){ log.debug("Waiting until the delete forwarding rule API call get succeeded"); } + if(OPERATION_TIMEOUT_MSILEC == timeout){ + if(log.isDebugEnabled()){ + log.debug("Operation timeout reached for delete target pool operation"); + } + } Thread.sleep(100); + timeout+=100; } } catch (IOException e) { @@ -474,6 +505,8 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar //execute Operation operation = compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); + + int timeout = 0; //wait until operation succeed while (true){ if(operation.getStatus().equals("DONE")){ @@ -492,7 +525,13 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar if(log.isDebugEnabled()){ log.debug("Waiting until the Add instances to target pool API call get succeeded"); } + if(OPERATION_TIMEOUT_MSILEC == timeout){ + if(log.isDebugEnabled()){ + log.debug("Operation timeout reached for delete target pool operation"); + } + } Thread.sleep(100); + timeout+=100; } } catch (IOException e) { e.printStackTrace(); @@ -518,7 +557,6 @@ public void createHealthCheck(String healthCheckName){ //wait until succeed while (true){ if(operation.getStatus().equals("DONE")){ - //log response if(log.isDebugEnabled()){ log.debug("Create health check operation Status: "+operation.getStatusMessage()); From a760aac36c4a0f7daa4410f3aaaf607763696af8 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 14:23:08 +0530 Subject: [PATCH 083/217] adding a time out for operations --- .../stratos/gce/extension/GCEOperations.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 00e67a15c8..ea367acdf1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -161,6 +161,7 @@ public void createTargetPool(String targetPoolName) { if(log.isDebugEnabled()){ log.debug("Operation timeout reached for create target pool operation"); } + return; } Thread.sleep(100); timeout+=100; @@ -205,6 +206,7 @@ public void deleteTargetPool(String targetPoolName){ if(log.isDebugEnabled()){ log.debug("Operation timeout reached for delete target pool operation"); } + return; } Thread.sleep(100); timeout+=100; @@ -260,8 +262,9 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } if(OPERATION_TIMEOUT_MSILEC == timeout){ if(log.isDebugEnabled()){ - log.debug("Operation timeout reached for delete target pool operation"); + log.debug("Operation timeout reached for create forwarding rule operation"); } + return; } Thread.sleep(100); timeout+=100; @@ -301,8 +304,9 @@ public void deleteForwardingRule(String forwardingRuleName){ } if(OPERATION_TIMEOUT_MSILEC == timeout){ if(log.isDebugEnabled()){ - log.debug("Operation timeout reached for delete target pool operation"); + log.debug("Operation timeout reached for delete forwarding rule operation"); } + return; } Thread.sleep(100); timeout+=100; @@ -527,8 +531,9 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar } if(OPERATION_TIMEOUT_MSILEC == timeout){ if(log.isDebugEnabled()){ - log.debug("Operation timeout reached for delete target pool operation"); + log.debug("Operation timeout reached for Add instances to target pool operation"); } + return; } Thread.sleep(100); timeout+=100; @@ -554,6 +559,7 @@ public void createHealthCheck(String healthCheckName){ try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID,httpHealthCheck).execute(); + int timeout = 0; //wait until succeed while (true){ if(operation.getStatus().equals("DONE")){ @@ -571,7 +577,14 @@ public void createHealthCheck(String healthCheckName){ if(log.isDebugEnabled()){ log.debug("Waiting until the create health check API call get succeeded"); } + if(OPERATION_TIMEOUT_MSILEC == timeout){ + if(log.isDebugEnabled()){ + log.debug("Operation timeout reached for create health check operation"); + } + return; + } Thread.sleep(100); + timeout+=100; } } catch (IOException e) { From 3851b67f7a68cb023b66b36bfe9244d8aa888a32 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 22:37:59 +0530 Subject: [PATCH 084/217] fix an issue in forwardingrulenamecreator method --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index ec6411e4f0..8ccf783fde 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -298,7 +298,7 @@ private String targetPoolNameCreator(String clusterID){ private String forwardingRuleNameCreator(int port,String clusterID){ String forwardingRuleName = GCEContext.getInstance().getNamePrefix() + "-" + - Integer.toString(port) + "-" + clusterID; + Integer.toString(port) + "-" + clusterID.trim().toLowerCase().replace(".","-"); //length should be les than 62 characters if(forwardingRuleName.length()>=62){ forwardingRuleName = forwardingRuleName.substring(0,62); From 219e2ef4f291c24dd02f7cc2d0cf4cde41a185b8 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 22:41:00 +0530 Subject: [PATCH 085/217] handling an exception in addInstancesToTargetPool method --- .../org/apache/stratos/gce/extension/GCEOperations.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index ea367acdf1..6881c783cc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -489,6 +489,13 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar log.info("Adding instances to target pool"); + if(instancesNamesList.isEmpty()){ + if(log.isDebugEnabled()){ + log.debug("Cannot add instances to target pool. InstancesNamesList is empty."); + } + return; + } + List instanceReferenceList = new ArrayList(); //add instance to instance reference list, we should use the instance URL From 899167c807f3197564cff07e8b8a5e487515cad4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 23:22:18 +0530 Subject: [PATCH 086/217] set a port range instead of using set of ports for forwarding rules --- .../gce/extension/GCELoadBalancer.java | 82 ++++++++++++------- .../stratos/gce/extension/GCEOperations.java | 3 +- .../extension/LoadBalancerConfiguration.java | 26 +++--- 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 8ccf783fde..c07d9713d1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -98,12 +98,34 @@ public void start() throws LoadBalancerExtensionException { loadBalancerConfiguration.getTargetPoolName()); //create forwarding rules in GCE - for (String forwardingRuleName : loadBalancerConfiguration.getForwardingRuleNames()) { //for each port - //create a forwarding rule in GCE - gceOperations.createForwardingRule(forwardingRuleName, - loadBalancerConfiguration.getTargetPoolName(), protocol); + List ipList = loadBalancerConfiguration.getIpList(); + //need to create a port range String + String portRange = ""; + //if the ip list is empty + if(ipList.isEmpty()){ + if(log.isDebugEnabled()){ + log.debug("Ip list is null"); + } + //as a temporary solution set all ports to be open + portRange = "1-65535"; + + } + //else if ip list has only one value + else if (ipList.size() == 1){ + portRange = Integer.toString(ipList.get(0))+"-"+Integer.toString(ipList.get(0)); + } + //else we have more than 1 value + else { + //first we need to take the port range. So arrange ipList in ascending order + Collections.sort(ipList); + //take the first one and last one + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size()-1)); } + //create the forwarding rule + gceOperations.createForwardingRule(loadBalancerConfiguration.getForwardingRuleName(), + loadBalancerConfiguration.getTargetPoolName(),protocol,portRange); + //set status to running loadBalancerConfiguration.setStatus(true); } @@ -129,11 +151,7 @@ public void stop() throws LoadBalancerExtensionException { if (loadBalancerConfiguration.getStatus()) { //if the load balancer is already running - //delete forwarding rules from GCE - for(String forwardingRuleName : loadBalancerConfiguration.getForwardingRuleNames()){ - gceOperations.deleteForwardingRule(forwardingRuleName); - } - + gceOperations.deleteForwardingRule(loadBalancerConfiguration.getForwardingRuleName()); //delete target pool from GCE gceOperations.deleteTargetPool(loadBalancerConfiguration.getTargetPoolName()); @@ -177,7 +195,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //check and update List updatedInstancesList = new ArrayList(); - HashMap updatedIpToForwardingRuleNameMap = new HashMap(); + List updatedIPList = new ArrayList(); for (Member member : cluster.getMembers()) { @@ -191,22 +209,18 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //checking for forwarding rules and updating for (Object port : member.getPorts()) { - int portValue = ((Port) port).getValue(); - //if not present update it - if (!updatedIpToForwardingRuleNameMap.containsKey(portValue)){ //if port is not in list - //create a new forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(portValue,cluster.getClusterId()); - //put the forwarding rule to map - updatedIpToForwardingRuleNameMap.put(portValue, forwardingRuleName); + if (!updatedIPList.contains(portValue)){ //if port is not in list + //put the forwarding rule to list + updatedIPList.add(portValue); } } } //set new forwarding rules and instances list - loadBalancerConfiguration.setIPToForwardingRuleNameMap(updatedIpToForwardingRuleNameMap); + loadBalancerConfiguration.setIpList(updatedIPList); loadBalancerConfiguration.setInstancesList(updatedInstancesList); if(loadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name @@ -215,6 +229,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio loadBalancerConfiguration.setTargetPoolName(targetPoolName); } + if (loadBalancerConfiguration.getForwardingRuleName() == null){ + //set forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); + loadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + } + if(loadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); @@ -222,11 +242,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } + } else { //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map List instancesList = new ArrayList(); - HashMap ipToForwardingRuleNameMap = new HashMap(); + List ipList = new ArrayList(); for (Member member : cluster.getMembers()) { @@ -236,24 +257,29 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //add forwarding rules(Ports to be forwarded) for (Object port : member.getPorts()) { int portValue = ((Port) port).getValue(); - if (!ipToForwardingRuleNameMap.containsKey(portValue)) { //if port is not in list - //create a new forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(portValue,cluster.getClusterId()); - //put the forwarding rule to map - ipToForwardingRuleNameMap.put(portValue,forwardingRuleName); + if (!ipList.contains(portValue)) { //if port is not in list + //put the forwarding rule to list + ipList.add(portValue); } } } LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( - cluster.getClusterId(), instancesList, ipToForwardingRuleNameMap); + cluster.getClusterId(), instancesList, ipList); + if(loadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); loadBalancerConfiguration.setTargetPoolName(targetPoolName); } + if (loadBalancerConfiguration.getForwardingRuleName() == null){ + //set forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); + loadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + } + if(loadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); @@ -296,9 +322,9 @@ private String targetPoolNameCreator(String clusterID){ return targetPoolName; } - private String forwardingRuleNameCreator(int port,String clusterID){ - String forwardingRuleName = GCEContext.getInstance().getNamePrefix() + "-" + - Integer.toString(port) + "-" + clusterID.trim().toLowerCase().replace(".","-"); + private String forwardingRuleNameCreator(String clusterID){ + String forwardingRuleName = GCEContext.getInstance().getNamePrefix() + + "-fr-" + clusterID.trim().toLowerCase().replace(".","-"); //length should be les than 62 characters if(forwardingRuleName.length()>=62){ forwardingRuleName = forwardingRuleName.substring(0,62); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 6881c783cc..b450664953 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -227,7 +227,7 @@ public void deleteTargetPool(String targetPoolName){ * @param protocol */ - public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol) { + public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol,String portRange) { //Need to get target pool resource URL TargetPool targetPool = getTargetPool(targetPoolName); @@ -236,6 +236,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam forwardingRule.setName(forwardingRuleName); forwardingRule.setTarget(targetPoolURL); forwardingRule.setIPProtocol(protocol); + forwardingRule.setPortRange(portRange); try { Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java index e05611d6fe..ad9fd5d0cb 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java @@ -36,11 +36,11 @@ public class LoadBalancerConfiguration { //A load balancer must have a target pool(set of instances) private List instancesList; - //A load balancer can have one or more forwarding rules(set of ports to be forwarded) - //we create a map to store the port IP and forwarding rule name - private HashMap ipToForwardingRuleNameMap; + //A load balancer can have one IPs to be forwarded + private List ipList; //cluster ID from stratos side private String clusterID; + private String forwardingRuleName; private String targetPoolName; private String healthCheckName; //Whether we have executed this configuration in GCE or not @@ -48,26 +48,26 @@ public class LoadBalancerConfiguration { public LoadBalancerConfiguration(String clusterID, List instancesList, - HashMap ipToForwardingRuleNameMap) { + List ipList) { this.clusterID = clusterID; this.instancesList = instancesList; - this.ipToForwardingRuleNameMap = ipToForwardingRuleNameMap; + this.ipList = ipList; } - public void setIPToForwardingRuleNameMap(HashMap ipToForwardingRuleNameMap) { - this.ipToForwardingRuleNameMap = ipToForwardingRuleNameMap; + public List getIpList() { + return ipList; } - public void addForwardingRule(int ip, String forwardingRuleName){ - this.ipToForwardingRuleNameMap.put(ip,forwardingRuleName); + public void setIpList(List ipList) { + this.ipList = ipList; } - public Set getPorts() { - return ipToForwardingRuleNameMap.keySet(); + public String getForwardingRuleName() { + return forwardingRuleName; } - public Collection getForwardingRuleNames(){ - return ipToForwardingRuleNameMap.values(); + public void setForwardingRuleName(String forwardingRuleName) { + this.forwardingRuleName = forwardingRuleName; } public List getInstancesList() { From 85c5af5757caaa33547b93b633cc6209040dfe4b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 23:52:51 +0530 Subject: [PATCH 087/217] set health checks to target pool --- .../stratos/gce/extension/GCEOperations.java | 200 +++++++++++------- 1 file changed, 124 insertions(+), 76 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index b450664953..18747fb1e2 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -64,7 +64,7 @@ public class GCEOperations { //health check private static final String HEALTH_CHECK_REQUEST_PATH = GCEContext.getInstance().getHealthCheckRequestPath(); private static final String HEALTH_CHECK_PORT = GCEContext.getInstance().getHealthCheckPort(); - private static final String HEALTH_CHECK_TIME_OUT_SEC =GCEContext.getInstance().getHealthCheckTimeOutSec(); + private static final String HEALTH_CHECK_TIME_OUT_SEC = GCEContext.getInstance().getHealthCheckTimeOutSec(); private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); /** @@ -128,10 +128,14 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep * * @param targetPoolName */ - public void createTargetPool(String targetPoolName) { + public void createTargetPool(String targetPoolName, String healthCheckName) { TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); + List httpHealthChecks = new ArrayList(); + httpHealthChecks.add(getHealthCheckURLFromName(healthCheckName)); + + targetPool.setHealthChecks(httpHealthChecks); //TODO:REMOVE try catch try { @@ -139,32 +143,32 @@ public void createTargetPool(String targetPoolName) { compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); //wait until operation succeed int timeout = 0; - while (true){ + while (true) { //todo: correct this line - if(operation.getStatus().equals("DONE")){ + if (operation.getStatus().equals("DONE")) { //log response - if(log.isDebugEnabled()){ - log.debug("Target pool creation operation Status: "+operation.getStatusMessage()); + if (log.isDebugEnabled()) { + log.debug("Target pool creation operation Status: " + operation.getStatusMessage()); } if (log.isErrorEnabled()) { - for ( Errors errors : operation.getError().getErrors()) { + for (Errors errors : operation.getError().getErrors()) { log.error("Target pool creation operation error: " + errors.getMessage()); } } return; } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Waiting until the create target pool API call get succeeded"); } - if(OPERATION_TIMEOUT_MSILEC == timeout){ - if(log.isDebugEnabled()){ + if (OPERATION_TIMEOUT_MSILEC == timeout) { + if (log.isDebugEnabled()) { log.debug("Operation timeout reached for create target pool operation"); } return; } Thread.sleep(100); - timeout+=100; + timeout += 100; } } catch (IOException e) { @@ -178,38 +182,38 @@ public void createTargetPool(String targetPoolName) { } - public void deleteTargetPool(String targetPoolName){ + public void deleteTargetPool(String targetPoolName) { try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); int timeout = 0; //wait until operation succeed - while (true){ //todo: correct this line + while (true) { //todo: correct this line - if(operation.getStatus().equals("DONE")){ + if (operation.getStatus().equals("DONE")) { //log response - if(log.isDebugEnabled()){ - log.debug("Delete target pool operation Status: "+operation.getStatusMessage()); + if (log.isDebugEnabled()) { + log.debug("Delete target pool operation Status: " + operation.getStatusMessage()); } if (log.isErrorEnabled()) { - for ( Errors errors : operation.getError().getErrors()) { + for (Errors errors : operation.getError().getErrors()) { log.error("Delete target pool operation error: " + errors.getMessage()); } } return; } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Waiting until the delete target pool API call get succeeded"); } - if(OPERATION_TIMEOUT_MSILEC == timeout){ - if(log.isDebugEnabled()){ + if (OPERATION_TIMEOUT_MSILEC == timeout) { + if (log.isDebugEnabled()) { log.debug("Operation timeout reached for delete target pool operation"); } return; } Thread.sleep(100); - timeout+=100; + timeout += 100; } } catch (IOException e) { @@ -227,7 +231,7 @@ public void deleteTargetPool(String targetPoolName){ * @param protocol */ - public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol,String portRange) { + public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol, String portRange) { //Need to get target pool resource URL TargetPool targetPool = getTargetPool(targetPoolName); @@ -243,32 +247,32 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam int timeout = 0; //wait until operation succeed - while (true){ //todo: correct this line + while (true) { //todo: correct this line - if(operation.getStatus().equals("DONE")){ + if (operation.getStatus().equals("DONE")) { //log response - if(log.isDebugEnabled()){ - log.debug("Create forwarding rule operation Status: "+operation.getStatusMessage()); + if (log.isDebugEnabled()) { + log.debug("Create forwarding rule operation Status: " + operation.getStatusMessage()); } if (log.isErrorEnabled()) { - for ( Errors errors : operation.getError().getErrors()) { + for (Errors errors : operation.getError().getErrors()) { log.error("Create forwarding rule operation error: " + errors.getMessage()); } } return; } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Waiting until the create forwarding rule API call get succeeded"); } - if(OPERATION_TIMEOUT_MSILEC == timeout){ - if(log.isDebugEnabled()){ + if (OPERATION_TIMEOUT_MSILEC == timeout) { + if (log.isDebugEnabled()) { log.debug("Operation timeout reached for create forwarding rule operation"); } return; } Thread.sleep(100); - timeout+=100; + timeout += 100; } } catch (IOException e) { @@ -278,39 +282,39 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } } - public void deleteForwardingRule(String forwardingRuleName){ + public void deleteForwardingRule(String forwardingRuleName) { try { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); int timeout = 0; //wait until operation succeed - while (true){ - if(operation.getStatus().equals("DONE")){ //todo: correct this line + while (true) { + if (operation.getStatus().equals("DONE")) { //todo: correct this line //log response - if(log.isDebugEnabled()){ - log.debug("delete forwarding rule operation Status: "+operation.getStatusMessage()); + if (log.isDebugEnabled()) { + log.debug("delete forwarding rule operation Status: " + operation.getStatusMessage()); } if (log.isErrorEnabled()) { - for ( Errors errors : operation.getError().getErrors()) { + for (Errors errors : operation.getError().getErrors()) { log.error("delete forwarding rule operation error: " + errors.getMessage()); } } return; } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Waiting until the delete forwarding rule API call get succeeded"); } - if(OPERATION_TIMEOUT_MSILEC == timeout){ - if(log.isDebugEnabled()){ + if (OPERATION_TIMEOUT_MSILEC == timeout) { + if (log.isDebugEnabled()) { log.debug("Operation timeout reached for delete forwarding rule operation"); } return; } Thread.sleep(100); - timeout+=100; + timeout += 100; } } catch (IOException e) { @@ -405,7 +409,6 @@ private void addInstancesToTargetPool(String targetPoolName, List instancesNamesList, String targetPoolName){ + public void addInstancesToTargetPool(List instancesNamesList, String targetPoolName) { log.info("Adding instances to target pool"); - if(instancesNamesList.isEmpty()){ - if(log.isDebugEnabled()){ + if (instancesNamesList.isEmpty()) { + if (log.isDebugEnabled()) { log.debug("Cannot add instances to target pool. InstancesNamesList is empty."); } return; @@ -500,7 +503,7 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar List instanceReferenceList = new ArrayList(); //add instance to instance reference list, we should use the instance URL - for(String instanceName : instancesNamesList ){ //for all instances + for (String instanceName : instancesNamesList) { //for all instances instanceReferenceList.add(new InstanceReference(). setInstance(getInstanceURLFromName(instanceName))); @@ -520,31 +523,31 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar int timeout = 0; //wait until operation succeed - while (true){ - if(operation.getStatus().equals("DONE")){ + while (true) { + if (operation.getStatus().equals("DONE")) { //log response - if(log.isDebugEnabled()){ - log.debug("Add instances to target pool operation Status: "+operation.getStatusMessage()); + if (log.isDebugEnabled()) { + log.debug("Add instances to target pool operation Status: " + operation.getStatusMessage()); } if (log.isErrorEnabled()) { - for ( Errors errors : operation.getError().getErrors()) { + for (Errors errors : operation.getError().getErrors()) { log.error("Add instances to target pool operation error: " + errors.getMessage()); } } return; } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Waiting until the Add instances to target pool API call get succeeded"); } - if(OPERATION_TIMEOUT_MSILEC == timeout){ - if(log.isDebugEnabled()){ + if (OPERATION_TIMEOUT_MSILEC == timeout) { + if (log.isDebugEnabled()) { log.debug("Operation timeout reached for Add instances to target pool operation"); } return; } Thread.sleep(100); - timeout+=100; + timeout += 100; } } catch (IOException e) { e.printStackTrace(); @@ -553,9 +556,9 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar } } - public void createHealthCheck(String healthCheckName){ + public void createHealthCheck(String healthCheckName) { - if(!isHealthCheckExists(healthCheckName)){//if the health check is not present already + if (!isHealthCheckExists(healthCheckName)) {//if the health check is not present already HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); httpHealthCheck.setName(healthCheckName); @@ -565,34 +568,34 @@ public void createHealthCheck(String healthCheckName){ httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { - Operation operation = compute.httpHealthChecks().insert(PROJECT_ID,httpHealthCheck).execute(); + Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); int timeout = 0; //wait until succeed - while (true){ - if(operation.getStatus().equals("DONE")){ + while (true) { + if (operation.getStatus().equals("DONE")) { //log response - if(log.isDebugEnabled()){ - log.debug("Create health check operation Status: "+operation.getStatusMessage()); + if (log.isDebugEnabled()) { + log.debug("Create health check operation Status: " + operation.getStatusMessage()); } if (log.isErrorEnabled()) { - for ( Errors errors : operation.getError().getErrors()) { + for (Errors errors : operation.getError().getErrors()) { log.error("Create create health check operation error: " + errors.getMessage()); } } return; } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Waiting until the create health check API call get succeeded"); } - if(OPERATION_TIMEOUT_MSILEC == timeout){ - if(log.isDebugEnabled()){ + if (OPERATION_TIMEOUT_MSILEC == timeout) { + if (log.isDebugEnabled()) { log.debug("Operation timeout reached for create health check operation"); } return; } Thread.sleep(100); - timeout+=100; + timeout += 100; } } catch (IOException e) { @@ -601,20 +604,18 @@ public void createHealthCheck(String healthCheckName){ e.printStackTrace(); } - } - - else { - if(log.isDebugEnabled()) { + } else { + if (log.isDebugEnabled()) { log.debug("Health check is already exist: " + healthCheckName); } } } - public boolean isHealthCheckExists(String healthCheckName){ + public boolean isHealthCheckExists(String healthCheckName) { try { - HttpHealthCheckList httpHealthCheckList = compute.httpHealthChecks().list(PROJECT_ID).execute(); - for(HttpHealthCheck httpHealthCheck: httpHealthCheckList.getItems()){ - if(httpHealthCheck.getName().equals(healthCheckName)){ + HttpHealthCheckList httpHealthCheckList = compute.httpHealthChecks().list(PROJECT_ID).execute(); + for (HttpHealthCheck httpHealthCheck : httpHealthCheckList.getItems()) { + if (httpHealthCheck.getName().equals(healthCheckName)) { return true; } } @@ -624,6 +625,53 @@ public boolean isHealthCheckExists(String healthCheckName){ return false; } + public HttpHealthCheck getHealthCheckFromName(String healthCheckName) { + + HttpHealthCheckList healthCheckList = getHealthCheckList(); + for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { + if (httpHealthCheck.getName().equals(healthCheckName)) { + //healthcheck is available + return httpHealthCheck; + } + } + return null; + } + + public static String getHealthCheckURLFromName(String healthCheckName) { + + String healthCheckURL; + + //check whether the given instance is available + HttpHealthCheckList healthCheckList = getHealthCheckList(); + for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { + if (httpHealthCheck.getName().equals(healthCheckName)) { + //instance is available + //getInstance URL + healthCheckURL = httpHealthCheck.getSelfLink(); + return healthCheckURL; + } + } + return null; + + } + + public static HttpHealthCheckList getHealthCheckList() { + try { + Compute.HttpHealthChecks.List healthChecks = compute.httpHealthChecks().list(PROJECT_ID); + HttpHealthCheckList healthCheckList = healthChecks.execute(); + if (healthCheckList.getItems() == null) { + log.info("No health check found for specified project"); + return null; + } else { + return healthCheckList; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + /** * this is a sample method using for testing purposes */ From e2bcec6a8815ec7183ea54404625022541d303af Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 9 Jun 2015 23:53:17 +0530 Subject: [PATCH 088/217] set health checks to target pool --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index c07d9713d1..14e51a6c21 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -91,7 +91,8 @@ public void start() throws LoadBalancerExtensionException { //todo: set firewall rule for health check //crate a target pool in GCE - gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName()); + gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName(), + loadBalancerConfiguration.getHealthCheckName()); //add instances to target pool gceOperations.addInstancesToTargetPool(loadBalancerConfiguration.getInstancesList(), From adc8f63c2ecaec6a23d49ae172b3eef5e785d87a Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 01:18:28 +0530 Subject: [PATCH 089/217] set health checks to target pool --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 18747fb1e2..9d50494c3f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -133,8 +133,6 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); List httpHealthChecks = new ArrayList(); - httpHealthChecks.add(getHealthCheckURLFromName(healthCheckName)); - targetPool.setHealthChecks(httpHealthChecks); //TODO:REMOVE try catch @@ -595,6 +593,7 @@ public void createHealthCheck(String healthCheckName) { return; } Thread.sleep(100); + timeout += 100; } From 104c7a1c46ed4092270251bee84e2d3c40270947 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 01:20:23 +0530 Subject: [PATCH 090/217] set health checks to target pool --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 9d50494c3f..b908a9290c 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -133,6 +133,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); List httpHealthChecks = new ArrayList(); + httpHealthChecks.add(getHealthCheckURLFromName(healthCheckName)); targetPool.setHealthChecks(httpHealthChecks); //TODO:REMOVE try catch From 599aecbfb9e1287be79cc288262142b22a4aee2b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 16:29:05 +0530 Subject: [PATCH 091/217] set health checks to target pool --- .../load/balancer/common/domain/Member.java | 9 +++ .../gce/extension/GCELoadBalancer.java | 80 +++++++++---------- ...java => GCELoadBalancerConfiguration.java} | 6 +- 3 files changed, 51 insertions(+), 44 deletions(-) rename extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/{LoadBalancerConfiguration.java => GCELoadBalancerConfiguration.java} (93%) diff --git a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java index 953dabd980..975c9c0f63 100644 --- a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java +++ b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java @@ -33,6 +33,7 @@ public class Member { private String memberId; private String hostName; private Map portMap; + private String instanceName; public Member(String serviceName, String clusterId, String memberId, String hostName) { this.serviceName = serviceName; @@ -86,4 +87,12 @@ public Collection getPorts() { public String getServiceName() { return serviceName; } + + public String getInstanceName() { + return instanceName; + } + + public void setInstanceName(String instanceName) { + this.instanceName = instanceName; + } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 14e51a6c21..84d29d565b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,7 +19,6 @@ package org.apache.stratos.gce.extension; -import com.google.api.services.compute.model.TargetPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.common.domain.*; @@ -37,12 +36,12 @@ public class GCELoadBalancer implements LoadBalancer { private GCEOperations gceOperations; /** - * We create one load balancer per cluster(stratos side). - * A Load balancer has one target pool and set of forwarding rules + * We have one configuration for cluster + * A Load balancer has one target pool forwarding rule and a health check * This hash map is used to hold cluster IDs and corresponding Load balancer configuration * So one cluster will have one loadBalancerConfiguration object */ - private HashMap clusterToLoadBalancerConfigurationMap; + private HashMap clusterToLoadBalancerConfigurationMap; //protocol should be TCP or UDP private String protocol = "TCP"; @@ -50,7 +49,7 @@ public class GCELoadBalancer implements LoadBalancer { public GCELoadBalancer() { try { gceOperations = new GCEOperations(); - clusterToLoadBalancerConfigurationMap = new HashMap(); + clusterToLoadBalancerConfigurationMap = new HashMap(); } catch (LoadBalancerExtensionException e) { log.error(e); @@ -79,27 +78,26 @@ public void start() throws LoadBalancerExtensionException { Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry)iterator.next(); String clusterID = ((String) clusterIDLoadBalancerConfigurationPair.getKey()); - LoadBalancerConfiguration loadBalancerConfiguration = - ((LoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - if(!loadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running + if(!GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running //create a health check - gceOperations.createHealthCheck(loadBalancerConfiguration.getHealthCheckName()); + gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); - //todo: add health check to target pool //todo: set firewall rule for health check //crate a target pool in GCE - gceOperations.createTargetPool(loadBalancerConfiguration.getTargetPoolName(), - loadBalancerConfiguration.getHealthCheckName()); + gceOperations.createTargetPool(GCELoadBalancerConfiguration.getTargetPoolName(), + GCELoadBalancerConfiguration.getHealthCheckName()); //add instances to target pool - gceOperations.addInstancesToTargetPool(loadBalancerConfiguration.getInstancesList(), - loadBalancerConfiguration.getTargetPoolName()); + gceOperations.addInstancesToTargetPool(GCELoadBalancerConfiguration.getInstancesList(), + GCELoadBalancerConfiguration.getTargetPoolName()); //create forwarding rules in GCE - List ipList = loadBalancerConfiguration.getIpList(); + List ipList = GCELoadBalancerConfiguration.getIpList(); //need to create a port range String String portRange = ""; //if the ip list is empty @@ -124,11 +122,11 @@ else if (ipList.size() == 1){ } //create the forwarding rule - gceOperations.createForwardingRule(loadBalancerConfiguration.getForwardingRuleName(), - loadBalancerConfiguration.getTargetPoolName(),protocol,portRange); + gceOperations.createForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName(), + GCELoadBalancerConfiguration.getTargetPoolName(),protocol,portRange); //set status to running - loadBalancerConfiguration.setStatus(true); + GCELoadBalancerConfiguration.setStatus(true); } } @@ -147,14 +145,14 @@ public void stop() throws LoadBalancerExtensionException { while (iterator.hasNext()) { //for each Load balancer configuration Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - LoadBalancerConfiguration loadBalancerConfiguration = - ((LoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - if (loadBalancerConfiguration.getStatus()) { //if the load balancer is already running + if (GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is already running - gceOperations.deleteForwardingRule(loadBalancerConfiguration.getForwardingRuleName()); + gceOperations.deleteForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName()); //delete target pool from GCE - gceOperations.deleteTargetPool(loadBalancerConfiguration.getTargetPoolName()); + gceOperations.deleteTargetPool(GCELoadBalancerConfiguration.getTargetPoolName()); } } @@ -191,7 +189,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //It has a loadBalancer configured. Take it and update it as the given topology. //get load balancer configuration - LoadBalancerConfiguration loadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. get(cluster.getClusterId()); //check and update @@ -221,31 +219,31 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } //set new forwarding rules and instances list - loadBalancerConfiguration.setIpList(updatedIPList); - loadBalancerConfiguration.setInstancesList(updatedInstancesList); + GCELoadBalancerConfiguration.setIpList(updatedIPList); + GCELoadBalancerConfiguration.setInstancesList(updatedInstancesList); - if(loadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name + if(GCELoadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - loadBalancerConfiguration.setTargetPoolName(targetPoolName); + GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); } - if (loadBalancerConfiguration.getForwardingRuleName() == null){ + if (GCELoadBalancerConfiguration.getForwardingRuleName() == null){ //set forwarding rule name String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - loadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); } - if(loadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name + if(GCELoadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - loadBalancerConfiguration.setHealthCheckName(healthCheckName); + GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); } } else { - //doesn't have a loadBalancerConfiguration object. So crate a new one and add to hash map + //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map List instancesList = new ArrayList(); List ipList = new ArrayList(); @@ -266,28 +264,28 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } - LoadBalancerConfiguration loadBalancerConfiguration = new LoadBalancerConfiguration( + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = new GCELoadBalancerConfiguration( cluster.getClusterId(), instancesList, ipList); - if(loadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name + if(GCELoadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - loadBalancerConfiguration.setTargetPoolName(targetPoolName); + GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); } - if (loadBalancerConfiguration.getForwardingRuleName() == null){ + if (GCELoadBalancerConfiguration.getForwardingRuleName() == null){ //set forwarding rule name String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - loadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); } - if(loadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name + if(GCELoadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - loadBalancerConfiguration.setHealthCheckName(healthCheckName); + GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); } - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), loadBalancerConfiguration); + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java similarity index 93% rename from extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java rename to extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java index ad9fd5d0cb..2fafa626ba 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/LoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java @@ -31,7 +31,7 @@ * This class is used to hold the configuration for a load balancer * Each cluster will have one object from this class */ -public class LoadBalancerConfiguration { +public class GCELoadBalancerConfiguration { //A load balancer must have a target pool(set of instances) @@ -47,8 +47,8 @@ public class LoadBalancerConfiguration { private boolean isRunning = false; - public LoadBalancerConfiguration(String clusterID, List instancesList, - List ipList) { + public GCELoadBalancerConfiguration(String clusterID, List instancesList, + List ipList) { this.clusterID = clusterID; this.instancesList = instancesList; this.ipList = ipList; From 6df323bede597b980565bee21a8a8d42bf09cbe7 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 21:32:57 +0530 Subject: [PATCH 092/217] set health checks to target pool --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 84d29d565b..53d6462d25 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -36,7 +36,7 @@ public class GCELoadBalancer implements LoadBalancer { private GCEOperations gceOperations; /** - * We have one configuration for cluster + * We have one configuration per cluster * A Load balancer has one target pool forwarding rule and a health check * This hash map is used to hold cluster IDs and corresponding Load balancer configuration * So one cluster will have one loadBalancerConfiguration object From 666b9444d6e4581a2026de80250caea1e6276f9f Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 22:29:45 +0530 Subject: [PATCH 093/217] fixing bug in operation completion --- .../load/balancer/common/domain/Member.java | 8 - .../stratos/gce/extension/GCEOperations.java | 197 ++---------------- 2 files changed, 16 insertions(+), 189 deletions(-) diff --git a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java index 975c9c0f63..ec40844b58 100644 --- a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java +++ b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java @@ -33,7 +33,6 @@ public class Member { private String memberId; private String hostName; private Map portMap; - private String instanceName; public Member(String serviceName, String clusterId, String memberId, String hostName) { this.serviceName = serviceName; @@ -88,11 +87,4 @@ public String getServiceName() { return serviceName; } - public String getInstanceName() { - return instanceName; - } - - public void setInstanceName(String instanceName) { - this.instanceName = instanceName; - } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index b908a9290c..d0f20a2376 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -140,43 +140,12 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { try { Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); - //wait until operation succeed - int timeout = 0; - while (true) { - //todo: correct this line - if (operation.getStatus().equals("DONE")) { - - //log response - if (log.isDebugEnabled()) { - log.debug("Target pool creation operation Status: " + operation.getStatusMessage()); - } - if (log.isErrorEnabled()) { - for (Errors errors : operation.getError().getErrors()) { - log.error("Target pool creation operation error: " + errors.getMessage()); - } - } - return; - } - if (log.isDebugEnabled()) { - log.debug("Waiting until the create target pool API call get succeeded"); - } - if (OPERATION_TIMEOUT_MSILEC == timeout) { - if (log.isDebugEnabled()) { - log.debug("Operation timeout reached for create target pool operation"); - } - return; - } - Thread.sleep(100); - timeout += 100; - } } catch (IOException e) { if (log.isErrorEnabled()) { log.error("failed to create target pool: " + targetPoolName); } e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); } } @@ -186,39 +155,10 @@ public void deleteTargetPool(String targetPoolName) { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); int timeout = 0; - //wait until operation succeed - while (true) { //todo: correct this line - - if (operation.getStatus().equals("DONE")) { - - //log response - if (log.isDebugEnabled()) { - log.debug("Delete target pool operation Status: " + operation.getStatusMessage()); - } - if (log.isErrorEnabled()) { - for (Errors errors : operation.getError().getErrors()) { - log.error("Delete target pool operation error: " + errors.getMessage()); - } - } - return; - } - if (log.isDebugEnabled()) { - log.debug("Waiting until the delete target pool API call get succeeded"); - } - if (OPERATION_TIMEOUT_MSILEC == timeout) { - if (log.isDebugEnabled()) { - log.debug("Operation timeout reached for delete target pool operation"); - } - return; - } - Thread.sleep(100); - timeout += 100; - } } catch (IOException e) { e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); + } } @@ -245,39 +185,9 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam int timeout = 0; - //wait until operation succeed - while (true) { //todo: correct this line - - if (operation.getStatus().equals("DONE")) { - - //log response - if (log.isDebugEnabled()) { - log.debug("Create forwarding rule operation Status: " + operation.getStatusMessage()); - } - if (log.isErrorEnabled()) { - for (Errors errors : operation.getError().getErrors()) { - log.error("Create forwarding rule operation error: " + errors.getMessage()); - } - } - return; - } - if (log.isDebugEnabled()) { - log.debug("Waiting until the create forwarding rule API call get succeeded"); - } - if (OPERATION_TIMEOUT_MSILEC == timeout) { - if (log.isDebugEnabled()) { - log.debug("Operation timeout reached for create forwarding rule operation"); - } - return; - } - Thread.sleep(100); - timeout += 100; - } } catch (IOException e) { e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); } } @@ -286,40 +196,9 @@ public void deleteForwardingRule(String forwardingRuleName) { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); - int timeout = 0; - //wait until operation succeed - while (true) { - if (operation.getStatus().equals("DONE")) { //todo: correct this line - - - //log response - if (log.isDebugEnabled()) { - log.debug("delete forwarding rule operation Status: " + operation.getStatusMessage()); - } - if (log.isErrorEnabled()) { - for (Errors errors : operation.getError().getErrors()) { - log.error("delete forwarding rule operation error: " + errors.getMessage()); - } - } - return; - } - if (log.isDebugEnabled()) { - log.debug("Waiting until the delete forwarding rule API call get succeeded"); - } - if (OPERATION_TIMEOUT_MSILEC == timeout) { - if (log.isDebugEnabled()) { - log.debug("Operation timeout reached for delete forwarding rule operation"); - } - return; - } - Thread.sleep(100); - timeout += 100; - } } catch (IOException e) { e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); } } @@ -522,36 +401,10 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar int timeout = 0; //wait until operation succeed - while (true) { - if (operation.getStatus().equals("DONE")) { - - //log response - if (log.isDebugEnabled()) { - log.debug("Add instances to target pool operation Status: " + operation.getStatusMessage()); - } - if (log.isErrorEnabled()) { - for (Errors errors : operation.getError().getErrors()) { - log.error("Add instances to target pool operation error: " + errors.getMessage()); - } - } - return; - } - if (log.isDebugEnabled()) { - log.debug("Waiting until the Add instances to target pool API call get succeeded"); - } - if (OPERATION_TIMEOUT_MSILEC == timeout) { - if (log.isDebugEnabled()) { - log.debug("Operation timeout reached for Add instances to target pool operation"); - } - return; - } - Thread.sleep(100); - timeout += 100; - } + + } catch (IOException e) { e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); } } @@ -568,40 +421,10 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); - - int timeout = 0; - //wait until succeed - while (true) { - if (operation.getStatus().equals("DONE")) { - //log response - if (log.isDebugEnabled()) { - log.debug("Create health check operation Status: " + operation.getStatusMessage()); - } - if (log.isErrorEnabled()) { - for (Errors errors : operation.getError().getErrors()) { - log.error("Create create health check operation error: " + errors.getMessage()); - } - } - return; - } - if (log.isDebugEnabled()) { - log.debug("Waiting until the create health check API call get succeeded"); - } - if (OPERATION_TIMEOUT_MSILEC == timeout) { - if (log.isDebugEnabled()) { - log.debug("Operation timeout reached for create health check operation"); - } - return; - } - Thread.sleep(100); - - timeout += 100; - } + waitForOperationCompletion(operation.getSelfLink()); } catch (IOException e) { e.printStackTrace(); - } catch (InterruptedException e) { - e.printStackTrace(); } } else { @@ -671,6 +494,18 @@ public static HttpHealthCheckList getHealthCheckList() { return null; } + private void waitForOperationCompletion(String operationSelfLink){ + try { + while (compute.regionOperations().get(PROJECT_ID,REGION_NAME,operationSelfLink).execute(). + getStatus().equals("DONE")){ + Thread.sleep(1000); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } /** * this is a sample method using for testing purposes From 76af30cd99d024dcc42e46878e10ed2fd801da27 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 22:56:23 +0530 Subject: [PATCH 094/217] fixing bug in operation completion --- .../org/apache/stratos/gce/extension/GCEOperations.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index d0f20a2376..c15f1e7088 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -421,7 +421,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); - waitForOperationCompletion(operation.getSelfLink()); + waitForOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); @@ -494,9 +494,9 @@ public static HttpHealthCheckList getHealthCheckList() { return null; } - private void waitForOperationCompletion(String operationSelfLink){ + private void waitForOperationCompletion(String operationName){ try { - while (compute.regionOperations().get(PROJECT_ID,REGION_NAME,operationSelfLink).execute(). + while (compute.regionOperations().get(PROJECT_ID,REGION_NAME,operationName).execute(). getStatus().equals("DONE")){ Thread.sleep(1000); } From a86f624776e4506949b900ad43a510a583eb53cb Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 23:11:11 +0530 Subject: [PATCH 095/217] fixing bug in operation completion --- .../apache/stratos/gce/extension/GCEOperations.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index c15f1e7088..0105e2ce98 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -140,6 +140,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { try { Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); + waitForOperationCompletion(operation.getName()); } catch (IOException e) { if (log.isErrorEnabled()) { @@ -153,6 +154,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { public void deleteTargetPool(String targetPoolName) { try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); + waitForOperationCompletion(operation.getName()); int timeout = 0; @@ -182,6 +184,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam forwardingRule.setPortRange(portRange); try { Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); + waitForOperationCompletion(operation.getName()); int timeout = 0; @@ -196,6 +199,7 @@ public void deleteForwardingRule(String forwardingRuleName) { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); + waitForOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); @@ -304,6 +308,7 @@ public void removeInstancesFromTargetPool(String targetPoolName, List instancesNamesList, String tar Operation operation = compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); - int timeout = 0; - //wait until operation succeed + waitForOperationCompletion(operation.getName()); } catch (IOException e) { @@ -496,7 +500,7 @@ public static HttpHealthCheckList getHealthCheckList() { private void waitForOperationCompletion(String operationName){ try { - while (compute.regionOperations().get(PROJECT_ID,REGION_NAME,operationName).execute(). + while (compute.regionOperations().get(PROJECT_ID, REGION_NAME,operationName).execute(). getStatus().equals("DONE")){ Thread.sleep(1000); } From 5aec905a53808a1b5cdd31428ad0d8d3fa9ce2a3 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 23:19:36 +0530 Subject: [PATCH 096/217] fixing bug in operation completion --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 0105e2ce98..f8b4df0b16 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -500,7 +500,7 @@ public static HttpHealthCheckList getHealthCheckList() { private void waitForOperationCompletion(String operationName){ try { - while (compute.regionOperations().get(PROJECT_ID, REGION_NAME,operationName).execute(). + while (compute.globalOperations().get(PROJECT_ID,operationName).execute(). getStatus().equals("DONE")){ Thread.sleep(1000); } From 75667c53f4f837e1c7f631f9f36acaa76c87b977 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 23:41:06 +0530 Subject: [PATCH 097/217] fixing bug in operation completion --- .../stratos/gce/extension/GCEOperations.java | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index f8b4df0b16..4821746914 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -140,7 +140,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { try { Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); - waitForOperationCompletion(operation.getName()); + waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { if (log.isErrorEnabled()) { @@ -154,7 +154,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { public void deleteTargetPool(String targetPoolName) { try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); - waitForOperationCompletion(operation.getName()); + waitForGlobalOperationCompletion(operation.getName()); int timeout = 0; @@ -184,7 +184,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam forwardingRule.setPortRange(portRange); try { Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); - waitForOperationCompletion(operation.getName()); + waitForGlobalOperationCompletion(operation.getName()); int timeout = 0; @@ -199,7 +199,7 @@ public void deleteForwardingRule(String forwardingRuleName) { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); - waitForOperationCompletion(operation.getName()); + waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); @@ -404,7 +404,7 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar Operation operation = compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); - waitForOperationCompletion(operation.getName()); + waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { @@ -425,7 +425,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); - waitForOperationCompletion(operation.getName()); + waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); @@ -498,7 +498,7 @@ public static HttpHealthCheckList getHealthCheckList() { return null; } - private void waitForOperationCompletion(String operationName){ + private void waitForGlobalOperationCompletion(String operationName){ try { while (compute.globalOperations().get(PROJECT_ID,operationName).execute(). getStatus().equals("DONE")){ @@ -511,6 +511,32 @@ private void waitForOperationCompletion(String operationName){ } } + private void waitForRegionOperationCompletion(String operationName){ + try { + while (compute.regionOperations().get(PROJECT_ID,REGION_NAME,operationName).execute(). + getStatus().equals("DONE")){ + Thread.sleep(1000); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + private void waitForZoneOperationCompletion(String operationName){ + try { + while (compute.zoneOperations().get(PROJECT_ID,ZONE_NAME,operationName).execute(). + getStatus().equals("DONE")){ + Thread.sleep(1000); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + /** * this is a sample method using for testing purposes */ From 5aff39d1243299f3e0c37ec063445576f0ecec0a Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 23:44:36 +0530 Subject: [PATCH 098/217] fixing bug in operation completion --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 4821746914..6df169a92b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -425,7 +425,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); - waitForGlobalOperationCompletion(operation.getName()); + waitForRegionOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); From b70b2ef8cf06b2ec6ad6907f8f657818956eb0ff Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 10 Jun 2015 23:49:14 +0530 Subject: [PATCH 099/217] fixing bug in operation completion --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 6df169a92b..4821746914 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -425,7 +425,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); - waitForRegionOperationCompletion(operation.getName()); + waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); From 5ac360d07ea7bccc64c5999c2090d674a6b166c2 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 00:16:53 +0530 Subject: [PATCH 100/217] fixing bug in operation completion --- .../org/apache/stratos/gce/extension/GCEOperations.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 4821746914..0bc870400f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -500,8 +500,11 @@ public static HttpHealthCheckList getHealthCheckList() { private void waitForGlobalOperationCompletion(String operationName){ try { - while (compute.globalOperations().get(PROJECT_ID,operationName).execute(). - getStatus().equals("DONE")){ + while (true){ + Operation operation = compute.globalOperations().get(PROJECT_ID,operationName).execute(); + if (operation.getStatus().equals("DONE")){ + return; + } Thread.sleep(1000); } } catch (IOException e) { @@ -513,7 +516,7 @@ private void waitForGlobalOperationCompletion(String operationName){ private void waitForRegionOperationCompletion(String operationName){ try { - while (compute.regionOperations().get(PROJECT_ID,REGION_NAME,operationName).execute(). + while (compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(). getStatus().equals("DONE")){ Thread.sleep(1000); } From 2da76de3a5eebbb48a29df1c747e4df66bf30abe Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 00:20:09 +0530 Subject: [PATCH 101/217] fixing bug in operation completion --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 0bc870400f..a15cfed8f1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -500,6 +500,7 @@ public static HttpHealthCheckList getHealthCheckList() { private void waitForGlobalOperationCompletion(String operationName){ try { + Thread.sleep(2000); while (true){ Operation operation = compute.globalOperations().get(PROJECT_ID,operationName).execute(); if (operation.getStatus().equals("DONE")){ From 0656d912c58df4ddf95f4e296e25b678073891e5 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 00:25:10 +0530 Subject: [PATCH 102/217] fixing bug in operation completion --- .../org/apache/stratos/gce/extension/GCEOperations.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index a15cfed8f1..54c4671b41 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -140,7 +140,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { try { Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); - waitForGlobalOperationCompletion(operation.getName()); + waitForRegionOperationCompletion(operation.getName()); } catch (IOException e) { if (log.isErrorEnabled()) { @@ -154,7 +154,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { public void deleteTargetPool(String targetPoolName) { try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); - waitForGlobalOperationCompletion(operation.getName()); + waitForRegionOperationCompletion(operation.getName()); int timeout = 0; @@ -184,7 +184,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam forwardingRule.setPortRange(portRange); try { Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); - waitForGlobalOperationCompletion(operation.getName()); + waitForRegionOperationCompletion(operation.getName()); int timeout = 0; @@ -404,7 +404,7 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar Operation operation = compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); - waitForGlobalOperationCompletion(operation.getName()); + waitForRegionOperationCompletion(operation.getName()); } catch (IOException e) { @@ -517,6 +517,7 @@ private void waitForGlobalOperationCompletion(String operationName){ private void waitForRegionOperationCompletion(String operationName){ try { + Thread.sleep(2000); while (compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(). getStatus().equals("DONE")){ Thread.sleep(1000); From 7554133c1271951ff1460287826386f972e025bc Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 00:32:49 +0530 Subject: [PATCH 103/217] fixing bug in operation completion --- .../stratos/gce/extension/GCEOperations.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 54c4671b41..5886b4be68 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -518,8 +518,11 @@ private void waitForGlobalOperationCompletion(String operationName){ private void waitForRegionOperationCompletion(String operationName){ try { Thread.sleep(2000); - while (compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(). - getStatus().equals("DONE")){ + while (true){ + Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); + if(operation.getStatus().equals("DONE")){ + return; + } Thread.sleep(1000); } } catch (IOException e) { @@ -531,8 +534,11 @@ private void waitForRegionOperationCompletion(String operationName){ private void waitForZoneOperationCompletion(String operationName){ try { - while (compute.zoneOperations().get(PROJECT_ID,ZONE_NAME,operationName).execute(). - getStatus().equals("DONE")){ + while (true){ + Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); + if (operation.getStatus().equals("DONE")){ + return; + } Thread.sleep(1000); } } catch (IOException e) { From f47e19cf4bc761fa40b9ee2cae2dc387f76bf5bd Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 18:16:42 +0530 Subject: [PATCH 104/217] fixing bug in operation completion --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 5886b4be68..93712f8f66 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -520,6 +520,7 @@ private void waitForRegionOperationCompletion(String operationName){ Thread.sleep(2000); while (true){ Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); + if(operation.getStatus().equals("DONE")){ return; } From dd351fa131a64690439e3be7ae3194071bfe46e5 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 22:21:03 +0530 Subject: [PATCH 105/217] fixing bug in operation complete --- .../controller/messaging/topology/TopologyBuilder.java | 1 + .../stratos/load/balancer/common/domain/Member.java | 9 +++++++++ .../LoadBalancerCommonTopologyEventReceiver.java | 3 +++ .../stratos/messaging/domain/topology/Member.java | 10 ++++++++++ 4 files changed, 23 insertions(+) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 8940ed029d..9f75582084 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -388,6 +388,7 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setStatus(MemberStatus.Created); member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); + member.setInstanceId(memberContext.getInstanceId()); cluster.addMember(member); TopologyManager.updateTopology(topology); } finally { diff --git a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java index ec40844b58..2019c76654 100644 --- a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java +++ b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/domain/Member.java @@ -32,6 +32,8 @@ public class Member { private String clusterId; private String memberId; private String hostName; + //instance id provided by IaaS in order to use in GCE load balancer + private String instanceId; private Map portMap; public Member(String serviceName, String clusterId, String memberId, String hostName) { @@ -87,4 +89,11 @@ public String getServiceName() { return serviceName; } + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } } diff --git a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java index ba3896720c..193c636008 100644 --- a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java +++ b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java @@ -445,6 +445,9 @@ private org.apache.stratos.load.balancer.common.domain.Member transformMember(Me member.addPort(transformPort(port)); } } + if(messagingMember.getInstanceId() != null){ + member.setInstanceId(messagingMember.getInstanceId()); + } return member; } } diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java index 2242075681..0ca6deb88c 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java @@ -60,6 +60,8 @@ public class Member implements Serializable, LifeCycleStateTransitionBehavior memberStateManager; private LoadBalancingIPType loadBalancingIPType; + //instance id provided by IaaS(In order to use in GCE Load balancer) + private String instanceId; public Member(String serviceName, String clusterId, String memberId, String clusterInstanceId, String networkPartitionId, String partitionId, LoadBalancingIPType loadBalancingIPType, @@ -209,6 +211,14 @@ public LoadBalancingIPType getLoadBalancingIPType() { return loadBalancingIPType; } + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } + @Override public String toString() { return "Member [serviceName=" + getServiceName() From acea041fdaabb0b33b5756a15a69d01ff1e691ab Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 22:41:52 +0530 Subject: [PATCH 106/217] printing topology --- extensions/load-balancer/gce-extension/pom.xml | 4 ++-- .../apache/stratos/gce/extension/GCELoadBalancer.java | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index 57cc3dbbd1..5eb73c4d18 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -83,13 +83,13 @@ v1-rev27-1.19.0 - + 1.19.0 diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 53d6462d25..407d0436a4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,6 +19,11 @@ package org.apache.stratos.gce.extension; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.reflection.FieldDictionary; +import com.thoughtworks.xstream.converters.reflection.ImmutableFieldKeySorter; +import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider; +import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.common.domain.*; @@ -172,11 +177,11 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Configuring Load balancer "); //printing topology value as a xml for testing purposes - /* XStream xstream = new XStream(new Sun14ReflectionProvider( + XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver("utf-8")); log.info(xstream.toXML(topology)); - */ + for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster From 91c6f8222d34a9d4eb09d37f020fdc7bdb51744a Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 23:19:32 +0530 Subject: [PATCH 107/217] printing topology --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 407d0436a4..9a8ea7a6b9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -211,6 +211,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } */ + log.info("===============Member instance id:============= " + member.getInstanceId()); //checking for forwarding rules and updating for (Object port : member.getPorts()) { int portValue = ((Port) port).getValue(); From b8629c068fb3a360fa6dd6cab557ada0308fd6dc Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 11 Jun 2015 23:25:57 +0530 Subject: [PATCH 108/217] printing topology --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 9a8ea7a6b9..6dec7b2383 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -211,7 +211,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } */ - log.info("===============Member instance id:============= " + member.getInstanceId()); + //checking for forwarding rules and updating for (Object port : member.getPorts()) { int portValue = ((Port) port).getValue(); @@ -258,6 +258,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //TODO:set instances(members) to instances list //instancesList.add(member.getMemberName); + log.info("===============Member instance id:============= " + member.getInstanceId()); //add forwarding rules(Ports to be forwarded) for (Object port : member.getPorts()) { From ca31ee7aed9872fca00a75b0e7dc2864329a3006 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 15 Jun 2015 11:16:03 +0530 Subject: [PATCH 109/217] testing member context --- .../stratos/cloud/controller/domain/InstanceContext.java | 9 +++++++++ .../services/impl/CloudControllerServiceImpl.java | 1 + .../apache/stratos/gce/extension/GCELoadBalancer.java | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java index 797c66549a..bacd3e7418 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java @@ -36,6 +36,8 @@ public class InstanceContext { private Properties properties; private boolean isVolumeRequired; private Volume[] volumes; + //instance id provided by IaaS provider + private String instanceId; public String getClusterId() { return clusterId; @@ -117,4 +119,11 @@ public void setVolumes(Volume[] volumes) { this.volumes = ArrayUtils.clone(volumes); } + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java index e6f0c044d3..28e9b42280 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java @@ -485,6 +485,7 @@ private MemberContext createMemberContext(String applicationId, String cartridge memberContext.setLoadBalancingIPType(loadBalancingIPType); memberContext.setInitTime(System.currentTimeMillis()); memberContext.setObsoleteExpiryTime(instanceContext.getObsoleteExpiryTime()); +// memberContext.setInstanceId(instanceContext.get); return memberContext; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 6dec7b2383..236f8ce171 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -26,6 +26,8 @@ import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.cloud.controller.context.CloudControllerContext; +import org.apache.stratos.cloud.controller.domain.MemberContext; import org.apache.stratos.load.balancer.common.domain.*; import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -260,6 +262,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //instancesList.add(member.getMemberName); log.info("===============Member instance id:============= " + member.getInstanceId()); + MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(member.getMemberId()); + //add forwarding rules(Ports to be forwarded) for (Object port : member.getPorts()) { int portValue = ((Port) port).getValue(); From eae02158c236a51c041097a51b5c07fbd33c7672 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 15 Jun 2015 11:26:50 +0530 Subject: [PATCH 110/217] testing member context --- extensions/load-balancer/gce-extension/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index 5eb73c4d18..0aa2d17207 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -82,6 +82,11 @@ google-api-services-compute v1-rev27-1.19.0 + + org.apache.stratos + org.apache.stratos.cloud.controller + ${project.version} + From 753792bd6682a4f5d1fb125dc0588d922da2edfe Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 15 Jun 2015 22:09:59 +0530 Subject: [PATCH 111/217] testing member context --- .../controller/services/impl/CloudControllerServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java index 4b558ce724..bf38388de2 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java @@ -485,7 +485,7 @@ private MemberContext createMemberContext(String applicationId, String cartridge memberContext.setLoadBalancingIPType(loadBalancingIPType); memberContext.setInitTime(System.currentTimeMillis()); memberContext.setObsoleteExpiryTime(instanceContext.getObsoleteExpiryTime()); -// memberContext.setInstanceId(instanceContext.get); + memberContext.setInstanceId(cloudControllerContext.getMemberContextOfMemberId(memberId).getInstanceId()); return memberContext; } From 25fd0d252424497a48d267aa1070af8bdae63f85 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 15 Jun 2015 22:32:09 +0530 Subject: [PATCH 112/217] testing member context --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 236f8ce171..2ea2381cc9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -262,7 +262,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //instancesList.add(member.getMemberName); log.info("===============Member instance id:============= " + member.getInstanceId()); - MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(member.getMemberId()); + // MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(member.getMemberId()); //add forwarding rules(Ports to be forwarded) for (Object port : member.getPorts()) { From 075207b9fa7a5011e4872c99057c7a446c469d72 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 15 Jun 2015 23:24:15 +0530 Subject: [PATCH 113/217] testing member context --- .../controller/services/impl/CloudControllerServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java index bf38388de2..d5099a876e 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java @@ -485,7 +485,7 @@ private MemberContext createMemberContext(String applicationId, String cartridge memberContext.setLoadBalancingIPType(loadBalancingIPType); memberContext.setInitTime(System.currentTimeMillis()); memberContext.setObsoleteExpiryTime(instanceContext.getObsoleteExpiryTime()); - memberContext.setInstanceId(cloudControllerContext.getMemberContextOfMemberId(memberId).getInstanceId()); + memberContext.setInstanceId(CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId).getInstanceId()); return memberContext; } From 4cad6d8375d9bba90ef2358847f714f916412aa9 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 16 Jun 2015 00:12:23 +0530 Subject: [PATCH 114/217] set instance Id --- .../cloud/controller/messaging/topology/TopologyBuilder.java | 2 +- .../controller/services/impl/CloudControllerServiceImpl.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 79d454449d..53e4bd3523 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -391,7 +391,7 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setStatus(MemberStatus.Created); member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); - member.setInstanceId(memberContext.getInstanceId()); + member.setInstanceId(CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId).getInstanceId()); cluster.addMember(member); TopologyManager.updateTopology(topology); } finally { diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java index d5099a876e..279280f5d5 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java @@ -485,7 +485,6 @@ private MemberContext createMemberContext(String applicationId, String cartridge memberContext.setLoadBalancingIPType(loadBalancingIPType); memberContext.setInitTime(System.currentTimeMillis()); memberContext.setObsoleteExpiryTime(instanceContext.getObsoleteExpiryTime()); - memberContext.setInstanceId(CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId).getInstanceId()); return memberContext; } From 90fd4a564c69da7eae90e703b6dbaebebb624907 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 16 Jun 2015 01:03:10 +0530 Subject: [PATCH 115/217] set instance Id --- .../cloud/controller/messaging/topology/TopologyBuilder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 53e4bd3523..fb160ca6bd 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -391,7 +391,6 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setStatus(MemberStatus.Created); member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); - member.setInstanceId(CloudControllerContext.getInstance().getMemberContextOfMemberId(memberId).getInstanceId()); cluster.addMember(member); TopologyManager.updateTopology(topology); } finally { @@ -441,6 +440,8 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } + member.setInstanceId(CloudControllerContext.getInstance().getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); + // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { From 0c2b808e160cdaeaaa2cbe7e1ccc7281e2a92c31 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 16 Jun 2015 02:12:10 +0530 Subject: [PATCH 116/217] add instance to target pool --- .../gce/extension/GCELoadBalancer.java | 12 ++--- .../GCELoadBalancerConfiguration.java | 2 +- .../stratos/gce/extension/GCEOperations.java | 50 ++++++++++++++++--- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 2ea2381cc9..4624c28c50 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -207,12 +207,10 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { //TODO:check instances(members) in instance list and update - /* EX: - if(!updatedInstancesList.contains(member.getMemberName())){ - updatedInstancesList.add(member.getMemberName); - } - */ + if(!updatedInstancesList.contains(member.getInstanceId())){ + updatedInstancesList.add(member.getInstanceId()); + } //checking for forwarding rules and updating for (Object port : member.getPorts()) { @@ -259,10 +257,10 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { //TODO:set instances(members) to instances list - //instancesList.add(member.getMemberName); log.info("===============Member instance id:============= " + member.getInstanceId()); - // MemberContext memberContext = CloudControllerContext.getInstance().getMemberContextOfMemberId(member.getMemberId()); + //add instance to instance list + instancesList.add(member.getInstanceId()); //add forwarding rules(Ports to be forwarded) for (Object port : member.getPorts()) { diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java index 2fafa626ba..c0bce6cc6f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java @@ -34,7 +34,7 @@ public class GCELoadBalancerConfiguration { - //A load balancer must have a target pool(set of instances) + //A load balancer must have set of instances private List instancesList; //A load balancer can have one IPs to be forwarded private List ipList; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 93712f8f66..c17122e1c7 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -335,13 +335,36 @@ public static InstanceList getInstanceList() throws IOException { } } + public static String getInstanceURLFromName(String instanceName) { + + //todo:remove try catch + String instanceURL; + try { + //check whether the given instance is available + InstanceList instanceList = getInstanceList(); + for (Instance instance : instanceList.getItems()) { + if (instance.getName().equals(instanceName)) { + //instance is available + //getInstance URL + instanceURL = instance.getSelfLink(); + return instanceURL; + } + } + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } + /** * Get instance resource URL from given instance name * - * @param instanceName + * @param instanceId * @return */ - public static String getInstanceURLFromName(String instanceName) { + public static String getInstanceURLFromId(String instanceId) { //todo:remove try catch String instanceURL; @@ -349,7 +372,7 @@ public static String getInstanceURLFromName(String instanceName) { //check whether the given instance is available InstanceList instanceList = getInstanceList(); for (Instance instance : instanceList.getItems()) { - if (instance.getName().equals(instanceName)) { + if ((instance.getZone() + "/" + instance.getName()).equals(instanceId)) { //instance is available //getInstance URL instanceURL = instance.getSelfLink(); @@ -372,11 +395,11 @@ public void setPortRangeToForwardingRule() { //todo:implement this method } - public void addInstancesToTargetPool(List instancesNamesList, String targetPoolName) { + public void addInstancesToTargetPool(List instancesIdsList, String targetPoolName) { log.info("Adding instances to target pool"); - if (instancesNamesList.isEmpty()) { + if (instancesIdsList.isEmpty()) { if (log.isDebugEnabled()) { log.debug("Cannot add instances to target pool. InstancesNamesList is empty."); } @@ -386,10 +409,10 @@ public void addInstancesToTargetPool(List instancesNamesList, String tar List instanceReferenceList = new ArrayList(); //add instance to instance reference list, we should use the instance URL - for (String instanceName : instancesNamesList) { //for all instances + for (String instanceId : instancesIdsList) { //for all instances instanceReferenceList.add(new InstanceReference(). - setInstance(getInstanceURLFromName(instanceName))); + setInstance(getInstanceURLFromId(instanceId))); } @@ -549,6 +572,19 @@ private void waitForZoneOperationCompletion(String operationName){ } } + //a test method + public void addInstanceToTargetPool(String instanceId){ + + List instanceReferenceList = new ArrayList(); + + //remove instance to instance reference list, we should use the instance URL + InstanceReference instanceReference1 = new InstanceReference(); + instanceReference1.setInstance(getInstanceURLFromName(instanceId)); + instanceReferenceList.add(instanceReference1); + addInstancesToTargetPool("testtargetpool", instanceReferenceList); + + } + /** * this is a sample method using for testing purposes */ From faea8da9ec9736616b79da14672d3823acfda029 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 16 Jun 2015 03:33:03 +0530 Subject: [PATCH 117/217] add instance to target pool --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index c17122e1c7..3cd9c153d8 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -372,7 +372,8 @@ public static String getInstanceURLFromId(String instanceId) { //check whether the given instance is available InstanceList instanceList = getInstanceList(); for (Instance instance : instanceList.getItems()) { - if ((instance.getZone() + "/" + instance.getName()).equals(instanceId)) { + String instanceIdInIaaS = instance.getZone() + "/" + instance.getName(); + if (instanceIdInIaaS.equals(instanceId)) { //instance is available //getInstance URL instanceURL = instance.getSelfLink(); From 40913f5e361fcbf3060487b289bdcb4f38fceaed Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 16 Jun 2015 03:41:15 +0530 Subject: [PATCH 118/217] add instance to target pool --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 3cd9c153d8..7c3af777f5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -372,7 +372,8 @@ public static String getInstanceURLFromId(String instanceId) { //check whether the given instance is available InstanceList instanceList = getInstanceList(); for (Instance instance : instanceList.getItems()) { - String instanceIdInIaaS = instance.getZone() + "/" + instance.getName(); + //todo: recheck following line + String instanceIdInIaaS = ZONE_NAME + "/" + instance.getName(); if (instanceIdInIaaS.equals(instanceId)) { //instance is available //getInstance URL From 8e20c618d14bb147b379b8cebcd5de38f461ea7e Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 16 Jun 2015 04:02:51 +0530 Subject: [PATCH 119/217] reformat code --- .../load-balancer/gce-extension/pom.xml | 4 +- .../gce/extension/GCELoadBalancer.java | 108 ++++++++-------- .../stratos/gce/extension/GCEOperations.java | 115 ++++++++++++++---- 3 files changed, 143 insertions(+), 84 deletions(-) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index 0aa2d17207..3453b63b4f 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -88,13 +88,13 @@ ${project.version} - + 1.19.0 diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 4624c28c50..af3d7409c9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,15 +19,8 @@ package org.apache.stratos.gce.extension; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.reflection.FieldDictionary; -import com.thoughtworks.xstream.converters.reflection.ImmutableFieldKeySorter; -import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider; -import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.context.CloudControllerContext; -import org.apache.stratos.cloud.controller.domain.MemberContext; import org.apache.stratos.load.balancer.common.domain.*; import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -44,8 +37,8 @@ public class GCELoadBalancer implements LoadBalancer { private GCEOperations gceOperations; /** * We have one configuration per cluster - * A Load balancer has one target pool forwarding rule and a health check - * This hash map is used to hold cluster IDs and corresponding Load balancer configuration + * One cluster has one target pool , one forwarding rule and a health check + * This hash map is used to hold cluster IDs and corresponding configuration * So one cluster will have one loadBalancerConfiguration object */ private HashMap clusterToLoadBalancerConfigurationMap; @@ -57,7 +50,6 @@ public GCELoadBalancer() { try { gceOperations = new GCEOperations(); clusterToLoadBalancerConfigurationMap = new HashMap(); - } catch (LoadBalancerExtensionException e) { log.error(e); } catch (GeneralSecurityException e) { @@ -80,15 +72,15 @@ public void start() throws LoadBalancerExtensionException { //} Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()){ //for each Load balancer configuration + while (iterator.hasNext()) { //for each Load balancer configuration - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry)iterator.next(); + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); String clusterID = ((String) clusterIDLoadBalancerConfigurationPair.getKey()); GCELoadBalancerConfiguration GCELoadBalancerConfiguration = ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - if(!GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running + if (!GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running //create a health check gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); @@ -108,8 +100,8 @@ public void start() throws LoadBalancerExtensionException { //need to create a port range String String portRange = ""; //if the ip list is empty - if(ipList.isEmpty()){ - if(log.isDebugEnabled()){ + if (ipList.isEmpty()) { + if (log.isDebugEnabled()) { log.debug("Ip list is null"); } //as a temporary solution set all ports to be open @@ -117,20 +109,20 @@ public void start() throws LoadBalancerExtensionException { } //else if ip list has only one value - else if (ipList.size() == 1){ - portRange = Integer.toString(ipList.get(0))+"-"+Integer.toString(ipList.get(0)); + else if (ipList.size() == 1) { + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); } //else we have more than 1 value else { //first we need to take the port range. So arrange ipList in ascending order Collections.sort(ipList); //take the first one and last one - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size()-1)); + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); } //create the forwarding rule gceOperations.createForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName(), - GCELoadBalancerConfiguration.getTargetPoolName(),protocol,portRange); + GCELoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); //set status to running GCELoadBalancerConfiguration.setStatus(true); @@ -178,13 +170,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Configuring Load balancer "); - //printing topology value as a xml for testing purposes - XStream xstream = new XStream(new Sun14ReflectionProvider( - new FieldDictionary(new ImmutableFieldKeySorter())), - new DomDriver("utf-8")); - log.info(xstream.toXML(topology)); - - for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster //we create one load balancer per cluster @@ -208,7 +193,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //TODO:check instances(members) in instance list and update - if(!updatedInstancesList.contains(member.getInstanceId())){ + if (!updatedInstancesList.contains(member.getInstanceId())) { updatedInstancesList.add(member.getInstanceId()); } @@ -216,9 +201,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Object port : member.getPorts()) { int portValue = ((Port) port).getValue(); //if not present update it - if (!updatedIPList.contains(portValue)){ //if port is not in list + if (!updatedIPList.contains(portValue)) { //if port is not in list //put the forwarding rule to list - updatedIPList.add(portValue); + updatedIPList.add(portValue); } } @@ -228,24 +213,23 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio GCELoadBalancerConfiguration.setIpList(updatedIPList); GCELoadBalancerConfiguration.setInstancesList(updatedInstancesList); - if(GCELoadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name + if (GCELoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); } - if (GCELoadBalancerConfiguration.getForwardingRuleName() == null){ + if (GCELoadBalancerConfiguration.getForwardingRuleName() == null) { //set forwarding rule name String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); } - if(GCELoadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name + if (GCELoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); - } - + } } else { @@ -256,9 +240,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { - //TODO:set instances(members) to instances list - log.info("===============Member instance id:============= " + member.getInstanceId()); - //add instance to instance list instancesList.add(member.getInstanceId()); @@ -276,19 +257,19 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio GCELoadBalancerConfiguration GCELoadBalancerConfiguration = new GCELoadBalancerConfiguration( cluster.getClusterId(), instancesList, ipList); - if(GCELoadBalancerConfiguration.getTargetPoolName() == null){ //this does not have a target pool name + if (GCELoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); } - if (GCELoadBalancerConfiguration.getForwardingRuleName() == null){ + if (GCELoadBalancerConfiguration.getForwardingRuleName() == null) { //set forwarding rule name String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); } - if(GCELoadBalancerConfiguration.getHealthCheckName() == null){//if this does not have a forwarding rule name + if (GCELoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); @@ -305,7 +286,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } /** - * * @throws LoadBalancerExtensionException */ @Override @@ -317,36 +297,54 @@ public void reload() throws LoadBalancerExtensionException { } - private String targetPoolNameCreator(String clusterID){ + /** + * Create a valid target pool name + * + * @param clusterId - Id of the cluster + * @return + */ + private String targetPoolNameCreator(String clusterId) { //create a valid target pool name by using cluster ID //remove spaces, make all to lower case, replace all "." --> "-" //add name prefix String targetPoolName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" + - clusterID.trim().toLowerCase().replace(".","-"); + clusterId.trim().toLowerCase().replace(".", "-"); //length should be les than 62 characters - if(targetPoolName.length()>=62){ - targetPoolName = targetPoolName.substring(0,62); + if (targetPoolName.length() >= 62) { + targetPoolName = targetPoolName.substring(0, 62); } - return targetPoolName; + return targetPoolName; } - private String forwardingRuleNameCreator(String clusterID){ + /** + * Create a valid forwarding rule name + * + * @param clusterID - Id of the cluster + * @return + */ + private String forwardingRuleNameCreator(String clusterID) { String forwardingRuleName = GCEContext.getInstance().getNamePrefix() - + "-fr-" + clusterID.trim().toLowerCase().replace(".","-"); + + "-fr-" + clusterID.trim().toLowerCase().replace(".", "-"); //length should be les than 62 characters - if(forwardingRuleName.length()>=62){ - forwardingRuleName = forwardingRuleName.substring(0,62); + if (forwardingRuleName.length() >= 62) { + forwardingRuleName = forwardingRuleName.substring(0, 62); } - return forwardingRuleName; + return forwardingRuleName; } - private String healthCheckNameCreator(String clusterID){ + /** + * create a valid health check name + * + * @param clusterID - id of the cluster + * @return + */ + private String healthCheckNameCreator(String clusterID) { String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-hc-" + - clusterID.trim().toLowerCase().replace(".","-"); + clusterID.trim().toLowerCase().replace(".", "-"); //length should be les than 62 characters - if(healthCheckName.length()>=62){ - healthCheckName = healthCheckName.substring(0,62); + if (healthCheckName.length() >= 62) { + healthCheckName = healthCheckName.substring(0, 62); } return healthCheckName; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 7c3af777f5..57bb75bd89 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -40,8 +40,6 @@ import java.util.Collections; import java.util.List; -import com.google.api.services.compute.model.Operation.Error.Errors; - /** * All the GCE API calls will be done using this class */ @@ -126,7 +124,7 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep /** * Creating a new target pool; name should be unique * - * @param targetPoolName + * @param targetPoolName - name of the target pool in IaaS */ public void createTargetPool(String targetPoolName, String healthCheckName) { @@ -151,6 +149,11 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { } + /** + * Deleting an exiting target pool in IaaS + * + * @param targetPoolName - Name of the target pool in IaaS + */ public void deleteTargetPool(String targetPoolName) { try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); @@ -167,9 +170,9 @@ public void deleteTargetPool(String targetPoolName) { /** * create forwarding rule by using given target pool and protocol * - * @param forwardingRuleName - * @param targetPoolName - * @param protocol + * @param forwardingRuleName - name of the forwarding rule in IaaS to be created + * @param targetPoolName - name of the target pool in IaaS which is already created + * @param protocol - The protocol which is used to forward trafic. Should be either TCP or UDP */ public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol, String portRange) { @@ -194,6 +197,11 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } } + /** + * Deleting a existing forwarding rule in IaaS + * + * @param forwardingRuleName - Forwarding rule name in IaaS + */ public void deleteForwardingRule(String forwardingRuleName) { try { Operation operation = compute.forwardingRules(). @@ -211,7 +219,7 @@ public void deleteForwardingRule(String forwardingRuleName) { * Check whether the given target pool is already exists in the given project and region. * Target pools are unique for regions, not for zones * - * @param targetPoolName + * @param targetPoolName - target pool name in IaaS */ public boolean isTargetPoolExists(String targetPoolName) { @@ -237,6 +245,12 @@ public boolean isTargetPoolExists(String targetPoolName) { } + /** + * Check whether a given forwarding rule is exists or not in the IaaS + * + * @param forwardingRuleName - forwarding rule name in IaaS + * @return + */ public boolean isForwardingRuleExists(String forwardingRuleName) { try { Compute.ForwardingRules.List forwardingRules = compute.forwardingRules().list(PROJECT_ID, REGION_NAME); @@ -255,7 +269,7 @@ public boolean isForwardingRuleExists(String forwardingRuleName) { /** * Get a target pool already created in GCE * - * @param targetPoolName + * @param targetPoolName - target pool name in IaaS * @return */ public TargetPool getTargetPool(String targetPoolName) { @@ -284,8 +298,8 @@ public TargetPool getTargetPool(String targetPoolName) { /** * Add given set of instances to given target pool. * - * @param targetPoolName - * @param instanceReferenceList + * @param targetPoolName - target pool name in IaaS + * @param instanceReferenceList - List of instances to be added to target pool */ private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { @@ -296,8 +310,8 @@ private void addInstancesToTargetPool(String targetPoolName, List instanceReferenceList) { @@ -397,6 +411,12 @@ public void setPortRangeToForwardingRule() { //todo:implement this method } + /** + * Add a given list of instances to a target pool + * + * @param instancesIdsList - list of instance Ids + * @param targetPoolName - target pool name in IaaS + */ public void addInstancesToTargetPool(List instancesIdsList, String targetPoolName) { log.info("Adding instances to target pool"); @@ -437,6 +457,11 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe } } + /** + * Create a health check in IaaS + * + * @param healthCheckName - name of the health check to be created + */ public void createHealthCheck(String healthCheckName) { if (!isHealthCheckExists(healthCheckName)) {//if the health check is not present already @@ -463,6 +488,12 @@ public void createHealthCheck(String healthCheckName) { } } + /** + * Checking whether a given health check is exists or not + * + * @param healthCheckName - name of the health check + * @return + */ public boolean isHealthCheckExists(String healthCheckName) { try { HttpHealthCheckList httpHealthCheckList = compute.httpHealthChecks().list(PROJECT_ID).execute(); @@ -477,6 +508,7 @@ public boolean isHealthCheckExists(String healthCheckName) { return false; } + //todo: remove this method(never used) public HttpHealthCheck getHealthCheckFromName(String healthCheckName) { HttpHealthCheckList healthCheckList = getHealthCheckList(); @@ -489,6 +521,12 @@ public HttpHealthCheck getHealthCheckFromName(String healthCheckName) { return null; } + /** + * Get a given health check resource URL + * + * @param healthCheckName - name of the health check in IaaS + * @return + */ public static String getHealthCheckURLFromName(String healthCheckName) { String healthCheckURL; @@ -507,6 +545,11 @@ public static String getHealthCheckURLFromName(String healthCheckName) { } + /** + * Get list of health checks + * + * @return + */ public static HttpHealthCheckList getHealthCheckList() { try { Compute.HttpHealthChecks.List healthChecks = compute.httpHealthChecks().list(PROJECT_ID); @@ -523,16 +566,22 @@ public static HttpHealthCheckList getHealthCheckList() { return null; } - private void waitForGlobalOperationCompletion(String operationName){ + /** + * Wait for a global operation completion. If the operation is related to whole project + * that is a global operation + * + * @param operationName - name of the operation in IaaS + */ + private void waitForGlobalOperationCompletion(String operationName) { try { Thread.sleep(2000); - while (true){ - Operation operation = compute.globalOperations().get(PROJECT_ID,operationName).execute(); - if (operation.getStatus().equals("DONE")){ - return; - } - Thread.sleep(1000); - } + while (true) { + Operation operation = compute.globalOperations().get(PROJECT_ID, operationName).execute(); + if (operation.getStatus().equals("DONE")) { + return; + } + Thread.sleep(1000); + } } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { @@ -540,13 +589,20 @@ private void waitForGlobalOperationCompletion(String operationName){ } } - private void waitForRegionOperationCompletion(String operationName){ + /** + * Wait for a region operation completion. If the operation is related to a region that is a + * region operation + * + * @param operationName - name of the region operation + */ + + private void waitForRegionOperationCompletion(String operationName) { try { Thread.sleep(2000); - while (true){ + while (true) { Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); - if(operation.getStatus().equals("DONE")){ + if (operation.getStatus().equals("DONE")) { return; } Thread.sleep(1000); @@ -558,11 +614,16 @@ private void waitForRegionOperationCompletion(String operationName){ } } - private void waitForZoneOperationCompletion(String operationName){ + /** + * wait for zone operation completion. If the operation is related to a zone, that is a zone operation + * + * @param operationName -operation name + */ + private void waitForZoneOperationCompletion(String operationName) { try { - while (true){ + while (true) { Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); - if (operation.getStatus().equals("DONE")){ + if (operation.getStatus().equals("DONE")) { return; } Thread.sleep(1000); @@ -575,7 +636,7 @@ private void waitForZoneOperationCompletion(String operationName){ } //a test method - public void addInstanceToTargetPool(String instanceId){ + public void addInstanceToTargetPool(String instanceId) { List instanceReferenceList = new ArrayList(); From 262d0f020946869075c60822f44fc807e84f51b7 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 12:38:24 +0530 Subject: [PATCH 120/217] reformat code --- .../apache/stratos/gce/extension/GCELoadBalancer.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index af3d7409c9..c55dccf6ef 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -76,7 +76,6 @@ public void start() throws LoadBalancerExtensionException { Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - String clusterID = ((String) clusterIDLoadBalancerConfigurationPair.getKey()); GCELoadBalancerConfiguration GCELoadBalancerConfiguration = ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); @@ -191,11 +190,11 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { - //TODO:check instances(members) in instance list and update - - if (!updatedInstancesList.contains(member.getInstanceId())) { - updatedInstancesList.add(member.getInstanceId()); - } + if(member.getInstanceId() != null) { + if (!updatedInstancesList.contains(member.getInstanceId())) { + updatedInstancesList.add(member.getInstanceId()); + } + } //checking for forwarding rules and updating for (Object port : member.getPorts()) { From 173571acbac6de1a2baa2153a3ab8e33214ed6d3 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 12:56:12 +0530 Subject: [PATCH 121/217] fixing heath check creation error --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 57bb75bd89..8d0b373232 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -497,6 +497,9 @@ public void createHealthCheck(String healthCheckName) { public boolean isHealthCheckExists(String healthCheckName) { try { HttpHealthCheckList httpHealthCheckList = compute.httpHealthChecks().list(PROJECT_ID).execute(); + if(httpHealthCheckList.size() == 0){ + return false; + } for (HttpHealthCheck httpHealthCheck : httpHealthCheckList.getItems()) { if (httpHealthCheck.getName().equals(healthCheckName)) { return true; From 1f244ab33d8d4960aa28769ccfb9c11da950d597 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 13:14:17 +0530 Subject: [PATCH 122/217] fixing heath check creation error --- .../org/apache/stratos/gce/extension/GCEOperations.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 8d0b373232..d726d56ff0 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -464,8 +464,6 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe */ public void createHealthCheck(String healthCheckName) { - if (!isHealthCheckExists(healthCheckName)) {//if the health check is not present already - HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); httpHealthCheck.setName(healthCheckName); httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); @@ -480,12 +478,6 @@ public void createHealthCheck(String healthCheckName) { } catch (IOException e) { e.printStackTrace(); } - - } else { - if (log.isDebugEnabled()) { - log.debug("Health check is already exist: " + healthCheckName); - } - } } /** From dc3649b75ab4bc626a072e6e7e9ef9a6e1829ead Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 14:25:22 +0530 Subject: [PATCH 123/217] implementing create forwarding rule method --- .../src/main/bin/gce-extension.sh | 3 +- .../stratos/gce/extension/Constants.java | 1 + .../stratos/gce/extension/GCEContext.java | 8 +++++ .../gce/extension/GCELoadBalancer.java | 2 +- .../stratos/gce/extension/GCEOperations.java | 29 ++++++++++++++++++- 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index a9e0b4ce20..c4adee56e8 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -50,7 +50,8 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dhealth.check.request.path=/ -Dhealth.check.port=80 -Dhealth.check.timeout.sec=5 - -Dhealth.check.unhealthy.threshold=2" + -Dhealth.check.unhealthy.threshold=2 + -Dnetwork.name=default" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index 60cdf62de7..f165441ebc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -40,5 +40,6 @@ public class Constants { public static final String HEALTH_CHECK_PORT = "health.check.port"; public static final String HEALTH_CHECK_TIME_OUT_SEC = "health.check.timeout.sec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "health.check.unhealthy.threshold"; + public static final String NETWORK_NAME = "network.name"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index b65c72ec81..40f8f50ece 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -48,6 +48,7 @@ public class GCEContext { private String healthCheckPort; private String healthCheckTimeOutSec; private String healthCheckUnhealthyThreshold; + private String networkName; @@ -70,6 +71,7 @@ private GCEContext() { this.healthCheckPort = System.getProperty(Constants.HEALTH_CHECK_PORT); this.healthCheckTimeOutSec = System.getProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); this.healthCheckUnhealthyThreshold = System.getProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); + this.networkName = System.getProperty(Constants.NETWORK_NAME); if (log.isDebugEnabled()) { @@ -90,6 +92,7 @@ private GCEContext() { log.debug(Constants.HEALTH_CHECK_PORT + " = " + healthCheckPort); log.debug(Constants.HEALTH_CHECK_TIME_OUT_SEC + " = " + healthCheckTimeOutSec); log.debug(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD + " = " + healthCheckUnhealthyThreshold); + log.debug(Constants.NETWORK_NAME + "="+ networkName); } @@ -121,6 +124,7 @@ public void validate() { validateSystemProperty(Constants.HEALTH_CHECK_PORT); validateSystemProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); validateSystemProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); + validateSystemProperty(Constants.NETWORK_NAME); if (cepStatsPublisherEnabled) { @@ -198,4 +202,8 @@ public String getHealthCheckTimeOutSec() { public String getHealthCheckUnhealthyThreshold() { return healthCheckUnhealthyThreshold; } + + public String getNetworkName() { + return networkName; + } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index c55dccf6ef..b4c19229e6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -84,7 +84,7 @@ public void start() throws LoadBalancerExtensionException { //create a health check gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); - //todo: set firewall rule for health check + gceOperations.createFirewallRule(); //crate a target pool in GCE gceOperations.createTargetPool(GCELoadBalancerConfiguration.getTargetPoolName(), diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index d726d56ff0..c138741271 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -64,7 +64,7 @@ public class GCEOperations { private static final String HEALTH_CHECK_PORT = GCEContext.getInstance().getHealthCheckPort(); private static final String HEALTH_CHECK_TIME_OUT_SEC = GCEContext.getInstance().getHealthCheckTimeOutSec(); private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); - + private static final String NETWORK_NAME = GCEContext.getInstance().getNetworkName(); /** * Directory to store user credentials. */ @@ -630,6 +630,33 @@ private void waitForZoneOperationCompletion(String operationName) { } } + public void createFirewallRule(){ + + List sourceRanges = new ArrayList(); + sourceRanges.add("0.0.0.0/0"); + + List ports = new ArrayList(); + ports.add(HEALTH_CHECK_PORT); + + Firewall.Allowed allowed = new Firewall.Allowed(); + allowed.setIPProtocol("TCP"); + allowed.setPorts(ports); + + List allowedRules = new ArrayList(); + allowedRules.add(allowed); + + Firewall firewall = new Firewall(); + firewall.setName("stratos-health-check-firewall"); + firewall.setNetwork(NETWORK_NAME); + firewall.setSourceRanges(sourceRanges); + firewall.setAllowed(allowedRules); + try { + compute.firewalls().insert(PROJECT_ID,firewall); + } catch (IOException e) { + e.printStackTrace(); + } + } + //a test method public void addInstanceToTargetPool(String instanceId) { From d382b52fad59b96ca5c9fa87e5a2f9c8998f0f1b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 18:31:27 +0530 Subject: [PATCH 124/217] testing --- .../gce/extension/GCELoadBalancer.java | 200 +++++++++--------- 1 file changed, 103 insertions(+), 97 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index b4c19229e6..11ef5b22f5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -59,103 +59,6 @@ public GCELoadBalancer() { } } - @Override - public void start() throws LoadBalancerExtensionException { - //topology has completed - - log.info("Starting GCE Load balancer instance"); - - //iterate through clusterToLoadBalancerConfigurationMap - //for each cluster{ - //if Load balancer status == not running --> - // execute commands through GCE API for start the load balancer - //} - - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()) { //for each Load balancer configuration - - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - - if (!GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running - - //create a health check - gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); - - gceOperations.createFirewallRule(); - - //crate a target pool in GCE - gceOperations.createTargetPool(GCELoadBalancerConfiguration.getTargetPoolName(), - GCELoadBalancerConfiguration.getHealthCheckName()); - - //add instances to target pool - gceOperations.addInstancesToTargetPool(GCELoadBalancerConfiguration.getInstancesList(), - GCELoadBalancerConfiguration.getTargetPoolName()); - - //create forwarding rules in GCE - List ipList = GCELoadBalancerConfiguration.getIpList(); - //need to create a port range String - String portRange = ""; - //if the ip list is empty - if (ipList.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Ip list is null"); - } - //as a temporary solution set all ports to be open - portRange = "1-65535"; - - } - //else if ip list has only one value - else if (ipList.size() == 1) { - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); - } - //else we have more than 1 value - else { - //first we need to take the port range. So arrange ipList in ascending order - Collections.sort(ipList); - //take the first one and last one - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); - } - - //create the forwarding rule - gceOperations.createForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName(), - GCELoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); - - //set status to running - GCELoadBalancerConfiguration.setStatus(true); - } - - } - - log.info("GCE Load balancer instance started"); - - } - - @Override - public void stop() throws LoadBalancerExtensionException { - - log.info("GCE Load Balancer is stopping"); - //iterate through hashmap and remove all - - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()) { //for each Load balancer configuration - - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - - if (GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is already running - - gceOperations.deleteForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName()); - //delete target pool from GCE - gceOperations.deleteTargetPool(GCELoadBalancerConfiguration.getTargetPoolName()); - - } - } - - } /** * Listen to latest topology and update load balancer configuration @@ -230,6 +133,10 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); } + //for testing purposes + start(); + + } else { //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map @@ -284,6 +191,105 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio return true; } + @Override + public void start() throws LoadBalancerExtensionException { + //topology has completed + + log.info("Starting GCE Load balancer instance"); + + //iterate through clusterToLoadBalancerConfigurationMap + //for each cluster{ + //if Load balancer status == not running --> + // execute commands through GCE API for start the load balancer + //} + + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()) { //for each Load balancer configuration + + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + + if (!GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running + + //create a health check + gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); + + gceOperations.createFirewallRule(); + + //crate a target pool in GCE + gceOperations.createTargetPool(GCELoadBalancerConfiguration.getTargetPoolName(), + GCELoadBalancerConfiguration.getHealthCheckName()); + + //add instances to target pool + gceOperations.addInstancesToTargetPool(GCELoadBalancerConfiguration.getInstancesList(), + GCELoadBalancerConfiguration.getTargetPoolName()); + + //create forwarding rules in GCE + List ipList = GCELoadBalancerConfiguration.getIpList(); + //need to create a port range String + String portRange = ""; + //if the ip list is empty + if (ipList.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("Ip list is null"); + } + //as a temporary solution set all ports to be open + portRange = "1-65535"; + + } + //else if ip list has only one value + else if (ipList.size() == 1) { + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); + } + //else we have more than 1 value + else { + //first we need to take the port range. So arrange ipList in ascending order + Collections.sort(ipList); + //take the first one and last one + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); + } + + //create the forwarding rule + gceOperations.createForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName(), + GCELoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); + + //set status to running + GCELoadBalancerConfiguration.setStatus(true); + } + + } + + log.info("GCE Load balancer instance started"); + + } + + @Override + public void stop() throws LoadBalancerExtensionException { + + log.info("GCE Load Balancer is stopping"); + //iterate through hashmap and remove all + + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()) { //for each Load balancer configuration + + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + + if (GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is already running + + gceOperations.deleteForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName()); + //delete target pool from GCE + gceOperations.deleteTargetPool(GCELoadBalancerConfiguration.getTargetPoolName()); + + } + } + + } + + /** * @throws LoadBalancerExtensionException */ From 76efe36a784430ac8497f98d5aa8cfe9a48ccce1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 18:59:26 +0530 Subject: [PATCH 125/217] implementing listening to topology and update it --- .../stratos/gce/extension/GCEContext.java | 4 +- .../gce/extension/GCELoadBalancer.java | 159 +++++---- .../GCELoadBalancerConfiguration.java | 19 +- .../stratos/gce/extension/GCEOperations.java | 325 ++++++++---------- 4 files changed, 233 insertions(+), 274 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 40f8f50ece..d950df1cfc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -51,7 +51,6 @@ public class GCEContext { private String networkName; - private GCEContext() { this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); @@ -92,7 +91,7 @@ private GCEContext() { log.debug(Constants.HEALTH_CHECK_PORT + " = " + healthCheckPort); log.debug(Constants.HEALTH_CHECK_TIME_OUT_SEC + " = " + healthCheckTimeOutSec); log.debug(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD + " = " + healthCheckUnhealthyThreshold); - log.debug(Constants.NETWORK_NAME + "="+ networkName); + log.debug(Constants.NETWORK_NAME + "=" + networkName); } @@ -186,7 +185,6 @@ public String getGceAccountID() { } - public String getHealthCheckRequestPath() { return healthCheckRequestPath; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 11ef5b22f5..68d6fc13fc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -93,11 +93,11 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { - if(member.getInstanceId() != null) { - if (!updatedInstancesList.contains(member.getInstanceId())) { - updatedInstancesList.add(member.getInstanceId()); - } - } + if (member.getInstanceId() != null) { + if (!updatedInstancesList.contains(member.getInstanceId())) { + updatedInstancesList.add(member.getInstanceId()); + } + } //checking for forwarding rules and updating for (Object port : member.getPorts()) { @@ -133,10 +133,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); } - //for testing purposes - start(); - - } else { //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map @@ -183,25 +179,52 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); + } } } + + //Overwrite all the things related to load balancing in IaaS side + + //delete all forwarding rules, target pools and health checks + deleteAll(); + //recreate all forwarding rules, target pools and health checks + recreateAll(); + return true; } - @Override - public void start() throws LoadBalancerExtensionException { - //topology has completed + /** + * This method is used to delete all fowarding rules, target pools and health checks + * in IaaS side according to new topology + */ + private void deleteAll() { + + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()) { //for each configuration + + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + + //delete forwarding rule + gceOperations.deleteForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName()); + //delete target pool from GCE + gceOperations.deleteTargetPool(GCELoadBalancerConfiguration.getTargetPoolName()); + //delete health check from GCE + gceOperations.deleteHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); - log.info("Starting GCE Load balancer instance"); - //iterate through clusterToLoadBalancerConfigurationMap - //for each cluster{ - //if Load balancer status == not running --> - // execute commands through GCE API for start the load balancer - //} + } + } + + /** + * This method is used to recreate all fowarding rules, target pools and health checks + * in IaaS side according to new topology + */ + private void recreateAll() { Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); while (iterator.hasNext()) { //for each Load balancer configuration @@ -211,56 +234,62 @@ public void start() throws LoadBalancerExtensionException { GCELoadBalancerConfiguration GCELoadBalancerConfiguration = ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - if (!GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is NOT already running - - //create a health check - gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); - gceOperations.createFirewallRule(); + //create a health check + gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); - //crate a target pool in GCE - gceOperations.createTargetPool(GCELoadBalancerConfiguration.getTargetPoolName(), - GCELoadBalancerConfiguration.getHealthCheckName()); + gceOperations.createFirewallRule(); - //add instances to target pool - gceOperations.addInstancesToTargetPool(GCELoadBalancerConfiguration.getInstancesList(), - GCELoadBalancerConfiguration.getTargetPoolName()); + //crate a target pool in GCE + gceOperations.createTargetPool(GCELoadBalancerConfiguration.getTargetPoolName(), + GCELoadBalancerConfiguration.getHealthCheckName()); - //create forwarding rules in GCE - List ipList = GCELoadBalancerConfiguration.getIpList(); - //need to create a port range String - String portRange = ""; - //if the ip list is empty - if (ipList.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Ip list is null"); - } - //as a temporary solution set all ports to be open - portRange = "1-65535"; + //add instances to target pool + gceOperations.addInstancesToTargetPool(GCELoadBalancerConfiguration.getInstancesList(), + GCELoadBalancerConfiguration.getTargetPoolName()); + //create forwarding rules in GCE + List ipList = GCELoadBalancerConfiguration.getIpList(); + //need to create a port range String + String portRange = ""; + //if the ip list is empty + if (ipList.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("Ip list is null"); } - //else if ip list has only one value - else if (ipList.size() == 1) { - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); - } - //else we have more than 1 value - else { - //first we need to take the port range. So arrange ipList in ascending order - Collections.sort(ipList); - //take the first one and last one - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); - } + //as a temporary solution set all ports to be open + portRange = "1-65535"; - //create the forwarding rule - gceOperations.createForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName(), - GCELoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); - - //set status to running - GCELoadBalancerConfiguration.setStatus(true); } + //else if ip list has only one value + else if (ipList.size() == 1) { + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); + } + //else we have more than 1 value + else { + //first we need to take the port range. So arrange ipList in ascending order + Collections.sort(ipList); + //take the first one and last one + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); + } + + //create the forwarding rule + gceOperations.createForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName(), + GCELoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); + } + } + + + @Override + public void start() throws LoadBalancerExtensionException { + //topology has completed + + log.info("Starting GCE Load balancer instance"); + + log.info("GCE Load balancer instance started"); } @@ -271,21 +300,7 @@ public void stop() throws LoadBalancerExtensionException { log.info("GCE Load Balancer is stopping"); //iterate through hashmap and remove all - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()) { //for each Load balancer configuration - - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - - if (GCELoadBalancerConfiguration.getStatus()) { //if the load balancer is already running - - gceOperations.deleteForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName()); - //delete target pool from GCE - gceOperations.deleteTargetPool(GCELoadBalancerConfiguration.getTargetPoolName()); - - } - } + deleteAll(); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java index c0bce6cc6f..f77370fbe0 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java @@ -19,10 +19,7 @@ package org.apache.stratos.gce.extension; -import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Set; /** * Since GCE have separate target pools and forwarding rules, we need @@ -43,8 +40,6 @@ public class GCELoadBalancerConfiguration { private String forwardingRuleName; private String targetPoolName; private String healthCheckName; - //Whether we have executed this configuration in GCE or not - private boolean isRunning = false; public GCELoadBalancerConfiguration(String clusterID, List instancesList, @@ -83,20 +78,12 @@ public String getClusterID() { return clusterID; } - public void setStatus(boolean status) { - this.isRunning = status; - } - - public void setTargetPoolName(String targetPoolName){ - this.targetPoolName = targetPoolName; - } - - public String getTargetPoolName(){ + public String getTargetPoolName() { return targetPoolName; } - public boolean getStatus() { - return isRunning; + public void setTargetPoolName(String targetPoolName) { + this.targetPoolName = targetPoolName; } public String getHealthCheckName() { diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index c138741271..72bddffb62 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -92,6 +92,125 @@ public GCEOperations() throws LoadBalancerExtensionException, } + /** + * Get list of running instances in given project and zone.(This method can be used + * when we need to check whether a given instance is available or not in a given project + * and zone) + * + * @return + * @throws IOException + */ + public static InstanceList getInstanceList() throws IOException { + Compute.Instances.List instances = compute.instances(). + list(PROJECT_ID, ZONE_NAME).setFilter(RUNNING_FILTER); + InstanceList instanceList = instances.execute(); + if (instanceList.getItems() == null) { + log.info("No instances found for specified zone"); + return null; + } else { + return instanceList; + } + } + + public static String getInstanceURLFromName(String instanceName) { + + //todo:remove try catch + String instanceURL; + try { + //check whether the given instance is available + InstanceList instanceList = getInstanceList(); + for (Instance instance : instanceList.getItems()) { + if (instance.getName().equals(instanceName)) { + //instance is available + //getInstance URL + instanceURL = instance.getSelfLink(); + return instanceURL; + } + } + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } + + /** + * Get instance resource URL from given instance name + * + * @param instanceId + * @return + */ + public static String getInstanceURLFromId(String instanceId) { + + //todo:remove try catch + String instanceURL; + try { + //check whether the given instance is available + InstanceList instanceList = getInstanceList(); + for (Instance instance : instanceList.getItems()) { + //todo: recheck following line + String instanceIdInIaaS = ZONE_NAME + "/" + instance.getName(); + if (instanceIdInIaaS.equals(instanceId)) { + //instance is available + //getInstance URL + instanceURL = instance.getSelfLink(); + return instanceURL; + } + } + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + + } + + /** + * Get a given health check resource URL + * + * @param healthCheckName - name of the health check in IaaS + * @return + */ + public static String getHealthCheckURLFromName(String healthCheckName) { + + String healthCheckURL; + + //check whether the given instance is available + HttpHealthCheckList healthCheckList = getHealthCheckList(); + for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { + if (httpHealthCheck.getName().equals(healthCheckName)) { + //instance is available + //getInstance URL + healthCheckURL = httpHealthCheck.getSelfLink(); + return healthCheckURL; + } + } + return null; + + } + + /** + * Get list of health checks + * + * @return + */ + public static HttpHealthCheckList getHealthCheckList() { + try { + Compute.HttpHealthChecks.List healthChecks = compute.httpHealthChecks().list(PROJECT_ID); + HttpHealthCheckList healthCheckList = healthChecks.execute(); + if (healthCheckList.getItems() == null) { + log.info("No health check found for specified project"); + return null; + } else { + return healthCheckList; + } + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + /** * Authorize and build compute engine object * @@ -120,7 +239,6 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep } - /** * Creating a new target pool; name should be unique * @@ -189,8 +307,6 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); waitForRegionOperationCompletion(operation.getName()); - int timeout = 0; - } catch (IOException e) { e.printStackTrace(); @@ -214,7 +330,6 @@ public void deleteForwardingRule(String forwardingRuleName) { } } - /** * Check whether the given target pool is already exists in the given project and region. * Target pools are unique for regions, not for zones @@ -295,17 +410,7 @@ public TargetPool getTargetPool(String targetPoolName) { } - /** - * Add given set of instances to given target pool. - * - * @param targetPoolName - target pool name in IaaS - * @param instanceReferenceList - List of instances to be added to target pool - */ - private void addInstancesToTargetPool(String targetPoolName, List - instanceReferenceList) { - - } /** * Remove given set of instances from target pool @@ -329,81 +434,6 @@ public void removeInstancesFromTargetPool(String targetPoolName, List instancesIdsList, String targe */ public void createHealthCheck(String healthCheckName) { - HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); - httpHealthCheck.setName(healthCheckName); - httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); - //TODO: read as integers - httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); - httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); - httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); + HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); + httpHealthCheck.setName(healthCheckName); + httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); + //TODO: read as integers + httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); + httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); + httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); + try { + Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); + waitForGlobalOperationCompletion(operation.getName()); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void deleteHealthCheck(String healthCheckName){ try { - Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); + Operation operation = compute.httpHealthChecks().delete(PROJECT_ID, healthCheckName).execute(); waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); + } + } /** @@ -489,7 +531,7 @@ public void createHealthCheck(String healthCheckName) { public boolean isHealthCheckExists(String healthCheckName) { try { HttpHealthCheckList httpHealthCheckList = compute.httpHealthChecks().list(PROJECT_ID).execute(); - if(httpHealthCheckList.size() == 0){ + if (httpHealthCheckList.size() == 0) { return false; } for (HttpHealthCheck httpHealthCheck : httpHealthCheckList.getItems()) { @@ -516,51 +558,6 @@ public HttpHealthCheck getHealthCheckFromName(String healthCheckName) { return null; } - /** - * Get a given health check resource URL - * - * @param healthCheckName - name of the health check in IaaS - * @return - */ - public static String getHealthCheckURLFromName(String healthCheckName) { - - String healthCheckURL; - - //check whether the given instance is available - HttpHealthCheckList healthCheckList = getHealthCheckList(); - for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { - if (httpHealthCheck.getName().equals(healthCheckName)) { - //instance is available - //getInstance URL - healthCheckURL = httpHealthCheck.getSelfLink(); - return healthCheckURL; - } - } - return null; - - } - - /** - * Get list of health checks - * - * @return - */ - public static HttpHealthCheckList getHealthCheckList() { - try { - Compute.HttpHealthChecks.List healthChecks = compute.httpHealthChecks().list(PROJECT_ID); - HttpHealthCheckList healthCheckList = healthChecks.execute(); - if (healthCheckList.getItems() == null) { - log.info("No health check found for specified project"); - return null; - } else { - return healthCheckList; - } - } catch (IOException e) { - e.printStackTrace(); - } - return null; - } - /** * Wait for a global operation completion. If the operation is related to whole project * that is a global operation @@ -630,7 +627,7 @@ private void waitForZoneOperationCompletion(String operationName) { } } - public void createFirewallRule(){ + public void createFirewallRule() { List sourceRanges = new ArrayList(); sourceRanges.add("0.0.0.0/0"); @@ -651,49 +648,11 @@ public void createFirewallRule(){ firewall.setSourceRanges(sourceRanges); firewall.setAllowed(allowedRules); try { - compute.firewalls().insert(PROJECT_ID,firewall); + compute.firewalls().insert(PROJECT_ID, firewall); } catch (IOException e) { e.printStackTrace(); } } - //a test method - public void addInstanceToTargetPool(String instanceId) { - - List instanceReferenceList = new ArrayList(); - - //remove instance to instance reference list, we should use the instance URL - InstanceReference instanceReference1 = new InstanceReference(); - instanceReference1.setInstance(getInstanceURLFromName(instanceId)); - instanceReferenceList.add(instanceReference1); - addInstancesToTargetPool("testtargetpool", instanceReferenceList); - - } - - /** - * this is a sample method using for testing purposes - */ - public void sampleMethodForAddingInstancesToTargetPool() { - List instanceReferenceList = new ArrayList(); - - //remove instance to instance reference list, we should use the instance URL - InstanceReference instanceReference1 = new InstanceReference(); - instanceReference1.setInstance(getInstanceURLFromName("instance-2")); - instanceReferenceList.add(instanceReference1); - addInstancesToTargetPool("testtargetpool", instanceReferenceList); - } - - /** - * this is a sample method using for testing purposes - */ - public void sampleMethodForRemovingInstancesToTargetPool() { - List instanceReferenceList = new ArrayList(); - - //add instances to instance reference list, we should use the instance URL - InstanceReference instanceReference1 = new InstanceReference(); - instanceReference1.setInstance(getInstanceURLFromName("instance-2")); - instanceReferenceList.add(instanceReference1); - removeInstancesFromTargetPool("testtargetpool", instanceReferenceList); - } } \ No newline at end of file From 0c71fe9d63ec386bcc47ecb059ffb0071d0a4282 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 21:06:30 +0530 Subject: [PATCH 126/217] implementing listening to topology and update it --- .../gce/extension/GCELoadBalancer.java | 160 ++++++++++-------- .../stratos/gce/extension/GCEOperations.java | 15 +- 2 files changed, 93 insertions(+), 82 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 68d6fc13fc..7b62fe7b34 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -74,13 +74,16 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster - //we create one load balancer per cluster - //Only create configuration object. Not execute. //check whether this cluster has a forwarding rule configuration or not if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { - //It has a loadBalancer configured. Take it and update it as the given topology. + //It already has a entry in clusterToLoadBalancerConfigurationMap. + //Take it and update it as the given topology. + + //delete all objects created in IaaS side(in load balancing perspective) relevant + // to this cluster before create new objects + deleteConfigurationForCluster(cluster.getClusterId()); //get load balancer configuration GCELoadBalancerConfiguration GCELoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. @@ -133,6 +136,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); } + //create objects in IaaS side + createConfigurationForCluster(cluster.getClusterId()); + } else { //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map @@ -178,107 +184,115 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); - + createConfigurationForCluster(cluster.getClusterId()); } } } - - //Overwrite all the things related to load balancing in IaaS side - - //delete all forwarding rules, target pools and health checks - deleteAll(); - //recreate all forwarding rules, target pools and health checks - recreateAll(); - - return true; - } - - /** - * This method is used to delete all fowarding rules, target pools and health checks - * in IaaS side according to new topology - */ - private void deleteAll() { + //check whether any cluster is removed. If removed, then remove the cluster from + //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); while (iterator.hasNext()) { //for each configuration Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - //delete forwarding rule - gceOperations.deleteForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName()); - //delete target pool from GCE - gceOperations.deleteTargetPool(GCELoadBalancerConfiguration.getTargetPoolName()); - //delete health check from GCE - gceOperations.deleteHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); - + boolean found = false; + //check whether cluster is in the map or not + for (Service service : topology.getServices()) { + for (Cluster cluster : service.getClusters()) { //for each cluster + if(cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())){ + found = true; + break; + } + } + if (found == true){ + break; + } + } + if (found==false){ + //remove cluster from map + clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); + deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); + } } + + + return true; } /** - * This method is used to recreate all fowarding rules, target pools and health checks + * This method is used to delete all fowarding rules, target pools and health checks * in IaaS side according to new topology */ - private void recreateAll() { + private void deleteConfigurationForCluster(String clusterId) { - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()) { //for each Load balancer configuration + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + //delete forwarding rule + gceOperations.deleteForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName()); + //delete target pool from GCE + gceOperations.deleteTargetPool(gceLoadBalancerConfiguration.getTargetPoolName()); + //delete health check from GCE + gceOperations.deleteHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + } + /** + * This method is used to create target pools, forwarding rule and a health check related to a cluster + * in IaaS side according to new topology + */ + private void createConfigurationForCluster(String clusterId) { - //create a health check - gceOperations.createHealthCheck(GCELoadBalancerConfiguration.getHealthCheckName()); + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); - gceOperations.createFirewallRule(); + //create a health check + gceOperations.createHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); - //crate a target pool in GCE - gceOperations.createTargetPool(GCELoadBalancerConfiguration.getTargetPoolName(), - GCELoadBalancerConfiguration.getHealthCheckName()); + gceOperations.createFirewallRule(); - //add instances to target pool - gceOperations.addInstancesToTargetPool(GCELoadBalancerConfiguration.getInstancesList(), - GCELoadBalancerConfiguration.getTargetPoolName()); + //crate a target pool in GCE + gceOperations.createTargetPool(gceLoadBalancerConfiguration.getTargetPoolName(), + gceLoadBalancerConfiguration.getHealthCheckName()); - //create forwarding rules in GCE - List ipList = GCELoadBalancerConfiguration.getIpList(); - //need to create a port range String - String portRange = ""; - //if the ip list is empty - if (ipList.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Ip list is null"); - } - //as a temporary solution set all ports to be open - portRange = "1-65535"; + //add instances to target pool + gceOperations.addInstancesToTargetPool(gceLoadBalancerConfiguration.getInstancesList(), + gceLoadBalancerConfiguration.getTargetPoolName()); + //create forwarding rules in GCE + List ipList = gceLoadBalancerConfiguration.getIpList(); + //need to create a port range String + String portRange = ""; + //if the ip list is empty + if (ipList.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("Ip list is null"); } - //else if ip list has only one value - else if (ipList.size() == 1) { - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); - } - //else we have more than 1 value - else { - //first we need to take the port range. So arrange ipList in ascending order - Collections.sort(ipList); - //take the first one and last one - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); - } + //as a temporary solution set all ports to be open + portRange = "1-65535"; - //create the forwarding rule - gceOperations.createForwardingRule(GCELoadBalancerConfiguration.getForwardingRuleName(), - GCELoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); + } + //else if ip list has only one value + else if (ipList.size() == 1) { + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); + } + //else we have more than 1 value + else { + //first we need to take the port range. So arrange ipList in ascending order + Collections.sort(ipList); + //take the first one and last one + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); + } + //create the forwarding rule + gceOperations.createForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName(), + gceLoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); - } } @@ -287,9 +301,6 @@ else if (ipList.size() == 1) { public void start() throws LoadBalancerExtensionException { //topology has completed - log.info("Starting GCE Load balancer instance"); - - log.info("GCE Load balancer instance started"); } @@ -298,9 +309,10 @@ public void start() throws LoadBalancerExtensionException { public void stop() throws LoadBalancerExtensionException { log.info("GCE Load Balancer is stopping"); + //iterate through hashmap and remove all - deleteAll(); + //deleteAll(); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 72bddffb62..71a9d16d5f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -411,7 +411,6 @@ public TargetPool getTargetPool(String targetPoolName) { } - /** * Remove given set of instances from target pool * @@ -510,15 +509,15 @@ public void createHealthCheck(String healthCheckName) { } } - public void deleteHealthCheck(String healthCheckName){ - try { - Operation operation = compute.httpHealthChecks().delete(PROJECT_ID, healthCheckName).execute(); - waitForGlobalOperationCompletion(operation.getName()); + public void deleteHealthCheck(String healthCheckName) { + try { + Operation operation = compute.httpHealthChecks().delete(PROJECT_ID, healthCheckName).execute(); + waitForGlobalOperationCompletion(operation.getName()); - } catch (IOException e) { - e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); - } + } } From f0e9970586d8edd9ecf4a93554ecbc84d096175b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 22:11:46 +0530 Subject: [PATCH 127/217] implementing listening to topology and update it --- .../java/org/apache/stratos/gce/extension/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 71a9d16d5f..bddc6b5490 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -323,7 +323,7 @@ public void deleteForwardingRule(String forwardingRuleName) { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); - waitForGlobalOperationCompletion(operation.getName()); + waitForRegionOperationCompletion(operation.getName()); } catch (IOException e) { e.printStackTrace(); From c6eb780f0f19356d6cf87ad1eebbac1fef05226c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 17 Jun 2015 22:46:46 +0530 Subject: [PATCH 128/217] implementing listening to topology and update it --- .../gce/extension/GCELoadBalancer.java | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 7b62fe7b34..671c9e5cfc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -72,6 +72,38 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Configuring Load balancer "); + //check whether any cluster is removed. If removed, then remove the cluster from + //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too + + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()) { //for each configuration + + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + + boolean found = false; + + //check whether cluster is in the map or not + for (Service service : topology.getServices()) { + for (Cluster cluster : service.getClusters()) { //for each cluster + if(cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())){ + found = true; + break; + } + } + if (found == true){ + break; + } + } + if (found==false){ + //remove cluster from map + clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); + deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); + } + } + + for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster @@ -191,37 +223,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } - //check whether any cluster is removed. If removed, then remove the cluster from - //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too - - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()) { //for each configuration - - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - - boolean found = false; - - //check whether cluster is in the map or not - for (Service service : topology.getServices()) { - for (Cluster cluster : service.getClusters()) { //for each cluster - if(cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())){ - found = true; - break; - } - } - if (found == true){ - break; - } - } - if (found==false){ - //remove cluster from map - clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); - deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); - } - } - return true; } From a6ee0ab2cd84b8262107401aa56dfee37091d3c4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 18 Jun 2015 10:27:15 +0530 Subject: [PATCH 129/217] implementing listening to topology and update it --- .../org/apache/stratos/gce/extension/GCELoadBalancer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 671c9e5cfc..f4ba2a683c 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -181,7 +181,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { //add instance to instance list - instancesList.add(member.getInstanceId()); + if (member.getInstanceId() != null) { + instancesList.add(member.getInstanceId()); + } //add forwarding rules(Ports to be forwarded) for (Object port : member.getPorts()) { From 0a272060c57d9f1b37d7f0f5a9b1e6b95fcf721b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 18 Jun 2015 11:21:02 +0530 Subject: [PATCH 130/217] implementing listening to topology and update it --- .../stratos/gce/extension/GCEOperations.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index bddc6b5490..c0e0ff85a8 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -246,6 +246,8 @@ private void buildComputeEngineObject() throws GeneralSecurityException, IOExcep */ public void createTargetPool(String targetPoolName, String healthCheckName) { + log.info("Creating target pool: " + targetPoolName); + TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); List httpHealthChecks = new ArrayList(); @@ -273,6 +275,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { * @param targetPoolName - Name of the target pool in IaaS */ public void deleteTargetPool(String targetPoolName) { + log.info("Deleting target pool: " + targetPoolName); try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); waitForRegionOperationCompletion(operation.getName()); @@ -283,6 +286,7 @@ public void deleteTargetPool(String targetPoolName) { e.printStackTrace(); } + log.info("Deleted target pool: "+ targetPoolName); } /** @@ -295,6 +299,7 @@ public void deleteTargetPool(String targetPoolName) { public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol, String portRange) { + log.info("Creating a forwarding rule: " + forwardingRuleName); //Need to get target pool resource URL TargetPool targetPool = getTargetPool(targetPoolName); String targetPoolURL = targetPool.getSelfLink(); @@ -311,6 +316,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } catch (IOException e) { e.printStackTrace(); } + log.info("Created forwarding rule: "+ forwardingRuleName); } /** @@ -319,6 +325,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam * @param forwardingRuleName - Forwarding rule name in IaaS */ public void deleteForwardingRule(String forwardingRuleName) { + log.info("Deleting forwarding rule: " + forwardingRuleName); try { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); @@ -328,6 +335,7 @@ public void deleteForwardingRule(String forwardingRuleName) { } catch (IOException e) { e.printStackTrace(); } + log.info("Deleted forwarding rule: " + forwardingRuleName); } /** @@ -448,12 +456,10 @@ public void setPortRangeToForwardingRule() { */ public void addInstancesToTargetPool(List instancesIdsList, String targetPoolName) { - log.info("Adding instances to target pool"); + log.info("Adding instances to target pool: " + targetPoolName); if (instancesIdsList.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Cannot add instances to target pool. InstancesNamesList is empty."); - } + log.info("Cannot add instances to target pool. InstancesNamesList is empty."); return; } @@ -484,6 +490,8 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe } catch (IOException e) { e.printStackTrace(); } + + log.info("Added instances to target pool: "+ targetPoolName); } /** @@ -493,6 +501,8 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe */ public void createHealthCheck(String healthCheckName) { + log.info("Creating health check: "+ healthCheckName); + HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); httpHealthCheck.setName(healthCheckName); httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); @@ -507,9 +517,11 @@ public void createHealthCheck(String healthCheckName) { } catch (IOException e) { e.printStackTrace(); } + log.info("Created health check: "+ healthCheckName); } public void deleteHealthCheck(String healthCheckName) { + log.info("Deleting Health Check: "+ healthCheckName); try { Operation operation = compute.httpHealthChecks().delete(PROJECT_ID, healthCheckName).execute(); waitForGlobalOperationCompletion(operation.getName()); @@ -518,6 +530,8 @@ public void deleteHealthCheck(String healthCheckName) { e.printStackTrace(); } + log.info("Deleted Health Check: "+ healthCheckName); + } @@ -628,6 +642,8 @@ private void waitForZoneOperationCompletion(String operationName) { public void createFirewallRule() { + log.info("Creating firewall rule"); + List sourceRanges = new ArrayList(); sourceRanges.add("0.0.0.0/0"); @@ -651,6 +667,7 @@ public void createFirewallRule() { } catch (IOException e) { e.printStackTrace(); } + log.info("Created firewall rule"); } From f91e38922799227c18b587d2a42b3a18e780d5bb Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 18 Jun 2015 12:02:36 +0530 Subject: [PATCH 131/217] implementing listening to topology and update it --- extensions/load-balancer/gce-extension/pom.xml | 3 +-- .../stratos/gce/extension/GCELoadBalancer.java | 14 ++++++++++++++ .../stratos/gce/extension/GCEOperations.java | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index 3453b63b4f..3a0df35c54 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -88,13 +88,12 @@ ${project.version} - + 1.19.0 diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index f4ba2a683c..752f858e5b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,6 +19,11 @@ package org.apache.stratos.gce.extension; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.converters.reflection.FieldDictionary; +import com.thoughtworks.xstream.converters.reflection.ImmutableFieldKeySorter; +import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider; +import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.common.domain.*; @@ -72,6 +77,11 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Configuring Load balancer "); + XStream xstream = new XStream(new Sun14ReflectionProvider( + new FieldDictionary(new ImmutableFieldKeySorter())), + new DomDriver("utf-8")); + log.info(xstream.toXML(topology)); + //check whether any cluster is removed. If removed, then remove the cluster from //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too @@ -110,6 +120,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //check whether this cluster has a forwarding rule configuration or not if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { + log.info("Reconfiguring the existing cluster: " + cluster.getClusterId()); + //It already has a entry in clusterToLoadBalancerConfigurationMap. //Take it and update it as the given topology. @@ -175,6 +187,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } else { //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map + log.info("Found a new cluster: " + cluster.getClusterId()); + List instancesList = new ArrayList(); List ipList = new ArrayList(); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index c0e0ff85a8..d00b8ce686 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -459,7 +459,7 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe log.info("Adding instances to target pool: " + targetPoolName); if (instancesIdsList.isEmpty()) { - log.info("Cannot add instances to target pool. InstancesNamesList is empty."); + log.warn("Cannot add instances to target pool. InstancesNamesList is empty."); return; } From 2e196cf1cb05dcd18115f5f0b9d1cb33e5343dbc Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 18 Jun 2015 13:49:23 +0530 Subject: [PATCH 132/217] changing the configure logic --- .../gce/extension/GCELoadBalancer.java | 167 +++++++++++------- .../GCELoadBalancerConfiguration.java | 34 +++- .../stratos/gce/extension/GCEOperations.java | 55 ++++-- 3 files changed, 166 insertions(+), 90 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 752f858e5b..db10150f09 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -97,16 +97,16 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //check whether cluster is in the map or not for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster - if(cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())){ + if (cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())) { found = true; break; } } - if (found == true){ + if (found == true) { break; } } - if (found==false){ + if (found == false) { //remove cluster from map clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); @@ -125,28 +125,70 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //It already has a entry in clusterToLoadBalancerConfigurationMap. //Take it and update it as the given topology. - //delete all objects created in IaaS side(in load balancing perspective) relevant - // to this cluster before create new objects - deleteConfigurationForCluster(cluster.getClusterId()); - - //get load balancer configuration - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. get(cluster.getClusterId()); - //check and update - List updatedInstancesList = new ArrayList(); - List updatedIPList = new ArrayList(); + //if the cluster does not contain at least one member + if (cluster.getMembers().size() == 0) { + + //remove all + deleteConfigurationForCluster(cluster.getClusterId()); + clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); + + } else { + //that cluster contains at least one member + + //***************detect member changes and update**************// + + //check for newly created members + List membersToBeAddedToTargetPool = new ArrayList(); + for (Member member : cluster.getMembers()) { + + if (member.getInstanceId() != null) { + if (!gceLoadBalancerConfiguration.getMemberList().contains(member.getInstanceId())) { + membersToBeAddedToTargetPool.add(member.getInstanceId()); + gceLoadBalancerConfiguration.addMember(member.getInstanceId()); + } + } + + } - for (Member member : cluster.getMembers()) { + if (membersToBeAddedToTargetPool.size() > 0) { //we have new members + //add to target pool + gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, + gceLoadBalancerConfiguration.getTargetPoolName()); + } - if (member.getInstanceId() != null) { - if (!updatedInstancesList.contains(member.getInstanceId())) { - updatedInstancesList.add(member.getInstanceId()); + //check for terminated members and remove them from cluster + List membersToBeRemovedFromTargetPool = new ArrayList(); + for (String memberId : gceLoadBalancerConfiguration.getMemberList()) { //for all members in Map + boolean found = false; + for (Member member : cluster.getMembers()) { //for all members in cluster + if (member.getMemberId().equals(memberId)) { + found = true; + break; + } + } + if (found == false) { + //remove member from map + gceLoadBalancerConfiguration.removeMember(memberId); + membersToBeRemovedFromTargetPool.add(memberId); } } - //checking for forwarding rules and updating + if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members + + //remove them + gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, + gceLoadBalancerConfiguration.getTargetPoolName()); + } + + //****************detect port map changes and update it*************// + + //todo detect port map changes and update it + + /* //checking for forwarding rules and updating for (Object port : member.getPorts()) { int portValue = ((Port) port).getValue(); //if not present update it @@ -156,84 +198,79 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } - } - - //set new forwarding rules and instances list - GCELoadBalancerConfiguration.setIpList(updatedIPList); - GCELoadBalancerConfiguration.setInstancesList(updatedInstancesList); + */ - if (GCELoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name - //set target pool name - String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); - } + //********************null checks**************// - if (GCELoadBalancerConfiguration.getForwardingRuleName() == null) { - //set forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); - } + if (gceLoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name + //set target pool name + String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); + gceLoadBalancerConfiguration.setTargetPoolName(targetPoolName); + } - if (GCELoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name - //set health check name - String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); - } + if (gceLoadBalancerConfiguration.getForwardingRuleName() == null) { + //set forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); + gceLoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + } - //create objects in IaaS side - createConfigurationForCluster(cluster.getClusterId()); + if (gceLoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name + //set health check name + String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); + gceLoadBalancerConfiguration.setHealthCheckName(healthCheckName); + } + } } else { //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map log.info("Found a new cluster: " + cluster.getClusterId()); - List instancesList = new ArrayList(); - List ipList = new ArrayList(); + if (cluster.getMembers().size() == 0) { + log.info("Cluster " + cluster.getClusterId() + "does not have any members. So not configuring"); + } else { + List instancesList = new ArrayList(); + List ipList = new ArrayList(); - for (Member member : cluster.getMembers()) { + for (Member member : cluster.getMembers()) { - //add instance to instance list - if (member.getInstanceId() != null) { - instancesList.add(member.getInstanceId()); - } + //add instance to instance list + if (member.getInstanceId() != null) { + instancesList.add(member.getInstanceId()); + } - //add forwarding rules(Ports to be forwarded) - for (Object port : member.getPorts()) { - int portValue = ((Port) port).getValue(); - if (!ipList.contains(portValue)) { //if port is not in list - //put the forwarding rule to list - ipList.add(portValue); + //add forwarding rules(Ports to be forwarded) + for (Object port : member.getPorts()) { + int portValue = ((Port) port).getValue(); + if (!ipList.contains(portValue)) { //if port is not in list + //put the forwarding rule to list + ipList.add(portValue); + } } - } - } + } - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = new GCELoadBalancerConfiguration( - cluster.getClusterId(), instancesList, ipList); + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = new GCELoadBalancerConfiguration( + cluster.getClusterId(), instancesList, ipList); - if (GCELoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); - } - if (GCELoadBalancerConfiguration.getForwardingRuleName() == null) { //set forwarding rule name String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); - } - if (GCELoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); - } - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); - createConfigurationForCluster(cluster.getClusterId()); + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); + createConfigurationForCluster(cluster.getClusterId()); + + } } } @@ -278,7 +315,7 @@ private void createConfigurationForCluster(String clusterId) { gceLoadBalancerConfiguration.getHealthCheckName()); //add instances to target pool - gceOperations.addInstancesToTargetPool(gceLoadBalancerConfiguration.getInstancesList(), + gceOperations.addInstancesToTargetPool(gceLoadBalancerConfiguration.getMemberList(), gceLoadBalancerConfiguration.getTargetPoolName()); //create forwarding rules in GCE diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java index f77370fbe0..96f2a21f33 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java @@ -31,9 +31,9 @@ public class GCELoadBalancerConfiguration { - //A load balancer must have set of instances - private List instancesList; - //A load balancer can have one IPs to be forwarded + //A cluster should have set of members + private List memberList; + //A cluster can have one IPs to be forwarded private List ipList; //cluster ID from stratos side private String clusterID; @@ -42,10 +42,10 @@ public class GCELoadBalancerConfiguration { private String healthCheckName; - public GCELoadBalancerConfiguration(String clusterID, List instancesList, + public GCELoadBalancerConfiguration(String clusterID, List memberList, List ipList) { this.clusterID = clusterID; - this.instancesList = instancesList; + this.memberList = memberList; this.ipList = ipList; } @@ -65,12 +65,12 @@ public void setForwardingRuleName(String forwardingRuleName) { this.forwardingRuleName = forwardingRuleName; } - public List getInstancesList() { - return instancesList; + public List getMemberList() { + return memberList; } - public void setInstancesList(List instancesList) { - this.instancesList = instancesList; + public void setMemberList(List memberList) { + this.memberList = memberList; } @@ -93,4 +93,20 @@ public String getHealthCheckName() { public void setHealthCheckName(String healthCheckName) { this.healthCheckName = healthCheckName; } + + public void addMember(String memberId) { + this.memberList.add(memberId); + } + + public void removeMember(String memberId) { + this.memberList.remove(memberId); + } + + public void addIp(int ip) { + this.ipList.add(ip); + } + + public void removeIp(int ip) { + this.ipList.remove(ip); + } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index d00b8ce686..d4a55309f9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -286,7 +286,7 @@ public void deleteTargetPool(String targetPoolName) { e.printStackTrace(); } - log.info("Deleted target pool: "+ targetPoolName); + log.info("Deleted target pool: " + targetPoolName); } /** @@ -316,7 +316,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } catch (IOException e) { e.printStackTrace(); } - log.info("Created forwarding rule: "+ forwardingRuleName); + log.info("Created forwarding rule: " + forwardingRuleName); } /** @@ -422,23 +422,46 @@ public TargetPool getTargetPool(String targetPoolName) { /** * Remove given set of instances from target pool * - * @param targetPoolName - target pool name from IaaS - * @param instanceReferenceList - List of instances to be removed from target pool + * @param targetPoolName - target pool name from IaaS + * @param instancesIdsList - List of instances to be removed from target pool */ - public void removeInstancesFromTargetPool(String targetPoolName, List - instanceReferenceList) { - TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest - = new TargetPoolsRemoveInstanceRequest(); + public void removeInstancesFromTargetPool(List instancesIdsList, String targetPoolName) { + log.info("Removing instances from target pool: " + targetPoolName); + + if (instancesIdsList.isEmpty()) { + log.warn("Cannot remove instances to target pool. InstancesNamesList is empty."); + return; + } + + List instanceReferenceList = new ArrayList(); + + //add instance to instance reference list, we should use the instance URL + for (String instanceId : instancesIdsList) { //for all instances + + instanceReferenceList.add(new InstanceReference(). + setInstance(getInstanceURLFromId(instanceId))); + + } + + //create target pools add instance request and set instance to it + TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest = new + TargetPoolsRemoveInstanceRequest(); targetPoolsRemoveInstanceRequest.setInstances(instanceReferenceList); - //TODO: remove try catch + + //todo Remove try catch try { - compute.targetPools().removeInstance(PROJECT_ID, REGION_NAME, + //execute + Operation operation = compute.targetPools().removeInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsRemoveInstanceRequest).execute(); + waitForRegionOperationCompletion(operation.getName()); + + } catch (IOException e) { e.printStackTrace(); } + log.info("Removed instances from target pool: " + targetPoolName); } /** @@ -459,7 +482,7 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe log.info("Adding instances to target pool: " + targetPoolName); if (instancesIdsList.isEmpty()) { - log.warn("Cannot add instances to target pool. InstancesNamesList is empty."); + log.warn("Cannot add instances to target pool. InstancesNamesList is empty."); return; } @@ -491,7 +514,7 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe e.printStackTrace(); } - log.info("Added instances to target pool: "+ targetPoolName); + log.info("Added instances to target pool: " + targetPoolName); } /** @@ -501,7 +524,7 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe */ public void createHealthCheck(String healthCheckName) { - log.info("Creating health check: "+ healthCheckName); + log.info("Creating health check: " + healthCheckName); HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); httpHealthCheck.setName(healthCheckName); @@ -517,11 +540,11 @@ public void createHealthCheck(String healthCheckName) { } catch (IOException e) { e.printStackTrace(); } - log.info("Created health check: "+ healthCheckName); + log.info("Created health check: " + healthCheckName); } public void deleteHealthCheck(String healthCheckName) { - log.info("Deleting Health Check: "+ healthCheckName); + log.info("Deleting Health Check: " + healthCheckName); try { Operation operation = compute.httpHealthChecks().delete(PROJECT_ID, healthCheckName).execute(); waitForGlobalOperationCompletion(operation.getName()); @@ -530,7 +553,7 @@ public void deleteHealthCheck(String healthCheckName) { e.printStackTrace(); } - log.info("Deleted Health Check: "+ healthCheckName); + log.info("Deleted Health Check: " + healthCheckName); } From 4e05e7605c30c6e1fd3323438d23af98800ab29e Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 18 Jun 2015 13:56:16 +0530 Subject: [PATCH 133/217] changing the configure logic --- .../apache/stratos/gce/extension/GCELoadBalancer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index db10150f09..7f071cbdfe 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -75,7 +75,7 @@ public GCELoadBalancer() { @Override public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("Configuring Load balancer "); + log.info("Topology received. Configuring Load balancer "); XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), @@ -108,6 +108,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } if (found == false) { //remove cluster from map + log.info("Removed cluster is found. Remove it from GCE too. Cluster Id: " + + gceLoadBalancerConfiguration.getClusterID()); clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); } @@ -132,6 +134,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //if the cluster does not contain at least one member if (cluster.getMembers().size() == 0) { + log.info("Cluster: " + cluster.getClusterId() + " does not have any member.So remove cluster " + + "from GCE too"); //remove all deleteConfigurationForCluster(cluster.getClusterId()); clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); @@ -155,6 +159,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } if (membersToBeAddedToTargetPool.size() > 0) { //we have new members + + log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + + "to cluster"); //add to target pool gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, gceLoadBalancerConfiguration.getTargetPoolName()); @@ -179,6 +186,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members + log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); + //remove them gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, gceLoadBalancerConfiguration.getTargetPoolName()); From f048b6d37a399dcc3fd1751e57540dc6897950d7 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 18 Jun 2015 14:33:57 +0530 Subject: [PATCH 134/217] changing the configure logic --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 7f071cbdfe..a6fe20dfa1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -172,7 +172,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (String memberId : gceLoadBalancerConfiguration.getMemberList()) { //for all members in Map boolean found = false; for (Member member : cluster.getMembers()) { //for all members in cluster - if (member.getMemberId().equals(memberId)) { + //todo: retest this line + if (member.getInstanceId().equals(memberId)) { found = true; break; } From 3a126c0f8f1d7d8cb7cf34c9b1f55356abe01359 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 18 Jun 2015 18:26:43 +0530 Subject: [PATCH 135/217] changing the configure logic --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index a6fe20dfa1..68e26382f1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -77,6 +77,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Topology received. Configuring Load balancer "); + + //printing the topology for tesging purposes XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver("utf-8")); From 9e7b79d0e0de53ccc18a9d5d7ea64bd0c71c9e37 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Fri, 19 Jun 2015 20:44:55 +0530 Subject: [PATCH 136/217] Exception handling --- .../messaging/topology/TopologyBuilder.java | 12 +- .../stratos/gce/extension/Constants.java | 1 - .../stratos/gce/extension/GCEContext.java | 1 - .../gce/extension/GCELoadBalancer.java | 401 +++++++++--------- .../stratos/gce/extension/GCEOperations.java | 279 ++++++------ 5 files changed, 348 insertions(+), 346 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index fb160ca6bd..10b2e6035f 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -392,6 +392,11 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); cluster.addMember(member); + if(CloudControllerContext.getInstance().getMemberContextOfMemberId( + memberContext.getMemberId()).getInstanceId() != null) { + member.setInstanceId(CloudControllerContext.getInstance(). + getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); + } TopologyManager.updateTopology(topology); } finally { TopologyManager.releaseWriteLock(); @@ -440,8 +445,11 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } - member.setInstanceId(CloudControllerContext.getInstance().getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); - + if(CloudControllerContext.getInstance().getMemberContextOfMemberId( + memberContext.getMemberId()).getInstanceId() != null) { + member.setInstanceId(CloudControllerContext.getInstance(). + getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); + } // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index f165441ebc..88d9a73d59 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -41,5 +41,4 @@ public class Constants { public static final String HEALTH_CHECK_TIME_OUT_SEC = "health.check.timeout.sec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "health.check.unhealthy.threshold"; public static final String NETWORK_NAME = "network.name"; - } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index d950df1cfc..7cf45b57f1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -184,7 +184,6 @@ public String getGceAccountID() { return gceAccountID; } - public String getHealthCheckRequestPath() { return healthCheckRequestPath; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 68e26382f1..36c9462796 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -30,8 +30,6 @@ import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; -import java.io.IOException; -import java.security.GeneralSecurityException; import java.util.*; //TODO: exception handling @@ -52,16 +50,10 @@ public class GCELoadBalancer implements LoadBalancer { private String protocol = "TCP"; public GCELoadBalancer() { - try { - gceOperations = new GCEOperations(); - clusterToLoadBalancerConfigurationMap = new HashMap(); - } catch (LoadBalancerExtensionException e) { - log.error(e); - } catch (GeneralSecurityException e) { - log.error(e); - } catch (IOException e) { - log.error(e); - } + + gceOperations = new GCEOperations(); + clusterToLoadBalancerConfigurationMap = new HashMap(); + } @@ -77,128 +69,127 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Topology received. Configuring Load balancer "); - //printing the topology for tesging purposes XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver("utf-8")); log.info(xstream.toXML(topology)); + try { + //check whether any cluster is removed. If removed, then remove the cluster from + //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too - //check whether any cluster is removed. If removed, then remove the cluster from - //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too - - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()) { //for each configuration + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()) { //for each configuration - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); - boolean found = false; + boolean found = false; - //check whether cluster is in the map or not - for (Service service : topology.getServices()) { - for (Cluster cluster : service.getClusters()) { //for each cluster - if (cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())) { - found = true; + //check whether cluster is in the map or not + for (Service service : topology.getServices()) { + for (Cluster cluster : service.getClusters()) { //for each cluster + if (cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())) { + found = true; + break; + } + } + if (found == true) { break; } } - if (found == true) { - break; + if (found == false) { + //remove cluster from map + log.info("Removed cluster is found. Remove it from GCE too. Cluster Id: " + + gceLoadBalancerConfiguration.getClusterID()); + clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); + deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); } } - if (found == false) { - //remove cluster from map - log.info("Removed cluster is found. Remove it from GCE too. Cluster Id: " + - gceLoadBalancerConfiguration.getClusterID()); - clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); - deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); - } - } - for (Service service : topology.getServices()) { - for (Cluster cluster : service.getClusters()) { //for each cluster + for (Service service : topology.getServices()) { + for (Cluster cluster : service.getClusters()) { //for each cluster - //check whether this cluster has a forwarding rule configuration or not - if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { + //check whether this cluster has a forwarding rule configuration or not + if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { - log.info("Reconfiguring the existing cluster: " + cluster.getClusterId()); + log.info("Reconfiguring the existing cluster: " + cluster.getClusterId()); - //It already has a entry in clusterToLoadBalancerConfigurationMap. - //Take it and update it as the given topology. + //It already has a entry in clusterToLoadBalancerConfigurationMap. + //Take it and update it as the given topology. - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. - get(cluster.getClusterId()); + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. + get(cluster.getClusterId()); - //if the cluster does not contain at least one member - if (cluster.getMembers().size() == 0) { + //if the cluster does not contain at least one member + if (cluster.getMembers().size() == 0) { - log.info("Cluster: " + cluster.getClusterId() + " does not have any member.So remove cluster " + - "from GCE too"); - //remove all - deleteConfigurationForCluster(cluster.getClusterId()); - clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); + log.info("Cluster: " + cluster.getClusterId() + " does not have any member.So remove cluster " + + "from GCE too"); + //remove all + deleteConfigurationForCluster(cluster.getClusterId()); + clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); - } else { - //that cluster contains at least one member + } else { + //that cluster contains at least one member - //***************detect member changes and update**************// + //***************detect member changes and update**************// - //check for newly created members - List membersToBeAddedToTargetPool = new ArrayList(); - for (Member member : cluster.getMembers()) { + //check for newly created members + List membersToBeAddedToTargetPool = new ArrayList(); + for (Member member : cluster.getMembers()) { - if (member.getInstanceId() != null) { - if (!gceLoadBalancerConfiguration.getMemberList().contains(member.getInstanceId())) { - membersToBeAddedToTargetPool.add(member.getInstanceId()); - gceLoadBalancerConfiguration.addMember(member.getInstanceId()); + if (member.getInstanceId() != null) { + if (!gceLoadBalancerConfiguration.getMemberList().contains(member.getInstanceId())) { + membersToBeAddedToTargetPool.add(member.getInstanceId()); + gceLoadBalancerConfiguration.addMember(member.getInstanceId()); + } } - } - } + } - if (membersToBeAddedToTargetPool.size() > 0) { //we have new members + if (membersToBeAddedToTargetPool.size() > 0) { //we have new members - log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + - "to cluster"); - //add to target pool - gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, - gceLoadBalancerConfiguration.getTargetPoolName()); - } + log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + + "to cluster"); + //add to target pool + gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, + gceLoadBalancerConfiguration.getTargetPoolName()); + } - //check for terminated members and remove them from cluster - List membersToBeRemovedFromTargetPool = new ArrayList(); - for (String memberId : gceLoadBalancerConfiguration.getMemberList()) { //for all members in Map - boolean found = false; - for (Member member : cluster.getMembers()) { //for all members in cluster - //todo: retest this line - if (member.getInstanceId().equals(memberId)) { - found = true; - break; + //check for terminated members and remove them from cluster + List membersToBeRemovedFromTargetPool = new ArrayList(); + for (String memberId : gceLoadBalancerConfiguration.getMemberList()) { //for all members in Map + boolean found = false; + for (Member member : cluster.getMembers()) { //for all members in cluster + //todo: retest this line + if (member.getInstanceId().equals(memberId)) { + found = true; + break; + } + } + if (found == false) { + //remove member from map + gceLoadBalancerConfiguration.removeMember(memberId); + membersToBeRemovedFromTargetPool.add(memberId); } } - if (found == false) { - //remove member from map - gceLoadBalancerConfiguration.removeMember(memberId); - membersToBeRemovedFromTargetPool.add(memberId); - } - } - if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members + if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members - log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); + log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); - //remove them - gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, - gceLoadBalancerConfiguration.getTargetPoolName()); - } + //remove them + gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, + gceLoadBalancerConfiguration.getTargetPoolName()); + } - //****************detect port map changes and update it*************// + //****************detect port map changes and update it*************// - //todo detect port map changes and update it + //todo detect port map changes and update it /* //checking for forwarding rules and updating for (Object port : member.getPorts()) { @@ -212,100 +203,112 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } */ - //********************null checks**************// + //********************null checks**************// - if (gceLoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name - //set target pool name - String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - gceLoadBalancerConfiguration.setTargetPoolName(targetPoolName); - } + if (gceLoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name + //set target pool name + String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); + gceLoadBalancerConfiguration.setTargetPoolName(targetPoolName); + } - if (gceLoadBalancerConfiguration.getForwardingRuleName() == null) { - //set forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - gceLoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); - } + if (gceLoadBalancerConfiguration.getForwardingRuleName() == null) { + //set forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); + gceLoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + } - if (gceLoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name - //set health check name - String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - gceLoadBalancerConfiguration.setHealthCheckName(healthCheckName); - } + if (gceLoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name + //set health check name + String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); + gceLoadBalancerConfiguration.setHealthCheckName(healthCheckName); + } - } + } - } else { - //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map + } else { + //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map - log.info("Found a new cluster: " + cluster.getClusterId()); + log.info("Found a new cluster: " + cluster.getClusterId()); - if (cluster.getMembers().size() == 0) { - log.info("Cluster " + cluster.getClusterId() + "does not have any members. So not configuring"); - } else { - List instancesList = new ArrayList(); - List ipList = new ArrayList(); + if (cluster.getMembers().size() == 0) { + log.info("Cluster " + cluster.getClusterId() + "does not have any members. So not configuring"); + } else { + List instancesList = new ArrayList(); + List ipList = new ArrayList(); - for (Member member : cluster.getMembers()) { + for (Member member : cluster.getMembers()) { - //add instance to instance list - if (member.getInstanceId() != null) { - instancesList.add(member.getInstanceId()); - } + //add instance to instance list + if (member.getInstanceId() != null) { + instancesList.add(member.getInstanceId()); + } - //add forwarding rules(Ports to be forwarded) - for (Object port : member.getPorts()) { - int portValue = ((Port) port).getValue(); - if (!ipList.contains(portValue)) { //if port is not in list - //put the forwarding rule to list - ipList.add(portValue); + //add forwarding rules(Ports to be forwarded) + for (Object port : member.getPorts()) { + int portValue = ((Port) port).getValue(); + if (!ipList.contains(portValue)) { //if port is not in list + //put the forwarding rule to list + ipList.add(portValue); + } } - } - } + } - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = new GCELoadBalancerConfiguration( - cluster.getClusterId(), instancesList, ipList); + GCELoadBalancerConfiguration GCELoadBalancerConfiguration = new GCELoadBalancerConfiguration( + cluster.getClusterId(), instancesList, ipList); - //set target pool name - String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); + //set target pool name + String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); + GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); - //set forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + //set forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); + GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); - //set health check name - String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); + //set health check name + String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); + GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); - createConfigurationForCluster(cluster.getClusterId()); + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); + createConfigurationForCluster(cluster.getClusterId()); + } } + } + } + log.info("Load balancer configured as given topology"); + return true; + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Failed to configure load balancer"); } + throw new LoadBalancerExtensionException(e); } - - - return true; } /** * This method is used to delete all fowarding rules, target pools and health checks * in IaaS side according to new topology */ - private void deleteConfigurationForCluster(String clusterId) { - - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); + private void deleteConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { - //delete forwarding rule - gceOperations.deleteForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName()); - //delete target pool from GCE - gceOperations.deleteTargetPool(gceLoadBalancerConfiguration.getTargetPoolName()); - //delete health check from GCE - gceOperations.deleteHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); + try { + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); + //delete forwarding rule + gceOperations.deleteForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName()); + //delete target pool from GCE + gceOperations.deleteTargetPool(gceLoadBalancerConfiguration.getTargetPoolName()); + //delete health check from GCE + gceOperations.deleteHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Could not delete configuration for cluster " + clusterId); + } + throw new LoadBalancerExtensionException(); + } } @@ -313,52 +316,59 @@ private void deleteConfigurationForCluster(String clusterId) { * This method is used to create target pools, forwarding rule and a health check related to a cluster * in IaaS side according to new topology */ - private void createConfigurationForCluster(String clusterId) { + private void createConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); + try { - //create a health check - gceOperations.createHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); - gceOperations.createFirewallRule(); + //create a health check + gceOperations.createHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); - //crate a target pool in GCE - gceOperations.createTargetPool(gceLoadBalancerConfiguration.getTargetPoolName(), - gceLoadBalancerConfiguration.getHealthCheckName()); + gceOperations.createFirewallRule(); - //add instances to target pool - gceOperations.addInstancesToTargetPool(gceLoadBalancerConfiguration.getMemberList(), - gceLoadBalancerConfiguration.getTargetPoolName()); + //crate a target pool in GCE + gceOperations.createTargetPool(gceLoadBalancerConfiguration.getTargetPoolName(), + gceLoadBalancerConfiguration.getHealthCheckName()); - //create forwarding rules in GCE - List ipList = gceLoadBalancerConfiguration.getIpList(); - //need to create a port range String - String portRange = ""; - //if the ip list is empty - if (ipList.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Ip list is null"); - } - //as a temporary solution set all ports to be open - portRange = "1-65535"; + //add instances to target pool + gceOperations.addInstancesToTargetPool(gceLoadBalancerConfiguration.getMemberList(), + gceLoadBalancerConfiguration.getTargetPoolName()); - } - //else if ip list has only one value - else if (ipList.size() == 1) { - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); - } - //else we have more than 1 value - else { - //first we need to take the port range. So arrange ipList in ascending order - Collections.sort(ipList); - //take the first one and last one - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); - } + //create forwarding rules in GCE + List ipList = gceLoadBalancerConfiguration.getIpList(); + //need to create a port range String + String portRange = ""; + //if the ip list is empty + if (ipList.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("Ip list is null"); + } + //as a temporary solution set all ports to be open + portRange = "1-65535"; - //create the forwarding rule - gceOperations.createForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName(), - gceLoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); + } + //else if ip list has only one value + else if (ipList.size() == 1) { + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); + } + //else we have more than 1 value + else { + //first we need to take the port range. So arrange ipList in ascending order + Collections.sort(ipList); + //take the first one and last one + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); + } + //create the forwarding rule + gceOperations.createForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName(), + gceLoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); + } catch (Exception e) { + if (log.isErrorEnabled()) { + log.error("Could not create configuration for cluster " + clusterId); + } + throw new LoadBalancerExtensionException(); + } } @@ -446,6 +456,5 @@ private String healthCheckNameCreator(String clusterID) { } return healthCheckName; - } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index d4a55309f9..5d4fda8048 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -24,8 +24,6 @@ import com.google.api.client.http.HttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.jackson2.JacksonFactory; -import com.google.api.client.util.store.DataStoreFactory; -import com.google.api.client.util.store.FileDataStoreFactory; import com.google.api.services.compute.Compute; import com.google.api.services.compute.ComputeScopes; import com.google.api.services.compute.model.*; @@ -65,13 +63,8 @@ public class GCEOperations { private static final String HEALTH_CHECK_TIME_OUT_SEC = GCEContext.getInstance().getHealthCheckTimeOutSec(); private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); private static final String NETWORK_NAME = GCEContext.getInstance().getNetworkName(); - /** - * Directory to store user credentials. - */ - private static final String DATA_STORE_DIR = ".store/gce-extension"; - private static final String RUNNING_FILTER = "status eq RUNNING"; - private static final int OPERATION_TIMEOUT_MSILEC = 10000; + private static final String RUNNING_FILTER = "status eq RUNNING"; static Compute compute; @@ -83,13 +76,8 @@ public class GCEOperations { * @throws GeneralSecurityException * @throws IOException */ - public GCEOperations() throws LoadBalancerExtensionException, - GeneralSecurityException, IOException { - + public GCEOperations() { buildComputeEngineObject(); - - //Calling following methods from here only for testing purposes - } /** @@ -97,87 +85,67 @@ public GCEOperations() throws LoadBalancerExtensionException, * when we need to check whether a given instance is available or not in a given project * and zone) * - * @return + * @return instanceList - list of instances(members in Stratos side) * @throws IOException */ - public static InstanceList getInstanceList() throws IOException { - Compute.Instances.List instances = compute.instances(). - list(PROJECT_ID, ZONE_NAME).setFilter(RUNNING_FILTER); - InstanceList instanceList = instances.execute(); - if (instanceList.getItems() == null) { - log.info("No instances found for specified zone"); - return null; - } else { - return instanceList; - } - } - - public static String getInstanceURLFromName(String instanceName) { - - //todo:remove try catch - String instanceURL; + public static InstanceList getInstanceList() { + Compute.Instances.List instances = null; try { - //check whether the given instance is available - InstanceList instanceList = getInstanceList(); - for (Instance instance : instanceList.getItems()) { - if (instance.getName().equals(instanceName)) { - //instance is available - //getInstance URL - instanceURL = instance.getSelfLink(); - return instanceURL; - } + instances = compute.instances(). + list(PROJECT_ID, ZONE_NAME).setFilter(RUNNING_FILTER); + InstanceList instanceList = instances.execute(); + if (instanceList.getItems() == null) { + log.info("No instances found for specified zone"); + return null; + } else { + return instanceList; } - } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not get instance list from GCE"); + } + throw new RuntimeException(e); } - return null; } + /** * Get instance resource URL from given instance name * - * @param instanceId - * @return + * @param instanceId - Id of the instance provided by IaaS + * @return - Resource URL of the instance in IaaS */ public static String getInstanceURLFromId(String instanceId) { - //todo:remove try catch String instanceURL; - try { - //check whether the given instance is available - InstanceList instanceList = getInstanceList(); - for (Instance instance : instanceList.getItems()) { - //todo: recheck following line - String instanceIdInIaaS = ZONE_NAME + "/" + instance.getName(); - if (instanceIdInIaaS.equals(instanceId)) { - //instance is available - //getInstance URL - instanceURL = instance.getSelfLink(); - return instanceURL; - } + //check whether the given instance is available + InstanceList instanceList = getInstanceList(); + for (Instance instance : instanceList.getItems()) { + String instanceIdInIaaS = ZONE_NAME + "/" + instance.getName(); + if (instanceIdInIaaS.equals(instanceId)) { + //instance is available + //getInstance URL + instanceURL = instance.getSelfLink(); + return instanceURL; } - - } catch (IOException e) { - e.printStackTrace(); } return null; - } /** * Get a given health check resource URL * * @param healthCheckName - name of the health check in IaaS - * @return + * @return - Resource URL of health check in IaaS side */ public static String getHealthCheckURLFromName(String healthCheckName) { String healthCheckURL; //check whether the given instance is available - HttpHealthCheckList healthCheckList = getHealthCheckList(); + HttpHealthCheckList healthCheckList; + healthCheckList = getHealthCheckList(); for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { if (httpHealthCheck.getName().equals(healthCheckName)) { //instance is available @@ -187,17 +155,18 @@ public static String getHealthCheckURLFromName(String healthCheckName) { } } return null; - } /** * Get list of health checks * - * @return + * @return - list of health checks */ - public static HttpHealthCheckList getHealthCheckList() { + private static HttpHealthCheckList getHealthCheckList() { + + Compute.HttpHealthChecks.List healthChecks; try { - Compute.HttpHealthChecks.List healthChecks = compute.httpHealthChecks().list(PROJECT_ID); + healthChecks = compute.httpHealthChecks().list(PROJECT_ID); HttpHealthCheckList healthCheckList = healthChecks.execute(); if (healthCheckList.getItems() == null) { log.info("No health check found for specified project"); @@ -206,9 +175,11 @@ public static HttpHealthCheckList getHealthCheckList() { return healthCheckList; } } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not get health check list from GCE"); + } + throw new RuntimeException(e); } - return null; } /** @@ -217,25 +188,35 @@ public static HttpHealthCheckList getHealthCheckList() { * @throws GeneralSecurityException * @throws IOException */ - private void buildComputeEngineObject() throws GeneralSecurityException, IOException { - - HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); - DataStoreFactory dataStoreFactory = new FileDataStoreFactory(new - File(System.getProperty("user.home"), DATA_STORE_DIR)); - JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); - - GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) - .setJsonFactory(jsonFactory) - .setServiceAccountId(ACCOUNT_ID) - .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) - .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_PATH)) - .build(); + private void buildComputeEngineObject() { - // Create compute engine object - compute = new Compute.Builder( - httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) - .setHttpRequestInitializer(credential).build(); + try { + HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); + JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); + + GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) + .setJsonFactory(jsonFactory) + .setServiceAccountId(ACCOUNT_ID) + .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) + .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_PATH)) + .build(); + + // Create compute engine object + compute = new Compute.Builder( + httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) + .setHttpRequestInitializer(credential).build(); + } catch (GeneralSecurityException e) { + if (log.isErrorEnabled()) { + log.error("Could not authenticate and build compute object"); + throw new RuntimeException(e); + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Could not authenticate and build compute object"); + throw new RuntimeException(e); + } + } } @@ -254,7 +235,6 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { httpHealthChecks.add(getHealthCheckURLFromName(healthCheckName)); targetPool.setHealthChecks(httpHealthChecks); - //TODO:REMOVE try catch try { Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); @@ -262,9 +242,9 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("failed to create target pool: " + targetPoolName); + log.error("Could not create target pool: " + targetPoolName); } - e.printStackTrace(); + throw new RuntimeException(e); } } @@ -280,13 +260,13 @@ public void deleteTargetPool(String targetPoolName) { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); waitForRegionOperationCompletion(operation.getName()); - int timeout = 0; - } catch (IOException e) { - e.printStackTrace(); - + if (log.isErrorEnabled()) { + log.error("Could not delete target pool " + targetPoolName); + } + throw new RuntimeException(e); } - log.info("Deleted target pool: " + targetPoolName); + log.info("Target pool: " + targetPoolName + " has been deleted"); } /** @@ -314,7 +294,10 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not create a forwarding rule " + forwardingRuleName); + } + throw new RuntimeException(e); } log.info("Created forwarding rule: " + forwardingRuleName); } @@ -333,7 +316,10 @@ public void deleteForwardingRule(String forwardingRuleName) { waitForRegionOperationCompletion(operation.getName()); } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not delete forwarding rule " + forwardingRuleName); + } + throw new RuntimeException(e); } log.info("Deleted forwarding rule: " + forwardingRuleName); } @@ -346,7 +332,6 @@ public void deleteForwardingRule(String forwardingRuleName) { */ public boolean isTargetPoolExists(String targetPoolName) { - //TODO: remove try catch try { Compute.TargetPools.List targetPools = compute.targetPools(). list(PROJECT_ID, REGION_NAME); @@ -362,7 +347,7 @@ public boolean isTargetPoolExists(String targetPoolName) { if (log.isErrorEnabled()) { log.error("Error caused when checking for target pools"); } - e.printStackTrace(); + throw new RuntimeException(e); } return false; @@ -372,7 +357,7 @@ public boolean isTargetPoolExists(String targetPoolName) { * Check whether a given forwarding rule is exists or not in the IaaS * * @param forwardingRuleName - forwarding rule name in IaaS - * @return + * @return - if forwarding rule exists in GCE return true. else return false */ public boolean isForwardingRuleExists(String forwardingRuleName) { try { @@ -384,7 +369,9 @@ public boolean isForwardingRuleExists(String forwardingRuleName) { } } } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not get check for forwarding rule " + forwardingRuleName); + } } return false; } @@ -393,16 +380,16 @@ public boolean isForwardingRuleExists(String forwardingRuleName) { * Get a target pool already created in GCE * * @param targetPoolName - target pool name in IaaS - * @return + * @return - target pool object */ public TargetPool getTargetPool(String targetPoolName) { - //todo:remove try catch + try { if (isTargetPoolExists(targetPoolName)) { return compute.targetPools().get(PROJECT_ID, REGION_NAME, targetPoolName).execute(); } else { if (log.isDebugEnabled()) { - log.debug("Requested Target Pool Is not Available"); + log.debug("Requested Target Pool " + targetPoolName + " Is not Available"); } } @@ -410,11 +397,10 @@ public TargetPool getTargetPool(String targetPoolName) { } catch (IOException e) { if (log.isErrorEnabled()) { - log.error("Exception caused when try to get target pool"); + log.error("Could not get target pool " + targetPoolName); } - e.printStackTrace(); + throw new RuntimeException(e); } - return null; } @@ -448,7 +434,6 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String TargetPoolsRemoveInstanceRequest(); targetPoolsRemoveInstanceRequest.setInstances(instanceReferenceList); - //todo Remove try catch try { //execute Operation operation = compute.targetPools().removeInstance(PROJECT_ID, REGION_NAME, @@ -458,7 +443,10 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not remove instances from target pool " + targetPoolName); + } + throw new RuntimeException(e); } log.info("Removed instances from target pool: " + targetPoolName); @@ -501,19 +489,18 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe TargetPoolsAddInstanceRequest(); targetPoolsAddInstanceRequest.setInstances(instanceReferenceList); - //todo Remove try catch try { //execute Operation operation = compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); - waitForRegionOperationCompletion(operation.getName()); - } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not add instance to target pool" + targetPoolName); + } + throw new RuntimeException(e); } - log.info("Added instances to target pool: " + targetPoolName); } @@ -529,7 +516,6 @@ public void createHealthCheck(String healthCheckName) { HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); httpHealthCheck.setName(healthCheckName); httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); - //TODO: read as integers httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); @@ -538,7 +524,10 @@ public void createHealthCheck(String healthCheckName) { waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not create health check " + healthCheckName); + } + throw new RuntimeException(e); } log.info("Created health check: " + healthCheckName); } @@ -550,19 +539,19 @@ public void deleteHealthCheck(String healthCheckName) { waitForGlobalOperationCompletion(operation.getName()); } catch (IOException e) { - e.printStackTrace(); - + if (log.isErrorEnabled()) { + log.error("Could not get delete health check " + healthCheckName); + } + throw new RuntimeException(e); } log.info("Deleted Health Check: " + healthCheckName); - - } /** * Checking whether a given health check is exists or not * * @param healthCheckName - name of the health check - * @return + * @return - if the health check exists in IaaS return true, else return false */ public boolean isHealthCheckExists(String healthCheckName) { try { @@ -576,22 +565,12 @@ public boolean isHealthCheckExists(String healthCheckName) { } } } catch (IOException e) { - e.printStackTrace(); - } - return false; - } - - //todo: remove this method(never used) - public HttpHealthCheck getHealthCheckFromName(String healthCheckName) { - - HttpHealthCheckList healthCheckList = getHealthCheckList(); - for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { - if (httpHealthCheck.getName().equals(healthCheckName)) { - //healthcheck is available - return httpHealthCheck; + if (log.isErrorEnabled()) { + log.error("Exception caused when checking for health checks "); } + throw new RuntimeException(e); } - return null; + return false; } /** @@ -610,10 +589,12 @@ private void waitForGlobalOperationCompletion(String operationName) { } Thread.sleep(1000); } - } catch (IOException e) { - e.printStackTrace(); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Could not wait for global operation completion " + operationName); + throw new RuntimeException(e); + } catch (IOException e) { + log.error("Could not wait for global operation completion " + operationName); + throw new RuntimeException(e); } } @@ -635,10 +616,12 @@ private void waitForRegionOperationCompletion(String operationName) { } Thread.sleep(1000); } - } catch (IOException e) { - e.printStackTrace(); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Could not wait for region operation completion " + operationName); + throw new RuntimeException(e); + } catch (IOException e) { + log.error("Could not wait for region operation completion " + operationName); + throw new RuntimeException(e); } } @@ -656,10 +639,12 @@ private void waitForZoneOperationCompletion(String operationName) { } Thread.sleep(1000); } - } catch (IOException e) { - e.printStackTrace(); } catch (InterruptedException e) { - e.printStackTrace(); + log.error("Could not wait for zone operation completion " + operationName); + throw new RuntimeException(e); + } catch (IOException e) { + log.error("Could not wait for zone operation completion " + operationName); + throw new RuntimeException(e); } } @@ -688,10 +673,12 @@ public void createFirewallRule() { try { compute.firewalls().insert(PROJECT_ID, firewall); } catch (IOException e) { - e.printStackTrace(); + if (log.isErrorEnabled()) { + log.error("Could not create firewall rule "); + } + throw new RuntimeException(e); } log.info("Created firewall rule"); } - } \ No newline at end of file From 9286f440bf68279ad22aae6acdbab97447121ec2 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Fri, 19 Jun 2015 20:45:27 +0530 Subject: [PATCH 137/217] Exception handling --- .../src/main/java/org/apache/stratos/gce/extension/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index f8cf2b3916..3420571ba3 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -75,7 +75,6 @@ public void run() { extension.setExecutorService(executorService); extension.execute(); - } catch (Exception e) { if (log.isErrorEnabled()) { log.error(e); From 737e962bfdd0e0965c72fd3aef057989a009c08b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 21 Jun 2015 10:31:18 +0530 Subject: [PATCH 138/217] stop method implementation --- .../stratos/gce/extension/GCELoadBalancer.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 36c9462796..d89180df9f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -231,7 +231,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Found a new cluster: " + cluster.getClusterId()); if (cluster.getMembers().size() == 0) { - log.info("Cluster " + cluster.getClusterId() + "does not have any members. So not configuring"); + log.info("Cluster " + cluster.getClusterId() + " does not have any members. So not configuring"); } else { List instancesList = new ArrayList(); List ipList = new ArrayList(); @@ -388,7 +388,16 @@ public void stop() throws LoadBalancerExtensionException { //iterate through hashmap and remove all - //deleteAll(); + Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); + while (iterator.hasNext()) { //for each configuration + + Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = + ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + + deleteConfigurationForCluster((String) clusterIDLoadBalancerConfigurationPair.getKey()); + + } } @@ -399,6 +408,7 @@ public void stop() throws LoadBalancerExtensionException { @Override public void reload() throws LoadBalancerExtensionException { + log.info("===========================reload method called==============="); //iterate through hash map //find what needs to be changed //execute From 3e5637d4693564c9ed990c195df095aebd036b7b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 25 Jun 2015 19:13:45 +0530 Subject: [PATCH 139/217] stop method implementation --- .../org/apache/stratos/gce/extension/GCELoadBalancer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index d89180df9f..8c0646f457 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -32,7 +32,6 @@ import java.util.*; -//TODO: exception handling public class GCELoadBalancer implements LoadBalancer { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); @@ -375,8 +374,7 @@ else if (ipList.size() == 1) { @Override public void start() throws LoadBalancerExtensionException { - //topology has completed - + //Configuration has completed log.info("GCE Load balancer instance started"); } From 1c8cb0ad5bee377c2610adbd14eee5a629736840 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 25 Jun 2015 19:41:58 +0530 Subject: [PATCH 140/217] stop method implementation --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 8c0646f457..51942ee9e6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -406,7 +406,7 @@ public void stop() throws LoadBalancerExtensionException { @Override public void reload() throws LoadBalancerExtensionException { - log.info("===========================reload method called==============="); + log.info("Configuration reloaded"); //iterate through hash map //find what needs to be changed //execute From c40d2d4caaeae03cb874ff684ada21251a58f5e2 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 25 Jun 2015 22:14:29 +0530 Subject: [PATCH 141/217] fixing a problem in LoadBalancerExtension class --- .../load/balancer/extension/api/LoadBalancerExtension.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java index 421b261a05..35b61ac31e 100644 --- a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java +++ b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java @@ -183,6 +183,9 @@ protected void onEvent(Event event) { if (!loadBalancerStarted) { configureAndStart(); } + else { + configureAndReload(); + } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Could not start load balancer", e); @@ -258,7 +261,7 @@ private void configureAndReload() throws LoadBalancerExtensionException { // Configure load balancer if (loadBalancer.configure(topologyProvider.getTopology())) { // Reload the load balancer - loadBalancer.reload(); + loadBalancer.reload(); } } From d1b9d1426e6e9c85e51c6f20a3b89136482ac363 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 25 Jun 2015 22:15:30 +0530 Subject: [PATCH 142/217] reverting changes in loadBalancerExtension class --- .../load/balancer/extension/api/LoadBalancerExtension.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java index 35b61ac31e..6722fc28f3 100644 --- a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java +++ b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java @@ -183,9 +183,6 @@ protected void onEvent(Event event) { if (!loadBalancerStarted) { configureAndStart(); } - else { - configureAndReload(); - } } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Could not start load balancer", e); From ca7f68aef3d08334450fb39d4d41cf685e817aba Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 10:38:43 +0530 Subject: [PATCH 143/217] refining GCELoadBalancer class code --- .../gce/extension/GCELoadBalancer.java | 51 ++++--------------- 1 file changed, 9 insertions(+), 42 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 51942ee9e6..4c304896f9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -68,7 +68,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Topology received. Configuring Load balancer "); - //printing the topology for tesging purposes + //printing the topology for testing purposes XStream xstream = new XStream(new Sun14ReflectionProvider( new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver("utf-8")); @@ -118,7 +118,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //It already has a entry in clusterToLoadBalancerConfigurationMap. //Take it and update it as the given topology. - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. get(cluster.getClusterId()); @@ -186,42 +185,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio gceLoadBalancerConfiguration.getTargetPoolName()); } - //****************detect port map changes and update it*************// - - //todo detect port map changes and update it - - /* //checking for forwarding rules and updating - for (Object port : member.getPorts()) { - int portValue = ((Port) port).getValue(); - //if not present update it - if (!updatedIPList.contains(portValue)) { //if port is not in list - //put the forwarding rule to list - updatedIPList.add(portValue); - } - - } - */ - - //********************null checks**************// - - if (gceLoadBalancerConfiguration.getTargetPoolName() == null) { //this does not have a target pool name - //set target pool name - String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - gceLoadBalancerConfiguration.setTargetPoolName(targetPoolName); - } - - if (gceLoadBalancerConfiguration.getForwardingRuleName() == null) { - //set forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - gceLoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); - } - - if (gceLoadBalancerConfiguration.getHealthCheckName() == null) {//if this does not have a forwarding rule name - //set health check name - String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - gceLoadBalancerConfiguration.setHealthCheckName(healthCheckName); - } - } } else { @@ -268,7 +231,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); createConfigurationForCluster(cluster.getClusterId()); @@ -295,6 +257,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio private void deleteConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { try { + log.info("Deleting forwarding rule for cluster " + clusterId); GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); //delete forwarding rule gceOperations.deleteForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName()); @@ -302,6 +265,7 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer gceOperations.deleteTargetPool(gceLoadBalancerConfiguration.getTargetPoolName()); //delete health check from GCE gceOperations.deleteHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); + log.info("Deleted forwarding rule for cluster " + clusterId); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Could not delete configuration for cluster " + clusterId); @@ -319,6 +283,8 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer try { + log.info("Creating configuration for cluster"); + GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); //create a health check @@ -362,6 +328,7 @@ else if (ipList.size() == 1) { //create the forwarding rule gceOperations.createForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName(), gceLoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); + log.info("Created configuration for cluster"); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Could not create configuration for cluster " + clusterId); @@ -369,6 +336,7 @@ else if (ipList.size() == 1) { throw new LoadBalancerExtensionException(); } + } @@ -397,6 +365,8 @@ public void stop() throws LoadBalancerExtensionException { } + log.info("GCE Load balancer stopped"); + } @@ -407,9 +377,6 @@ public void stop() throws LoadBalancerExtensionException { public void reload() throws LoadBalancerExtensionException { log.info("Configuration reloaded"); - //iterate through hash map - //find what needs to be changed - //execute } From 846c4e2eb2f3dd0aa7399a2bd16a945a366fccff Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 11:00:29 +0530 Subject: [PATCH 144/217] remove instanceId field from instanceContext class --- .../stratos/cloud/controller/domain/InstanceContext.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java index bacd3e7418..797c66549a 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java @@ -36,8 +36,6 @@ public class InstanceContext { private Properties properties; private boolean isVolumeRequired; private Volume[] volumes; - //instance id provided by IaaS provider - private String instanceId; public String getClusterId() { return clusterId; @@ -119,11 +117,4 @@ public void setVolumes(Volume[] volumes) { this.volumes = ArrayUtils.clone(volumes); } - public String getInstanceId() { - return instanceId; - } - - public void setInstanceId(String instanceId) { - this.instanceId = instanceId; - } } From a3a98c0c6c3d6733f43e25a349da25265627dae2 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 11:09:07 +0530 Subject: [PATCH 145/217] removing member.setInstanceId from member initialized event in TopologyBuilder Class --- .../messaging/topology/TopologyBuilder.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index f35b0b9120..745672f1f7 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -420,10 +420,8 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); cluster.addMember(member); - if(CloudControllerContext.getInstance().getMemberContextOfMemberId( - memberContext.getMemberId()).getInstanceId() != null) { - member.setInstanceId(CloudControllerContext.getInstance(). - getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); + if(memberContext.getInstanceId() != null) { + member.setInstanceId(memberContext.getInstanceId()); } TopologyManager.updateTopology(topology); } finally { @@ -473,12 +471,6 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } - if(CloudControllerContext.getInstance().getMemberContextOfMemberId( - memberContext.getMemberId()).getInstanceId() != null) { - member.setInstanceId(CloudControllerContext.getInstance(). - getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); - } - // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { log.error("Invalid state transition from " + member.getStatus() + " to " + From 32ae9b220d3454fedfe8f97d4e467a8e0cf43ebf Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 11:12:41 +0530 Subject: [PATCH 146/217] remove extra tab in LoadBalancerExtension class --- .../load/balancer/extension/api/LoadBalancerExtension.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java index 6722fc28f3..421b261a05 100644 --- a/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java +++ b/components/org.apache.stratos.load.balancer.extension.api/src/main/java/org/apache/stratos/load/balancer/extension/api/LoadBalancerExtension.java @@ -258,7 +258,7 @@ private void configureAndReload() throws LoadBalancerExtensionException { // Configure load balancer if (loadBalancer.configure(topologyProvider.getTopology())) { // Reload the load balancer - loadBalancer.reload(); + loadBalancer.reload(); } } From 163b45f5a6ad4deedf1221a05bcb748b9bd56dec Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 11:15:54 +0530 Subject: [PATCH 147/217] adding removed "/n" in TopologyBuilder class --- .../cloud/controller/messaging/topology/TopologyBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 745672f1f7..9cddb4370c 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -471,6 +471,7 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } + // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { log.error("Invalid state transition from " + member.getStatus() + " to " + From b3eb7bbc686afa49645569353024de3e2c396605 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 11:44:56 +0530 Subject: [PATCH 148/217] remove setting instanceId in member initialized event --- .../controller/messaging/topology/TopologyBuilder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 9cddb4370c..a41d7e2cc8 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -420,8 +420,10 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); cluster.addMember(member); - if(memberContext.getInstanceId() != null) { - member.setInstanceId(memberContext.getInstanceId()); + if(CloudControllerContext.getInstance().getMemberContextOfMemberId( + memberContext.getMemberId()).getInstanceId() != null) { + member.setInstanceId(CloudControllerContext.getInstance(). + getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); } TopologyManager.updateTopology(topology); } finally { From 8b3d1f099aad3c57aa651b3689e66727e6777868 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 12:10:29 +0530 Subject: [PATCH 149/217] setting instanceId in member initialized event --- .../cloud/controller/messaging/topology/TopologyBuilder.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index a41d7e2cc8..f35b0b9120 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -473,6 +473,11 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } + if(CloudControllerContext.getInstance().getMemberContextOfMemberId( + memberContext.getMemberId()).getInstanceId() != null) { + member.setInstanceId(CloudControllerContext.getInstance(). + getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); + } // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { From fc2fa2c5a77d62c1a2e37da246b3d51562756f8d Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 12:55:28 +0530 Subject: [PATCH 150/217] Adding instance Id field again to instanceContext class --- .../stratos/cloud/controller/domain/InstanceContext.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java index 797c66549a..bacd3e7418 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java @@ -36,6 +36,8 @@ public class InstanceContext { private Properties properties; private boolean isVolumeRequired; private Volume[] volumes; + //instance id provided by IaaS provider + private String instanceId; public String getClusterId() { return clusterId; @@ -117,4 +119,11 @@ public void setVolumes(Volume[] volumes) { this.volumes = ArrayUtils.clone(volumes); } + public String getInstanceId() { + return instanceId; + } + + public void setInstanceId(String instanceId) { + this.instanceId = instanceId; + } } From 1d529b74b5f59227ff0669ff11bccd87ecf0b15a Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 13:19:39 +0530 Subject: [PATCH 151/217] revert changes in topologyBuilder class and InstanceContext class --- .../stratos/cloud/controller/domain/InstanceContext.java | 9 --------- .../controller/messaging/topology/TopologyBuilder.java | 5 ----- 2 files changed, 14 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java index bacd3e7418..797c66549a 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/InstanceContext.java @@ -36,8 +36,6 @@ public class InstanceContext { private Properties properties; private boolean isVolumeRequired; private Volume[] volumes; - //instance id provided by IaaS provider - private String instanceId; public String getClusterId() { return clusterId; @@ -119,11 +117,4 @@ public void setVolumes(Volume[] volumes) { this.volumes = ArrayUtils.clone(volumes); } - public String getInstanceId() { - return instanceId; - } - - public void setInstanceId(String instanceId) { - this.instanceId = instanceId; - } } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index f35b0b9120..a41d7e2cc8 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -473,11 +473,6 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } - if(CloudControllerContext.getInstance().getMemberContextOfMemberId( - memberContext.getMemberId()).getInstanceId() != null) { - member.setInstanceId(CloudControllerContext.getInstance(). - getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); - } // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { From 97baeaa645b8423be9d8f6323cb476a2b371a59c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 13:32:36 +0530 Subject: [PATCH 152/217] revert changes in topologyBuilder class and InstanceContext class --- .../controller/messaging/topology/TopologyBuilder.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index a41d7e2cc8..3b67cd1605 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -420,11 +420,7 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); cluster.addMember(member); - if(CloudControllerContext.getInstance().getMemberContextOfMemberId( - memberContext.getMemberId()).getInstanceId() != null) { - member.setInstanceId(CloudControllerContext.getInstance(). - getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); - } + member.setInstanceId(memberContext.getInstanceId()); TopologyManager.updateTopology(topology); } finally { TopologyManager.releaseWriteLock(); From eb858b8258c7a0d737933bf2c72748601d0b2e82 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 13:41:38 +0530 Subject: [PATCH 153/217] revert changes in topologyBuilder class and InstanceContext class --- .../controller/messaging/topology/TopologyBuilder.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 3b67cd1605..4b3085dd8a 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -420,7 +420,6 @@ public static void handleMemberCreatedEvent(MemberContext memberContext) { member.setLbClusterId(lbClusterId); member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); cluster.addMember(member); - member.setInstanceId(memberContext.getInstanceId()); TopologyManager.updateTopology(topology); } finally { TopologyManager.releaseWriteLock(); @@ -469,6 +468,11 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } + if(CloudControllerContext.getInstance().getMemberContextOfMemberId( + memberContext.getMemberId()).getInstanceId() != null) { + member.setInstanceId(CloudControllerContext.getInstance(). + getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); + } // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { From 82eaa2b3f81575385b1d624658660c08681d8e20 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 15:27:26 +0530 Subject: [PATCH 154/217] fixing an error in topology builder class --- .../controller/messaging/topology/TopologyBuilder.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 4b3085dd8a..a73cd14e88 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -468,11 +468,7 @@ public static void handleMemberInitializedEvent(MemberContext memberContext) { if (memberContext.getPublicIPs() != null) { member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); } - if(CloudControllerContext.getInstance().getMemberContextOfMemberId( - memberContext.getMemberId()).getInstanceId() != null) { - member.setInstanceId(CloudControllerContext.getInstance(). - getMemberContextOfMemberId(memberContext.getMemberId()).getInstanceId()); - } + member.setInstanceId(memberContext.getInstanceId()); // try update lifecycle state if (!member.isStateTransitionValid(MemberStatus.Initialized)) { From 9f44791884a54499997a0e5d00f7a4b46047b3b2 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 27 Jun 2015 20:14:42 +0530 Subject: [PATCH 155/217] adding instaceID to message processor side --- .../cartridge/agent/test/JavaCartridgeAgentTest.java | 3 ++- .../messaging/publisher/TopologyEventPublisher.java | 3 ++- .../messaging/event/topology/MemberInitializedEvent.java | 9 ++++++++- .../topology/MemberInitializedMessageProcessor.java | 1 + .../test/PythonCartridgeAgentTest.java | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java b/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java index 3f0e73e510..d8126c80b4 100644 --- a/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java +++ b/components/org.apache.stratos.cartridge.agent/src/test/java/org/apache/stratos/cartridge/agent/test/JavaCartridgeAgentTest.java @@ -78,6 +78,7 @@ public class JavaCartridgeAgentTest { private static final String TENANT_ID = "-1234"; private static final String SERVICE_NAME = "php"; public static final String AGENT_NAME = "apache-stratos-cartridge-agent-4.1.0-SNAPSHOT"; + private static final String INSTANCE_ID = "instance-1"; private static HashMap executorList; private static ArrayList serverSocketList; private final ArtifactUpdatedEvent artifactUpdatedEvent; @@ -327,7 +328,7 @@ public void run() { // Publish member initialized event log.info("Publishing member initialized event..."); MemberInitializedEvent memberInitializedEvent = new MemberInitializedEvent( - SERVICE_NAME, CLUSTER_ID, CLUSTER_INSTANCE_ID, MEMBER_ID, NETWORK_PARTITION_ID, PARTITION_ID + SERVICE_NAME, CLUSTER_ID, CLUSTER_INSTANCE_ID, MEMBER_ID, NETWORK_PARTITION_ID, PARTITION_ID, INSTANCE_ID ); publishEvent(memberInitializedEvent); log.info("Member initialized event published"); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java index 7225a61f8a..b55d3a2b62 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java @@ -171,7 +171,8 @@ public static void sendMemberInitializedEvent(MemberContext memberContext) { memberContext.getClusterInstanceId(), memberContext.getMemberId(), memberContext.getNetworkPartitionId(), - memberContext.getPartition().getId()); + memberContext.getPartition().getId(), + memberContext.getInstanceId()); memberInitializedEvent.setDefaultPrivateIP(memberContext.getDefaultPrivateIP()); if (memberContext.getPrivateIPs() != null) { diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberInitializedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberInitializedEvent.java index edf64e307e..45adcc55ae 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberInitializedEvent.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberInitializedEvent.java @@ -36,6 +36,8 @@ public class MemberInitializedEvent extends TopologyEvent implements Serializabl private final String networkPartitionId; private final String partitionId; private final String memberId; + //instance Id provided by IaaS + private final String instanceId; private List memberPublicIPs; private String defaultPublicIP; @@ -44,13 +46,14 @@ public class MemberInitializedEvent extends TopologyEvent implements Serializabl private Properties properties; public MemberInitializedEvent(String serviceName, String clusterId, String clusterInstanceId, String memberId, - String networkPartitionId, String partitionId) { + String networkPartitionId, String partitionId, String instanceId) { this.serviceName = serviceName; this.clusterId = clusterId; this.clusterInstanceId = clusterInstanceId; this.memberId = memberId; this.networkPartitionId = networkPartitionId; this.partitionId = partitionId; + this.instanceId = instanceId; } public String getServiceName() { @@ -116,4 +119,8 @@ public List getMemberPrivateIPs() { public void setMemberPrivateIPs(List memberPrivateIPs) { this.memberPrivateIPs = memberPrivateIPs; } + + public String getInstanceId() { + return instanceId; + } } diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberInitializedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberInitializedMessageProcessor.java index bf3bb975ae..d0761b9a83 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberInitializedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberInitializedMessageProcessor.java @@ -133,6 +133,7 @@ private boolean doProcess(MemberInitializedEvent event, Topology topology) { member.setMemberPublicIPs(event.getMemberPublicIPs()); member.setDefaultPrivateIP(event.getDefaultPrivateIP()); member.setMemberPrivateIPs(event.getMemberPrivateIPs()); + member.setInstanceId(event.getInstanceId()); if (log.isInfoEnabled()) { log.info(String.format("Member initialized: [service] %s [cluster] %s [member] %s", diff --git a/components/org.apache.stratos.python.cartridge.agent/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java b/components/org.apache.stratos.python.cartridge.agent/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java index bb116cecf3..7a4e788272 100644 --- a/components/org.apache.stratos.python.cartridge.agent/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java +++ b/components/org.apache.stratos.python.cartridge.agent/src/test/java/org/apache/stratos/python.cartridge.agent/test/PythonCartridgeAgentTest.java @@ -70,6 +70,7 @@ public class PythonCartridgeAgentTest { private static final String TENANT_ID = "-1234"; private static final String SERVICE_NAME = "php"; public static final String SOURCE_PATH = "/tmp/stratos-pca-test-app-path/"; + private static final String INSTANCE_ID = "instance-1"; private static List serverSocketList; private static Map executorList; @@ -256,7 +257,7 @@ public void run() { // Publish member initialized event log.info("Publishing member initialized event..."); MemberInitializedEvent memberInitializedEvent = new MemberInitializedEvent( - SERVICE_NAME, CLUSTER_ID, CLUSTER_INSTANCE_ID, MEMBER_ID, NETWORK_PARTITION_ID, PARTITION_ID + SERVICE_NAME, CLUSTER_ID, CLUSTER_INSTANCE_ID, MEMBER_ID, NETWORK_PARTITION_ID, PARTITION_ID, INSTANCE_ID ); publishEvent(memberInitializedEvent); log.info("Member initialized event published"); From 9df565f1296707165e96755ca6a0b1c37bea53b1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 28 Jun 2015 11:14:19 +0530 Subject: [PATCH 156/217] Adding a timeout for operation completion --- .../src/main/bin/gce-extension.sh | 3 ++- .../stratos/gce/extension/Constants.java | 1 + .../stratos/gce/extension/GCEContext.java | 9 +++++++- .../stratos/gce/extension/GCEOperations.java | 23 +++++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index c4adee56e8..83a2149956 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -51,7 +51,8 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dhealth.check.port=80 -Dhealth.check.timeout.sec=5 -Dhealth.check.unhealthy.threshold=2 - -Dnetwork.name=default" + -Dnetwork.name=default + -Doperation.timeout=10000" # Uncomment below line to enable remote debugging debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java index 88d9a73d59..09fa4edffe 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java @@ -41,4 +41,5 @@ public class Constants { public static final String HEALTH_CHECK_TIME_OUT_SEC = "health.check.timeout.sec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "health.check.unhealthy.threshold"; public static final String NETWORK_NAME = "network.name"; + public static final String OPERATION_TIMEOUT = "operation.timeout"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java index 7cf45b57f1..47312366d2 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java @@ -49,6 +49,7 @@ public class GCEContext { private String healthCheckTimeOutSec; private String healthCheckUnhealthyThreshold; private String networkName; + private String operationTimeout; private GCEContext() { @@ -71,6 +72,7 @@ private GCEContext() { this.healthCheckTimeOutSec = System.getProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); this.healthCheckUnhealthyThreshold = System.getProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); this.networkName = System.getProperty(Constants.NETWORK_NAME); + this.operationTimeout = System.getProperty(Constants.OPERATION_TIMEOUT); if (log.isDebugEnabled()) { @@ -92,6 +94,7 @@ private GCEContext() { log.debug(Constants.HEALTH_CHECK_TIME_OUT_SEC + " = " + healthCheckTimeOutSec); log.debug(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD + " = " + healthCheckUnhealthyThreshold); log.debug(Constants.NETWORK_NAME + "=" + networkName); + log.debug(Constants.OPERATION_TIMEOUT + "=" + operationTimeout); } @@ -124,7 +127,7 @@ public void validate() { validateSystemProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); validateSystemProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); validateSystemProperty(Constants.NETWORK_NAME); - + validateSystemProperty(Constants.OPERATION_TIMEOUT); if (cepStatsPublisherEnabled) { validateSystemProperty(Constants.THRIFT_RECEIVER_IP); @@ -203,4 +206,8 @@ public String getHealthCheckUnhealthyThreshold() { public String getNetworkName() { return networkName; } + + public String getOperationTimeout() { + return operationTimeout; + } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java index 5d4fda8048..f3ea7a6fd4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java @@ -64,8 +64,12 @@ public class GCEOperations { private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); private static final String NETWORK_NAME = GCEContext.getInstance().getNetworkName(); + //a filter for get only running instances from IaaS side private static final String RUNNING_FILTER = "status eq RUNNING"; + //a timeout for operation completion + private static final int OPERATION_TIMEOUT = Integer.parseInt(GCEContext.getInstance().getOperationTimeout()); + static Compute compute; @@ -582,12 +586,18 @@ public boolean isHealthCheckExists(String healthCheckName) { private void waitForGlobalOperationCompletion(String operationName) { try { Thread.sleep(2000); + int timeout = 0; while (true) { Operation operation = compute.globalOperations().get(PROJECT_ID, operationName).execute(); if (operation.getStatus().equals("DONE")) { return; } + if (timeout >= OPERATION_TIMEOUT) { + log.warn("Timeout reached for operation " + operationName + ". Existing.."); + return; + } Thread.sleep(1000); + timeout += 1000; } } catch (InterruptedException e) { log.error("Could not wait for global operation completion " + operationName); @@ -608,13 +618,19 @@ private void waitForGlobalOperationCompletion(String operationName) { private void waitForRegionOperationCompletion(String operationName) { try { Thread.sleep(2000); + int timeout = 0; while (true) { Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); if (operation.getStatus().equals("DONE")) { return; } + if (timeout >= OPERATION_TIMEOUT) { + log.warn("Timeout reached for operation " + operationName + ". Existing.."); + return; + } Thread.sleep(1000); + timeout += 1000; } } catch (InterruptedException e) { log.error("Could not wait for region operation completion " + operationName); @@ -632,12 +648,19 @@ private void waitForRegionOperationCompletion(String operationName) { */ private void waitForZoneOperationCompletion(String operationName) { try { + Thread.sleep(2000); + int timeout = 0; while (true) { Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); if (operation.getStatus().equals("DONE")) { return; } + if (timeout >= OPERATION_TIMEOUT) { + log.warn("Timeout reached for operation " + operationName + ". Existing.."); + return; + } Thread.sleep(1000); + timeout += 1000; } } catch (InterruptedException e) { log.error("Could not wait for zone operation completion " + operationName); From 451e9a80fd1b3e90ec1e03a4db07c8730d071610 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 1 Jul 2015 19:29:03 +0530 Subject: [PATCH 157/217] configuration read from a xml file-1 --- .../load-balancer/gce-extension/pom.xml | 5 + .../src/main/conf/gce-configuration.xml | 47 +++++ .../gce/extension/GCELoadBalancer.java | 77 ++++---- .../apache/stratos/gce/extension/Main.java | 14 ++ .../gce/extension/{ => config}/Constants.java | 7 +- .../GCEClusterConfigurationHolder.java} | 8 +- .../config/GCEConfigurationHolder.java | 173 ++++++++++++++++++ .../extension/{ => config}/GCEContext.java | 24 +-- .../config/parser/GCEConfigParser.java | 48 +++++ .../extension/{ => util}/GCEOperations.java | 4 +- 10 files changed, 337 insertions(+), 70 deletions(-) create mode 100644 extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml rename extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/{ => config}/Constants.java (86%) rename extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/{GCELoadBalancerConfiguration.java => config/GCEClusterConfigurationHolder.java} (92%) create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java rename extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/{ => config}/GCEContext.java (89%) create mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java rename extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/{ => util}/GCEOperations.java (99%) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index 3a0df35c54..cb519a6bee 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -93,6 +93,11 @@ xstream 1.4.8 + + org.apache.ws.commons.axiom.wso2 + axiom + 1.2.11.wso2v4 + diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml new file mode 100644 index 0000000000..6b8edf1f1f --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -0,0 +1,47 @@ + + + + + + 127.0.0.1 + 7615 + + + lb + + MyFirstProject + gold-access-96509 + europe-west1-b + europe-west1 + /home/sanjaya/keys/p12key-donwloaded.p12 + 164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com + default + + + + / + 80 + 5 + 2 + + + 10000 + + \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 4c304896f9..377921be47 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -26,6 +26,9 @@ import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.gce.extension.config.GCEClusterConfigurationHolder; +import org.apache.stratos.gce.extension.config.GCEContext; +import org.apache.stratos.gce.extension.util.GCEOperations; import org.apache.stratos.load.balancer.common.domain.*; import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -43,7 +46,7 @@ public class GCELoadBalancer implements LoadBalancer { * This hash map is used to hold cluster IDs and corresponding configuration * So one cluster will have one loadBalancerConfiguration object */ - private HashMap clusterToLoadBalancerConfigurationMap; + private HashMap clusterToLoadBalancerConfigurationMap; //protocol should be TCP or UDP private String protocol = "TCP"; @@ -51,7 +54,7 @@ public class GCELoadBalancer implements LoadBalancer { public GCELoadBalancer() { gceOperations = new GCEOperations(); - clusterToLoadBalancerConfigurationMap = new HashMap(); + clusterToLoadBalancerConfigurationMap = new HashMap(); } @@ -81,15 +84,15 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio while (iterator.hasNext()) { //for each configuration Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + GCEClusterConfigurationHolder gceClusterConfigurationHolder = + ((GCEClusterConfigurationHolder) clusterIDLoadBalancerConfigurationPair.getValue()); boolean found = false; //check whether cluster is in the map or not for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster - if (cluster.getClusterId().equals(gceLoadBalancerConfiguration.getClusterID())) { + if (cluster.getClusterId().equals(gceClusterConfigurationHolder.getClusterID())) { found = true; break; } @@ -101,9 +104,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (found == false) { //remove cluster from map log.info("Removed cluster is found. Remove it from GCE too. Cluster Id: " + - gceLoadBalancerConfiguration.getClusterID()); - clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); - deleteConfigurationForCluster(gceLoadBalancerConfiguration.getClusterID()); + gceClusterConfigurationHolder.getClusterID()); + clusterToLoadBalancerConfigurationMap.remove(gceClusterConfigurationHolder.getClusterID()); + deleteConfigurationForCluster(gceClusterConfigurationHolder.getClusterID()); } } @@ -118,7 +121,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //It already has a entry in clusterToLoadBalancerConfigurationMap. //Take it and update it as the given topology. - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap. + GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap. get(cluster.getClusterId()); @@ -129,7 +132,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio "from GCE too"); //remove all deleteConfigurationForCluster(cluster.getClusterId()); - clusterToLoadBalancerConfigurationMap.remove(gceLoadBalancerConfiguration.getClusterID()); + clusterToLoadBalancerConfigurationMap.remove(gceClusterConfigurationHolder.getClusterID()); } else { //that cluster contains at least one member @@ -141,9 +144,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (Member member : cluster.getMembers()) { if (member.getInstanceId() != null) { - if (!gceLoadBalancerConfiguration.getMemberList().contains(member.getInstanceId())) { + if (!gceClusterConfigurationHolder.getMemberList().contains(member.getInstanceId())) { membersToBeAddedToTargetPool.add(member.getInstanceId()); - gceLoadBalancerConfiguration.addMember(member.getInstanceId()); + gceClusterConfigurationHolder.addMember(member.getInstanceId()); } } @@ -155,12 +158,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio "to cluster"); //add to target pool gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, - gceLoadBalancerConfiguration.getTargetPoolName()); + gceClusterConfigurationHolder.getTargetPoolName()); } //check for terminated members and remove them from cluster List membersToBeRemovedFromTargetPool = new ArrayList(); - for (String memberId : gceLoadBalancerConfiguration.getMemberList()) { //for all members in Map + for (String memberId : gceClusterConfigurationHolder.getMemberList()) { //for all members in Map boolean found = false; for (Member member : cluster.getMembers()) { //for all members in cluster //todo: retest this line @@ -171,7 +174,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } if (found == false) { //remove member from map - gceLoadBalancerConfiguration.removeMember(memberId); + gceClusterConfigurationHolder.removeMember(memberId); membersToBeRemovedFromTargetPool.add(memberId); } } @@ -182,13 +185,13 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //remove them gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, - gceLoadBalancerConfiguration.getTargetPoolName()); + gceClusterConfigurationHolder.getTargetPoolName()); } } } else { - //doesn't have a GCELoadBalancerConfiguration object. So crate a new one and add to hash map + //doesn't have a GCEClusterConfigurationHolder object. So crate a new one and add to hash map log.info("Found a new cluster: " + cluster.getClusterId()); @@ -216,22 +219,22 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } - GCELoadBalancerConfiguration GCELoadBalancerConfiguration = new GCELoadBalancerConfiguration( + GCEClusterConfigurationHolder GCEClusterConfigurationHolder = new GCEClusterConfigurationHolder( cluster.getClusterId(), instancesList, ipList); //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setTargetPoolName(targetPoolName); + GCEClusterConfigurationHolder.setTargetPoolName(targetPoolName); //set forwarding rule name String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setForwardingRuleName(forwardingRuleName); + GCEClusterConfigurationHolder.setForwardingRuleName(forwardingRuleName); //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - GCELoadBalancerConfiguration.setHealthCheckName(healthCheckName); + GCEClusterConfigurationHolder.setHealthCheckName(healthCheckName); - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCELoadBalancerConfiguration); + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCEClusterConfigurationHolder); createConfigurationForCluster(cluster.getClusterId()); } @@ -258,13 +261,13 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer try { log.info("Deleting forwarding rule for cluster " + clusterId); - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); + GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); //delete forwarding rule - gceOperations.deleteForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName()); + gceOperations.deleteForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName()); //delete target pool from GCE - gceOperations.deleteTargetPool(gceLoadBalancerConfiguration.getTargetPoolName()); + gceOperations.deleteTargetPool(gceClusterConfigurationHolder.getTargetPoolName()); //delete health check from GCE - gceOperations.deleteHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); + gceOperations.deleteHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); log.info("Deleted forwarding rule for cluster " + clusterId); } catch (Exception e) { if (log.isErrorEnabled()) { @@ -285,23 +288,23 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer log.info("Creating configuration for cluster"); - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = clusterToLoadBalancerConfigurationMap.get(clusterId); + GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); //create a health check - gceOperations.createHealthCheck(gceLoadBalancerConfiguration.getHealthCheckName()); + gceOperations.createHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); gceOperations.createFirewallRule(); //crate a target pool in GCE - gceOperations.createTargetPool(gceLoadBalancerConfiguration.getTargetPoolName(), - gceLoadBalancerConfiguration.getHealthCheckName()); + gceOperations.createTargetPool(gceClusterConfigurationHolder.getTargetPoolName(), + gceClusterConfigurationHolder.getHealthCheckName()); //add instances to target pool - gceOperations.addInstancesToTargetPool(gceLoadBalancerConfiguration.getMemberList(), - gceLoadBalancerConfiguration.getTargetPoolName()); + gceOperations.addInstancesToTargetPool(gceClusterConfigurationHolder.getMemberList(), + gceClusterConfigurationHolder.getTargetPoolName()); //create forwarding rules in GCE - List ipList = gceLoadBalancerConfiguration.getIpList(); + List ipList = gceClusterConfigurationHolder.getIpList(); //need to create a port range String String portRange = ""; //if the ip list is empty @@ -326,8 +329,8 @@ else if (ipList.size() == 1) { } //create the forwarding rule - gceOperations.createForwardingRule(gceLoadBalancerConfiguration.getForwardingRuleName(), - gceLoadBalancerConfiguration.getTargetPoolName(), protocol, portRange); + gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), + gceClusterConfigurationHolder.getTargetPoolName(), protocol, portRange); log.info("Created configuration for cluster"); } catch (Exception e) { if (log.isErrorEnabled()) { @@ -358,8 +361,8 @@ public void stop() throws LoadBalancerExtensionException { while (iterator.hasNext()) { //for each configuration Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCELoadBalancerConfiguration gceLoadBalancerConfiguration = - ((GCELoadBalancerConfiguration) clusterIDLoadBalancerConfigurationPair.getValue()); + GCEClusterConfigurationHolder gceClusterConfigurationHolder = + ((GCEClusterConfigurationHolder) clusterIDLoadBalancerConfigurationPair.getValue()); deleteConfigurationForCluster((String) clusterIDLoadBalancerConfigurationPair.getKey()); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 3420571ba3..d929e588e8 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -19,10 +19,14 @@ package org.apache.stratos.gce.extension; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.PropertyConfigurator; import org.apache.stratos.common.threading.StratosThreadPool; +import org.apache.stratos.gce.extension.config.GCEContext; +import org.apache.stratos.gce.extension.config.parser.GCEConfigParser; import org.apache.stratos.load.balancer.common.topology.TopologyProvider; import org.apache.stratos.load.balancer.extension.api.LoadBalancerExtension; @@ -31,14 +35,24 @@ /** * GCE extension main class. */ + + public class Main { private static final Log log = LogFactory.getLog(Main.class); private static ExecutorService executorService; + private static String configFilePath = "/conf/gce-configuration.xml"; + + public static void main(String[] args) { LoadBalancerExtension extension = null; try { + + //read configuration from gce-configuration.xml and store configuration in GCEConfigurationHolder class + OMElement documentElement = new StAXOMBuilder(configFilePath).getDocumentElement(); + GCEConfigParser.parse(documentElement); + // Configure log4j properties PropertyConfigurator.configure(System.getProperty("log4j.properties.file.path")); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java similarity index 86% rename from extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java rename to extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 09fa4edffe..6efd2501b5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.stratos.gce.extension; +package org.apache.stratos.gce.extension.config; /** * GCE extension constants. @@ -26,10 +26,7 @@ public class Constants { public static final String CEP_STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"; public static final String THRIFT_RECEIVER_IP = "thrift.receiver.ip"; public static final String THRIFT_RECEIVER_PORT = "thrift.receiver.port"; - public static final String NETWORK_PARTITION_ID = "network.partition.id"; - public static final String CLUSTER_ID = "cluster.id"; - public static final String SERVICE_NAME = "service.name"; - public static final String NAME_PREFIX = "name.prefix"; + static final String NAME_PREFIX = "name.prefix"; public static final String PROJECT_NAME = "project.name"; public static final String PROJECT_ID = "project.id"; public static final String ZONE_NAME = "zone.name"; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java similarity index 92% rename from extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java rename to extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java index 96f2a21f33..ee09205bdc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancerConfiguration.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.stratos.gce.extension; +package org.apache.stratos.gce.extension.config; import java.util.List; @@ -28,7 +28,7 @@ * This class is used to hold the configuration for a load balancer * Each cluster will have one object from this class */ -public class GCELoadBalancerConfiguration { +public class GCEClusterConfigurationHolder { //A cluster should have set of members @@ -42,8 +42,8 @@ public class GCELoadBalancerConfiguration { private String healthCheckName; - public GCELoadBalancerConfiguration(String clusterID, List memberList, - List ipList) { + public GCEClusterConfigurationHolder(String clusterID, List memberList, + List ipList) { this.clusterID = clusterID; this.memberList = memberList; this.ipList = ipList; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java new file mode 100644 index 0000000000..baf9b2eb52 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java @@ -0,0 +1,173 @@ +package org.apache.stratos.gce.extension.config; + +/** + * GCE config parser parse the gce-configuration.xml and stores + * the configuration in this singleton class to be used in the runtime. + */ +public class GCEConfigurationHolder { + + private static volatile GCEConfigurationHolder instance; + + private String cepStatsPublisherEnabled; + private String thriftReceiverIp; + private String thriftReceiverPort; + private String namePrefix; + private String projectName; + private String projectId; + private String zoneName; + private String regionName; + private String keyFilePath; + private String gceAccountId; + private String healthCheckRequestPath; + private String healthCheckRequestPort; + private String healthCheckTimeoutSec; + private String healthCheckUnhealthyThreshold; + private String networkName; + private String operationTimeout; + + //private constructor + private GCEConfigurationHolder(){} + + public static GCEConfigurationHolder getInstance() { + if (instance == null) { + synchronized (GCEConfigurationHolder.class) { + if (instance == null) { + instance = new GCEConfigurationHolder(); + } + } + } + return instance; + } + + public static void setInstance(GCEConfigurationHolder instance) { + GCEConfigurationHolder.instance = instance; + } + + public String getCepStatsPublisherEnabled() { + return cepStatsPublisherEnabled; + } + + public void setCepStatsPublisherEnabled(String cepStatsPublisherEnabled) { + this.cepStatsPublisherEnabled = cepStatsPublisherEnabled; + } + + public String getThriftReceiverIp() { + return thriftReceiverIp; + } + + public void setThriftReceiverIp(String thriftReceiverIp) { + this.thriftReceiverIp = thriftReceiverIp; + } + + public String getThriftReceiverPort() { + return thriftReceiverPort; + } + + public void setThriftReceiverPort(String thriftReceiverPort) { + this.thriftReceiverPort = thriftReceiverPort; + } + + public String getNamePrefix() { + return namePrefix; + } + + public void setNamePrefix(String namePrefix) { + this.namePrefix = namePrefix; + } + + public String getProjectName() { + return projectName; + } + + public void setProjectName(String projectName) { + this.projectName = projectName; + } + + public String getProjectId() { + return projectId; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + public String getZoneName() { + return zoneName; + } + + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + + public String getRegionName() { + return regionName; + } + + public void setRegionName(String regionName) { + this.regionName = regionName; + } + + public String getKeyFilePath() { + return keyFilePath; + } + + public void setKeyFilePath(String keyFilePath) { + this.keyFilePath = keyFilePath; + } + + public String getGceAccountId() { + return gceAccountId; + } + + public void setGceAccountId(String gceAccountId) { + this.gceAccountId = gceAccountId; + } + + public String getHealthCheckRequestPath() { + return healthCheckRequestPath; + } + + public void setHealthCheckRequestPath(String healthCheckRequestPath) { + this.healthCheckRequestPath = healthCheckRequestPath; + } + + public String getHealthCheckRequestPort() { + return healthCheckRequestPort; + } + + public void setHealthCheckRequestPort(String healthCheckRequestPort) { + this.healthCheckRequestPort = healthCheckRequestPort; + } + + public String getHealthCheckTimeoutSec() { + return healthCheckTimeoutSec; + } + + public void setHealthCheckTimeoutSec(String healthCheckTimeoutSec) { + this.healthCheckTimeoutSec = healthCheckTimeoutSec; + } + + public String getHealthCheckUnhealthyThreshold() { + return healthCheckUnhealthyThreshold; + } + + public void setHealthCheckUnhealthyThreshold(String healthCheckUnhealthyThreshold) { + this.healthCheckUnhealthyThreshold = healthCheckUnhealthyThreshold; + } + + public String getNetworkName() { + return networkName; + } + + public void setNetworkName(String networkName) { + this.networkName = networkName; + } + + public String getOperationTimeout() { + return operationTimeout; + } + + public void setOperationTimeout(String operationTimeout) { + this.operationTimeout = operationTimeout; + } +} diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java similarity index 89% rename from extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java rename to extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 47312366d2..4425bceb9c 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.stratos.gce.extension; +package org.apache.stratos.gce.extension.config; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; @@ -34,9 +34,6 @@ public class GCEContext { private boolean cepStatsPublisherEnabled; private String thriftReceiverIp; private String thriftReceiverPort; - private String networkPartitionId; - private String clusterId; - private String serviceName; private String namePrefix; private String projectName; private String projectID; @@ -57,9 +54,6 @@ private GCEContext() { this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); this.thriftReceiverIp = System.getProperty(Constants.THRIFT_RECEIVER_IP); this.thriftReceiverPort = System.getProperty(Constants.THRIFT_RECEIVER_PORT); - this.networkPartitionId = System.getProperty(Constants.NETWORK_PARTITION_ID); - this.clusterId = System.getProperty(Constants.CLUSTER_ID); - this.serviceName = System.getProperty(Constants.SERVICE_NAME); this.namePrefix = System.getProperty(Constants.NAME_PREFIX); this.projectName = System.getProperty(Constants.PROJECT_NAME); this.projectID = System.getProperty(Constants.PROJECT_ID); @@ -80,8 +74,6 @@ private GCEContext() { log.debug(Constants.THRIFT_RECEIVER_IP + " = " + thriftReceiverIp); log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); - log.debug(Constants.NETWORK_PARTITION_ID + " = " + networkPartitionId); - log.debug(Constants.CLUSTER_ID + " = " + clusterId); log.debug(Constants.NAME_PREFIX + " = " + namePrefix); log.debug(Constants.PROJECT_NAME + " = " + projectName); log.debug(Constants.PROJECT_ID + " = " + projectID); @@ -114,7 +106,6 @@ public static GCEContext getInstance() { public void validate() { validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED); - validateSystemProperty(Constants.CLUSTER_ID); validateSystemProperty(Constants.NAME_PREFIX); validateSystemProperty(Constants.PROJECT_NAME); validateSystemProperty(Constants.PROJECT_ID); @@ -132,7 +123,6 @@ public void validate() { if (cepStatsPublisherEnabled) { validateSystemProperty(Constants.THRIFT_RECEIVER_IP); validateSystemProperty(Constants.THRIFT_RECEIVER_PORT); - validateSystemProperty(Constants.NETWORK_PARTITION_ID); } } @@ -147,18 +137,6 @@ public boolean isCEPStatsPublisherEnabled() { return cepStatsPublisherEnabled; } - public String getNetworkPartitionId() { - return networkPartitionId; - } - - public String getClusterId() { - return clusterId; - } - - public String getServiceName() { - return serviceName; - } - public String getNamePrefix() { return namePrefix; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java new file mode 100644 index 0000000000..536a68d3ed --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -0,0 +1,48 @@ +package org.apache.stratos.gce.extension.config.parser; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMNode; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.stratos.common.exception.MalformedConfigurationFileException; +import org.apache.stratos.common.util.AxiomXpathParserUtil; + +public class GCEConfigParser { + private static final Log log = LogFactory.getLog(GCEConfigParser.class); + + /** + * Parse the gce-configuration file. + * + * @param documentElement axiom document element. + * @throws MalformedConfigurationFileException + */ + public static void parse(OMElement documentElement) throws MalformedConfigurationFileException { + + //get cep info + OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement,"cepStatsPublisher"); + log.info(cepInfoElement.getText()); + + //todo rest + + } + +} diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java similarity index 99% rename from extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java rename to extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index f3ea7a6fd4..93c7198f16 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.stratos.gce.extension; +package org.apache.stratos.gce.extension.util; import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; @@ -29,6 +29,8 @@ import com.google.api.services.compute.model.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.gce.extension.GCELoadBalancer; +import org.apache.stratos.gce.extension.config.GCEContext; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; import java.io.File; From 515b5438816362ce87ec6d1d2171994ca4ce1806 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 1 Jul 2015 19:37:35 +0530 Subject: [PATCH 158/217] configuration read from a xml file-1 --- .../stratos/gce/extension/config/parser/GCEConfigParser.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 536a68d3ed..1e34536b9b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -41,6 +41,7 @@ public static void parse(OMElement documentElement) throws MalformedConfiguratio OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement,"cepStatsPublisher"); log.info(cepInfoElement.getText()); + //todo rest } From 9404fe7cd2099cab5571b8edda1a78e92db40f69 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 1 Jul 2015 21:31:10 +0530 Subject: [PATCH 159/217] configuration read from a xml file-1 --- .../stratos/gce/extension/config/parser/GCEConfigParser.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 1e34536b9b..536a68d3ed 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -41,7 +41,6 @@ public static void parse(OMElement documentElement) throws MalformedConfiguratio OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement,"cepStatsPublisher"); log.info(cepInfoElement.getText()); - //todo rest } From 3ac6c823d4c74784a1e071594926e417fa6cab3d Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 1 Jul 2015 21:40:50 +0530 Subject: [PATCH 160/217] configuration read from a xml file-1 --- .../src/main/java/org/apache/stratos/gce/extension/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index d929e588e8..720e238a5c 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -41,7 +41,7 @@ public class Main { private static final Log log = LogFactory.getLog(Main.class); private static ExecutorService executorService; - private static String configFilePath = "/conf/gce-configuration.xml"; + private static String configFilePath = "conf/gce-configuration.xml"; public static void main(String[] args) { From f4872652fb285ff5469a2eb4afbf007fc6f360d8 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 1 Jul 2015 22:04:46 +0530 Subject: [PATCH 161/217] configuration read from a xml file-1 --- .../load-balancer/gce-extension/src/main/bin/gce-extension.sh | 1 - .../src/main/java/org/apache/stratos/gce/extension/Main.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 83a2149956..b4b9cd6559 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -22,7 +22,6 @@ echo "Starting gce load balancer extension..." script_path="$( cd -P "$( dirname "$SOURCE" )" && pwd )/`dirname $0`" -echo ${script_path} lib_path=${script_path}/../lib/ class_path=`echo ${lib_path}/*.jar | tr ' ' ':'` diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 720e238a5c..915772407a 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -41,7 +41,7 @@ public class Main { private static final Log log = LogFactory.getLog(Main.class); private static ExecutorService executorService; - private static String configFilePath = "conf/gce-configuration.xml"; + private static String configFilePath = "../conf/gce-configuration.xml"; public static void main(String[] args) { From 9a150a9c7bb6c5a788ae1b1f90055aff303ef1bb Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 1 Jul 2015 22:20:51 +0530 Subject: [PATCH 162/217] configuration read from a xml file-fixing file path issue --- .../src/main/java/org/apache/stratos/gce/extension/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 915772407a..8e56107e42 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -41,7 +41,7 @@ public class Main { private static final Log log = LogFactory.getLog(Main.class); private static ExecutorService executorService; - private static String configFilePath = "../conf/gce-configuration.xml"; + private static String configFilePath = "src/main/conf/gce-configuration.xml"; public static void main(String[] args) { From f96e464edc26ab7036cf81112c078a633458bf6f Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 2 Jul 2015 18:58:50 +0530 Subject: [PATCH 163/217] configuration read from a xml file-fixing file path issue --- .../gce-extension/src/main/assembly/bin.xml | 1 + .../gce-extension/src/main/bin/gce-extension.sh | 2 +- .../java/org/apache/stratos/gce/extension/Main.java | 10 ++++++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/assembly/bin.xml b/extensions/load-balancer/gce-extension/src/main/assembly/bin.xml index 42e0761b74..8e9afacb1a 100644 --- a/extensions/load-balancer/gce-extension/src/main/assembly/bin.xml +++ b/extensions/load-balancer/gce-extension/src/main/assembly/bin.xml @@ -41,6 +41,7 @@ jndi.properties log4j.properties thrift-client-config.xml + gce-configuration.xml diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index b4b9cd6559..c9b69d909e 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -54,6 +54,6 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Doperation.timeout=10000" # Uncomment below line to enable remote debugging -debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" +#debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $* \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 8e56107e42..76f12cda03 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -25,11 +25,13 @@ import org.apache.commons.logging.LogFactory; import org.apache.log4j.PropertyConfigurator; import org.apache.stratos.common.threading.StratosThreadPool; +import org.apache.stratos.common.util.AxiomXpathParserUtil; import org.apache.stratos.gce.extension.config.GCEContext; import org.apache.stratos.gce.extension.config.parser.GCEConfigParser; import org.apache.stratos.load.balancer.common.topology.TopologyProvider; import org.apache.stratos.load.balancer.extension.api.LoadBalancerExtension; +import java.io.File; import java.util.concurrent.ExecutorService; /** @@ -41,7 +43,8 @@ public class Main { private static final Log log = LogFactory.getLog(Main.class); private static ExecutorService executorService; - private static String configFilePath = "src/main/conf/gce-configuration.xml"; + private static String configFileName = "gce-configuration.xml"; + private static String configFolderName = "conf"; public static void main(String[] args) { @@ -50,7 +53,10 @@ public static void main(String[] args) { try { //read configuration from gce-configuration.xml and store configuration in GCEConfigurationHolder class - OMElement documentElement = new StAXOMBuilder(configFilePath).getDocumentElement(); + String workingDirectory = System.getProperty("user.dir"); + String configFilePath = workingDirectory + File.separator + ".." + File.separator + configFolderName + File.separator + configFileName; + File configFile = new File(configFilePath); + OMElement documentElement = AxiomXpathParserUtil.parse(configFile); GCEConfigParser.parse(documentElement); // Configure log4j properties From 116dae4245913736ab7fdc567bdc3f9b34d0e3c7 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 2 Jul 2015 19:03:21 +0530 Subject: [PATCH 164/217] delaying configure method as a temporary solution for topology update problem --- .../org/apache/stratos/gce/extension/GCELoadBalancer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 377921be47..01a03696eb 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -77,6 +77,11 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio new DomDriver("utf-8")); log.info(xstream.toXML(topology)); try { + + //delaying the configuration as a temporary solution( Because topology may not be updated when the configure + // method calls) + Thread.sleep(10000); + //check whether any cluster is removed. If removed, then remove the cluster from //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too From d8256222b959721763354e8149a6f975dd8e3d76 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 4 Jul 2015 14:03:17 +0530 Subject: [PATCH 165/217] let the configuration read from configuration file instead of system properties --- .../src/main/bin/gce-extension.sh | 24 +-- .../src/main/conf/gce-configuration.xml | 4 +- .../gce/extension/GCELoadBalancer.java | 2 +- .../apache/stratos/gce/extension/Main.java | 16 +- .../gce/extension/config/Constants.java | 47 +++-- .../config/GCEConfigurationHolder.java | 173 ------------------ .../gce/extension/config/GCEContext.java | 89 ++++++++- .../config/parser/GCEConfigParser.java | 98 +++++++++- 8 files changed, 225 insertions(+), 228 deletions(-) delete mode 100644 extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index c9b69d909e..1113c8c339 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -29,31 +29,11 @@ class_path=`echo ${lib_path}/*.jar | tr ' ' ':'` properties="-Djndi.properties.dir=${script_path}/../conf -Dstats.socket.file.path=/tmp/haproxy-stats.socket - -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties -Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks -Djavax.net.ssl.trustStorePassword=wso2carbon - -Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml - -Dcep.stats.publisher.enabled=false - -Dthrift.receiver.ip=127.0.0.1 - -Dthrift.receiver.port=7615 - -Dnetwork.partition.id=network-partition-1 - -Dcluster.id=cluster-1 - -Dservice.name=php - -Dname.prefix=lb - -Dproject.name=MyFirstProject - -Dproject.id=gold-access-96509 - -Dzone.name=europe-west1-b - -Dregion.name=europe-west1 - -Dkey.file.path=/home/sanjaya/keys/p12key-donwloaded.p12 - -Dgce.account.id=164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com - -Dhealth.check.request.path=/ - -Dhealth.check.port=80 - -Dhealth.check.timeout.sec=5 - -Dhealth.check.unhealthy.threshold=2 - -Dnetwork.name=default - -Doperation.timeout=10000" + -Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml" # Uncomment below line to enable remote debugging -#debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" +debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $* \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index 6b8edf1f1f..bd7d1b0b91 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -24,7 +24,6 @@ 7615 - lb MyFirstProject gold-access-96509 @@ -43,5 +42,8 @@ 10000 + lb + + log4j.properties \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 01a03696eb..ef42734db1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -81,7 +81,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //delaying the configuration as a temporary solution( Because topology may not be updated when the configure // method calls) Thread.sleep(10000); - + //check whether any cluster is removed. If removed, then remove the cluster from //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 76f12cda03..8aec6bd023 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -20,12 +20,12 @@ package org.apache.stratos.gce.extension; import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.PropertyConfigurator; import org.apache.stratos.common.threading.StratosThreadPool; import org.apache.stratos.common.util.AxiomXpathParserUtil; +import org.apache.stratos.gce.extension.config.Constants; import org.apache.stratos.gce.extension.config.GCEContext; import org.apache.stratos.gce.extension.config.parser.GCEConfigParser; import org.apache.stratos.load.balancer.common.topology.TopologyProvider; @@ -43,8 +43,6 @@ public class Main { private static final Log log = LogFactory.getLog(Main.class); private static ExecutorService executorService; - private static String configFileName = "gce-configuration.xml"; - private static String configFolderName = "conf"; public static void main(String[] args) { @@ -53,14 +51,12 @@ public static void main(String[] args) { try { //read configuration from gce-configuration.xml and store configuration in GCEConfigurationHolder class - String workingDirectory = System.getProperty("user.dir"); - String configFilePath = workingDirectory + File.separator + ".." + File.separator + configFolderName + File.separator + configFileName; - File configFile = new File(configFilePath); + File configFile = new File(getFilePathOfConfigFile(Constants.CONFIG_FILE_NAME)); OMElement documentElement = AxiomXpathParserUtil.parse(configFile); GCEConfigParser.parse(documentElement); // Configure log4j properties - PropertyConfigurator.configure(System.getProperty("log4j.properties.file.path")); + PropertyConfigurator.configure(getFilePathOfConfigFile(GCEContext.getInstance().getLog4jPropertiesFileName())); if (log.isInfoEnabled()) { log.info("GCE extension started"); @@ -105,4 +101,10 @@ public void run() { } } } + + private static String getFilePathOfConfigFile(String fileName) { + String workingDirectory = System.getProperty("user.dir"); + String FilePath = workingDirectory + File.separator + ".." + File.separator + Constants.CONFIG_FOLDER_NAME + File.separator + fileName; + return FilePath; + } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 6efd2501b5..575650a4a4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -23,20 +23,35 @@ * GCE extension constants. */ public class Constants { - public static final String CEP_STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"; - public static final String THRIFT_RECEIVER_IP = "thrift.receiver.ip"; - public static final String THRIFT_RECEIVER_PORT = "thrift.receiver.port"; - static final String NAME_PREFIX = "name.prefix"; - public static final String PROJECT_NAME = "project.name"; - public static final String PROJECT_ID = "project.id"; - public static final String ZONE_NAME = "zone.name"; - public static final String REGION_NAME = "region.name"; - public static final String KEY_FILE_PATH = "key.file.path"; - public static final String GCE_ACCOUNT_ID = "gce.account.id"; - public static final String HEALTH_CHECK_REQUEST_PATH = "health.check.request.path"; - public static final String HEALTH_CHECK_PORT = "health.check.port"; - public static final String HEALTH_CHECK_TIME_OUT_SEC = "health.check.timeout.sec"; - public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "health.check.unhealthy.threshold"; - public static final String NETWORK_NAME = "network.name"; - public static final String OPERATION_TIMEOUT = "operation.timeout"; + + public static final String CONFIG_FILE_NAME = "gce-configuration.xml"; + public static final String CONFIG_FOLDER_NAME = "conf"; + + //CEP configuration + public static final String CEP_STATS_PUBLISHER_ELEMENT = "cepStatsPublisher"; + public static final String CEP_STATS_PUBLISHER_ENABLED = "enable"; + public static final String THRIFT_RECEIVER_IP = "thriftReceiverIp"; + public static final String THRIFT_RECEIVER_PORT = "thriftReceiverPort"; + + //IaaS provider configuration + public static final String IAAS_PROPERTIES_ELEMENT = "iaasProperties"; + public static final String PROJECT_NAME = "projectName"; + public static final String PROJECT_ID = "projectId"; + public static final String ZONE_NAME = "zoneName"; + public static final String REGION_NAME = "regionName"; + public static final String KEY_FILE_PATH = "keyFilePath"; + public static final String GCE_ACCOUNT_ID = "gceAccountId"; + public static final String NETWORK_NAME = "networkName"; + + //health check configuration + public static final String HEALTH_CHECK_PROPERTIES_ELEMENT = "healthCheckProperties"; + public static final String HEALTH_CHECK_REQUEST_PATH = "healthCheckRequestPath"; + public static final String HEALTH_CHECK_PORT = "healthCheckPort"; + public static final String HEALTH_CHECK_TIME_OUT_SEC = "healthCheckTimeoutSec"; + public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "healthCheckUnhealthyThreshold"; + + //other properties + public static final String OPERATION_TIMEOUT = "operationTimeout"; + public static final String NAME_PREFIX = "namePrefix"; + public static final String LOG4J_PROPERTIES_FILE_NAME = "log4jPropertiesFileName"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java deleted file mode 100644 index baf9b2eb52..0000000000 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEConfigurationHolder.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.apache.stratos.gce.extension.config; - -/** - * GCE config parser parse the gce-configuration.xml and stores - * the configuration in this singleton class to be used in the runtime. - */ -public class GCEConfigurationHolder { - - private static volatile GCEConfigurationHolder instance; - - private String cepStatsPublisherEnabled; - private String thriftReceiverIp; - private String thriftReceiverPort; - private String namePrefix; - private String projectName; - private String projectId; - private String zoneName; - private String regionName; - private String keyFilePath; - private String gceAccountId; - private String healthCheckRequestPath; - private String healthCheckRequestPort; - private String healthCheckTimeoutSec; - private String healthCheckUnhealthyThreshold; - private String networkName; - private String operationTimeout; - - //private constructor - private GCEConfigurationHolder(){} - - public static GCEConfigurationHolder getInstance() { - if (instance == null) { - synchronized (GCEConfigurationHolder.class) { - if (instance == null) { - instance = new GCEConfigurationHolder(); - } - } - } - return instance; - } - - public static void setInstance(GCEConfigurationHolder instance) { - GCEConfigurationHolder.instance = instance; - } - - public String getCepStatsPublisherEnabled() { - return cepStatsPublisherEnabled; - } - - public void setCepStatsPublisherEnabled(String cepStatsPublisherEnabled) { - this.cepStatsPublisherEnabled = cepStatsPublisherEnabled; - } - - public String getThriftReceiverIp() { - return thriftReceiverIp; - } - - public void setThriftReceiverIp(String thriftReceiverIp) { - this.thriftReceiverIp = thriftReceiverIp; - } - - public String getThriftReceiverPort() { - return thriftReceiverPort; - } - - public void setThriftReceiverPort(String thriftReceiverPort) { - this.thriftReceiverPort = thriftReceiverPort; - } - - public String getNamePrefix() { - return namePrefix; - } - - public void setNamePrefix(String namePrefix) { - this.namePrefix = namePrefix; - } - - public String getProjectName() { - return projectName; - } - - public void setProjectName(String projectName) { - this.projectName = projectName; - } - - public String getProjectId() { - return projectId; - } - - public void setProjectId(String projectId) { - this.projectId = projectId; - } - - public String getZoneName() { - return zoneName; - } - - public void setZoneName(String zoneName) { - this.zoneName = zoneName; - } - - public String getRegionName() { - return regionName; - } - - public void setRegionName(String regionName) { - this.regionName = regionName; - } - - public String getKeyFilePath() { - return keyFilePath; - } - - public void setKeyFilePath(String keyFilePath) { - this.keyFilePath = keyFilePath; - } - - public String getGceAccountId() { - return gceAccountId; - } - - public void setGceAccountId(String gceAccountId) { - this.gceAccountId = gceAccountId; - } - - public String getHealthCheckRequestPath() { - return healthCheckRequestPath; - } - - public void setHealthCheckRequestPath(String healthCheckRequestPath) { - this.healthCheckRequestPath = healthCheckRequestPath; - } - - public String getHealthCheckRequestPort() { - return healthCheckRequestPort; - } - - public void setHealthCheckRequestPort(String healthCheckRequestPort) { - this.healthCheckRequestPort = healthCheckRequestPort; - } - - public String getHealthCheckTimeoutSec() { - return healthCheckTimeoutSec; - } - - public void setHealthCheckTimeoutSec(String healthCheckTimeoutSec) { - this.healthCheckTimeoutSec = healthCheckTimeoutSec; - } - - public String getHealthCheckUnhealthyThreshold() { - return healthCheckUnhealthyThreshold; - } - - public void setHealthCheckUnhealthyThreshold(String healthCheckUnhealthyThreshold) { - this.healthCheckUnhealthyThreshold = healthCheckUnhealthyThreshold; - } - - public String getNetworkName() { - return networkName; - } - - public void setNetworkName(String networkName) { - this.networkName = networkName; - } - - public String getOperationTimeout() { - return operationTimeout; - } - - public void setOperationTimeout(String operationTimeout) { - this.operationTimeout = operationTimeout; - } -} diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 4425bceb9c..1507c641fd 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -31,27 +31,34 @@ public class GCEContext { private static volatile GCEContext context; + //cep stat publisher properties private boolean cepStatsPublisherEnabled; private String thriftReceiverIp; private String thriftReceiverPort; - private String namePrefix; + + //IaaS properties private String projectName; private String projectID; private String zoneName; private String regionName; private String keyFilePath; private String gceAccountID; + private String networkName; + + //healthcheck properties private String healthCheckRequestPath; private String healthCheckPort; private String healthCheckTimeOutSec; private String healthCheckUnhealthyThreshold; - private String networkName; - private String operationTimeout; + //other properties + private String namePrefix; + private String operationTimeout; + private String log4jPropertiesFileName; private GCEContext() { - this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); + /* this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); this.thriftReceiverIp = System.getProperty(Constants.THRIFT_RECEIVER_IP); this.thriftReceiverPort = System.getProperty(Constants.THRIFT_RECEIVER_PORT); this.namePrefix = System.getProperty(Constants.NAME_PREFIX); @@ -89,6 +96,7 @@ private GCEContext() { log.debug(Constants.OPERATION_TIMEOUT + "=" + operationTimeout); } + */ } @@ -103,6 +111,14 @@ public static GCEContext getInstance() { return context; } + public String getLog4jPropertiesFileName() { + return log4jPropertiesFileName; + } + + public void setLog4jPropertiesFileName(String log4jPropertiesFileName) { + this.log4jPropertiesFileName = log4jPropertiesFileName; + } + public void validate() { validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED); @@ -141,51 +157,116 @@ public String getNamePrefix() { return namePrefix; } + public void setNamePrefix(String namePrefix) { + this.namePrefix = namePrefix; + } + public String getProjectName() { return projectName; } + public void setProjectName(String projectName) { + this.projectName = projectName; + } + public String getProjectID() { return projectID; } + public void setProjectID(String projectID) { + this.projectID = projectID; + } + public String getZoneName() { return zoneName; } + public void setZoneName(String zoneName) { + this.zoneName = zoneName; + } + public String getRegionName() { return regionName; } + public void setRegionName(String regionName) { + this.regionName = regionName; + } + public String getKeyFilePath() { return keyFilePath; } + public void setKeyFilePath(String keyFilePath) { + this.keyFilePath = keyFilePath; + } + public String getGceAccountID() { return gceAccountID; } + public void setGceAccountID(String gceAccountID) { + this.gceAccountID = gceAccountID; + } + public String getHealthCheckRequestPath() { return healthCheckRequestPath; } + public void setHealthCheckRequestPath(String healthCheckRequestPath) { + this.healthCheckRequestPath = healthCheckRequestPath; + } + public String getHealthCheckPort() { return healthCheckPort; } + public void setHealthCheckPort(String healthCheckPort) { + this.healthCheckPort = healthCheckPort; + } + public String getHealthCheckTimeOutSec() { return healthCheckTimeOutSec; } + public void setHealthCheckTimeOutSec(String healthCheckTimeOutSec) { + this.healthCheckTimeOutSec = healthCheckTimeOutSec; + } + public String getHealthCheckUnhealthyThreshold() { return healthCheckUnhealthyThreshold; } + public void setHealthCheckUnhealthyThreshold(String healthCheckUnhealthyThreshold) { + this.healthCheckUnhealthyThreshold = healthCheckUnhealthyThreshold; + } + public String getNetworkName() { return networkName; } + public void setNetworkName(String networkName) { + this.networkName = networkName; + } + public String getOperationTimeout() { return operationTimeout; } + + public void setOperationTimeout(String operationTimeout) { + this.operationTimeout = operationTimeout; + } + + public void setCepStatsPublisherEnabled(boolean cepStatsPublisherEnabled) { + this.cepStatsPublisherEnabled = cepStatsPublisherEnabled; + } + + public void setThriftReceiverIp(String thriftReceiverIp) { + this.thriftReceiverIp = thriftReceiverIp; + } + + public void setThriftReceiverPort(String thriftReceiverPort) { + this.thriftReceiverPort = thriftReceiverPort; + } + } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 536a68d3ed..05a857d6c5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -20,14 +20,18 @@ */ import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMNode; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.exception.MalformedConfigurationFileException; import org.apache.stratos.common.util.AxiomXpathParserUtil; +import org.apache.stratos.gce.extension.config.Constants; +import org.apache.stratos.gce.extension.config.GCEContext; + +import javax.xml.namespace.QName; public class GCEConfigParser { private static final Log log = LogFactory.getLog(GCEConfigParser.class); + private static GCEContext gceContext; /** * Parse the gce-configuration file. @@ -38,11 +42,97 @@ public class GCEConfigParser { public static void parse(OMElement documentElement) throws MalformedConfigurationFileException { //get cep info - OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement,"cepStatsPublisher"); - log.info(cepInfoElement.getText()); + OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.CEP_STATS_PUBLISHER_ELEMENT); + extractCepConfiguration(cepInfoElement); + + //get GCE IaaS info + OMElement gceIaasInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.IAAS_PROPERTIES_ELEMENT); + extractGceIaasInformation(gceIaasInfoElement); + + //get heath check info + OMElement healthCheckPropertiesElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.HEALTH_CHECK_PROPERTIES_ELEMENT); + extractHealthCheckProperties(healthCheckPropertiesElement); + + //extract other properties + extractOtherProperties(documentElement); + + //validate extradted properties + //gceContext.validate(); + + + + } + + private static void extractCepConfiguration(OMElement cepInfoElement) { + + //Check whether the cep stat publisher enabled or not + QName qName = new QName(Constants.CEP_STATS_PUBLISHER_ENABLED); + String enabled = cepInfoElement.getAttributeValue(qName); + + gceContext = GCEContext.getInstance(); + gceContext.setCepStatsPublisherEnabled(Boolean.parseBoolean(enabled)); + + //if stat publisher is enabled + if (Boolean.parseBoolean(enabled)) { + //extract rest configuration of cep + + String thriftReceiverIp = AxiomXpathParserUtil.getFirstChildElement(cepInfoElement, Constants.THRIFT_RECEIVER_IP).getText(); + String thriftReceiverPort = AxiomXpathParserUtil.getFirstChildElement(cepInfoElement, Constants.THRIFT_RECEIVER_PORT).getText(); + + //set extracted ip and port to gceContext object + gceContext.setThriftReceiverIp(thriftReceiverIp); + gceContext.setThriftReceiverPort(thriftReceiverPort); + + //validate above properties + + } + + } + + private static void extractGceIaasInformation(OMElement gceIaasInfoElement) { + + String projectName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_NAME).getText(); + String projectId = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_ID).getText(); + String zoneName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.ZONE_NAME).getText(); + String regionName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.REGION_NAME).getText(); + String keyFilePath = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.KEY_FILE_PATH).getText(); + String gceAccountId = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.GCE_ACCOUNT_ID).getText(); + String networkName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.NETWORK_NAME).getText(); + + //set extracted properties to gceContext object + gceContext.setProjectName(projectName); + gceContext.setProjectID(projectId); + gceContext.setZoneName(zoneName); + gceContext.setRegionName(regionName); + gceContext.setKeyFilePath(keyFilePath); + gceContext.setGceAccountID(gceAccountId); + gceContext.setNetworkName(networkName); + + } + + private static void extractHealthCheckProperties(OMElement healthCheckPropertiesElement) { + + String healthCheckRequestPath = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_REQUEST_PATH).getText(); + String healthCheckPort = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_PORT).getText(); + String healthCheckTimeoutSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_TIME_OUT_SEC).getText(); + String healthCheckUnhealthyThreshold = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD).getText(); + + //set extracted properties to gceContext object + gceContext.setHealthCheckRequestPath(healthCheckRequestPath); + gceContext.setHealthCheckPort(healthCheckPort); + gceContext.setHealthCheckTimeOutSec(healthCheckTimeoutSec); + gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThreshold); + } - //todo rest + private static void extractOtherProperties(OMElement documentElement) { + String operationTimeout = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.OPERATION_TIMEOUT).getText(); + String namePrefix = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX).getText(); + String log4jPropertiesFileName = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.LOG4J_PROPERTIES_FILE_NAME).getText(); + //set extracted properties to gceContext object + gceContext.setOperationTimeout(operationTimeout); + gceContext.setNamePrefix(namePrefix); + gceContext.setLog4jPropertiesFileName(log4jPropertiesFileName); } } From 52872e1c0a2e29a75b21dddd595945b3b810823e Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 4 Jul 2015 14:26:00 +0530 Subject: [PATCH 166/217] reformat the code and adding some comments --- .../apache/stratos/gce/extension/Main.java | 11 ++++++---- .../config/GCEClusterConfigurationHolder.java | 2 -- .../config/parser/GCEConfigParser.java | 21 ++++++++++++++++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 8aec6bd023..276300aca9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -37,14 +37,11 @@ /** * GCE extension main class. */ - - public class Main { + private static final Log log = LogFactory.getLog(Main.class); private static ExecutorService executorService; - - public static void main(String[] args) { LoadBalancerExtension extension = null; @@ -102,6 +99,12 @@ public void run() { } } + /** + * get the full path of a given file which is located in conf folder + * + * @param fileName - name of file name + * @return - full path of given file + */ private static String getFilePathOfConfigFile(String fileName) { String workingDirectory = System.getProperty("user.dir"); String FilePath = workingDirectory + File.separator + ".." + File.separator + Constants.CONFIG_FOLDER_NAME + File.separator + fileName; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java index ee09205bdc..6f766ea965 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java @@ -30,7 +30,6 @@ */ public class GCEClusterConfigurationHolder { - //A cluster should have set of members private List memberList; //A cluster can have one IPs to be forwarded @@ -41,7 +40,6 @@ public class GCEClusterConfigurationHolder { private String targetPoolName; private String healthCheckName; - public GCEClusterConfigurationHolder(String clusterID, List memberList, List ipList) { this.clusterID = clusterID; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 05a857d6c5..4463d75190 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -34,7 +34,7 @@ public class GCEConfigParser { private static GCEContext gceContext; /** - * Parse the gce-configuration file. + * Parse the gce-configuration.xml file. * * @param documentElement axiom document element. * @throws MalformedConfigurationFileException @@ -63,6 +63,11 @@ public static void parse(OMElement documentElement) throws MalformedConfiguratio } + /** + * Extract cep ip and port and store in gceContext object + * + * @param cepInfoElement + */ private static void extractCepConfiguration(OMElement cepInfoElement) { //Check whether the cep stat publisher enabled or not @@ -89,6 +94,11 @@ private static void extractCepConfiguration(OMElement cepInfoElement) { } + /** + * extract Iaas propreties from given OMElement and store it in gceContext object + * + * @param gceIaasInfoElement - OMElement which contains Iaas properties + */ private static void extractGceIaasInformation(OMElement gceIaasInfoElement) { String projectName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_NAME).getText(); @@ -110,6 +120,10 @@ private static void extractGceIaasInformation(OMElement gceIaasInfoElement) { } + /** + * extract health check properties from given OMElement and store it in gceContext object + * @param healthCheckPropertiesElement - OMElement which contains health check properties + */ private static void extractHealthCheckProperties(OMElement healthCheckPropertiesElement) { String healthCheckRequestPath = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_REQUEST_PATH).getText(); @@ -124,6 +138,11 @@ private static void extractHealthCheckProperties(OMElement healthCheckProperties gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThreshold); } + /** + * extract all other properties which is not extracted from above methods and store in gceContext object + * + * @param documentElement - OMElement which contains other properties + */ private static void extractOtherProperties(OMElement documentElement) { String operationTimeout = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.OPERATION_TIMEOUT).getText(); String namePrefix = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX).getText(); From 40584e84d34045412b618d250fd01cd610ed71c1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Fri, 10 Jul 2015 15:08:39 +0530 Subject: [PATCH 167/217] Merge branch 'master' of https://github.com/apache/stratos --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index ef42734db1..88a3a287f3 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -58,7 +58,6 @@ public GCELoadBalancer() { } - /** * Listen to latest topology and update load balancer configuration * From 8003da5549989c15c3dacc8b5e41fffa8c4b7e42 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Fri, 10 Jul 2015 17:11:37 +0530 Subject: [PATCH 168/217] Merge branch 'master' of https://github.com/apache/stratos remove snapshot from pom --- extensions/load-balancer/gce-extension/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index cb519a6bee..e969a22305 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -24,7 +24,7 @@ org.apache.stratos stratos-load-balancer-extensions - 4.1.0-SNAPSHOT + 4.1.0 org.apache.stratos.gce.extension From 421212d71871b7d687afa675863425f1e1872ef1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 11 Jul 2015 22:38:30 +0530 Subject: [PATCH 169/217] let the zone name detect from instance object-1 --- .../apache/stratos/gce/extension/util/GCEOperations.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 93c7198f16..196ec36d0e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -128,7 +128,7 @@ public static String getInstanceURLFromId(String instanceId) { //check whether the given instance is available InstanceList instanceList = getInstanceList(); for (Instance instance : instanceList.getItems()) { - String instanceIdInIaaS = ZONE_NAME + "/" + instance.getName(); + String instanceIdInIaaS = getZoneNameFromZoneURL(instance.getZone()) + "/" + instance.getName(); if (instanceIdInIaaS.equals(instanceId)) { //instance is available //getInstance URL @@ -706,4 +706,10 @@ public void createFirewallRule() { log.info("Created firewall rule"); } + private static String getZoneNameFromZoneURL(String zoneURL){ + int lastIndexOfSlash = zoneURL.lastIndexOf("/"); + String zoneName = zoneURL.substring(lastIndexOfSlash); + return zoneName; + } + } \ No newline at end of file From b4ae9abc9cea23acb4d4f19c3016f88a20078625 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 11 Jul 2015 23:00:21 +0530 Subject: [PATCH 170/217] let the zone name detect from instance object-2 --- .../gce/extension/config/Constants.java | 1 - .../gce/extension/config/GCEContext.java | 10 ----- .../config/parser/GCEConfigParser.java | 2 - .../gce/extension/util/GCEOperations.java | 44 +++---------------- 4 files changed, 7 insertions(+), 50 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 575650a4a4..1fdf3efbcb 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -37,7 +37,6 @@ public class Constants { public static final String IAAS_PROPERTIES_ELEMENT = "iaasProperties"; public static final String PROJECT_NAME = "projectName"; public static final String PROJECT_ID = "projectId"; - public static final String ZONE_NAME = "zoneName"; public static final String REGION_NAME = "regionName"; public static final String KEY_FILE_PATH = "keyFilePath"; public static final String GCE_ACCOUNT_ID = "gceAccountId"; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 1507c641fd..84130b941d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -39,7 +39,6 @@ public class GCEContext { //IaaS properties private String projectName; private String projectID; - private String zoneName; private String regionName; private String keyFilePath; private String gceAccountID; @@ -125,7 +124,6 @@ public void validate() { validateSystemProperty(Constants.NAME_PREFIX); validateSystemProperty(Constants.PROJECT_NAME); validateSystemProperty(Constants.PROJECT_ID); - validateSystemProperty(Constants.ZONE_NAME); validateSystemProperty(Constants.REGION_NAME); validateSystemProperty(Constants.KEY_FILE_PATH); validateSystemProperty(Constants.GCE_ACCOUNT_ID); @@ -177,14 +175,6 @@ public void setProjectID(String projectID) { this.projectID = projectID; } - public String getZoneName() { - return zoneName; - } - - public void setZoneName(String zoneName) { - this.zoneName = zoneName; - } - public String getRegionName() { return regionName; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 4463d75190..a625af8904 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -103,7 +103,6 @@ private static void extractGceIaasInformation(OMElement gceIaasInfoElement) { String projectName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_NAME).getText(); String projectId = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_ID).getText(); - String zoneName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.ZONE_NAME).getText(); String regionName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.REGION_NAME).getText(); String keyFilePath = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.KEY_FILE_PATH).getText(); String gceAccountId = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.GCE_ACCOUNT_ID).getText(); @@ -112,7 +111,6 @@ private static void extractGceIaasInformation(OMElement gceIaasInfoElement) { //set extracted properties to gceContext object gceContext.setProjectName(projectName); gceContext.setProjectID(projectId); - gceContext.setZoneName(zoneName); gceContext.setRegionName(regionName); gceContext.setKeyFilePath(keyFilePath); gceContext.setGceAccountID(gceAccountId); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 196ec36d0e..bba963a888 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -52,7 +52,6 @@ public class GCEOperations { //project related private static final String PROJECT_NAME = GCEContext.getInstance().getProjectName(); private static final String PROJECT_ID = GCEContext.getInstance().getProjectID(); - private static final String ZONE_NAME = GCEContext.getInstance().getZoneName(); private static final String REGION_NAME = GCEContext.getInstance().getRegionName(); //auth @@ -94,11 +93,11 @@ public GCEOperations() { * @return instanceList - list of instances(members in Stratos side) * @throws IOException */ - public static InstanceList getInstanceList() { + public static InstanceList getInstanceList(String zoneName) { Compute.Instances.List instances = null; try { instances = compute.instances(). - list(PROJECT_ID, ZONE_NAME).setFilter(RUNNING_FILTER); + list(PROJECT_ID, zoneName).setFilter(RUNNING_FILTER); InstanceList instanceList = instances.execute(); if (instanceList.getItems() == null) { log.info("No instances found for specified zone"); @@ -125,10 +124,11 @@ public static InstanceList getInstanceList() { public static String getInstanceURLFromId(String instanceId) { String instanceURL; + String zoneName = getZoneNameFromInstanceId(instanceId); //check whether the given instance is available - InstanceList instanceList = getInstanceList(); + InstanceList instanceList = getInstanceList(zoneName); for (Instance instance : instanceList.getItems()) { - String instanceIdInIaaS = getZoneNameFromZoneURL(instance.getZone()) + "/" + instance.getName(); + String instanceIdInIaaS = zoneName + "/" + instance.getName(); if (instanceIdInIaaS.equals(instanceId)) { //instance is available //getInstance URL @@ -643,36 +643,6 @@ private void waitForRegionOperationCompletion(String operationName) { } } - /** - * wait for zone operation completion. If the operation is related to a zone, that is a zone operation - * - * @param operationName -operation name - */ - private void waitForZoneOperationCompletion(String operationName) { - try { - Thread.sleep(2000); - int timeout = 0; - while (true) { - Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); - if (operation.getStatus().equals("DONE")) { - return; - } - if (timeout >= OPERATION_TIMEOUT) { - log.warn("Timeout reached for operation " + operationName + ". Existing.."); - return; - } - Thread.sleep(1000); - timeout += 1000; - } - } catch (InterruptedException e) { - log.error("Could not wait for zone operation completion " + operationName); - throw new RuntimeException(e); - } catch (IOException e) { - log.error("Could not wait for zone operation completion " + operationName); - throw new RuntimeException(e); - } - } - public void createFirewallRule() { log.info("Creating firewall rule"); @@ -706,9 +676,9 @@ public void createFirewallRule() { log.info("Created firewall rule"); } - private static String getZoneNameFromZoneURL(String zoneURL){ + private static String getZoneNameFromInstanceId(String zoneURL){ int lastIndexOfSlash = zoneURL.lastIndexOf("/"); - String zoneName = zoneURL.substring(lastIndexOfSlash); + String zoneName = zoneURL.substring(lastIndexOfSlash+1); return zoneName; } From 4bb4394fac51fc53b942aff7278bf142d7e2f25b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 11 Jul 2015 23:20:53 +0530 Subject: [PATCH 171/217] let the zone name detect from instance object-2 --- .../gce-extension/src/main/conf/gce-configuration.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index bd7d1b0b91..fdf4250f11 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -19,7 +19,7 @@ --> - + 127.0.0.1 7615 From 4059e3f6c543194b04320d93daccd9b3b5296f08 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 11 Jul 2015 23:49:12 +0530 Subject: [PATCH 172/217] fixing a bug in getZoneNameFromInstanceId method --- .../apache/stratos/gce/extension/util/GCEOperations.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index bba963a888..366f8ed0e4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -676,9 +676,9 @@ public void createFirewallRule() { log.info("Created firewall rule"); } - private static String getZoneNameFromInstanceId(String zoneURL){ - int lastIndexOfSlash = zoneURL.lastIndexOf("/"); - String zoneName = zoneURL.substring(lastIndexOfSlash+1); + private static String getZoneNameFromInstanceId(String instanceId){ + int lastIndexOfSlash = instanceId.lastIndexOf("/"); + String zoneName = instanceId.substring(0,lastIndexOfSlash-1); return zoneName; } From 8920d502229f2e753c293a84abc2328737c00a78 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 11 Jul 2015 23:56:37 +0530 Subject: [PATCH 173/217] fixing a bug in getZoneNameFromInstanceId method --- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 366f8ed0e4..b18f61d534 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -678,7 +678,7 @@ public void createFirewallRule() { private static String getZoneNameFromInstanceId(String instanceId){ int lastIndexOfSlash = instanceId.lastIndexOf("/"); - String zoneName = instanceId.substring(0,lastIndexOfSlash-1); + String zoneName = instanceId.substring(0,lastIndexOfSlash); return zoneName; } From 5c73978a5fb1af2801457abdff030e46f454378b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 15:02:56 +0530 Subject: [PATCH 174/217] resolving the ConcurrentModificationException occurs when terminating a member --- .../gce/extension/GCELoadBalancer.java | 21 ++++++++++++++----- .../gce/extension/util/GCEOperations.java | 3 +++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 88a3a287f3..45d726b305 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -150,7 +150,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (member.getInstanceId() != null) { if (!gceClusterConfigurationHolder.getMemberList().contains(member.getInstanceId())) { membersToBeAddedToTargetPool.add(member.getInstanceId()); - gceClusterConfigurationHolder.addMember(member.getInstanceId()); } } @@ -160,7 +159,14 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + "to cluster"); - //add to target pool + + //add them to configuration holder + for (String memberId : membersToBeAddedToTargetPool) { + gceClusterConfigurationHolder.addMember(memberId); + + } + + //add them to target pool too gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, gceClusterConfigurationHolder.getTargetPoolName()); } @@ -177,8 +183,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } if (found == false) { - //remove member from map - gceClusterConfigurationHolder.removeMember(memberId); + //add member id to membersToBeRemovedFromTargetPool in order remove member from map membersToBeRemovedFromTargetPool.add(memberId); } } @@ -187,7 +192,13 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); - //remove them + //remove them from configuration holder + for (String memberId : membersToBeRemovedFromTargetPool) { + gceClusterConfigurationHolder.removeMember(memberId); + + } + + //remove them from GCE too gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, gceClusterConfigurationHolder.getTargetPoolName()); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index b18f61d534..ab6002eeda 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -433,6 +433,9 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String instanceReferenceList.add(new InstanceReference(). setInstance(getInstanceURLFromId(instanceId))); + //remove them from configuration holder too + + } //create target pools add instance request and set instance to it From 1d3c444b18437a8236c5f715af4627f6a018b7c9 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 15:23:58 +0530 Subject: [PATCH 175/217] removing a to-do --- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index ab6002eeda..9f566cf15c 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -44,7 +44,6 @@ * All the GCE API calls will be done using this class */ -//TODO: exception handling public class GCEOperations { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); From 5ec1f0e4f884b7c9893ef35edd873126aac520e9 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 15:35:14 +0530 Subject: [PATCH 176/217] fixing a issue in getInstanceURLFromId method --- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 9f566cf15c..823dad5b01 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -122,7 +122,7 @@ public static InstanceList getInstanceList(String zoneName) { */ public static String getInstanceURLFromId(String instanceId) { - String instanceURL; + String instanceURL = null; String zoneName = getZoneNameFromInstanceId(instanceId); //check whether the given instance is available InstanceList instanceList = getInstanceList(zoneName); @@ -135,7 +135,7 @@ public static String getInstanceURLFromId(String instanceId) { return instanceURL; } } - return null; + return instanceURL; } /** From e73dd7a0d7f6c3564505959976e4f35a53d8dd83 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 15:57:29 +0530 Subject: [PATCH 177/217] fix issues in GCEOperations.java class --- .../gce/extension/util/GCEOperations.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 823dad5b01..2891e07304 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -92,11 +92,11 @@ public GCEOperations() { * @return instanceList - list of instances(members in Stratos side) * @throws IOException */ - public static InstanceList getInstanceList(String zoneName) { + public static InstanceList getInstanceList(String zoneName , String filter) { Compute.Instances.List instances = null; try { instances = compute.instances(). - list(PROJECT_ID, zoneName).setFilter(RUNNING_FILTER); + list(PROJECT_ID, zoneName).setFilter(filter); InstanceList instanceList = instances.execute(); if (instanceList.getItems() == null) { log.info("No instances found for specified zone"); @@ -124,8 +124,9 @@ public static String getInstanceURLFromId(String instanceId) { String instanceURL = null; String zoneName = getZoneNameFromInstanceId(instanceId); + String filter = "name eq " + getInstanceNameFromInstanceId(instanceId); //check whether the given instance is available - InstanceList instanceList = getInstanceList(zoneName); + InstanceList instanceList = getInstanceList(zoneName,filter); for (Instance instance : instanceList.getItems()) { String instanceIdInIaaS = zoneName + "/" + instance.getName(); if (instanceIdInIaaS.equals(instanceId)) { @@ -146,7 +147,7 @@ public static String getInstanceURLFromId(String instanceId) { */ public static String getHealthCheckURLFromName(String healthCheckName) { - String healthCheckURL; + String healthCheckURL = null; //check whether the given instance is available HttpHealthCheckList healthCheckList; @@ -159,7 +160,7 @@ public static String getHealthCheckURLFromName(String healthCheckName) { return healthCheckURL; } } - return null; + return healthCheckURL; } /** @@ -684,4 +685,12 @@ private static String getZoneNameFromInstanceId(String instanceId){ return zoneName; } + private static String getInstanceNameFromInstanceId(String instanceId){ + int lastIndexOfSlash = instanceId.lastIndexOf("/"); + String instanceName = instanceId.substring(lastIndexOfSlash+1); + return instanceName; + } + + + } \ No newline at end of file From 81d91d963150c62bbc555d1317405e6d7d9dbab8 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 16:22:41 +0530 Subject: [PATCH 178/217] fixing an error related to log --- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 2891e07304..b24d2d7c85 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -46,7 +46,7 @@ public class GCEOperations { - private static final Log log = LogFactory.getLog(GCELoadBalancer.class); + private static final Log log = LogFactory.getLog(GCEOperations.class); //project related private static final String PROJECT_NAME = GCEContext.getInstance().getProjectName(); From 22f247aef42214c79fbe2170f8b8d6fdce5d0e05 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 16:44:22 +0530 Subject: [PATCH 179/217] adding some null checks for gceOperations.java --- .../gce/extension/util/GCEOperations.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index b24d2d7c85..99c075ee17 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -430,17 +430,24 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String //add instance to instance reference list, we should use the instance URL for (String instanceId : instancesIdsList) { //for all instances - instanceReferenceList.add(new InstanceReference(). - setInstance(getInstanceURLFromId(instanceId))); - - //remove them from configuration holder too - + String instanceUrl = getInstanceURLFromId(instanceId); + if(instanceUrl != null) { + instanceReferenceList.add(new InstanceReference(). + setInstance(instanceUrl)); + } + else { + log.warn("failed to get instance URL for instance: " + instanceId); + } } //create target pools add instance request and set instance to it TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest = new TargetPoolsRemoveInstanceRequest(); + if(instanceReferenceList.size() == 0){ + log.warn("Could not remove instances from target pool " + targetPoolName + " because instance reference list is null"); + return; + } targetPoolsRemoveInstanceRequest.setInstances(instanceReferenceList); try { @@ -488,14 +495,22 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe //add instance to instance reference list, we should use the instance URL for (String instanceId : instancesIdsList) { //for all instances - instanceReferenceList.add(new InstanceReference(). - setInstance(getInstanceURLFromId(instanceId))); + String instanceUrl = getInstanceURLFromId(instanceId); + if(instanceUrl != null){ + instanceReferenceList.add(new InstanceReference(). + setInstance(instanceUrl)); + } } //create target pools add instance request and set instance to it TargetPoolsAddInstanceRequest targetPoolsAddInstanceRequest = new TargetPoolsAddInstanceRequest(); + if (instanceReferenceList.size() == 0) { + log.warn("Could not add instances to target pool " + targetPoolName + " because instance reference list is null"); + return; + } + targetPoolsAddInstanceRequest.setInstances(instanceReferenceList); try { From 9e1afb249e820519be143ca6c555dd30160b48cb Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 17:27:33 +0530 Subject: [PATCH 180/217] adding some null checks for gceOperations.java --- .../apache/stratos/gce/extension/util/GCEOperations.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 99c075ee17..3072509e98 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -122,11 +122,15 @@ public static InstanceList getInstanceList(String zoneName , String filter) { */ public static String getInstanceURLFromId(String instanceId) { - String instanceURL = null; + String instanceURL; String zoneName = getZoneNameFromInstanceId(instanceId); String filter = "name eq " + getInstanceNameFromInstanceId(instanceId); //check whether the given instance is available InstanceList instanceList = getInstanceList(zoneName,filter); + if (instanceList.getItems().size() == 0){ + log.warn("No matching instance found for filter " + filter); + return null; + } for (Instance instance : instanceList.getItems()) { String instanceIdInIaaS = zoneName + "/" + instance.getName(); if (instanceIdInIaaS.equals(instanceId)) { @@ -136,7 +140,8 @@ public static String getInstanceURLFromId(String instanceId) { return instanceURL; } } - return instanceURL; + log.warn("No matching instance found for filter " + filter); + return null; } /** From 64f54559cbf7bef079b7896e1ab2fef06fa8e518 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 18 Jul 2015 17:41:52 +0530 Subject: [PATCH 181/217] adding some null checks for gceOperations.java --- .../gce/extension/util/GCEOperations.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 3072509e98..8199a0ec0f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -76,9 +76,6 @@ public class GCEOperations { /** * Constructor for GCE Operations Class * - * @throws LoadBalancerExtensionException - * @throws GeneralSecurityException - * @throws IOException */ public GCEOperations() { buildComputeEngineObject(); @@ -90,10 +87,9 @@ public GCEOperations() { * and zone) * * @return instanceList - list of instances(members in Stratos side) - * @throws IOException */ public static InstanceList getInstanceList(String zoneName , String filter) { - Compute.Instances.List instances = null; + Compute.Instances.List instances; try { instances = compute.instances(). list(PROJECT_ID, zoneName).setFilter(filter); @@ -127,7 +123,7 @@ public static String getInstanceURLFromId(String instanceId) { String filter = "name eq " + getInstanceNameFromInstanceId(instanceId); //check whether the given instance is available InstanceList instanceList = getInstanceList(zoneName,filter); - if (instanceList.getItems().size() == 0){ + if (instanceList == null){ log.warn("No matching instance found for filter " + filter); return null; } @@ -152,11 +148,15 @@ public static String getInstanceURLFromId(String instanceId) { */ public static String getHealthCheckURLFromName(String healthCheckName) { - String healthCheckURL = null; + String healthCheckURL; //check whether the given instance is available HttpHealthCheckList healthCheckList; healthCheckList = getHealthCheckList(); + if(healthCheckList == null){ + log.warn("Could not found health check " + healthCheckName + "since healthcheck is null"); + return null; + } for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { if (httpHealthCheck.getName().equals(healthCheckName)) { //instance is available @@ -165,7 +165,7 @@ public static String getHealthCheckURLFromName(String healthCheckName) { return healthCheckURL; } } - return healthCheckURL; + return null; } /** @@ -196,8 +196,6 @@ private static HttpHealthCheckList getHealthCheckList() { /** * Authorize and build compute engine object * - * @throws GeneralSecurityException - * @throws IOException */ private void buildComputeEngineObject() { From a21a0322d66fd3270b162ee3a9c0df4a4084709f Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 18:07:33 +0530 Subject: [PATCH 182/217] removed the instance filter for testing purposes --- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 8199a0ec0f..b5aede9b20 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -91,8 +91,10 @@ public GCEOperations() { public static InstanceList getInstanceList(String zoneName , String filter) { Compute.Instances.List instances; try { + /*instances = compute.instances(). + list(PROJECT_ID, zoneName).setFilter(filter);*/ instances = compute.instances(). - list(PROJECT_ID, zoneName).setFilter(filter); + list(PROJECT_ID, zoneName); InstanceList instanceList = instances.execute(); if (instanceList.getItems() == null) { log.info("No instances found for specified zone"); From 06c95a3f9049943630727bed2a69dda6dbd98d6b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 18:36:36 +0530 Subject: [PATCH 183/217] fixing an issue related to get instance URL when the member is terminating --- .../gce/extension/util/GCEOperations.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index b5aede9b20..01e317931b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -91,13 +91,11 @@ public GCEOperations() { public static InstanceList getInstanceList(String zoneName , String filter) { Compute.Instances.List instances; try { - /*instances = compute.instances(). - list(PROJECT_ID, zoneName).setFilter(filter);*/ instances = compute.instances(). - list(PROJECT_ID, zoneName); + list(PROJECT_ID, zoneName).setFilter(filter); InstanceList instanceList = instances.execute(); if (instanceList.getItems() == null) { - log.info("No instances found for specified zone"); + log.info("No instances found for filter " + filter + " and zone " + zoneName); return null; } else { return instanceList; @@ -435,15 +433,9 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String //add instance to instance reference list, we should use the instance URL for (String instanceId : instancesIdsList) { //for all instances - String instanceUrl = getInstanceURLFromId(instanceId); - if(instanceUrl != null) { + String instanceUrl = createInstanceSelfLink(instanceId); instanceReferenceList.add(new InstanceReference(). setInstance(instanceUrl)); - } - else { - log.warn("failed to get instance URL for instance: " + instanceId); - } - } //create target pools add instance request and set instance to it @@ -711,6 +703,17 @@ private static String getInstanceNameFromInstanceId(String instanceId){ return instanceName; } + /** + * Manually create the self link for an instance. This method is useful when the instance is deleted from IaaS + * @return + */ + private static String createInstanceSelfLink(String instanceId){ + + String selfLink = "https://www.googleapis.com/compute/v1/projects/"+PROJECT_ID+ + "/zones/"+getZoneNameFromInstanceId(instanceId)+"/instances/"+getInstanceNameFromInstanceId(instanceId); + return selfLink; + } + } \ No newline at end of file From f3990547da83b84f7f1a221cb0ac68ab41b10135 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 19:19:46 +0530 Subject: [PATCH 184/217] log the error messages related to operation completion --- .../stratos/gce/extension/util/GCEOperations.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 01e317931b..6befa69290 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -609,6 +609,12 @@ private void waitForGlobalOperationCompletion(String operationName) { if (operation.getStatus().equals("DONE")) { return; } + if(operation.getError().getErrors().size()>0){ + //operation has one or more errors + for (Operation.Error.Errors error :operation.getError().getErrors()){ + log.error(error.getMessage()); + } + } if (timeout >= OPERATION_TIMEOUT) { log.warn("Timeout reached for operation " + operationName + ". Existing.."); return; @@ -642,6 +648,12 @@ private void waitForRegionOperationCompletion(String operationName) { if (operation.getStatus().equals("DONE")) { return; } + if(operation.getError().getErrors().size()>0){ + //operation has one or more errors + for (Operation.Error.Errors error :operation.getError().getErrors()){ + log.error(error.getMessage()); + } + } if (timeout >= OPERATION_TIMEOUT) { log.warn("Timeout reached for operation " + operationName + ". Existing.."); return; From 793891a1319f2e6b31b20903d19109e507d2dcf3 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 20:09:59 +0530 Subject: [PATCH 185/217] set health check interval --- .../gce-extension/src/main/conf/gce-configuration.xml | 1 + .../apache/stratos/gce/extension/config/Constants.java | 1 + .../stratos/gce/extension/config/GCEContext.java | 10 ++++++++++ .../gce/extension/config/parser/GCEConfigParser.java | 2 ++ .../stratos/gce/extension/util/GCEOperations.java | 2 ++ 5 files changed, 16 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index fdf4250f11..610a545830 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -38,6 +38,7 @@ / 80 5 + 5 2 diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 1fdf3efbcb..4dc5a87dee 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -46,6 +46,7 @@ public class Constants { public static final String HEALTH_CHECK_PROPERTIES_ELEMENT = "healthCheckProperties"; public static final String HEALTH_CHECK_REQUEST_PATH = "healthCheckRequestPath"; public static final String HEALTH_CHECK_PORT = "healthCheckPort"; + public static final String HEALTH_CHECK_INTERVAL_SEC= "healthCheckIntervalSec"; public static final String HEALTH_CHECK_TIME_OUT_SEC = "healthCheckTimeoutSec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "healthCheckUnhealthyThreshold"; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 84130b941d..b245f5ab96 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -48,6 +48,7 @@ public class GCEContext { private String healthCheckRequestPath; private String healthCheckPort; private String healthCheckTimeOutSec; + private String healthCheckIntervalSec; private String healthCheckUnhealthyThreshold; //other properties @@ -130,6 +131,7 @@ public void validate() { validateSystemProperty(Constants.HEALTH_CHECK_REQUEST_PATH); validateSystemProperty(Constants.HEALTH_CHECK_PORT); validateSystemProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); + validateSystemProperty(Constants.HEALTH_CHECK_INTERVAL_SEC); validateSystemProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); validateSystemProperty(Constants.NETWORK_NAME); validateSystemProperty(Constants.OPERATION_TIMEOUT); @@ -147,6 +149,14 @@ private void validateSystemProperty(String propertyName) { } } + public String getHealthCheckIntervalSec() { + return healthCheckIntervalSec; + } + + public void setHealthCheckIntervalSec(String healthCheckIntervalSec) { + this.healthCheckIntervalSec = healthCheckIntervalSec; + } + public boolean isCEPStatsPublisherEnabled() { return cepStatsPublisherEnabled; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index a625af8904..35b4f270ff 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -128,11 +128,13 @@ private static void extractHealthCheckProperties(OMElement healthCheckProperties String healthCheckPort = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_PORT).getText(); String healthCheckTimeoutSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_TIME_OUT_SEC).getText(); String healthCheckUnhealthyThreshold = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD).getText(); + String heathCheckIntervalSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD).getText(); //set extracted properties to gceContext object gceContext.setHealthCheckRequestPath(healthCheckRequestPath); gceContext.setHealthCheckPort(healthCheckPort); gceContext.setHealthCheckTimeOutSec(healthCheckTimeoutSec); + gceContext.setHealthCheckIntervalSec(heathCheckIntervalSec); gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThreshold); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 6befa69290..214f7c621b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -61,6 +61,7 @@ public class GCEOperations { private static final String HEALTH_CHECK_REQUEST_PATH = GCEContext.getInstance().getHealthCheckRequestPath(); private static final String HEALTH_CHECK_PORT = GCEContext.getInstance().getHealthCheckPort(); private static final String HEALTH_CHECK_TIME_OUT_SEC = GCEContext.getInstance().getHealthCheckTimeOutSec(); + private static final String HEALTH_CHECK_INTERVAL_SEC = GCEContext.getInstance().getHealthCheckIntervalSec(); private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); private static final String NETWORK_NAME = GCEContext.getInstance().getNetworkName(); @@ -539,6 +540,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); + httpHealthCheck.setCheckIntervalSec(Integer.parseInt(HEALTH_CHECK_INTERVAL_SEC)); httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); From c99599ea0310a44021102dc62cae441cd49814dd Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 20:58:06 +0530 Subject: [PATCH 186/217] set health check interval --- .../stratos/gce/extension/config/parser/GCEConfigParser.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 35b4f270ff..e3a0f7d5ce 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -128,14 +128,15 @@ private static void extractHealthCheckProperties(OMElement healthCheckProperties String healthCheckPort = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_PORT).getText(); String healthCheckTimeoutSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_TIME_OUT_SEC).getText(); String healthCheckUnhealthyThreshold = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD).getText(); - String heathCheckIntervalSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD).getText(); + String heathCheckIntervalSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_INTERVAL_SEC).getText(); //set extracted properties to gceContext object gceContext.setHealthCheckRequestPath(healthCheckRequestPath); gceContext.setHealthCheckPort(healthCheckPort); gceContext.setHealthCheckTimeOutSec(healthCheckTimeoutSec); - gceContext.setHealthCheckIntervalSec(heathCheckIntervalSec); gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThreshold); + gceContext.setHealthCheckIntervalSec(heathCheckIntervalSec); + } /** From e9f950e7626fb80b2d488aefcd766e3972f65fa7 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 21:24:26 +0530 Subject: [PATCH 187/217] set health check interval --- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 214f7c621b..14b7d08c5d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -540,7 +540,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); - httpHealthCheck.setCheckIntervalSec(Integer.parseInt(HEALTH_CHECK_INTERVAL_SEC)); + // httpHealthCheck.setCheckIntervalSec(Integer.parseInt(HEALTH_CHECK_INTERVAL_SEC)); httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); From 5fd3819956c3715238ea229332686a9669d52853 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 21:50:28 +0530 Subject: [PATCH 188/217] set health check interval --- .../gce-extension/src/main/conf/gce-configuration.xml | 2 +- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index 610a545830..434bcb3137 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -37,7 +37,7 @@ / 80 - 5 + 2 5 2 diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 14b7d08c5d..214f7c621b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -540,7 +540,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); - // httpHealthCheck.setCheckIntervalSec(Integer.parseInt(HEALTH_CHECK_INTERVAL_SEC)); + httpHealthCheck.setCheckIntervalSec(Integer.parseInt(HEALTH_CHECK_INTERVAL_SEC)); httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); From 017c8af7bc41d9d8bf5405308014cd5f4a509f6a Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 22:05:15 +0530 Subject: [PATCH 189/217] adding health check healthy threshold --- .../gce-extension/src/main/conf/gce-configuration.xml | 1 + .../apache/stratos/gce/extension/config/Constants.java | 1 + .../stratos/gce/extension/config/GCEContext.java | 10 ++++++++++ .../gce/extension/config/parser/GCEConfigParser.java | 3 +++ .../stratos/gce/extension/util/GCEOperations.java | 3 +++ 5 files changed, 18 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index 434bcb3137..3b0f13e8b1 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -40,6 +40,7 @@ 2 5 2 + 2 10000 diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 4dc5a87dee..59f515d980 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -49,6 +49,7 @@ public class Constants { public static final String HEALTH_CHECK_INTERVAL_SEC= "healthCheckIntervalSec"; public static final String HEALTH_CHECK_TIME_OUT_SEC = "healthCheckTimeoutSec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "healthCheckUnhealthyThreshold"; + public static final String HEALTH_CHECK_HEALTHY_THRESHOLD = "healthCheckHealthyThreshold"; //other properties public static final String OPERATION_TIMEOUT = "operationTimeout"; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index b245f5ab96..32de31d925 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -50,6 +50,7 @@ public class GCEContext { private String healthCheckTimeOutSec; private String healthCheckIntervalSec; private String healthCheckUnhealthyThreshold; + private String healthCheckHealthyThreshold; //other properties private String namePrefix; @@ -133,6 +134,7 @@ public void validate() { validateSystemProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); validateSystemProperty(Constants.HEALTH_CHECK_INTERVAL_SEC); validateSystemProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); + validateSystemProperty(Constants.HEALTH_CHECK_HEALTHY_THRESHOLD); validateSystemProperty(Constants.NETWORK_NAME); validateSystemProperty(Constants.OPERATION_TIMEOUT); @@ -217,6 +219,14 @@ public void setHealthCheckRequestPath(String healthCheckRequestPath) { this.healthCheckRequestPath = healthCheckRequestPath; } + public String getHealthCheckHealthyThreshold() { + return healthCheckHealthyThreshold; + } + + public void setHealthCheckHealthyThreshold(String healthCheckHealthyThreshold) { + this.healthCheckHealthyThreshold = healthCheckHealthyThreshold; + } + public String getHealthCheckPort() { return healthCheckPort; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index e3a0f7d5ce..2540c31cf4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -129,6 +129,8 @@ private static void extractHealthCheckProperties(OMElement healthCheckProperties String healthCheckTimeoutSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_TIME_OUT_SEC).getText(); String healthCheckUnhealthyThreshold = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD).getText(); String heathCheckIntervalSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_INTERVAL_SEC).getText(); + String healthCheckHealthyThreshold = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_HEALTHY_THRESHOLD).getText(); + //set extracted properties to gceContext object gceContext.setHealthCheckRequestPath(healthCheckRequestPath); @@ -136,6 +138,7 @@ private static void extractHealthCheckProperties(OMElement healthCheckProperties gceContext.setHealthCheckTimeOutSec(healthCheckTimeoutSec); gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThreshold); gceContext.setHealthCheckIntervalSec(heathCheckIntervalSec); + gceContext.setHealthCheckHealthyThreshold(healthCheckHealthyThreshold); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 214f7c621b..8f08f9ebc9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -63,6 +63,7 @@ public class GCEOperations { private static final String HEALTH_CHECK_TIME_OUT_SEC = GCEContext.getInstance().getHealthCheckTimeOutSec(); private static final String HEALTH_CHECK_INTERVAL_SEC = GCEContext.getInstance().getHealthCheckIntervalSec(); private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); + private static final String HEALTH_CHECK_HEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckHealthyThreshold(); private static final String NETWORK_NAME = GCEContext.getInstance().getNetworkName(); //a filter for get only running instances from IaaS side @@ -542,6 +543,7 @@ public void createHealthCheck(String healthCheckName) { httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); httpHealthCheck.setCheckIntervalSec(Integer.parseInt(HEALTH_CHECK_INTERVAL_SEC)); httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); + httpHealthCheck.setHealthyThreshold(Integer.parseInt(HEALTH_CHECK_HEALTHY_THRESHOLD)); try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); waitForGlobalOperationCompletion(operation.getName()); @@ -550,6 +552,7 @@ public void createHealthCheck(String healthCheckName) { if (log.isErrorEnabled()) { log.error("Could not create health check " + healthCheckName); } + log.error(e.getMessage()); throw new RuntimeException(e); } log.info("Created health check: " + healthCheckName); From 958263c74fa4b4469334d5db0bae5f1efb4fd6ba Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 22:14:19 +0530 Subject: [PATCH 190/217] adding health check healthy threshold --- .../org/apache/stratos/gce/extension/GCELoadBalancer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 45d726b305..e3dd5396df 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -344,8 +344,8 @@ else if (ipList.size() == 1) { } //create the forwarding rule - gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), - gceClusterConfigurationHolder.getTargetPoolName(), protocol, portRange); + //gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), + // gceClusterConfigurationHolder.getTargetPoolName(), protocol, portRange); log.info("Created configuration for cluster"); } catch (Exception e) { if (log.isErrorEnabled()) { From 1cae53b495ec85450345ca483ae7a6bd0e669ee5 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 22:20:52 +0530 Subject: [PATCH 191/217] adding health check healthy threshold --- .../org/apache/stratos/gce/extension/GCELoadBalancer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index e3dd5396df..45d726b305 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -344,8 +344,8 @@ else if (ipList.size() == 1) { } //create the forwarding rule - //gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), - // gceClusterConfigurationHolder.getTargetPoolName(), protocol, portRange); + gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), + gceClusterConfigurationHolder.getTargetPoolName(), protocol, portRange); log.info("Created configuration for cluster"); } catch (Exception e) { if (log.isErrorEnabled()) { From 947f6fe61b40263bb38e2203e8dc6464e29a7fa4 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 23:12:52 +0530 Subject: [PATCH 192/217] adding health check healthy threshold --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 45d726b305..dccd2e0355 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -351,6 +351,7 @@ else if (ipList.size() == 1) { if (log.isErrorEnabled()) { log.error("Could not create configuration for cluster " + clusterId); } + log.error(e.getMessage()); throw new LoadBalancerExtensionException(); } From 09be072d597faba1bad2ccae59002df71c11ed6c Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 21 Jul 2015 23:21:56 +0530 Subject: [PATCH 193/217] removing error logging in operation completion --- .../stratos/gce/extension/util/GCEOperations.java | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 8f08f9ebc9..29aa4893bb 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -614,12 +614,7 @@ private void waitForGlobalOperationCompletion(String operationName) { if (operation.getStatus().equals("DONE")) { return; } - if(operation.getError().getErrors().size()>0){ - //operation has one or more errors - for (Operation.Error.Errors error :operation.getError().getErrors()){ - log.error(error.getMessage()); - } - } + if (timeout >= OPERATION_TIMEOUT) { log.warn("Timeout reached for operation " + operationName + ". Existing.."); return; @@ -653,12 +648,6 @@ private void waitForRegionOperationCompletion(String operationName) { if (operation.getStatus().equals("DONE")) { return; } - if(operation.getError().getErrors().size()>0){ - //operation has one or more errors - for (Operation.Error.Errors error :operation.getError().getErrors()){ - log.error(error.getMessage()); - } - } if (timeout >= OPERATION_TIMEOUT) { log.warn("Timeout reached for operation " + operationName + ". Existing.."); return; From 3ebd60cf3a0dc1a423fea646125c90b25f81b258 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 22 Jul 2015 21:29:06 +0530 Subject: [PATCH 194/217] configuration properties are validated --- .../gce/extension/config/GCEContext.java | 87 +++++-------------- .../config/parser/GCEConfigParser.java | 15 ++-- 2 files changed, 31 insertions(+), 71 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 32de31d925..d78a323ebc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -24,11 +24,10 @@ import org.apache.commons.logging.LogFactory; /** - * This class is used to read and store system properties + * This class is used to store configuration properties for gce-extension */ public class GCEContext { private static final Log log = LogFactory.getLog(GCEContext.class); - private static volatile GCEContext context; //cep stat publisher properties @@ -57,48 +56,8 @@ public class GCEContext { private String operationTimeout; private String log4jPropertiesFileName; + //private constructor private GCEContext() { - - /* this.cepStatsPublisherEnabled = Boolean.getBoolean(Constants.CEP_STATS_PUBLISHER_ENABLED); - this.thriftReceiverIp = System.getProperty(Constants.THRIFT_RECEIVER_IP); - this.thriftReceiverPort = System.getProperty(Constants.THRIFT_RECEIVER_PORT); - this.namePrefix = System.getProperty(Constants.NAME_PREFIX); - this.projectName = System.getProperty(Constants.PROJECT_NAME); - this.projectID = System.getProperty(Constants.PROJECT_ID); - this.zoneName = System.getProperty(Constants.ZONE_NAME); - this.regionName = System.getProperty(Constants.REGION_NAME); - this.keyFilePath = System.getProperty(Constants.KEY_FILE_PATH); - this.gceAccountID = System.getProperty(Constants.GCE_ACCOUNT_ID); - this.healthCheckRequestPath = System.getProperty(Constants.HEALTH_CHECK_REQUEST_PATH); - this.healthCheckPort = System.getProperty(Constants.HEALTH_CHECK_PORT); - this.healthCheckTimeOutSec = System.getProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); - this.healthCheckUnhealthyThreshold = System.getProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); - this.networkName = System.getProperty(Constants.NETWORK_NAME); - this.operationTimeout = System.getProperty(Constants.OPERATION_TIMEOUT); - - - if (log.isDebugEnabled()) { - log.debug(Constants.CEP_STATS_PUBLISHER_ENABLED + " = " + cepStatsPublisherEnabled); - log.debug(Constants.THRIFT_RECEIVER_IP + " = " + thriftReceiverIp); - log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); - log.debug(Constants.THRIFT_RECEIVER_PORT + " = " + thriftReceiverPort); - log.debug(Constants.NAME_PREFIX + " = " + namePrefix); - log.debug(Constants.PROJECT_NAME + " = " + projectName); - log.debug(Constants.PROJECT_ID + " = " + projectID); - log.debug(Constants.ZONE_NAME + " = " + zoneName); - log.debug(Constants.REGION_NAME + " = " + regionName); - log.debug(Constants.KEY_FILE_PATH + " = " + keyFilePath); - log.debug(Constants.GCE_ACCOUNT_ID + " = " + gceAccountID); - log.debug(Constants.HEALTH_CHECK_REQUEST_PATH + " = " + healthCheckRequestPath); - log.debug(Constants.HEALTH_CHECK_PORT + " = " + healthCheckPort); - log.debug(Constants.HEALTH_CHECK_TIME_OUT_SEC + " = " + healthCheckTimeOutSec); - log.debug(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD + " = " + healthCheckUnhealthyThreshold); - log.debug(Constants.NETWORK_NAME + "=" + networkName); - log.debug(Constants.OPERATION_TIMEOUT + "=" + operationTimeout); - - } - */ - } public static GCEContext getInstance() { @@ -121,33 +80,31 @@ public void setLog4jPropertiesFileName(String log4jPropertiesFileName) { } public void validate() { - - validateSystemProperty(Constants.CEP_STATS_PUBLISHER_ENABLED); - validateSystemProperty(Constants.NAME_PREFIX); - validateSystemProperty(Constants.PROJECT_NAME); - validateSystemProperty(Constants.PROJECT_ID); - validateSystemProperty(Constants.REGION_NAME); - validateSystemProperty(Constants.KEY_FILE_PATH); - validateSystemProperty(Constants.GCE_ACCOUNT_ID); - validateSystemProperty(Constants.HEALTH_CHECK_REQUEST_PATH); - validateSystemProperty(Constants.HEALTH_CHECK_PORT); - validateSystemProperty(Constants.HEALTH_CHECK_TIME_OUT_SEC); - validateSystemProperty(Constants.HEALTH_CHECK_INTERVAL_SEC); - validateSystemProperty(Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); - validateSystemProperty(Constants.HEALTH_CHECK_HEALTHY_THRESHOLD); - validateSystemProperty(Constants.NETWORK_NAME); - validateSystemProperty(Constants.OPERATION_TIMEOUT); + validateProperty(Boolean.toString(cepStatsPublisherEnabled)); + validateProperty(namePrefix); + validateProperty(projectName); + validateProperty(projectID); + validateProperty(regionName); + validateProperty(keyFilePath); + validateProperty(gceAccountID); + validateProperty(healthCheckRequestPath); + validateProperty(healthCheckPort); + validateProperty(healthCheckTimeOutSec); + validateProperty(healthCheckIntervalSec); + validateProperty(healthCheckHealthyThreshold); + validateProperty(healthCheckHealthyThreshold); + validateProperty(networkName); + validateProperty(operationTimeout); if (cepStatsPublisherEnabled) { - validateSystemProperty(Constants.THRIFT_RECEIVER_IP); - validateSystemProperty(Constants.THRIFT_RECEIVER_PORT); + validateProperty(Constants.THRIFT_RECEIVER_IP); + validateProperty(Constants.THRIFT_RECEIVER_PORT); } } - private void validateSystemProperty(String propertyName) { - String value = System.getProperty(propertyName); - if (StringUtils.isEmpty(value)) { - throw new RuntimeException("System property was not found: " + propertyName); + private void validateProperty(String propertyName) { + if (StringUtils.isEmpty(propertyName)) { + throw new RuntimeException("Property was not found: " + propertyName); } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 2540c31cf4..92e149b7c0 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -34,7 +34,7 @@ public class GCEConfigParser { private static GCEContext gceContext; /** - * Parse the gce-configuration.xml file. + * Parse the gce-configuration.xml file when the extension is starting up. * * @param documentElement axiom document element. * @throws MalformedConfigurationFileException @@ -42,22 +42,25 @@ public class GCEConfigParser { public static void parse(OMElement documentElement) throws MalformedConfigurationFileException { //get cep info - OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.CEP_STATS_PUBLISHER_ELEMENT); + OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, + Constants.CEP_STATS_PUBLISHER_ELEMENT); extractCepConfiguration(cepInfoElement); //get GCE IaaS info - OMElement gceIaasInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.IAAS_PROPERTIES_ELEMENT); + OMElement gceIaasInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, + Constants.IAAS_PROPERTIES_ELEMENT); extractGceIaasInformation(gceIaasInfoElement); //get heath check info - OMElement healthCheckPropertiesElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.HEALTH_CHECK_PROPERTIES_ELEMENT); + OMElement healthCheckPropertiesElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, + Constants.HEALTH_CHECK_PROPERTIES_ELEMENT); extractHealthCheckProperties(healthCheckPropertiesElement); //extract other properties extractOtherProperties(documentElement); - //validate extradted properties - //gceContext.validate(); + //validate extracted properties + gceContext.validate(); From 2b7631ba6ef6c0faa95f70558b4796905d1db3c6 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 22 Jul 2015 22:02:44 +0530 Subject: [PATCH 195/217] added null checks for config parser --- .../gce/extension/GCELoadBalancer.java | 4 +- .../gce/extension/config/Constants.java | 1 - .../config/parser/GCEConfigParser.java | 143 +++++++++++------- 3 files changed, 94 insertions(+), 54 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index dccd2e0355..f02176d66e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -288,7 +288,7 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer if (log.isErrorEnabled()) { log.error("Could not delete configuration for cluster " + clusterId); } - throw new LoadBalancerExtensionException(); + throw new LoadBalancerExtensionException(e); } } @@ -352,7 +352,7 @@ else if (ipList.size() == 1) { log.error("Could not create configuration for cluster " + clusterId); } log.error(e.getMessage()); - throw new LoadBalancerExtensionException(); + throw new LoadBalancerExtensionException(e); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 59f515d980..55b86640c0 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -23,7 +23,6 @@ * GCE extension constants. */ public class Constants { - public static final String CONFIG_FILE_NAME = "gce-configuration.xml"; public static final String CONFIG_FOLDER_NAME = "conf"; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 92e149b7c0..9522936859 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -26,11 +26,9 @@ import org.apache.stratos.common.util.AxiomXpathParserUtil; import org.apache.stratos.gce.extension.config.Constants; import org.apache.stratos.gce.extension.config.GCEContext; - import javax.xml.namespace.QName; public class GCEConfigParser { - private static final Log log = LogFactory.getLog(GCEConfigParser.class); private static GCEContext gceContext; /** @@ -40,7 +38,6 @@ public class GCEConfigParser { * @throws MalformedConfigurationFileException */ public static void parse(OMElement documentElement) throws MalformedConfigurationFileException { - //get cep info OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.CEP_STATS_PUBLISHER_ELEMENT); @@ -59,20 +56,16 @@ public static void parse(OMElement documentElement) throws MalformedConfiguratio //extract other properties extractOtherProperties(documentElement); - //validate extracted properties + //validate all extracted properties - just a null check gceContext.validate(); - - - } /** * Extract cep ip and port and store in gceContext object * - * @param cepInfoElement + * @param cepInfoElement - OMElement which is containing the cep information */ private static void extractCepConfiguration(OMElement cepInfoElement) { - //Check whether the cep stat publisher enabled or not QName qName = new QName(Constants.CEP_STATS_PUBLISHER_ENABLED); String enabled = cepInfoElement.getAttributeValue(qName); @@ -84,65 +77,104 @@ private static void extractCepConfiguration(OMElement cepInfoElement) { if (Boolean.parseBoolean(enabled)) { //extract rest configuration of cep - String thriftReceiverIp = AxiomXpathParserUtil.getFirstChildElement(cepInfoElement, Constants.THRIFT_RECEIVER_IP).getText(); - String thriftReceiverPort = AxiomXpathParserUtil.getFirstChildElement(cepInfoElement, Constants.THRIFT_RECEIVER_PORT).getText(); - - //set extracted ip and port to gceContext object - gceContext.setThriftReceiverIp(thriftReceiverIp); - gceContext.setThriftReceiverPort(thriftReceiverPort); + OMElement thriftReceiverIpElement = AxiomXpathParserUtil.getFirstChildElement(cepInfoElement, + Constants.THRIFT_RECEIVER_IP); + OMElement thriftReceiverPortElement = AxiomXpathParserUtil.getFirstChildElement(cepInfoElement, + Constants.THRIFT_RECEIVER_PORT); - //validate above properties + if (thriftReceiverIpElement != null) { + //set extracted ip to gceContext object + gceContext.setThriftReceiverIp(thriftReceiverIpElement.getText()); + } + if (thriftReceiverPortElement != null) { + //set extracted port to gceContext object + gceContext.setThriftReceiverPort(thriftReceiverPortElement.getText()); + } } - } /** - * extract Iaas propreties from given OMElement and store it in gceContext object + * extract Iaas properties from given OMElement and store it in gceContext object * * @param gceIaasInfoElement - OMElement which contains Iaas properties */ private static void extractGceIaasInformation(OMElement gceIaasInfoElement) { - - String projectName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_NAME).getText(); - String projectId = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_ID).getText(); - String regionName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.REGION_NAME).getText(); - String keyFilePath = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.KEY_FILE_PATH).getText(); - String gceAccountId = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.GCE_ACCOUNT_ID).getText(); - String networkName = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.NETWORK_NAME).getText(); + OMElement projectNameElement = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_NAME); + OMElement projectIdElement = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.PROJECT_ID); + OMElement regionNameElement = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.REGION_NAME); + OMElement keyFilePathElement = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.KEY_FILE_PATH); + OMElement gceAccountIdElement = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.GCE_ACCOUNT_ID); + OMElement networkNameElement = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.NETWORK_NAME); //set extracted properties to gceContext object - gceContext.setProjectName(projectName); - gceContext.setProjectID(projectId); - gceContext.setRegionName(regionName); - gceContext.setKeyFilePath(keyFilePath); - gceContext.setGceAccountID(gceAccountId); - gceContext.setNetworkName(networkName); + if(projectNameElement != null){ + gceContext.setProjectName(projectNameElement.getText()); + } + + if(projectIdElement != null){ + gceContext.setProjectID(projectIdElement.getText()); + } + + if(regionNameElement != null){ + gceContext.setRegionName(regionNameElement.getText()); + } + if(keyFilePathElement != null){ + gceContext.setKeyFilePath(keyFilePathElement.getText()); + } + + if(gceAccountIdElement != null){ + gceContext.setGceAccountID(gceAccountIdElement.getText()); + } + if(networkNameElement != null){ + gceContext.setNetworkName(networkNameElement.getText()); + } } /** * extract health check properties from given OMElement and store it in gceContext object + * * @param healthCheckPropertiesElement - OMElement which contains health check properties */ private static void extractHealthCheckProperties(OMElement healthCheckPropertiesElement) { + OMElement healthCheckRequestPathElement = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, + Constants.HEALTH_CHECK_REQUEST_PATH); + OMElement healthCheckPortElement = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, + Constants.HEALTH_CHECK_PORT); + OMElement healthCheckTimeoutSecElement = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, + Constants.HEALTH_CHECK_TIME_OUT_SEC); + OMElement healthCheckUnhealthyThresholdElement = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, + Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD); + OMElement heathCheckIntervalSecElement = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, + Constants.HEALTH_CHECK_INTERVAL_SEC); + OMElement healthCheckHealthyThresholdElement = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, + Constants.HEALTH_CHECK_HEALTHY_THRESHOLD); - String healthCheckRequestPath = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_REQUEST_PATH).getText(); - String healthCheckPort = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_PORT).getText(); - String healthCheckTimeoutSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_TIME_OUT_SEC).getText(); - String healthCheckUnhealthyThreshold = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_UNHEALTHY_THRESHOLD).getText(); - String heathCheckIntervalSec = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_INTERVAL_SEC).getText(); - String healthCheckHealthyThreshold = AxiomXpathParserUtil.getFirstChildElement(healthCheckPropertiesElement, Constants.HEALTH_CHECK_HEALTHY_THRESHOLD).getText(); + //set extracted properties to gceContext object + if(healthCheckRequestPathElement != null){ + gceContext.setHealthCheckRequestPath(healthCheckRequestPathElement.getText()); + } + if(healthCheckPortElement != null){ + gceContext.setHealthCheckPort(healthCheckPortElement.getText()); + } - //set extracted properties to gceContext object - gceContext.setHealthCheckRequestPath(healthCheckRequestPath); - gceContext.setHealthCheckPort(healthCheckPort); - gceContext.setHealthCheckTimeOutSec(healthCheckTimeoutSec); - gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThreshold); - gceContext.setHealthCheckIntervalSec(heathCheckIntervalSec); - gceContext.setHealthCheckHealthyThreshold(healthCheckHealthyThreshold); + if(healthCheckTimeoutSecElement != null){ + gceContext.setHealthCheckTimeOutSec(healthCheckTimeoutSecElement.getText()); + } + + if(healthCheckUnhealthyThresholdElement != null){ + gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThresholdElement.getText()); + } + if(heathCheckIntervalSecElement != null){ + gceContext.setHealthCheckIntervalSec(heathCheckIntervalSecElement.getText()); + } + + if(healthCheckHealthyThresholdElement != null){ + gceContext.setHealthCheckHealthyThreshold(healthCheckHealthyThresholdElement.getText()); + } } /** @@ -151,14 +183,23 @@ private static void extractHealthCheckProperties(OMElement healthCheckProperties * @param documentElement - OMElement which contains other properties */ private static void extractOtherProperties(OMElement documentElement) { - String operationTimeout = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.OPERATION_TIMEOUT).getText(); - String namePrefix = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX).getText(); - String log4jPropertiesFileName = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.LOG4J_PROPERTIES_FILE_NAME).getText(); + OMElement operationTimeoutElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants. + OPERATION_TIMEOUT); + OMElement namePrefixElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX); + OMElement log4jPropertiesFileNameElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants. + LOG4J_PROPERTIES_FILE_NAME); //set extracted properties to gceContext object - gceContext.setOperationTimeout(operationTimeout); - gceContext.setNamePrefix(namePrefix); - gceContext.setLog4jPropertiesFileName(log4jPropertiesFileName); - } + if(operationTimeoutElement != null){ + gceContext.setOperationTimeout(operationTimeoutElement.getText()); + } + if(namePrefixElement != null){ + gceContext.setNamePrefix(namePrefixElement.getText()); + } + + if(log4jPropertiesFileNameElement != null){ + gceContext.setLog4jPropertiesFileName(log4jPropertiesFileNameElement.getText()); + } + } } From 6cbdebc0eaa42e248e01b1dcfd21ab15b9bcc66a Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 22 Jul 2015 22:23:41 +0530 Subject: [PATCH 196/217] code reformatted --- .../gce/extension/GCELoadBalancer.java | 57 +++++---------- .../gce/extension/GCEStatisticsReader.java | 2 +- .../apache/stratos/gce/extension/Main.java | 5 +- .../config/GCEClusterConfigurationHolder.java | 17 ----- .../config/parser/GCEConfigParser.java | 2 - .../gce/extension/util/GCEOperations.java | 72 ++----------------- 6 files changed, 24 insertions(+), 131 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index f02176d66e..924bede3d9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -48,11 +48,10 @@ public class GCELoadBalancer implements LoadBalancer { */ private HashMap clusterToLoadBalancerConfigurationMap; - //protocol should be TCP or UDP - private String protocol = "TCP"; + //PROTOCOL should be TCP or UDP + private static final String PROTOCOL = "TCP"; public GCELoadBalancer() { - gceOperations = new GCEOperations(); clusterToLoadBalancerConfigurationMap = new HashMap(); @@ -62,12 +61,11 @@ public GCELoadBalancer() { * Listen to latest topology and update load balancer configuration * * @param topology latest topology to be configured - * @return + * @return - true - if the load balancer was successfully configured. else false * @throws LoadBalancerExtensionException */ @Override public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("Topology received. Configuring Load balancer "); //printing the topology for testing purposes @@ -75,18 +73,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio new FieldDictionary(new ImmutableFieldKeySorter())), new DomDriver("utf-8")); log.info(xstream.toXML(topology)); - try { - //delaying the configuration as a temporary solution( Because topology may not be updated when the configure - // method calls) - Thread.sleep(10000); - + try { //check whether any cluster is removed. If removed, then remove the cluster from //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); while (iterator.hasNext()) { //for each configuration - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); GCEClusterConfigurationHolder gceClusterConfigurationHolder = ((GCEClusterConfigurationHolder) clusterIDLoadBalancerConfigurationPair.getValue()); @@ -101,11 +93,11 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio break; } } - if (found == true) { + if (found) { break; } } - if (found == false) { + if (!found) { //remove cluster from map log.info("Removed cluster is found. Remove it from GCE too. Cluster Id: " + gceClusterConfigurationHolder.getClusterID()); @@ -114,7 +106,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } - for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster @@ -128,7 +119,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap. get(cluster.getClusterId()); - //if the cluster does not contain at least one member if (cluster.getMembers().size() == 0) { @@ -176,20 +166,18 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (String memberId : gceClusterConfigurationHolder.getMemberList()) { //for all members in Map boolean found = false; for (Member member : cluster.getMembers()) { //for all members in cluster - //todo: retest this line if (member.getInstanceId().equals(memberId)) { found = true; break; } } - if (found == false) { + if (!found) { //add member id to membersToBeRemovedFromTargetPool in order remove member from map membersToBeRemovedFromTargetPool.add(memberId); } } if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members - log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); //remove them from configuration holder @@ -215,7 +203,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } else { List instancesList = new ArrayList(); List ipList = new ArrayList(); - for (Member member : cluster.getMembers()) { //add instance to instance list @@ -321,13 +308,11 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer //create forwarding rules in GCE List ipList = gceClusterConfigurationHolder.getIpList(); //need to create a port range String - String portRange = ""; + String portRange; //if the ip list is empty if (ipList.isEmpty()) { - if (log.isDebugEnabled()) { - log.debug("Ip list is null"); - } - //as a temporary solution set all ports to be open + log.warn("Ip list is null"); + //set all ports to be opened portRange = "1-65535"; } @@ -345,7 +330,7 @@ else if (ipList.size() == 1) { //create the forwarding rule gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), - gceClusterConfigurationHolder.getTargetPoolName(), protocol, portRange); + gceClusterConfigurationHolder.getTargetPoolName(), PROTOCOL, portRange); log.info("Created configuration for cluster"); } catch (Exception e) { if (log.isErrorEnabled()) { @@ -354,11 +339,8 @@ else if (ipList.size() == 1) { log.error(e.getMessage()); throw new LoadBalancerExtensionException(e); } - - } - @Override public void start() throws LoadBalancerExtensionException { //Configuration has completed @@ -371,30 +353,23 @@ public void stop() throws LoadBalancerExtensionException { log.info("GCE Load Balancer is stopping"); - //iterate through hashmap and remove all - + //iterate through hash map and remove all Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); while (iterator.hasNext()) { //for each configuration - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCEClusterConfigurationHolder gceClusterConfigurationHolder = - ((GCEClusterConfigurationHolder) clusterIDLoadBalancerConfigurationPair.getValue()); - deleteConfigurationForCluster((String) clusterIDLoadBalancerConfigurationPair.getKey()); - } log.info("GCE Load balancer stopped"); - } - /** * @throws LoadBalancerExtensionException */ @Override public void reload() throws LoadBalancerExtensionException { + //nothing to do here log.info("Configuration reloaded"); } @@ -403,7 +378,7 @@ public void reload() throws LoadBalancerExtensionException { * Create a valid target pool name * * @param clusterId - Id of the cluster - * @return + * @return - a proper name for target pool */ private String targetPoolNameCreator(String clusterId) { //create a valid target pool name by using cluster ID @@ -422,7 +397,7 @@ private String targetPoolNameCreator(String clusterId) { * Create a valid forwarding rule name * * @param clusterID - Id of the cluster - * @return + * @return - a proper name for forwarding rule */ private String forwardingRuleNameCreator(String clusterID) { String forwardingRuleName = GCEContext.getInstance().getNamePrefix() @@ -438,7 +413,7 @@ private String forwardingRuleNameCreator(String clusterID) { * create a valid health check name * * @param clusterID - id of the cluster - * @return + * @return - a proper name for health check */ private String healthCheckNameCreator(String clusterID) { String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-hc-" + diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index 6aa1de0fe1..fdebc142d3 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -46,7 +46,7 @@ public String getClusterInstanceId() { @Override public int getInFlightRequestCount(String clusterId) { - + //no way found in GCE API to get this return 0; } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 276300aca9..6fd9eb5efc 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -66,7 +66,7 @@ public static void main(String[] args) { public void run() { try { if (finalExtension != null) { - log.info("GCE gce instance..."); + log.info("GCE instance is stopping..."); finalExtension.stop(); } mainThread.join(); @@ -107,7 +107,6 @@ public void run() { */ private static String getFilePathOfConfigFile(String fileName) { String workingDirectory = System.getProperty("user.dir"); - String FilePath = workingDirectory + File.separator + ".." + File.separator + Constants.CONFIG_FOLDER_NAME + File.separator + fileName; - return FilePath; + return workingDirectory + File.separator + ".." + File.separator + Constants.CONFIG_FOLDER_NAME + File.separator + fileName; } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java index 6f766ea965..324f096454 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java @@ -51,10 +51,6 @@ public List getIpList() { return ipList; } - public void setIpList(List ipList) { - this.ipList = ipList; - } - public String getForwardingRuleName() { return forwardingRuleName; } @@ -67,11 +63,6 @@ public List getMemberList() { return memberList; } - public void setMemberList(List memberList) { - this.memberList = memberList; - } - - public String getClusterID() { return clusterID; } @@ -99,12 +90,4 @@ public void addMember(String memberId) { public void removeMember(String memberId) { this.memberList.remove(memberId); } - - public void addIp(int ip) { - this.ipList.add(ip); - } - - public void removeIp(int ip) { - this.ipList.remove(ip); - } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 9522936859..458526b0c3 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -20,8 +20,6 @@ */ import org.apache.axiom.om.OMElement; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.exception.MalformedConfigurationFileException; import org.apache.stratos.common.util.AxiomXpathParserUtil; import org.apache.stratos.gce.extension.config.Constants; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 29aa4893bb..76af35df7d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -29,10 +29,7 @@ import com.google.api.services.compute.model.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.gce.extension.GCELoadBalancer; import org.apache.stratos.gce.extension.config.GCEContext; -import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; - import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; @@ -45,7 +42,6 @@ */ public class GCEOperations { - private static final Log log = LogFactory.getLog(GCEOperations.class); //project related @@ -71,10 +67,8 @@ public class GCEOperations { //a timeout for operation completion private static final int OPERATION_TIMEOUT = Integer.parseInt(GCEContext.getInstance().getOperationTimeout()); - static Compute compute; - /** * Constructor for GCE Operations Class * @@ -364,29 +358,6 @@ public boolean isTargetPoolExists(String targetPoolName) { } - /** - * Check whether a given forwarding rule is exists or not in the IaaS - * - * @param forwardingRuleName - forwarding rule name in IaaS - * @return - if forwarding rule exists in GCE return true. else return false - */ - public boolean isForwardingRuleExists(String forwardingRuleName) { - try { - Compute.ForwardingRules.List forwardingRules = compute.forwardingRules().list(PROJECT_ID, REGION_NAME); - ForwardingRuleList forwardingRuleList = forwardingRules.execute(); - for (ForwardingRule forwardingRule : forwardingRuleList.getItems()) { - if (forwardingRule.getName().equals(forwardingRuleName)) { - return true; - } - } - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not get check for forwarding rule " + forwardingRuleName); - } - } - return false; - } - /** * Get a target pool already created in GCE * @@ -471,7 +442,7 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String * This method is used for set port rage for forwarding rule */ public void setPortRangeToForwardingRule() { - //todo:implement this method + //todo:discuss and implement this method } /** @@ -573,32 +544,6 @@ public void deleteHealthCheck(String healthCheckName) { log.info("Deleted Health Check: " + healthCheckName); } - /** - * Checking whether a given health check is exists or not - * - * @param healthCheckName - name of the health check - * @return - if the health check exists in IaaS return true, else return false - */ - public boolean isHealthCheckExists(String healthCheckName) { - try { - HttpHealthCheckList httpHealthCheckList = compute.httpHealthChecks().list(PROJECT_ID).execute(); - if (httpHealthCheckList.size() == 0) { - return false; - } - for (HttpHealthCheck httpHealthCheck : httpHealthCheckList.getItems()) { - if (httpHealthCheck.getName().equals(healthCheckName)) { - return true; - } - } - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Exception caused when checking for health checks "); - } - throw new RuntimeException(e); - } - return false; - } - /** * Wait for a global operation completion. If the operation is related to whole project * that is a global operation @@ -699,27 +644,20 @@ public void createFirewallRule() { private static String getZoneNameFromInstanceId(String instanceId){ int lastIndexOfSlash = instanceId.lastIndexOf("/"); - String zoneName = instanceId.substring(0,lastIndexOfSlash); - return zoneName; + return instanceId.substring(0,lastIndexOfSlash); } private static String getInstanceNameFromInstanceId(String instanceId){ int lastIndexOfSlash = instanceId.lastIndexOf("/"); - String instanceName = instanceId.substring(lastIndexOfSlash+1); - return instanceName; + return instanceId.substring(lastIndexOfSlash+1); } /** * Manually create the self link for an instance. This method is useful when the instance is deleted from IaaS - * @return + * @return - the self link of the instance */ private static String createInstanceSelfLink(String instanceId){ - - String selfLink = "https://www.googleapis.com/compute/v1/projects/"+PROJECT_ID+ + return "https://www.googleapis.com/compute/v1/projects/"+PROJECT_ID+ "/zones/"+getZoneNameFromInstanceId(instanceId)+"/instances/"+getInstanceNameFromInstanceId(instanceId); - return selfLink; } - - - } \ No newline at end of file From 2d2b9b98515dad53b173e483715700ca40c32e46 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 22 Jul 2015 22:32:51 +0530 Subject: [PATCH 197/217] adding license and notice --- .../gce-extension/src/main/license/LICENSE | 481 ++++++++++++++++++ .../gce-extension/src/main/notice/NOTICE | 395 ++++++++++++++ 2 files changed, 876 insertions(+) create mode 100644 extensions/load-balancer/gce-extension/src/main/license/LICENSE create mode 100644 extensions/load-balancer/gce-extension/src/main/notice/NOTICE diff --git a/extensions/load-balancer/gce-extension/src/main/license/LICENSE b/extensions/load-balancer/gce-extension/src/main/license/LICENSE new file mode 100644 index 0000000000..7f14067dc8 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/license/LICENSE @@ -0,0 +1,481 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +=================================================================================== + +=================================================================================== +The Apache Stratos distribution includes a number of run time dependencies with +separate copyright notices and license terms. Your use of the Apache Stratos code +is subject to the terms and conditions of the following licenses. +=================================================================================== + +=============================================================================== +The following components come under Apache Software License 2.0 +=============================================================================== + +org.wso2.carbon.base-4.2.0.jar +org.wso2.carbon.bootstrap-4.2.0.jar +org.wso2.carbon.core-4.2.0.jar +org.wso2.carbon.core.common-4.2.0.jar +org.wso2.carbon.databridge.agent.thrift-4.2 +org.wso2.carbon.databridge.commons-4.2. +org.wso2.carbon.databridge.commons.thrif +org.wso2.carbon.logging-4.2.0.jar +org.wso2.carbon.ndatasource.common-4.2. +org.wso2.carbon.ndatasource.rdbms-4.2.0.j +org.wso2.carbon.queuing-4.2.0.jar +org.wso2.carbon.registry.api-4.2.0.jar +org.wso2.carbon.registry.core-4.2.0.jar +org.wso2.carbon.registry.xboot-4.2.0.jar +org.wso2.carbon.securevault-4.2.0.jar +org.wso2.carbon.user.api-4.2.0.jar +org.wso2.carbon.user.core-4.2.0.jar +org.wso2.carbon.user.mgt-4.2.0.jar +org.wso2.carbon.user.mgt.common-4.2.0.ja +org.wso2.carbon.utils-4.2.0.jar +org.wso2.securevault-1.0.0-wso2v2.jar +abdera-1.0.0.wso2v3.jar +andes-client-0.13.wso2v8.jar +annotations-1.3.2.jar +ant-1.7.0.jar +ant-launcher-1.7.0.jar +axiom-1.2.11.wso2v4.jar +axiom-api-1.2.11.jar +axiom-impl-1.2.11.jar +axis2-1.6.1.wso2v10.jar +commons-cli-1.0.jar +commons-codec-1.2.jar +commons-collections-3.2.0.wso2v +commons-collections-3.2.1.jar +commons-dbcp-1.4.0.wso2v1.jar +commons-fileupload-1.2.0.wso2v1 +commons-fileupload-1.2.jar +commons-httpclient-3.1.0.wso2v2. +commons-httpclient-3.1.jar +commons-io-2.0.0.wso2v2.jar +commons-io-2.0.jar +commons-lang-2.4.jar +commons-lang-2.6.0.wso2v1.jar +commons-lang3-3.1.jar +commons-logging-1.1.1.jar +commons-pool-1.5.6.jar +commons-pool-1.5.6.wso2v1.jar +compass-2.0.1.wso2v2.jar +geronimo-activation_1.1_spec-1.0.2.jar +geronimo-javamail_1.4_spec-1.6.jar +geronimo-jms_1.1_spec-1.1.jar +geronimo-stax-api_1.0_spec-1.0.1.jar +gson-2.2.4.jar +hazelcast-3.0.1.jar +hazelcast-3.0.1.wso2v1.jar +httpclient-4.1.1-wso2v1.jar +httpclient-4.2.5.jar +httpcore-4.1.0-wso2v1.jar +httpcore-4.2.4.jar +javax.cache.wso2-4.2.0.jar +java-xmlbuilder-0.6.jar +javax.servlet-3.0.0.v201112011016.jar +jdbc-pool-7.0.34.wso2v1.jar +jdom-1.0.jar +tomcat-catalina-ha-7.0.34.jar +tomcat-ha-7.0.34.wso2v1.jar +tomcat-jdbc-7.0.34.jar +tomcat-juli-7.0.34.jar +tomcat-tribes-7.0.34.jar +tomcat-util-7.0.34.jar +velocity-1.7.jar +json-2.0.0.wso2v1.jar +libthrift-0.7.wso2v1.jar +libthrift-0.9.1.jar +log4j-1.2.17.jar +neethi-2.0.4.wso2v4.jar +not-yet-commons-ssl-0.3.9.jar +opencsv-1.8.wso2v1.jar +org.apache.log4j-1.2.13.v200706111418.jar +org.apache.stratos.common-4.1.0.jar +org.apache.stratos.load.balancer.common-4.1.0.jar +org.apache.stratos.load.balancer.extension.api-4.1.0.jar +org.apache.stratos.messaging-4.1.0.jar +poi-3.9.jar +poi-ooxml-3.9.0.wso2v1.jar +poi-ooxml-3.9.jar +poi-ooxml-schemas-3.9.jar +poi-scratchpad-3.9.0.wso2v1.jar +poi-scratchpad-3.9.jar +smack-3.0.4.wso2v1.jar +smackx-3.0.4.wso2v1.jar +stax-api-1.0.1.jar +tomcat-annotations-api-7.0.34.jar +tomcat-api-7.0.34.jar +tomcat-catalina-7.0.34.jar + + +=============================================================================== +The following components come under Public Domain License +=============================================================================== + +For base64-2.3.8.jar + +=============================================================================== +The following components come under BouncyCastle License +=============================================================================== + +For bcprov-jdk15-132.jar + +Copyright (c) 2000 - 2013 The Legion of the Bouncy Castle Inc. (http://www.bouncycastle.org) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +=============================================================================== +The following components are Licensed under BSD license +=============================================================================== + +For dom4j-1.6.1.jar, +jline-0.9.94.jar, +jsch-0.1.49.jar +jaxen-1.1.1.jar + +Copyright (c) 2010 Terence Parr +All rights reserved. + +[The BSD License] + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of JiBX nor the names of its contributors may be used + to endorse or promote products derived from this software without specific + prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +=============================================================================== +The following components are licensed under EPL +=============================================================================== + +For junit-3.8.1.jar, +org.eclipse.equinox.http.helper-1.1.0.wso2v1.jar, +org.eclipse.osgi-3.8.1.v20120830-144521.jar, +org.eclipse.osgi.services-3.3.100.v20120522-1822.jar + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + +a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and +b) in the case of each subsequent Contributor: +i) changes to the Program, and +ii) additions to the Program; +where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program. +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form. +b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder. +c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program. +d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement. +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that: + +a) it complies with the terms and conditions of this Agreement; and +b) its license agreement: +i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose; +ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits; +iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and +iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange. +When the Program is made available in source code form: + +a) it must be made available under this Agreement; and +b) a copy of this Agreement must be included with each copy of the Program. +Contributors may not remove or alter any copyright notices contained within the Program. + +Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation. + + +=============================================================================== +The following components are licensed under MIT license +=============================================================================== + +For slf4j-1.5.10.wso2v1.jar, +slf4j-api-1.7.5.jar, +slf4j-log4j12-1.7.5.jar + +The MIT License (MIT) + +Copyright (c) 2004-2013 QOS.ch + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + + + diff --git a/extensions/load-balancer/gce-extension/src/main/notice/NOTICE b/extensions/load-balancer/gce-extension/src/main/notice/NOTICE new file mode 100644 index 0000000000..254608b3e0 --- /dev/null +++ b/extensions/load-balancer/gce-extension/src/main/notice/NOTICE @@ -0,0 +1,395 @@ +Apache Software +Copyright 2015 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). + +================================================================================ +Apache Abdera Notice: + +Portions of Abdera were orginally developed by +International Business Machines Corporation and are +licensed to the Apache Software Foundation under the +"Software Grant and Corporate Contribution License Agreement", +informally known as the "Abdera CLA". + +This software's test suite contains data files derived from the +Universal Feed Parser, Copyright (c) 2002-2005, Mark Pilgrim. + +This software's extensions module contains a JSON writer for Atom XML +that utilizes a JSON parser, Copyright (c) 2002, json.org. The code was +licensed using Apache License by the author Douglas Crockford and made +available at http://json.org/java/apache.zip We have included portions +of the code in the extensions module. + +=============================================================================== +Apache Ant Notice: + +The task is based on code Copyright (c) 2002, Landmark +Graphics Corp that has been kindly donated to the Apache Software +Foundation. + +================================================================================ +Apache Axiom Notice: + +Portions Copyright 2006 International Business Machines Corp. + +================================================================================ +Apache Axis2 Notice: + +Portions Copyright 2006 International Business Machines Corp. +Portions Copyright 2005-2007 WSO2, Inc. + +This product also includes schemas and specification developed by: +- the W3C consortium (http://www.w3c.org) + +This product also includes WS-* schemas developed by International +Business Machines Corporation, Microsoft Corporation, BEA Systems, +TIBCO Software, SAP AG, Sonic Software, and VeriSign + +This product also includes a WSDL developed by salesforce.com +- Copyright 1999-2006 salesforce.com, inc. + +Portions of the included xmlbeans library were originally based on the following: +- software copyright (c) 2000-2003, BEA Systems, . + +================================================================================ +Apache Commons-Lang Notice: + +This product includes software from the Spring Framework, +under the Apache License 2.0 (see: StringUtils.containsWhitespace()) + +================================================================================ +Apache Commons-Pool Notice: + +The LinkedBlockingDeque implementation is based on an implementation written by +Doug Lea with assistance from members of JCP JSR-166 Expert Group and released +to the public domain, as explained at +http://creativecommons.org/licenses/publicdomain + +================================================================================ +Apache Commons-httpclient Notice: + +This project contains annotations derived from JCIP-ANNOTATIONS +Copyright (c) 2005 Brian Goetz and Tim Peierls. See http://www.jcip.net + +=============================================================================== +Apache Tomcat Notice: + +The Windows Installer is built with the Nullsoft +Scriptable Install System (NSIS), which is +open source software. The original software and +related information is available at +http://nsis.sourceforge.net. + +Java compilation software for JSP pages is provided by Eclipse, +which is open source software. The original software and +related information is available at +http://www.eclipse.org. + +For the bayeux implementation +The org.apache.cometd.bayeux API is derivative work originating at the Dojo Foundation +* Copyright 2007-2008 Guy Molinari +* Copyright 2007-2008 Filip Hanik +* Copyright 2007 Dojo Foundation +* Copyright 2007 Mort Bay Consulting Pty. Ltd. + +The original XML Schemas for Java EE Deployment Descriptors: + - javaee_5.xsd + - javaee_web_services_1_2.xsd + - javaee_web_services_client_1_2.xsd + - javaee_6.xsd + - javaee_web_services_1_3.xsd + - javaee_web_services_client_1_3.xsd + - jsp_2_2.xsd + - web-app_3_0.xsd + - web-common_3_0.xsd + - web-fragment_3_0.xsd + - javaee_7.xsd + - javaee_web_services_1_4.xsd + - javaee_web_services_client_1_4.xsd + - jsp_2_3.xsd + - web-app_3_1.xsd + - web-common_3_1.xsd + - web-fragment_3_1.xsd + +may be obtained from: +http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html + +================================================================================ +Apache Geranimo Notice: + +Apache Geronimo +Copyright 2003-2011 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +Portions of the Web Console were orginally developed by International +Business Machines Corporation and are licensed to the Apache Software +Foundation under the "Software Grant and Corporate Contribution +License Agreement", informally known as the "IBM Console CLA". + +Portions of the ASN1 codec implementation in +framework/modules/geronimo-crypto/ were developed by the Bouncy Castle +project (http://www.bouncycastle.org/). + +Copyright (c) 2000-2005 +The Legion Of The Bouncy Castle (http://www.bouncycastle.org) + +ORB Portions of this software were developed at IONA Technologies. + +Object Management Group (OMG) classes used by the orb. +The original classes are available from www.org.omg. + +The RMI over IIOP implementation were developed at Trifork Technologies. + +Copyright 2004-2009 Tranql project committers +This product includes software developed at +Tranql (http://tranql.codehaus.org/). + +This product includes software developed by the Protocol Buffers +project (http://code.google.com/apis/protocolbuffers). + +This product includes also software developed by : + - the W3C consortium (http://www.w3c.org) , + - the SAX project (http://www.saxproject.org) + +The task is based on code Copyright (c) 2002, Landmark +Graphics Corp that has been kindly donated to the Apache Software +Foundation. + +Portions of this software were originally based on the following: + - software copyright (c) 1999, IBM Corporation., http://www.ibm.com. + - software copyright (c) 1999, Sun Microsystems., http://www.sun.com. + - voluntary contributions made by Paul Eng on behalf of the + Apache Software Foundation that were originally developed at iClick, Inc., + software copyright (c) 1999. + + +Portions Copyright 2006 International Business Machines Corp. +Portions Copyright 2005-2007 WSO2, Inc. + +This product also includes schemas and specification developed by: +- the W3C consortium (http://www.w3c.org) + +This product also includes WS-* schemas developed by International +Business Machines Corporation, Microsoft Corporation, BEA Systems, +TIBCO Software, SAP AG, Sonic Software, and VeriSign + +This product also includes a WSDL developed by salesforce.com +- Copyright 1999-2006 salesforce.com, inc. + +Portions of the included xmlbeans library were originally based on the following: +- software copyright (c) 2000-2003, BEA Systems, . + +This product also includes schemas and specification developed by: + - the W3C consortium (http://www.w3c.org) + (http://www.w3.org/XML/1998/namespace) + +This product also includes WS-* schemas developed by International + Business Machines Corporation, Microsoft Corporation, BEA Systems, + TIBCO Software, SAP AG, Sonic Software, and VeriSign + (http://schemas.xmlsoap.org/wsdl/2003-02-11.xsd) + (http://schemas.xmlsoap.org/ws/2004/08/addressing/) + (http://schemas.xmlsoap.org/wsdl/http) + (http://schemas.xmlsoap.org/ws/2005/02/rm/wsrm.xsd) + (http://www.w3.org/2005/08/addressing/ws-addr.xsd) + +Portions of Derby were originally developed by +International Business Machines Corporation and are +licensed to the Apache Software Foundation under the +"Software Grant and Corporate Contribution License Agreement", +informally known as the "Derby CLA". +The following copyright notice(s) were affixed to portions of the code +with which this file is now or was at one time distributed +and are placed here unaltered. + +(C) Copyright 1997,2004 International Business Machines Corporation. All rights reserved. + +(C) Copyright IBM Corp. 2003. + +The portion of the functionTests under 'nist' was originally +developed by the National Institute of Standards and Technology (NIST), +an agency of the United States Department of Commerce, and adapted by +International Business Machines Corporation in accordance with the NIST +Software Acknowledgment and Redistribution document at +http://www.itl.nist.gov/div897/ctg/sql_form.htm + +* OpenJPA includes software written by Miroslav Nachev. + +* OpenJPA uses test code written by Charles Tillman. + +XMLSec was originally based on software copyright (c) 2001, Institute for +Data Communications Systems, . + +The development of XMLSec was partly funded by the European +Commission in the project in the ISIS Programme. + +This product also includes software developed by : + + - IBM Corporation (http://www.ibm.com), + WSDL4J was the initial code contribution for the Apache Woden + project and some of the WSDL4J design and code has been reused. + - The W3C Consortium (http://www.w3c.org), + Common W3C XML Schema and DTD files are packaged with Apache Woden. + +Portions Copyright 2006 International Business Machines Corp. + +Portions of this software were originally based on the following: + - software copyright (c) 2000-2003, BEA Systems, . + +Aside from contributions to the Apache XMLBeans project, this +software also includes: + + - one or more source files from the Apache Xerces-J and Apache Axis + products, Copyright (c) 1999-2003 Apache Software Foundation + + - W3C XML Schema documents Copyright 2001-2003 (c) World Wide Web + Consortium (Massachusetts Institute of Technology, European Research + Consortium for Informatics and Mathematics, Keio University) + + - resolver.jar from Apache Xml Commons project, + Copyright (c) 2001-2003 Apache Software Foundation + + - Piccolo XML Parser for Java from http://piccolo.sourceforge.net/, + Copyright 2002 Yuval Oren under the terms of the Apache Software License 2.0 + + - JSR-173 Streaming API for XML from http://sourceforge.net/projects/xmlpullparser/, + Copyright 2005 BEA under the terms of the Apache Software License 2.0 + +This product includes software developed by the Simple XML Compiler (SXC) +project (http://sxc.codehaus.org/project-info.html) + +This product includes software developed for the JAXB Reference +Implementation project. (https://jaxb.dev.java.net/). Apache Geronimo elects +to include this software in this distribution under the CDDL license. + +This product includes software developed for SOAP with Attachments +API for Java (SAAJ). The software is available from the GlassFish project +(https://saaj.dev.java.net/). Apache Geronimo elects to include this +software in this distribution under the CDDL license. + +This product includes software developed for Java API for XML Web Services +project (JAX-WS) (https://jax-ws.dev.java.net/). Apache Geronimo elects +to include this software in this distribution under the CDDL license. + +This product includes software developed for the Java Server Pages Tag +Library project (https://jstl.dev.java.net/). Apache Geronimo elects +to include this software in this distribution under the CDDL license. + +This product includes schema files developed for the Glassfish Java EE +reference implementation (http://java.sun.com/xml/ns/j2ee/). +Apache Geronimo elects to include this software in this distribution +under the CDDL license. You can obtain a copy of the License at: + https://glassfish.dev.java.net/public/CDDL+GPL.html +The source code is available at: + https://glassfish.dev.java.net/source/browse/glassfish/ + +The following schemas are included: + +---------------------------------- + application-client_1_4.xsd + application_1_4.xsd + connector_1_5.xsd + datatypes.dtd + ejb-jar_2_1.xsd + j2ee_1_4.xsd + j2ee_jaxrpc_mapping_1_1.xsd + j2ee_web_services_1_1.xsd + j2ee_web_services_client_1_1.xsd + jsp_2_0.xsd + web-app_2_4.xsd + web-jsptaglibrary_2_0.xsd + application-client_5.xsd + application_5.xsd + ejb-jar_3_0.xsd + handler-chain.xsd + javaee_5.xsd + javaee_web_services_1_2.xsd + javaee_web_services_client_1_2.xsd + jsp_2_1.xsd + persistence_1_0.xsd + web-app_2_5.xsd + web-facelettaglibrary_2_0.xsd + web-facesconfig_2_0.xsd + web-partialresponse_2_0.xsd + web-jsptaglibrary_2_1.xsd + application_6.xsd + application-client_6.xsd + connector_1_6.xsd + ejb-jar_3_1.xsd + javaee_6.xsd + javaee_web_services_1_3.xsd + javaee_web_services_client_1_3.xsd + jsp_2_2.xsd + persistence_2_0.xsd + web-app_3_0.xsd + web-common_3_0.xsd + web-fragment_3_0.xsd +-------------------------------- + +This product includes software developed at +the OSGi Alliance (http://www.osgi.org/). + + This product includes software developed at + OPS4J (http://www.ops4j.org/). +------------------------------------------------------------------------------- + +The product contains the software developed in javassist.org (http://www.javassist.org) +which is released under both the Mozilla Public License +(http://www.mozilla.org/MPL/MPL-1.1.html) and the GNU Lesser General Public +License (http://www.gnu.org/licenses/lgpl-2.1.html). + +The Apache Geronimo project elects to distribute this software under the terms of +the Mozilla Public License. + +------------------------------------------------------------------------------- + +The product contains the software developed in json.org which released under the following license. + +http://www.json.org/license.html + +Copyright (c) 2002 JSON.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +The Software shall be used for Good, not Evil. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +================================================================================ +Apache Httpclient Notice: + +This project contains annotations derived from JCIP-ANNOTATIONS +Copyright (c) 2005 Brian Goetz and Tim Peierls. See http://www.jcip.net + +================================================================================ +Apache Httpcore Notice: + +This project contains annotations derived from JCIP-ANNOTATIONS +Copyright (c) 2005 Brian Goetz and Tim Peierls. See http://www.jcip.net + +=============================================================================== +Apache POI Notice: + +This product contains the DOM4J library (http://www.dom4j.org). +Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved. + +This product contains parts that were originally based on software from BEA. +Copyright (c) 2000-2003, BEA Systems, . + +This product contains W3C XML Schema documents. Copyright 2001-2003 (c) +World Wide Web Consortium (Massachusetts Institute of Technology, European +Research Consortium for Informatics and Mathematics, Keio University) + +This product contains the Piccolo XML Parser for Java +(http://piccolo.sourceforge.net/). Copyright 2002 Yuval Oren. + +This product contains the chunks_parse_cmds.tbl file from the vsdump program. +Copyright (C) 2006-2007 Valek Filippov (frob@df.ru) + + + From 2e130ed3d626f421d430d2c2f459aca2a5aa449b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 27 Jul 2015 12:51:49 +0530 Subject: [PATCH 198/217] change the logic for removing configuration for removed cluster in GCELoadBalancer.java file --- .../src/main/conf/gce-configuration.xml | 44 ++++++------ .../gce/extension/GCELoadBalancer.java | 67 ++++++------------- 2 files changed, 47 insertions(+), 64 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index 3b0f13e8b1..2cdcaca882 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -1,22 +1,29 @@ - + + + + + + + + + + + + + + + + + + + + + + + ]> @@ -27,7 +34,6 @@ MyFirstProject gold-access-96509 - europe-west1-b europe-west1 /home/sanjaya/keys/p12key-donwloaded.p12 164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 924bede3d9..9077efc791 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -38,7 +38,8 @@ public class GCELoadBalancer implements LoadBalancer { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); - + //PROTOCOL should be TCP or UDP + private static final String PROTOCOL = "TCP"; private GCEOperations gceOperations; /** * We have one configuration per cluster @@ -48,9 +49,6 @@ public class GCELoadBalancer implements LoadBalancer { */ private HashMap clusterToLoadBalancerConfigurationMap; - //PROTOCOL should be TCP or UDP - private static final String PROTOCOL = "TCP"; - public GCELoadBalancer() { gceOperations = new GCEOperations(); clusterToLoadBalancerConfigurationMap = new HashMap(); @@ -75,41 +73,14 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info(xstream.toXML(topology)); try { - //check whether any cluster is removed. If removed, then remove the cluster from - //clusterToLoadBalancerConfigurationMap and remove all objects in IaaS side too - Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); - while (iterator.hasNext()) { //for each configuration - Map.Entry clusterIDLoadBalancerConfigurationPair = (Map.Entry) iterator.next(); - GCEClusterConfigurationHolder gceClusterConfigurationHolder = - ((GCEClusterConfigurationHolder) clusterIDLoadBalancerConfigurationPair.getValue()); - - boolean found = false; - - //check whether cluster is in the map or not - for (Service service : topology.getServices()) { - for (Cluster cluster : service.getClusters()) { //for each cluster - if (cluster.getClusterId().equals(gceClusterConfigurationHolder.getClusterID())) { - found = true; - break; - } - } - if (found) { - break; - } - } - if (!found) { - //remove cluster from map - log.info("Removed cluster is found. Remove it from GCE too. Cluster Id: " + - gceClusterConfigurationHolder.getClusterID()); - clusterToLoadBalancerConfigurationMap.remove(gceClusterConfigurationHolder.getClusterID()); - deleteConfigurationForCluster(gceClusterConfigurationHolder.getClusterID()); - } - } + + //this list is used to hold the current clusters available in topology and which has at least one member. + List activeClusterIdList = new ArrayList(); for (Service service : topology.getServices()) { for (Cluster cluster : service.getClusters()) { //for each cluster - //check whether this cluster has a forwarding rule configuration or not + //check whether this cluster has a load balancer configuration or not if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { log.info("Reconfiguring the existing cluster: " + cluster.getClusterId()); @@ -119,17 +90,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap. get(cluster.getClusterId()); - //if the cluster does not contain at least one member - if (cluster.getMembers().size() == 0) { + //if the cluster contains at least one member + if (cluster.getMembers().size() > 0) { + //that cluster contains at least one member - log.info("Cluster: " + cluster.getClusterId() + " does not have any member.So remove cluster " + - "from GCE too"); - //remove all - deleteConfigurationForCluster(cluster.getClusterId()); - clusterToLoadBalancerConfigurationMap.remove(gceClusterConfigurationHolder.getClusterID()); + activeClusterIdList.add(cluster.getClusterId()); - } else { - //that cluster contains at least one member //***************detect member changes and update**************// @@ -201,6 +167,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (cluster.getMembers().size() == 0) { log.info("Cluster " + cluster.getClusterId() + " does not have any members. So not configuring"); } else { + activeClusterIdList.add(cluster.getClusterId()); List instancesList = new ArrayList(); List ipList = new ArrayList(); for (Member member : cluster.getMembers()) { @@ -245,6 +212,16 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } + //if any cluster is removed from the topology or if any cluster does not have at least one member, + //remove those clusters from map and remove the configuration from GCE too + for (String clusterId : clusterToLoadBalancerConfigurationMap.keySet()) { + if (!activeClusterIdList.contains(clusterId)) { + log.info("Removing the configuration for cluster " + clusterId); + clusterToLoadBalancerConfigurationMap.remove(clusterId); + deleteConfigurationForCluster(clusterId); + } + } + log.info("Load balancer configured as given topology"); return true; } catch (Exception e) { @@ -311,7 +288,7 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer String portRange; //if the ip list is empty if (ipList.isEmpty()) { - log.warn("Ip list is null"); + log.warn("Ip list is null"); //set all ports to be opened portRange = "1-65535"; From 78e325ade828b45166e76aca1867fa76e4595c9b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 27 Jul 2015 12:53:38 +0530 Subject: [PATCH 199/217] change the logic for removing configuration for removed cluster in GCELoadBalancer.java file --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 9077efc791..4f1dea5901 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -222,6 +222,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } + activeClusterIdList.clear(); + log.info("Load balancer configured as given topology"); return true; } catch (Exception e) { From 2d6ad4b57e2c5c2ec8f6db4ca00ea1c34457ddbb Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 27 Jul 2015 12:59:05 +0530 Subject: [PATCH 200/217] change the logic for removing configuration for removed cluster in GCELoadBalancer.java file --- .../src/main/conf/gce-configuration.xml | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index 2cdcaca882..3b0d1e11c3 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -1,29 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - ]> From cc8784a33d6f87633914f5bb81886d1dc6054ba7 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Mon, 27 Jul 2015 13:08:49 +0530 Subject: [PATCH 201/217] change the logic for removing configuration for removed cluster in GCELoadBalancer.java file --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 4f1dea5901..66d2ad467e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -217,8 +217,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio for (String clusterId : clusterToLoadBalancerConfigurationMap.keySet()) { if (!activeClusterIdList.contains(clusterId)) { log.info("Removing the configuration for cluster " + clusterId); - clusterToLoadBalancerConfigurationMap.remove(clusterId); deleteConfigurationForCluster(clusterId); + clusterToLoadBalancerConfigurationMap.remove(clusterId); } } From 0cf407442d8619b59b642080a72eb57cda958011 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 1 Aug 2015 17:40:09 +0530 Subject: [PATCH 202/217] exception handling --- .../gce/extension/GCELoadBalancer.java | 333 ++++++++---------- .../gce/extension/util/GCEOperations.java | 265 +++++--------- 2 files changed, 240 insertions(+), 358 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 66d2ad467e..5eb6e5ae95 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -33,6 +33,7 @@ import org.apache.stratos.load.balancer.extension.api.LoadBalancer; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; +import java.io.IOException; import java.util.*; public class GCELoadBalancer implements LoadBalancer { @@ -42,14 +43,13 @@ public class GCELoadBalancer implements LoadBalancer { private static final String PROTOCOL = "TCP"; private GCEOperations gceOperations; /** - * We have one configuration per cluster + * One configuration object per cluster will be created * One cluster has one target pool , one forwarding rule and a health check * This hash map is used to hold cluster IDs and corresponding configuration - * So one cluster will have one loadBalancerConfiguration object */ private HashMap clusterToLoadBalancerConfigurationMap; - public GCELoadBalancer() { + public GCELoadBalancer() throws IOException { gceOperations = new GCEOperations(); clusterToLoadBalancerConfigurationMap = new HashMap(); @@ -72,190 +72,174 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio new DomDriver("utf-8")); log.info(xstream.toXML(topology)); - try { + //this list is used to hold the current clusters available in topology and which has at least one member. + List activeClusterIdList = new ArrayList(); - //this list is used to hold the current clusters available in topology and which has at least one member. - List activeClusterIdList = new ArrayList(); + for (Service service : topology.getServices()) { + for (Cluster cluster : service.getClusters()) { //for each cluster - for (Service service : topology.getServices()) { - for (Cluster cluster : service.getClusters()) { //for each cluster + //check whether this cluster has a load balancer configuration or not + if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { - //check whether this cluster has a load balancer configuration or not - if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { + log.info("Reconfiguring the existing cluster: " + cluster.getClusterId()); - log.info("Reconfiguring the existing cluster: " + cluster.getClusterId()); + //It already has a entry in clusterToLoadBalancerConfigurationMap. + //Take it and update it as the given topology. + GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap. + get(cluster.getClusterId()); - //It already has a entry in clusterToLoadBalancerConfigurationMap. - //Take it and update it as the given topology. - GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap. - get(cluster.getClusterId()); + //if the cluster contains at least one member + if (cluster.getMembers().size() > 0) { + //that cluster contains at least one member - //if the cluster contains at least one member - if (cluster.getMembers().size() > 0) { - //that cluster contains at least one member + activeClusterIdList.add(cluster.getClusterId()); - activeClusterIdList.add(cluster.getClusterId()); + //***************detect member changes and update**************// + //check for newly created members + List membersToBeAddedToTargetPool = new ArrayList(); + for (Member member : cluster.getMembers()) { - //***************detect member changes and update**************// - - //check for newly created members - List membersToBeAddedToTargetPool = new ArrayList(); - for (Member member : cluster.getMembers()) { - - if (member.getInstanceId() != null) { - if (!gceClusterConfigurationHolder.getMemberList().contains(member.getInstanceId())) { - membersToBeAddedToTargetPool.add(member.getInstanceId()); - } + if (member.getInstanceId() != null) { + if (!gceClusterConfigurationHolder.getMemberList().contains(member.getInstanceId())) { + membersToBeAddedToTargetPool.add(member.getInstanceId()); } - } - if (membersToBeAddedToTargetPool.size() > 0) { //we have new members + } - log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + - "to cluster"); + if (membersToBeAddedToTargetPool.size() > 0) { //we have new members - //add them to configuration holder - for (String memberId : membersToBeAddedToTargetPool) { - gceClusterConfigurationHolder.addMember(memberId); + log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + + "to cluster"); - } + //add them to configuration holder + for (String memberId : membersToBeAddedToTargetPool) { + gceClusterConfigurationHolder.addMember(memberId); - //add them to target pool too - gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, - gceClusterConfigurationHolder.getTargetPoolName()); } - //check for terminated members and remove them from cluster - List membersToBeRemovedFromTargetPool = new ArrayList(); - for (String memberId : gceClusterConfigurationHolder.getMemberList()) { //for all members in Map - boolean found = false; - for (Member member : cluster.getMembers()) { //for all members in cluster - if (member.getInstanceId().equals(memberId)) { - found = true; - break; - } - } - if (!found) { - //add member id to membersToBeRemovedFromTargetPool in order remove member from map - membersToBeRemovedFromTargetPool.add(memberId); + //add them to target pool too + gceOperations.addInstancesToTargetPool(membersToBeAddedToTargetPool, + gceClusterConfigurationHolder.getTargetPoolName()); + } + + //check for terminated members and remove them from cluster + List membersToBeRemovedFromTargetPool = new ArrayList(); + for (String memberId : gceClusterConfigurationHolder.getMemberList()) { //for all members in Map + boolean found = false; + for (Member member : cluster.getMembers()) { //for all members in cluster + if (member.getInstanceId().equals(memberId)) { + found = true; + break; } } + if (!found) { + //add member id to membersToBeRemovedFromTargetPool in order remove member from map + membersToBeRemovedFromTargetPool.add(memberId); + } + } - if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members - log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); - - //remove them from configuration holder - for (String memberId : membersToBeRemovedFromTargetPool) { - gceClusterConfigurationHolder.removeMember(memberId); + if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members + log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); - } + //remove them from configuration holder + for (String memberId : membersToBeRemovedFromTargetPool) { + gceClusterConfigurationHolder.removeMember(memberId); - //remove them from GCE too - gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, - gceClusterConfigurationHolder.getTargetPoolName()); } + //remove them from GCE too + gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, + gceClusterConfigurationHolder.getTargetPoolName()); } - } else { - //doesn't have a GCEClusterConfigurationHolder object. So crate a new one and add to hash map + } - log.info("Found a new cluster: " + cluster.getClusterId()); + } else { + //doesn't have a GCEClusterConfigurationHolder object. So crate a new one and add to hash map - if (cluster.getMembers().size() == 0) { - log.info("Cluster " + cluster.getClusterId() + " does not have any members. So not configuring"); - } else { - activeClusterIdList.add(cluster.getClusterId()); - List instancesList = new ArrayList(); - List ipList = new ArrayList(); - for (Member member : cluster.getMembers()) { + log.info("Found a new cluster: " + cluster.getClusterId()); - //add instance to instance list - if (member.getInstanceId() != null) { - instancesList.add(member.getInstanceId()); - } + if (cluster.getMembers().size() == 0) { + log.info("Cluster " + cluster.getClusterId() + " does not have any members. So not configuring"); + } else { + activeClusterIdList.add(cluster.getClusterId()); + List instancesList = new ArrayList(); + List ipList = new ArrayList(); + for (Member member : cluster.getMembers()) { + + //add instance to instance list + if (member.getInstanceId() != null) { + instancesList.add(member.getInstanceId()); + } - //add forwarding rules(Ports to be forwarded) - for (Object port : member.getPorts()) { - int portValue = ((Port) port).getValue(); - if (!ipList.contains(portValue)) { //if port is not in list - //put the forwarding rule to list - ipList.add(portValue); - } + //add forwarding rules(Ports to be forwarded) + for (Object port : member.getPorts()) { + int portValue = ((Port) port).getValue(); + if (!ipList.contains(portValue)) { //if port is not in list + //put the forwarding rule to list + ipList.add(portValue); } - } - GCEClusterConfigurationHolder GCEClusterConfigurationHolder = new GCEClusterConfigurationHolder( - cluster.getClusterId(), instancesList, ipList); + } - //set target pool name - String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - GCEClusterConfigurationHolder.setTargetPoolName(targetPoolName); + GCEClusterConfigurationHolder GCEClusterConfigurationHolder = new GCEClusterConfigurationHolder( + cluster.getClusterId(), instancesList, ipList); - //set forwarding rule name - String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - GCEClusterConfigurationHolder.setForwardingRuleName(forwardingRuleName); + //set target pool name + String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); + GCEClusterConfigurationHolder.setTargetPoolName(targetPoolName); - //set health check name - String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - GCEClusterConfigurationHolder.setHealthCheckName(healthCheckName); + //set forwarding rule name + String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); + GCEClusterConfigurationHolder.setForwardingRuleName(forwardingRuleName); - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCEClusterConfigurationHolder); - createConfigurationForCluster(cluster.getClusterId()); + //set health check name + String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); + GCEClusterConfigurationHolder.setHealthCheckName(healthCheckName); - } - } + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCEClusterConfigurationHolder); + createConfigurationForCluster(cluster.getClusterId()); + } } - } - //if any cluster is removed from the topology or if any cluster does not have at least one member, - //remove those clusters from map and remove the configuration from GCE too - for (String clusterId : clusterToLoadBalancerConfigurationMap.keySet()) { - if (!activeClusterIdList.contains(clusterId)) { - log.info("Removing the configuration for cluster " + clusterId); - deleteConfigurationForCluster(clusterId); - clusterToLoadBalancerConfigurationMap.remove(clusterId); - } } + } - activeClusterIdList.clear(); - - log.info("Load balancer configured as given topology"); - return true; - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Failed to configure load balancer"); + //if any cluster is removed from the topology or if any cluster does not have at least one member, + //remove those clusters from map and remove the configuration from GCE too + for (String clusterId : clusterToLoadBalancerConfigurationMap.keySet()) { + if (!activeClusterIdList.contains(clusterId)) { + log.info("Removing the configuration for cluster " + clusterId); + deleteConfigurationForCluster(clusterId); + clusterToLoadBalancerConfigurationMap.remove(clusterId); } - throw new LoadBalancerExtensionException(e); } + activeClusterIdList.clear(); + + log.info("Load balancer configured as given topology"); + return true; + } /** - * This method is used to delete all fowarding rules, target pools and health checks + * This method is used to delete all forwarding rules, target pools and health checks * in IaaS side according to new topology */ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { - try { - log.info("Deleting forwarding rule for cluster " + clusterId); - GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); - //delete forwarding rule - gceOperations.deleteForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName()); - //delete target pool from GCE - gceOperations.deleteTargetPool(gceClusterConfigurationHolder.getTargetPoolName()); - //delete health check from GCE - gceOperations.deleteHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); - log.info("Deleted forwarding rule for cluster " + clusterId); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Could not delete configuration for cluster " + clusterId); - } - throw new LoadBalancerExtensionException(e); - } + log.info("Deleting forwarding rule for cluster " + clusterId); + GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); + //delete forwarding rule + gceOperations.deleteForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName()); + //delete target pool from GCE + gceOperations.deleteTargetPool(gceClusterConfigurationHolder.getTargetPoolName()); + //delete health check from GCE + gceOperations.deleteHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); + log.info("Deleted forwarding rule for cluster " + clusterId); } @@ -265,59 +249,48 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer */ private void createConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { - try { + log.info("Creating configuration for cluster"); - log.info("Creating configuration for cluster"); + GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); - GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); + //create a health check + gceOperations.createHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); - //create a health check - gceOperations.createHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); + //crate a target pool in GCE + gceOperations.createTargetPool(gceClusterConfigurationHolder.getTargetPoolName(), + gceClusterConfigurationHolder.getHealthCheckName()); - gceOperations.createFirewallRule(); + //add instances to target pool + gceOperations.addInstancesToTargetPool(gceClusterConfigurationHolder.getMemberList(), + gceClusterConfigurationHolder.getTargetPoolName()); - //crate a target pool in GCE - gceOperations.createTargetPool(gceClusterConfigurationHolder.getTargetPoolName(), - gceClusterConfigurationHolder.getHealthCheckName()); + //create forwarding rules in GCE + List ipList = gceClusterConfigurationHolder.getIpList(); + //need to create a port range String + String portRange; + //if the ip list is empty + if (ipList.isEmpty()) { + log.warn("Ip list is null"); + //set all ports to be opened + portRange = "1-65535"; - //add instances to target pool - gceOperations.addInstancesToTargetPool(gceClusterConfigurationHolder.getMemberList(), - gceClusterConfigurationHolder.getTargetPoolName()); - - //create forwarding rules in GCE - List ipList = gceClusterConfigurationHolder.getIpList(); - //need to create a port range String - String portRange; - //if the ip list is empty - if (ipList.isEmpty()) { - log.warn("Ip list is null"); - //set all ports to be opened - portRange = "1-65535"; - - } - //else if ip list has only one value - else if (ipList.size() == 1) { - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); - } - //else we have more than 1 value - else { - //first we need to take the port range. So arrange ipList in ascending order - Collections.sort(ipList); - //take the first one and last one - portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); - } - - //create the forwarding rule - gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), - gceClusterConfigurationHolder.getTargetPoolName(), PROTOCOL, portRange); - log.info("Created configuration for cluster"); - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Could not create configuration for cluster " + clusterId); - } - log.error(e.getMessage()); - throw new LoadBalancerExtensionException(e); } + //else if ip list has only one value + else if (ipList.size() == 1) { + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(0)); + } + //else we have more than 1 value + else { + //first we need to take the port range. So arrange ipList in ascending order + Collections.sort(ipList); + //take the first one and last one + portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); + } + + //create the forwarding rule + gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), + gceClusterConfigurationHolder.getTargetPoolName(), PROTOCOL, portRange); + log.info("Created configuration for cluster"); } @Override diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 76af35df7d..7653c05779 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.gce.extension.config.GCEContext; + import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; @@ -60,10 +61,6 @@ public class GCEOperations { private static final String HEALTH_CHECK_INTERVAL_SEC = GCEContext.getInstance().getHealthCheckIntervalSec(); private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); private static final String HEALTH_CHECK_HEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckHealthyThreshold(); - private static final String NETWORK_NAME = GCEContext.getInstance().getNetworkName(); - - //a filter for get only running instances from IaaS side - private static final String RUNNING_FILTER = "status eq RUNNING"; //a timeout for operation completion private static final int OPERATION_TIMEOUT = Integer.parseInt(GCEContext.getInstance().getOperationTimeout()); @@ -71,20 +68,51 @@ public class GCEOperations { /** * Constructor for GCE Operations Class - * */ - public GCEOperations() { + public GCEOperations() throws IOException { buildComputeEngineObject(); } + /** + * Authorize and build compute engine object + */ + private void buildComputeEngineObject() throws IOException { + + try { + + HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); + JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); + + GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) + .setJsonFactory(jsonFactory) + .setServiceAccountId(ACCOUNT_ID) + .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) + .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_PATH)) + .build(); + + // Create compute engine object + compute = new Compute.Builder( + httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) + .setHttpRequestInitializer(credential).build(); + } catch (GeneralSecurityException e) { + if (log.isErrorEnabled()) { + log.error("Could not authenticate and build compute object"); + throw new RuntimeException(e); + } + } catch (IOException e) { + log.fatal("Could not authenticate and build compute object"); + throw new IOException(e); + } + } + /** * Get list of running instances in given project and zone.(This method can be used - * when we need to check whether a given instance is available or not in a given project + * to check whether a given instance is available or not in a given project * and zone) * * @return instanceList - list of instances(members in Stratos side) */ - public static InstanceList getInstanceList(String zoneName , String filter) { + public static InstanceList getInstanceList(String zoneName, String filter) { Compute.Instances.List instances; try { instances = compute.instances(). @@ -97,12 +125,10 @@ public static InstanceList getInstanceList(String zoneName , String filter) { return instanceList; } } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not get instance list from GCE"); - } - throw new RuntimeException(e); - } + log.warn("Could not get instance list from GCE", e); + } + return null; } @@ -118,8 +144,8 @@ public static String getInstanceURLFromId(String instanceId) { String zoneName = getZoneNameFromInstanceId(instanceId); String filter = "name eq " + getInstanceNameFromInstanceId(instanceId); //check whether the given instance is available - InstanceList instanceList = getInstanceList(zoneName,filter); - if (instanceList == null){ + InstanceList instanceList = getInstanceList(zoneName, filter); + if (instanceList == null) { log.warn("No matching instance found for filter " + filter); return null; } @@ -149,8 +175,8 @@ public static String getHealthCheckURLFromName(String healthCheckName) { //check whether the given instance is available HttpHealthCheckList healthCheckList; healthCheckList = getHealthCheckList(); - if(healthCheckList == null){ - log.warn("Could not found health check " + healthCheckName + "since healthcheck is null"); + if (healthCheckList == null) { + log.warn("Could not found health check " + healthCheckName + "since health check list is null"); return null; } for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { @@ -182,47 +208,19 @@ private static HttpHealthCheckList getHealthCheckList() { return healthCheckList; } } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not get health check list from GCE"); - } - throw new RuntimeException(e); + log.warn("Could not get health check list from GCE", e); + return null; } } /** - * Authorize and build compute engine object + * Manually create the self link for an instance. This method is useful when the instance is deleted from IaaS * + * @return - the self link of the instance */ - private void buildComputeEngineObject() { - - try { - - HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); - JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); - - GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport) - .setJsonFactory(jsonFactory) - .setServiceAccountId(ACCOUNT_ID) - .setServiceAccountScopes(Collections.singleton(ComputeScopes.COMPUTE)) - .setServiceAccountPrivateKeyFromP12File(new File(KEY_FILE_PATH)) - .build(); - - // Create compute engine object - compute = new Compute.Builder( - httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) - .setHttpRequestInitializer(credential).build(); - } catch (GeneralSecurityException e) { - if (log.isErrorEnabled()) { - log.error("Could not authenticate and build compute object"); - throw new RuntimeException(e); - } - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not authenticate and build compute object"); - throw new RuntimeException(e); - } - } - + private static String createInstanceSelfLink(String instanceId) { + return "https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID + + "/zones/" + getZoneNameFromInstanceId(instanceId) + "/instances/" + getInstanceNameFromInstanceId(instanceId); } /** @@ -245,11 +243,8 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); waitForRegionOperationCompletion(operation.getName()); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not create target pool: " + targetPoolName); - } - throw new RuntimeException(e); + } catch (Exception e) { + log.warn("Could not create target pool: " + targetPoolName + " " + e); } } @@ -265,11 +260,8 @@ public void deleteTargetPool(String targetPoolName) { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); waitForRegionOperationCompletion(operation.getName()); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not delete target pool " + targetPoolName); - } - throw new RuntimeException(e); + } catch (Exception e) { + log.warn("Could not delete target pool " + targetPoolName + " " + e); } log.info("Target pool: " + targetPoolName + " has been deleted"); } @@ -282,7 +274,8 @@ public void deleteTargetPool(String targetPoolName) { * @param protocol - The protocol which is used to forward trafic. Should be either TCP or UDP */ - public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol, String portRange) { + public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol, + String portRange) { log.info("Creating a forwarding rule: " + forwardingRuleName); //Need to get target pool resource URL @@ -296,13 +289,8 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam try { Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); waitForRegionOperationCompletion(operation.getName()); - - - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not create a forwarding rule " + forwardingRuleName); - } - throw new RuntimeException(e); + } catch (Exception e) { + log.warn("Could not create a forwarding rule " + forwardingRuleName + " " + e); } log.info("Created forwarding rule: " + forwardingRuleName); } @@ -317,14 +305,9 @@ public void deleteForwardingRule(String forwardingRuleName) { try { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); - waitForRegionOperationCompletion(operation.getName()); - - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not delete forwarding rule " + forwardingRuleName); - } - throw new RuntimeException(e); + } catch (Exception e) { + log.warn("Could not delete forwarding rule " + forwardingRuleName + " " + e); } log.info("Deleted forwarding rule: " + forwardingRuleName); } @@ -349,13 +332,9 @@ public boolean isTargetPoolExists(String targetPoolName) { } } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Error caused when checking for target pools"); - } - throw new RuntimeException(e); + log.warn("Could not check whether the target pool " + targetPoolName + " is exists or not " + e); } return false; - } /** @@ -378,15 +357,12 @@ public TargetPool getTargetPool(String targetPoolName) { return null; } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not get target pool " + targetPoolName); - } - throw new RuntimeException(e); + log.warn("Could not get target pool " + targetPoolName + " " + e); } + return null; } - /** * Remove given set of instances from target pool * @@ -407,14 +383,14 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String for (String instanceId : instancesIdsList) { //for all instances String instanceUrl = createInstanceSelfLink(instanceId); - instanceReferenceList.add(new InstanceReference(). - setInstance(instanceUrl)); + instanceReferenceList.add(new InstanceReference(). + setInstance(instanceUrl)); } //create target pools add instance request and set instance to it TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest = new TargetPoolsRemoveInstanceRequest(); - if(instanceReferenceList.size() == 0){ + if (instanceReferenceList.size() == 0) { log.warn("Could not remove instances from target pool " + targetPoolName + " because instance reference list is null"); return; } @@ -427,24 +403,13 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String waitForRegionOperationCompletion(operation.getName()); - - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not remove instances from target pool " + targetPoolName); - } - throw new RuntimeException(e); + } catch (Exception e) { + log.warn("Could not remove instances from target pool " + targetPoolName + " " + e); } log.info("Removed instances from target pool: " + targetPoolName); } - /** - * This method is used for set port rage for forwarding rule - */ - public void setPortRangeToForwardingRule() { - //todo:discuss and implement this method - } - /** * Add a given list of instances to a target pool * @@ -466,7 +431,7 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe for (String instanceId : instancesIdsList) { //for all instances String instanceUrl = getInstanceURLFromId(instanceId); - if(instanceUrl != null){ + if (instanceUrl != null) { instanceReferenceList.add(new InstanceReference(). setInstance(instanceUrl)); } @@ -489,11 +454,8 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe targetPoolName, targetPoolsAddInstanceRequest).execute(); waitForRegionOperationCompletion(operation.getName()); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not add instance to target pool" + targetPoolName); - } - throw new RuntimeException(e); + } catch (Exception e) { + log.warn("Could not add instance to target pool" + targetPoolName + " " + e); } log.info("Added instances to target pool: " + targetPoolName); } @@ -519,12 +481,8 @@ public void createHealthCheck(String healthCheckName) { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); waitForGlobalOperationCompletion(operation.getName()); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not create health check " + healthCheckName); - } - log.error(e.getMessage()); - throw new RuntimeException(e); + } catch (Exception e) { + log.error("Could not create health check " + healthCheckName + " " + e); } log.info("Created health check: " + healthCheckName); } @@ -535,11 +493,8 @@ public void deleteHealthCheck(String healthCheckName) { Operation operation = compute.httpHealthChecks().delete(PROJECT_ID, healthCheckName).execute(); waitForGlobalOperationCompletion(operation.getName()); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not get delete health check " + healthCheckName); - } - throw new RuntimeException(e); + } catch (Exception e) { + log.warn("Could not get delete health check " + healthCheckName + " " + e); } log.info("Deleted Health Check: " + healthCheckName); } @@ -550,7 +505,7 @@ public void deleteHealthCheck(String healthCheckName) { * * @param operationName - name of the operation in IaaS */ - private void waitForGlobalOperationCompletion(String operationName) { + private void waitForGlobalOperationCompletion(String operationName) throws Exception { try { Thread.sleep(2000); int timeout = 0; @@ -567,12 +522,9 @@ private void waitForGlobalOperationCompletion(String operationName) { Thread.sleep(1000); timeout += 1000; } - } catch (InterruptedException e) { - log.error("Could not wait for global operation completion " + operationName); - throw new RuntimeException(e); - } catch (IOException e) { + } catch (Exception e) { log.error("Could not wait for global operation completion " + operationName); - throw new RuntimeException(e); + throw new Exception(e); } } @@ -583,7 +535,7 @@ private void waitForGlobalOperationCompletion(String operationName) { * @param operationName - name of the region operation */ - private void waitForRegionOperationCompletion(String operationName) { + private void waitForRegionOperationCompletion(String operationName) throws Exception { try { Thread.sleep(2000); int timeout = 0; @@ -600,64 +552,21 @@ private void waitForRegionOperationCompletion(String operationName) { Thread.sleep(1000); timeout += 1000; } - } catch (InterruptedException e) { + } catch (Exception e) { log.error("Could not wait for region operation completion " + operationName); - throw new RuntimeException(e); - } catch (IOException e) { - log.error("Could not wait for region operation completion " + operationName); - throw new RuntimeException(e); - } - } - - public void createFirewallRule() { - - log.info("Creating firewall rule"); - - List sourceRanges = new ArrayList(); - sourceRanges.add("0.0.0.0/0"); - - List ports = new ArrayList(); - ports.add(HEALTH_CHECK_PORT); - - Firewall.Allowed allowed = new Firewall.Allowed(); - allowed.setIPProtocol("TCP"); - allowed.setPorts(ports); - - List allowedRules = new ArrayList(); - allowedRules.add(allowed); - - Firewall firewall = new Firewall(); - firewall.setName("stratos-health-check-firewall"); - firewall.setNetwork(NETWORK_NAME); - firewall.setSourceRanges(sourceRanges); - firewall.setAllowed(allowedRules); - try { - compute.firewalls().insert(PROJECT_ID, firewall); - } catch (IOException e) { - if (log.isErrorEnabled()) { - log.error("Could not create firewall rule "); - } - throw new RuntimeException(e); + throw new Exception(e); } - log.info("Created firewall rule"); } - private static String getZoneNameFromInstanceId(String instanceId){ + private static String getZoneNameFromInstanceId(String instanceId) { int lastIndexOfSlash = instanceId.lastIndexOf("/"); - return instanceId.substring(0,lastIndexOfSlash); + return instanceId.substring(0, lastIndexOfSlash); } - private static String getInstanceNameFromInstanceId(String instanceId){ + private static String getInstanceNameFromInstanceId(String instanceId) { int lastIndexOfSlash = instanceId.lastIndexOf("/"); - return instanceId.substring(lastIndexOfSlash+1); + return instanceId.substring(lastIndexOfSlash + 1); } - /** - * Manually create the self link for an instance. This method is useful when the instance is deleted from IaaS - * @return - the self link of the instance - */ - private static String createInstanceSelfLink(String instanceId){ - return "https://www.googleapis.com/compute/v1/projects/"+PROJECT_ID+ - "/zones/"+getZoneNameFromInstanceId(instanceId)+"/instances/"+getInstanceNameFromInstanceId(instanceId); - } -} \ No newline at end of file +} + From d5a68a7ca268a1b1794a7d06d000c8a107446013 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Fri, 7 Aug 2015 13:16:22 +0530 Subject: [PATCH 203/217] Adding debug logs and reformat the code --- .../load-balancer/gce-extension/pom.xml | 9 +- .../gce/extension/GCELoadBalancer.java | 58 +++++++----- .../gce/extension/GCEStatisticsReader.java | 2 +- .../apache/stratos/gce/extension/Main.java | 2 +- .../gce/extension/config/Constants.java | 2 +- .../gce/extension/config/GCEContext.java | 2 +- .../config/parser/GCEConfigParser.java | 93 ++++++++++++++++--- .../gce/extension/util/GCEOperations.java | 78 +++++++++------- 8 files changed, 166 insertions(+), 80 deletions(-) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index e969a22305..e27de33860 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -87,23 +87,18 @@ org.apache.stratos.cloud.controller ${project.version} - - - com.thoughtworks.xstream - xstream - 1.4.8 - org.apache.ws.commons.axiom.wso2 axiom 1.2.11.wso2v4 - + 1.19.0 1.19.0 + diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 5eb6e5ae95..3514451994 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -19,11 +19,6 @@ package org.apache.stratos.gce.extension; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.converters.reflection.FieldDictionary; -import com.thoughtworks.xstream.converters.reflection.ImmutableFieldKeySorter; -import com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider; -import com.thoughtworks.xstream.io.xml.DomDriver; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.gce.extension.config.GCEClusterConfigurationHolder; @@ -34,6 +29,7 @@ import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; import java.io.IOException; +import java.security.GeneralSecurityException; import java.util.*; public class GCELoadBalancer implements LoadBalancer { @@ -44,12 +40,12 @@ public class GCELoadBalancer implements LoadBalancer { private GCEOperations gceOperations; /** * One configuration object per cluster will be created - * One cluster has one target pool , one forwarding rule and a health check + * One cluster has one target pool,one forwarding rule and a health check * This hash map is used to hold cluster IDs and corresponding configuration */ private HashMap clusterToLoadBalancerConfigurationMap; - public GCELoadBalancer() throws IOException { + public GCELoadBalancer() throws IOException, GeneralSecurityException { gceOperations = new GCEOperations(); clusterToLoadBalancerConfigurationMap = new HashMap(); @@ -64,13 +60,7 @@ public GCELoadBalancer() throws IOException { */ @Override public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("Topology received. Configuring Load balancer "); - - //printing the topology for testing purposes - XStream xstream = new XStream(new Sun14ReflectionProvider( - new FieldDictionary(new ImmutableFieldKeySorter())), - new DomDriver("utf-8")); - log.info(xstream.toXML(topology)); + log.info("Complete topology received. Configuring Load balancer "); //this list is used to hold the current clusters available in topology and which has at least one member. List activeClusterIdList = new ArrayList(); @@ -81,7 +71,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //check whether this cluster has a load balancer configuration or not if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { - log.info("Reconfiguring the existing cluster: " + cluster.getClusterId()); + if (log.isDebugEnabled()) { + log.debug("Reconfiguring the existing cluster: " + cluster.getClusterId()); + } //It already has a entry in clusterToLoadBalancerConfigurationMap. //Take it and update it as the given topology. @@ -92,6 +84,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (cluster.getMembers().size() > 0) { //that cluster contains at least one member + if (log.isDebugEnabled()) { + log.debug("Cluster " + cluster.getClusterId() + " has one or more members"); + } activeClusterIdList.add(cluster.getClusterId()); //***************detect member changes and update**************// @@ -102,14 +97,15 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (member.getInstanceId() != null) { if (!gceClusterConfigurationHolder.getMemberList().contains(member.getInstanceId())) { + if (log.isDebugEnabled()) { + log.debug("New member found: " + member.getInstanceId()); + } membersToBeAddedToTargetPool.add(member.getInstanceId()); } } - } if (membersToBeAddedToTargetPool.size() > 0) { //we have new members - log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + "to cluster"); @@ -136,6 +132,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } if (!found) { //add member id to membersToBeRemovedFromTargetPool in order remove member from map + if (log.isDebugEnabled()) { + log.debug("Terminated member found: " + memberId); + } membersToBeRemovedFromTargetPool.add(memberId); } } @@ -171,7 +170,16 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //add instance to instance list if (member.getInstanceId() != null) { + if (log.isDebugEnabled()) { + log.debug("Adding member " + member.getMemberId() + " to instance list since the" + + "member id is not null"); + } instancesList.add(member.getInstanceId()); + } else { + if (log.isDebugEnabled()) { + log.debug("Instance ID is null for " + member.getMemberId() + " so not adding to" + + "the instance list"); + } } //add forwarding rules(Ports to be forwarded) @@ -179,10 +187,12 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio int portValue = ((Port) port).getValue(); if (!ipList.contains(portValue)) { //if port is not in list //put the forwarding rule to list + if (log.isDebugEnabled()) { + log.debug("Port found: " + portValue); + } ipList.add(portValue); } } - } GCEClusterConfigurationHolder GCEClusterConfigurationHolder = new GCEClusterConfigurationHolder( @@ -220,9 +230,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } activeClusterIdList.clear(); - log.info("Load balancer configured as given topology"); + log.info("Load balancer was configured as given topology"); return true; - } /** @@ -231,7 +240,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio */ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { - log.info("Deleting forwarding rule for cluster " + clusterId); + log.info("Deleting configuration for cluster " + clusterId); GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); //delete forwarding rule gceOperations.deleteForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName()); @@ -239,7 +248,7 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer gceOperations.deleteTargetPool(gceClusterConfigurationHolder.getTargetPoolName()); //delete health check from GCE gceOperations.deleteHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); - log.info("Deleted forwarding rule for cluster " + clusterId); + log.info("Deleted configuration for cluster " + clusterId); } @@ -287,6 +296,10 @@ else if (ipList.size() == 1) { portRange = Integer.toString(ipList.get(0)) + "-" + Integer.toString(ipList.get(ipList.size() - 1)); } + if (log.isDebugEnabled()) { + log.debug("Port range set as: " + portRange); + } + //create the forwarding rule gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), gceClusterConfigurationHolder.getTargetPoolName(), PROTOCOL, portRange); @@ -375,7 +388,6 @@ private String healthCheckNameCreator(String clusterID) { if (healthCheckName.length() >= 62) { healthCheckName = healthCheckName.substring(0, 62); } - return healthCheckName; } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index fdebc142d3..c78a569b79 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -46,7 +46,7 @@ public String getClusterInstanceId() { @Override public int getInFlightRequestCount(String clusterId) { - //no way found in GCE API to get this + //There is no way in GCE API to get in flight request count! return 0; } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 6fd9eb5efc..7acac51ef4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -49,7 +49,7 @@ public static void main(String[] args) { //read configuration from gce-configuration.xml and store configuration in GCEConfigurationHolder class File configFile = new File(getFilePathOfConfigFile(Constants.CONFIG_FILE_NAME)); - OMElement documentElement = AxiomXpathParserUtil.parse(configFile); + OMElement documentElement = AxiomXpathParserUtil.parse(configFile); GCEConfigParser.parse(documentElement); // Configure log4j properties diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 55b86640c0..9232d6a8df 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -45,7 +45,7 @@ public class Constants { public static final String HEALTH_CHECK_PROPERTIES_ELEMENT = "healthCheckProperties"; public static final String HEALTH_CHECK_REQUEST_PATH = "healthCheckRequestPath"; public static final String HEALTH_CHECK_PORT = "healthCheckPort"; - public static final String HEALTH_CHECK_INTERVAL_SEC= "healthCheckIntervalSec"; + public static final String HEALTH_CHECK_INTERVAL_SEC = "healthCheckIntervalSec"; public static final String HEALTH_CHECK_TIME_OUT_SEC = "healthCheckTimeoutSec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "healthCheckUnhealthyThreshold"; public static final String HEALTH_CHECK_HEALTHY_THRESHOLD = "healthCheckHealthyThreshold"; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index d78a323ebc..9889d03ecd 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -43,7 +43,7 @@ public class GCEContext { private String gceAccountID; private String networkName; - //healthcheck properties + //health check properties private String healthCheckRequestPath; private String healthCheckPort; private String healthCheckTimeOutSec; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 458526b0c3..e25d50d9a6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -20,13 +20,17 @@ */ import org.apache.axiom.om.OMElement; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.stratos.common.exception.MalformedConfigurationFileException; import org.apache.stratos.common.util.AxiomXpathParserUtil; import org.apache.stratos.gce.extension.config.Constants; import org.apache.stratos.gce.extension.config.GCEContext; + import javax.xml.namespace.QName; public class GCEConfigParser { + private static final Log log = LogFactory.getLog(GCEConfigParser.class); private static GCEContext gceContext; /** @@ -36,6 +40,11 @@ public class GCEConfigParser { * @throws MalformedConfigurationFileException */ public static void parse(OMElement documentElement) throws MalformedConfigurationFileException { + + if (log.isDebugEnabled()) { + log.debug("Parsing the configuration xml file "); + } + //get cep info OMElement cepInfoElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.CEP_STATS_PUBLISHER_ELEMENT); @@ -55,6 +64,9 @@ public static void parse(OMElement documentElement) throws MalformedConfiguratio extractOtherProperties(documentElement); //validate all extracted properties - just a null check + if (log.isDebugEnabled()) { + log.debug("Validating the properties read from configuration xml file"); + } gceContext.validate(); } @@ -83,11 +95,17 @@ private static void extractCepConfiguration(OMElement cepInfoElement) { if (thriftReceiverIpElement != null) { //set extracted ip to gceContext object gceContext.setThriftReceiverIp(thriftReceiverIpElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Thrift receiver IP: " + thriftReceiverIpElement.getText()); + } } if (thriftReceiverPortElement != null) { //set extracted port to gceContext object gceContext.setThriftReceiverPort(thriftReceiverPortElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Thrift receiver port: " + thriftReceiverPortElement.getText()); + } } } } @@ -106,27 +124,45 @@ private static void extractGceIaasInformation(OMElement gceIaasInfoElement) { OMElement networkNameElement = AxiomXpathParserUtil.getFirstChildElement(gceIaasInfoElement, Constants.NETWORK_NAME); //set extracted properties to gceContext object - if(projectNameElement != null){ + if (projectNameElement != null) { gceContext.setProjectName(projectNameElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Project Name: " + projectNameElement.getText()); + } } - if(projectIdElement != null){ + if (projectIdElement != null) { gceContext.setProjectID(projectIdElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Project ID: " + projectIdElement.getText()); + } } - if(regionNameElement != null){ + if (regionNameElement != null) { gceContext.setRegionName(regionNameElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Region Name: " + regionNameElement.getText()); + } } - if(keyFilePathElement != null){ + if (keyFilePathElement != null) { gceContext.setKeyFilePath(keyFilePathElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Key file path: " + keyFilePathElement.getText()); + } } - if(gceAccountIdElement != null){ + if (gceAccountIdElement != null) { gceContext.setGceAccountID(gceAccountIdElement.getText()); + if (log.isDebugEnabled()) { + log.debug("GCE Account ID: " + gceAccountIdElement.getText()); + } } - if(networkNameElement != null){ + if (networkNameElement != null) { gceContext.setNetworkName(networkNameElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Network Name: " + networkNameElement.getText()); + } } } @@ -150,28 +186,46 @@ private static void extractHealthCheckProperties(OMElement healthCheckProperties Constants.HEALTH_CHECK_HEALTHY_THRESHOLD); //set extracted properties to gceContext object - if(healthCheckRequestPathElement != null){ + if (healthCheckRequestPathElement != null) { gceContext.setHealthCheckRequestPath(healthCheckRequestPathElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Health check request path: " + healthCheckRequestPathElement.getText()); + } } - if(healthCheckPortElement != null){ + if (healthCheckPortElement != null) { gceContext.setHealthCheckPort(healthCheckPortElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Health check port: " + healthCheckPortElement.getText()); + } } - if(healthCheckTimeoutSecElement != null){ + if (healthCheckTimeoutSecElement != null) { gceContext.setHealthCheckTimeOutSec(healthCheckTimeoutSecElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Health check timeout sec: " + healthCheckTimeoutSecElement.getText()); + } } - if(healthCheckUnhealthyThresholdElement != null){ + if (healthCheckUnhealthyThresholdElement != null) { gceContext.setHealthCheckUnhealthyThreshold(healthCheckUnhealthyThresholdElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Health check unhealthy threshold: " + healthCheckUnhealthyThresholdElement.getText()); + } } - if(heathCheckIntervalSecElement != null){ + if (heathCheckIntervalSecElement != null) { gceContext.setHealthCheckIntervalSec(heathCheckIntervalSecElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Health check interval sec: " + heathCheckIntervalSecElement.getText()); + } } - if(healthCheckHealthyThresholdElement != null){ + if (healthCheckHealthyThresholdElement != null) { gceContext.setHealthCheckHealthyThreshold(healthCheckHealthyThresholdElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Health check healthy threshold: " + healthCheckHealthyThresholdElement.getText()); + } } } @@ -188,16 +242,25 @@ private static void extractOtherProperties(OMElement documentElement) { LOG4J_PROPERTIES_FILE_NAME); //set extracted properties to gceContext object - if(operationTimeoutElement != null){ + if (operationTimeoutElement != null) { gceContext.setOperationTimeout(operationTimeoutElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Operation timeout: " + operationTimeoutElement.getText()); + } } - if(namePrefixElement != null){ + if (namePrefixElement != null) { gceContext.setNamePrefix(namePrefixElement.getText()); + if (log.isDebugEnabled()) { + log.debug("Name prefix: " + namePrefixElement.getText()); + } } - if(log4jPropertiesFileNameElement != null){ + if (log4jPropertiesFileNameElement != null) { gceContext.setLog4jPropertiesFileName(log4jPropertiesFileNameElement.getText()); + if (log.isDebugEnabled()) { + log.debug("log4j properties file name: " + log4jPropertiesFileNameElement.getText()); + } } } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 7653c05779..3b6ff48e74 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -69,17 +69,21 @@ public class GCEOperations { /** * Constructor for GCE Operations Class */ - public GCEOperations() throws IOException { + public GCEOperations() throws IOException, GeneralSecurityException { buildComputeEngineObject(); } /** * Authorize and build compute engine object */ - private void buildComputeEngineObject() throws IOException { + private void buildComputeEngineObject() throws IOException, GeneralSecurityException { try { + if (log.isDebugEnabled()) { + log.debug("Authorizing and building the compute engine object"); + } + HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); @@ -94,12 +98,15 @@ private void buildComputeEngineObject() throws IOException { compute = new Compute.Builder( httpTransport, jsonFactory, null).setApplicationName(PROJECT_NAME) .setHttpRequestInitializer(credential).build(); - } catch (GeneralSecurityException e) { - if (log.isErrorEnabled()) { - log.error("Could not authenticate and build compute object"); - throw new RuntimeException(e); + if (log.isDebugEnabled()) { + log.debug("Successfully built the compute engine object"); } + } catch (GeneralSecurityException e) { + //Security exception occurred. Cant proceed further + log.fatal("Could not authenticate and build compute object"); + throw new GeneralSecurityException(e); } catch (IOException e) { + //IO exception occurred. Cant proceed further log.fatal("Could not authenticate and build compute object"); throw new IOException(e); } @@ -119,16 +126,15 @@ public static InstanceList getInstanceList(String zoneName, String filter) { list(PROJECT_ID, zoneName).setFilter(filter); InstanceList instanceList = instances.execute(); if (instanceList.getItems() == null) { - log.info("No instances found for filter " + filter + " and zone " + zoneName); + log.warn("No instances found for filter " + filter + " and zone " + zoneName); return null; } else { return instanceList; } } catch (IOException e) { - log.warn("Could not get instance list from GCE", e); - + log.warn("Could not get instance list from GCE ", e); + return null; } - return null; } @@ -176,7 +182,7 @@ public static String getHealthCheckURLFromName(String healthCheckName) { HttpHealthCheckList healthCheckList; healthCheckList = getHealthCheckList(); if (healthCheckList == null) { - log.warn("Could not found health check " + healthCheckName + "since health check list is null"); + log.warn("Could not found health check " + healthCheckName + " because the health check list is null"); return null; } for (HttpHealthCheck httpHealthCheck : healthCheckList.getItems()) { @@ -187,6 +193,7 @@ public static String getHealthCheckURLFromName(String healthCheckName) { return healthCheckURL; } } + log.warn("Could not found the health check " + healthCheckName); return null; } @@ -231,7 +238,6 @@ private static String createInstanceSelfLink(String instanceId) { public void createTargetPool(String targetPoolName, String healthCheckName) { log.info("Creating target pool: " + targetPoolName); - TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); List httpHealthChecks = new ArrayList(); @@ -246,7 +252,7 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { } catch (Exception e) { log.warn("Could not create target pool: " + targetPoolName + " " + e); } - + log.info("Target pool " + targetPoolName + " was created"); } /** @@ -263,7 +269,7 @@ public void deleteTargetPool(String targetPoolName) { } catch (Exception e) { log.warn("Could not delete target pool " + targetPoolName + " " + e); } - log.info("Target pool: " + targetPoolName + " has been deleted"); + log.info("Target pool: " + targetPoolName + " was deleted"); } /** @@ -292,7 +298,7 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam } catch (Exception e) { log.warn("Could not create a forwarding rule " + forwardingRuleName + " " + e); } - log.info("Created forwarding rule: " + forwardingRuleName); + log.info("Forwarding rule: " + forwardingRuleName + " was created"); } /** @@ -309,7 +315,7 @@ public void deleteForwardingRule(String forwardingRuleName) { } catch (Exception e) { log.warn("Could not delete forwarding rule " + forwardingRuleName + " " + e); } - log.info("Deleted forwarding rule: " + forwardingRuleName); + log.info("Forwarding rule " + forwardingRuleName + " was deleted"); } /** @@ -326,13 +332,17 @@ public boolean isTargetPoolExists(String targetPoolName) { TargetPoolList targetPoolList = targetPools.execute(); for (TargetPool targetPool : targetPoolList.getItems()) { if (targetPool.getName().equals(targetPoolName)) { + if (log.isDebugEnabled()) { + log.debug("Target pool " + targetPoolName + " exists"); + } return true; } - } - } catch (IOException e) { - log.warn("Could not check whether the target pool " + targetPoolName + " is exists or not " + e); + log.warn("Could not check whether the target pool " + targetPoolName + " exists or not " + e); + } + if (log.isDebugEnabled()) { + log.debug("Target pool " + targetPoolName + " does not exist"); } return false; } @@ -353,14 +363,11 @@ public TargetPool getTargetPool(String targetPoolName) { log.debug("Requested Target Pool " + targetPoolName + " Is not Available"); } } - return null; - } catch (IOException e) { log.warn("Could not get target pool " + targetPoolName + " " + e); } return null; - } /** @@ -370,10 +377,10 @@ public TargetPool getTargetPool(String targetPoolName) { * @param instancesIdsList - List of instances to be removed from target pool */ public void removeInstancesFromTargetPool(List instancesIdsList, String targetPoolName) { - log.info("Removing instances from target pool: " + targetPoolName); + log.info("Removing instances from target pool: " + targetPoolName); if (instancesIdsList.isEmpty()) { - log.warn("Cannot remove instances to target pool. InstancesNamesList is empty."); + log.warn("Cannot remove instances to target pool. Because instancesNamesList is empty."); return; } @@ -381,7 +388,6 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String //add instance to instance reference list, we should use the instance URL for (String instanceId : instancesIdsList) { //for all instances - String instanceUrl = createInstanceSelfLink(instanceId); instanceReferenceList.add(new InstanceReference(). setInstance(instanceUrl)); @@ -400,14 +406,12 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String //execute Operation operation = compute.targetPools().removeInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsRemoveInstanceRequest).execute(); - waitForRegionOperationCompletion(operation.getName()); } catch (Exception e) { log.warn("Could not remove instances from target pool " + targetPoolName + " " + e); } - - log.info("Removed instances from target pool: " + targetPoolName); + log.info("Instances are removed from target pool: " + targetPoolName); } /** @@ -484,7 +488,7 @@ public void createHealthCheck(String healthCheckName) { } catch (Exception e) { log.error("Could not create health check " + healthCheckName + " " + e); } - log.info("Created health check: " + healthCheckName); + log.info("Health check " + healthCheckName + " was created"); } public void deleteHealthCheck(String healthCheckName) { @@ -496,7 +500,7 @@ public void deleteHealthCheck(String healthCheckName) { } catch (Exception e) { log.warn("Could not get delete health check " + healthCheckName + " " + e); } - log.info("Deleted Health Check: " + healthCheckName); + log.info("Health check: " + healthCheckName + " was deleted"); } /** @@ -507,11 +511,18 @@ public void deleteHealthCheck(String healthCheckName) { */ private void waitForGlobalOperationCompletion(String operationName) throws Exception { try { + if (log.isDebugEnabled()) { + log.debug("Waiting for operation " + operationName + " completion"); + } + //initially sleep for two seconds Thread.sleep(2000); int timeout = 0; while (true) { Operation operation = compute.globalOperations().get(PROJECT_ID, operationName).execute(); if (operation.getStatus().equals("DONE")) { + if (log.isDebugEnabled()) { + log.debug("Operation " + operationName + " completed successfully"); + } return; } @@ -519,6 +530,7 @@ private void waitForGlobalOperationCompletion(String operationName) throws Excep log.warn("Timeout reached for operation " + operationName + ". Existing.."); return; } + //sleep one second Thread.sleep(1000); timeout += 1000; } @@ -537,18 +549,23 @@ private void waitForGlobalOperationCompletion(String operationName) throws Excep private void waitForRegionOperationCompletion(String operationName) throws Exception { try { + //initially wait for two seconds Thread.sleep(2000); int timeout = 0; while (true) { Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); if (operation.getStatus().equals("DONE")) { + if (log.isDebugEnabled()) { + log.debug("Operation " + operationName + " completed successfully"); + } return; } if (timeout >= OPERATION_TIMEOUT) { log.warn("Timeout reached for operation " + operationName + ". Existing.."); return; } + //wait for one second Thread.sleep(1000); timeout += 1000; } @@ -567,6 +584,5 @@ private static String getInstanceNameFromInstanceId(String instanceId) { int lastIndexOfSlash = instanceId.lastIndexOf("/"); return instanceId.substring(lastIndexOfSlash + 1); } - } From 75c3d15bdb1302e85313cc2faca03494d66bc9a2 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Fri, 7 Aug 2015 20:33:32 +0530 Subject: [PATCH 204/217] changing the parent extension version --- extensions/load-balancer/gce-extension/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/pom.xml b/extensions/load-balancer/gce-extension/pom.xml index e27de33860..7f03ebfc4a 100644 --- a/extensions/load-balancer/gce-extension/pom.xml +++ b/extensions/load-balancer/gce-extension/pom.xml @@ -24,7 +24,7 @@ org.apache.stratos stratos-load-balancer-extensions - 4.1.0 + 4.1.1-SNAPSHOT org.apache.stratos.gce.extension From 92a20f94f8767ce18860cbc99d08cae95f9e75b3 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 8 Aug 2015 19:23:32 +0530 Subject: [PATCH 205/217] solved some issues pointed out by sonarqube --- .../gce/extension/GCELoadBalancer.java | 25 +++++++++---------- .../apache/stratos/gce/extension/Main.java | 1 + .../gce/extension/config/GCEContext.java | 10 +++----- .../config/parser/GCEConfigParser.java | 3 ++- .../gce/extension/util/GCEOperations.java | 20 +++++++-------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 3514451994..40ebfb88d5 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -43,7 +43,7 @@ public class GCELoadBalancer implements LoadBalancer { * One cluster has one target pool,one forwarding rule and a health check * This hash map is used to hold cluster IDs and corresponding configuration */ - private HashMap clusterToLoadBalancerConfigurationMap; + private Map clusterToLoadBalancerConfigurationMap; public GCELoadBalancer() throws IOException, GeneralSecurityException { gceOperations = new GCEOperations(); @@ -81,7 +81,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio get(cluster.getClusterId()); //if the cluster contains at least one member - if (cluster.getMembers().size() > 0) { + if (!cluster.getMembers().isEmpty()) { //that cluster contains at least one member if (log.isDebugEnabled()) { @@ -95,17 +95,16 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio List membersToBeAddedToTargetPool = new ArrayList(); for (Member member : cluster.getMembers()) { - if (member.getInstanceId() != null) { - if (!gceClusterConfigurationHolder.getMemberList().contains(member.getInstanceId())) { + if (member.getInstanceId() != null && !gceClusterConfigurationHolder.getMemberList(). + contains(member.getInstanceId())) { if (log.isDebugEnabled()) { log.debug("New member found: " + member.getInstanceId()); } membersToBeAddedToTargetPool.add(member.getInstanceId()); - } } } - if (membersToBeAddedToTargetPool.size() > 0) { //we have new members + if (!membersToBeAddedToTargetPool.isEmpty()) { //we have new members log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + "to cluster"); @@ -139,7 +138,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } - if (membersToBeRemovedFromTargetPool.size() > 0) { //found terminated members + if (!membersToBeRemovedFromTargetPool.isEmpty()) { //found terminated members log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); //remove them from configuration holder @@ -160,7 +159,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.info("Found a new cluster: " + cluster.getClusterId()); - if (cluster.getMembers().size() == 0) { + if (cluster.getMembers().isEmpty()) { log.info("Cluster " + cluster.getClusterId() + " does not have any members. So not configuring"); } else { activeClusterIdList.add(cluster.getClusterId()); @@ -195,22 +194,22 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } - GCEClusterConfigurationHolder GCEClusterConfigurationHolder = new GCEClusterConfigurationHolder( + GCEClusterConfigurationHolder gceClusterConfigurationHolder = new GCEClusterConfigurationHolder( cluster.getClusterId(), instancesList, ipList); //set target pool name String targetPoolName = targetPoolNameCreator(cluster.getClusterId()); - GCEClusterConfigurationHolder.setTargetPoolName(targetPoolName); + gceClusterConfigurationHolder.setTargetPoolName(targetPoolName); //set forwarding rule name String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); - GCEClusterConfigurationHolder.setForwardingRuleName(forwardingRuleName); + gceClusterConfigurationHolder.setForwardingRuleName(forwardingRuleName); //set health check name String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - GCEClusterConfigurationHolder.setHealthCheckName(healthCheckName); + gceClusterConfigurationHolder.setHealthCheckName(healthCheckName); - clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), GCEClusterConfigurationHolder); + clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), gceClusterConfigurationHolder); createConfigurationForCluster(cluster.getClusterId()); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 7acac51ef4..0256d3e4da 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -63,6 +63,7 @@ public static void main(String[] args) { final Thread mainThread = Thread.currentThread(); final LoadBalancerExtension finalExtension = extension; Runtime.getRuntime().addShutdownHook(new Thread() { + @Override public void run() { try { if (finalExtension != null) { diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 9889d03ecd..598aac0f0d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -20,14 +20,12 @@ package org.apache.stratos.gce.extension.config; import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; /** * This class is used to store configuration properties for gce-extension */ public class GCEContext { - private static final Log log = LogFactory.getLog(GCEContext.class); private static volatile GCEContext context; //cep stat publisher properties @@ -79,7 +77,7 @@ public void setLog4jPropertiesFileName(String log4jPropertiesFileName) { this.log4jPropertiesFileName = log4jPropertiesFileName; } - public void validate() { + public void validate() throws LoadBalancerExtensionException { validateProperty(Boolean.toString(cepStatsPublisherEnabled)); validateProperty(namePrefix); validateProperty(projectName); @@ -102,9 +100,9 @@ public void validate() { } } - private void validateProperty(String propertyName) { + private void validateProperty(String propertyName) throws LoadBalancerExtensionException { if (StringUtils.isEmpty(propertyName)) { - throw new RuntimeException("Property was not found: " + propertyName); + throw new LoadBalancerExtensionException("Property was not found: " + propertyName); } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index e25d50d9a6..66080d5504 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -26,6 +26,7 @@ import org.apache.stratos.common.util.AxiomXpathParserUtil; import org.apache.stratos.gce.extension.config.Constants; import org.apache.stratos.gce.extension.config.GCEContext; +import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; import javax.xml.namespace.QName; @@ -39,7 +40,7 @@ public class GCEConfigParser { * @param documentElement axiom document element. * @throws MalformedConfigurationFileException */ - public static void parse(OMElement documentElement) throws MalformedConfigurationFileException { + public static void parse(OMElement documentElement) throws MalformedConfigurationFileException, LoadBalancerExtensionException { if (log.isDebugEnabled()) { log.debug("Parsing the configuration xml file "); diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 3b6ff48e74..605757281b 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -30,6 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.gce.extension.config.GCEContext; +import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; import java.io.File; import java.io.IOException; @@ -41,7 +42,6 @@ /** * All the GCE API calls will be done using this class */ - public class GCEOperations { private static final Log log = LogFactory.getLog(GCEOperations.class); @@ -277,7 +277,7 @@ public void deleteTargetPool(String targetPoolName) { * * @param forwardingRuleName - name of the forwarding rule in IaaS to be created * @param targetPoolName - name of the target pool in IaaS which is already created - * @param protocol - The protocol which is used to forward trafic. Should be either TCP or UDP + * @param protocol - The protocol which is used to forward traffic. Should be either TCP or UDP */ public void createForwardingRule(String forwardingRuleName, String targetPoolName, String protocol, @@ -396,7 +396,7 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String //create target pools add instance request and set instance to it TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest = new TargetPoolsRemoveInstanceRequest(); - if (instanceReferenceList.size() == 0) { + if (instanceReferenceList.isEmpty()) { log.warn("Could not remove instances from target pool " + targetPoolName + " because instance reference list is null"); return; } @@ -445,7 +445,7 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe //create target pools add instance request and set instance to it TargetPoolsAddInstanceRequest targetPoolsAddInstanceRequest = new TargetPoolsAddInstanceRequest(); - if (instanceReferenceList.size() == 0) { + if (instanceReferenceList.isEmpty()) { log.warn("Could not add instances to target pool " + targetPoolName + " because instance reference list is null"); return; } @@ -509,7 +509,7 @@ public void deleteHealthCheck(String healthCheckName) { * * @param operationName - name of the operation in IaaS */ - private void waitForGlobalOperationCompletion(String operationName) throws Exception { + private void waitForGlobalOperationCompletion(String operationName) throws LoadBalancerExtensionException { try { if (log.isDebugEnabled()) { log.debug("Waiting for operation " + operationName + " completion"); @@ -519,7 +519,7 @@ private void waitForGlobalOperationCompletion(String operationName) throws Excep int timeout = 0; while (true) { Operation operation = compute.globalOperations().get(PROJECT_ID, operationName).execute(); - if (operation.getStatus().equals("DONE")) { + if (("DONE").equals(operation.getStatus())) { if (log.isDebugEnabled()) { log.debug("Operation " + operationName + " completed successfully"); } @@ -536,7 +536,7 @@ private void waitForGlobalOperationCompletion(String operationName) throws Excep } } catch (Exception e) { log.error("Could not wait for global operation completion " + operationName); - throw new Exception(e); + throw new LoadBalancerExtensionException(e); } } @@ -547,7 +547,7 @@ private void waitForGlobalOperationCompletion(String operationName) throws Excep * @param operationName - name of the region operation */ - private void waitForRegionOperationCompletion(String operationName) throws Exception { + private void waitForRegionOperationCompletion(String operationName) throws LoadBalancerExtensionException { try { //initially wait for two seconds Thread.sleep(2000); @@ -555,7 +555,7 @@ private void waitForRegionOperationCompletion(String operationName) throws Excep while (true) { Operation operation = compute.regionOperations().get(PROJECT_ID, REGION_NAME, operationName).execute(); - if (operation.getStatus().equals("DONE")) { + if (("DONE").equals(operation.getStatus())) { if (log.isDebugEnabled()) { log.debug("Operation " + operationName + " completed successfully"); } @@ -571,7 +571,7 @@ private void waitForRegionOperationCompletion(String operationName) throws Excep } } catch (Exception e) { log.error("Could not wait for region operation completion " + operationName); - throw new Exception(e); + throw new LoadBalancerExtensionException(e); } } From 8a426706c8c61db3b9703f2bca1edebb0d20add1 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sat, 8 Aug 2015 19:35:56 +0530 Subject: [PATCH 206/217] get rid of throwing a runtime exception --- .../stratos/gce/extension/config/parser/GCEConfigParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 66080d5504..3cb944ca96 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -40,7 +40,7 @@ public class GCEConfigParser { * @param documentElement axiom document element. * @throws MalformedConfigurationFileException */ - public static void parse(OMElement documentElement) throws MalformedConfigurationFileException, LoadBalancerExtensionException { + public static void parse(OMElement documentElement) throws LoadBalancerExtensionException { if (log.isDebugEnabled()) { log.debug("Parsing the configuration xml file "); From 12504129ddc7320ac0dc20c8fd933d87381bb870 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 11 Aug 2015 12:44:44 +0530 Subject: [PATCH 207/217] log error messages in log.error(object,throwable) format and change the position of some log messages --- .../gce/extension/GCELoadBalancer.java | 1 - .../gce/extension/util/GCEOperations.java | 54 +++++++++---------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 40ebfb88d5..98b2521d65 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -228,7 +228,6 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } } activeClusterIdList.clear(); - log.info("Load balancer was configured as given topology"); return true; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 605757281b..e6b244d03f 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -103,11 +103,11 @@ private void buildComputeEngineObject() throws IOException, GeneralSecurityExcep } } catch (GeneralSecurityException e) { //Security exception occurred. Cant proceed further - log.fatal("Could not authenticate and build compute object"); + log.error("Could not authenticate and build compute object"); throw new GeneralSecurityException(e); } catch (IOException e) { //IO exception occurred. Cant proceed further - log.fatal("Could not authenticate and build compute object"); + log.error("Could not authenticate and build compute object"); throw new IOException(e); } } @@ -132,7 +132,7 @@ public static InstanceList getInstanceList(String zoneName, String filter) { return instanceList; } } catch (IOException e) { - log.warn("Could not get instance list from GCE ", e); + log.error("Could not get instance list from GCE ", e); return null; } } @@ -215,7 +215,7 @@ private static HttpHealthCheckList getHealthCheckList() { return healthCheckList; } } catch (IOException e) { - log.warn("Could not get health check list from GCE", e); + log.error("Could not get health check list from GCE", e); return null; } } @@ -248,11 +248,10 @@ public void createTargetPool(String targetPoolName, String healthCheckName) { Operation operation = compute.targetPools().insert(PROJECT_ID, REGION_NAME, targetPool).execute(); waitForRegionOperationCompletion(operation.getName()); - + log.info("Target pool " + targetPoolName + " was created"); } catch (Exception e) { - log.warn("Could not create target pool: " + targetPoolName + " " + e); + log.error("Could not create target pool: " + targetPoolName, e); } - log.info("Target pool " + targetPoolName + " was created"); } /** @@ -265,11 +264,10 @@ public void deleteTargetPool(String targetPoolName) { try { Operation operation = compute.targetPools().delete(PROJECT_ID, REGION_NAME, targetPoolName).execute(); waitForRegionOperationCompletion(operation.getName()); - + log.info("Target pool: " + targetPoolName + " was deleted"); } catch (Exception e) { - log.warn("Could not delete target pool " + targetPoolName + " " + e); + log.error("Could not delete target pool " + targetPoolName, e); } - log.info("Target pool: " + targetPoolName + " was deleted"); } /** @@ -295,10 +293,10 @@ public void createForwardingRule(String forwardingRuleName, String targetPoolNam try { Operation operation = compute.forwardingRules().insert(PROJECT_ID, REGION_NAME, forwardingRule).execute(); waitForRegionOperationCompletion(operation.getName()); + log.info("Forwarding rule: " + forwardingRuleName + " was created"); } catch (Exception e) { - log.warn("Could not create a forwarding rule " + forwardingRuleName + " " + e); + log.error("Could not create a forwarding rule " + forwardingRuleName, e); } - log.info("Forwarding rule: " + forwardingRuleName + " was created"); } /** @@ -312,10 +310,10 @@ public void deleteForwardingRule(String forwardingRuleName) { Operation operation = compute.forwardingRules(). delete(PROJECT_ID, REGION_NAME, forwardingRuleName).execute(); waitForRegionOperationCompletion(operation.getName()); + log.info("Forwarding rule " + forwardingRuleName + " was deleted"); } catch (Exception e) { - log.warn("Could not delete forwarding rule " + forwardingRuleName + " " + e); + log.error("Could not delete forwarding rule " + forwardingRuleName, e); } - log.info("Forwarding rule " + forwardingRuleName + " was deleted"); } /** @@ -339,7 +337,7 @@ public boolean isTargetPoolExists(String targetPoolName) { } } } catch (IOException e) { - log.warn("Could not check whether the target pool " + targetPoolName + " exists or not " + e); + log.error("Could not check whether the target pool " + targetPoolName + " exists or not ", e); } if (log.isDebugEnabled()) { log.debug("Target pool " + targetPoolName + " does not exist"); @@ -365,7 +363,7 @@ public TargetPool getTargetPool(String targetPoolName) { } return null; } catch (IOException e) { - log.warn("Could not get target pool " + targetPoolName + " " + e); + log.error("Could not get target pool " + targetPoolName, e); } return null; } @@ -407,11 +405,10 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String Operation operation = compute.targetPools().removeInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsRemoveInstanceRequest).execute(); waitForRegionOperationCompletion(operation.getName()); - + log.info("Instances are removed from target pool: " + targetPoolName); } catch (Exception e) { - log.warn("Could not remove instances from target pool " + targetPoolName + " " + e); + log.error("Could not remove instances from target pool " + targetPoolName, e); } - log.info("Instances are removed from target pool: " + targetPoolName); } /** @@ -457,11 +454,10 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe Operation operation = compute.targetPools().addInstance(PROJECT_ID, REGION_NAME, targetPoolName, targetPoolsAddInstanceRequest).execute(); waitForRegionOperationCompletion(operation.getName()); - + log.info("Added instances to target pool: " + targetPoolName); } catch (Exception e) { - log.warn("Could not add instance to target pool" + targetPoolName + " " + e); + log.error("Could not add instance to target pool" + targetPoolName, e); } - log.info("Added instances to target pool: " + targetPoolName); } /** @@ -484,11 +480,10 @@ public void createHealthCheck(String healthCheckName) { try { Operation operation = compute.httpHealthChecks().insert(PROJECT_ID, httpHealthCheck).execute(); waitForGlobalOperationCompletion(operation.getName()); - + log.info("Health check " + healthCheckName + " was created"); } catch (Exception e) { - log.error("Could not create health check " + healthCheckName + " " + e); + log.error("Could not create health check " + healthCheckName, e); } - log.info("Health check " + healthCheckName + " was created"); } public void deleteHealthCheck(String healthCheckName) { @@ -496,11 +491,10 @@ public void deleteHealthCheck(String healthCheckName) { try { Operation operation = compute.httpHealthChecks().delete(PROJECT_ID, healthCheckName).execute(); waitForGlobalOperationCompletion(operation.getName()); - + log.info("Health check: " + healthCheckName + " was deleted"); } catch (Exception e) { - log.warn("Could not get delete health check " + healthCheckName + " " + e); + log.error("Could not get delete health check " + healthCheckName, e); } - log.info("Health check: " + healthCheckName + " was deleted"); } /** @@ -535,7 +529,7 @@ private void waitForGlobalOperationCompletion(String operationName) throws LoadB timeout += 1000; } } catch (Exception e) { - log.error("Could not wait for global operation completion " + operationName); + log.error("Could not wait for global operation completion " + operationName , e); throw new LoadBalancerExtensionException(e); } } @@ -570,7 +564,7 @@ private void waitForRegionOperationCompletion(String operationName) throws LoadB timeout += 1000; } } catch (Exception e) { - log.error("Could not wait for region operation completion " + operationName); + log.error("Could not wait for region operation completion " + operationName , e); throw new LoadBalancerExtensionException(e); } } From 4862b295486a3cd3e4c15164a5de8ab0b902061b Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Thu, 13 Aug 2015 13:31:06 +0530 Subject: [PATCH 208/217] refine logs and fixing some issues mentioned by imesh --- ...adBalancerCommonTopologyEventReceiver.java | 2 +- .../load-balancer/gce-extension/README.md | 17 ++++ .../src/main/bin/gce-extension.sh | 5 +- .../src/main/conf/gce-configuration.xml | 6 +- .../gce/extension/GCELoadBalancer.java | 79 +++++++++---------- .../gce/extension/GCEStatisticsReader.java | 3 +- .../apache/stratos/gce/extension/Main.java | 3 +- .../gce/extension/config/Constants.java | 8 +- .../gce/extension/config/GCEContext.java | 10 --- .../config/parser/GCEConfigParser.java | 12 +-- .../gce/extension/util/GCEOperations.java | 21 +++-- 11 files changed, 86 insertions(+), 80 deletions(-) create mode 100644 extensions/load-balancer/gce-extension/README.md diff --git a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java index 02a75e7d09..9f658115c4 100644 --- a/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java +++ b/components/org.apache.stratos.load.balancer.common/src/main/java/org/apache/stratos/load/balancer/common/event/receivers/LoadBalancerCommonTopologyEventReceiver.java @@ -440,7 +440,7 @@ private org.apache.stratos.load.balancer.common.domain.Member transformMember(Me member.addPort(transformPort(port)); } } - if(messagingMember.getInstanceId() != null){ + if (messagingMember.getInstanceId() != null) { member.setInstanceId(messagingMember.getInstanceId()); } return member; diff --git a/extensions/load-balancer/gce-extension/README.md b/extensions/load-balancer/gce-extension/README.md new file mode 100644 index 0000000000..c22387e192 --- /dev/null +++ b/extensions/load-balancer/gce-extension/README.md @@ -0,0 +1,17 @@ +# Apache Stratos GCE Extension + +Apache Stratos GCE extension is a load balancer extension for Google Compute Engine Load balancer. +It is an executable program which can manage Google Compute Engine Load balancing according to the topology, +composite application model and tenant application signups information received from Stratos via +the message broker. + +## How it works +1. Wait for the complete topology event message to initialize the topology. +2. Configure and create relevant forwarding rules, target pools and health checks in GCE. +3. Listen to topology, application, application signup events. +4. Reconfigure the load balancer with the new topology configuration. + +## Installation +Please refer bellow document for information on the installation process. + +https://docs.google.com/document/d/1a2ZptPScpjuavfpxVu1R1GC7R95jjzHo3L372zL2bRY/edit \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh index 1113c8c339..2e9f4fbf61 100644 --- a/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh +++ b/extensions/load-balancer/gce-extension/src/main/bin/gce-extension.sh @@ -31,9 +31,10 @@ properties="-Djndi.properties.dir=${script_path}/../conf -Dstats.socket.file.path=/tmp/haproxy-stats.socket -Djavax.net.ssl.trustStore=${script_path}/../security/client-truststore.jks -Djavax.net.ssl.trustStorePassword=wso2carbon - -Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml" + -Dthrift.client.config.file.path=${script_path}/../conf/thrift-client-config.xml + -Dlog4j.properties.file.path=${script_path}/../conf/log4j.properties" # Uncomment below line to enable remote debugging -debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" +#debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5006" java -cp "${class_path}" ${properties} ${debug} org.apache.stratos.gce.extension.Main $* \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index 3b0d1e11c3..a1314ce238 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -8,10 +8,10 @@ MyFirstProject - gold-access-96509 + gold-access-xxxx europe-west1 - /home/sanjaya/keys/p12key-donwloaded.p12 - 164588286821-a517i85433f83e0nthc4qjmoupri394q@developer.gserviceaccount.com + path-to-key-file/keyfile.p12 + xxxxxxxxxxxxx.gserviceaccount.com default diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 98b2521d65..fcafacc285 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.gce.extension.config.Constants; import org.apache.stratos.gce.extension.config.GCEClusterConfigurationHolder; import org.apache.stratos.gce.extension.config.GCEContext; import org.apache.stratos.gce.extension.util.GCEOperations; @@ -32,11 +33,12 @@ import java.security.GeneralSecurityException; import java.util.*; +/** + * All the methods in Stratos load balancer API have been implemented in this class + */ public class GCELoadBalancer implements LoadBalancer { private static final Log log = LogFactory.getLog(GCELoadBalancer.class); - //PROTOCOL should be TCP or UDP - private static final String PROTOCOL = "TCP"; private GCEOperations gceOperations; /** * One configuration object per cluster will be created @@ -48,7 +50,6 @@ public class GCELoadBalancer implements LoadBalancer { public GCELoadBalancer() throws IOException, GeneralSecurityException { gceOperations = new GCEOperations(); clusterToLoadBalancerConfigurationMap = new HashMap(); - } /** @@ -60,7 +61,7 @@ public GCELoadBalancer() throws IOException, GeneralSecurityException { */ @Override public boolean configure(Topology topology) throws LoadBalancerExtensionException { - log.info("Complete topology received. Configuring Load balancer "); + log.info("Complete topology received. Configuring Load balancer..."); //this list is used to hold the current clusters available in topology and which has at least one member. List activeClusterIdList = new ArrayList(); @@ -72,7 +73,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (clusterToLoadBalancerConfigurationMap.containsKey(cluster.getClusterId())) { if (log.isDebugEnabled()) { - log.debug("Reconfiguring the existing cluster: " + cluster.getClusterId()); + log.debug("Reconfiguring the existing cluster: " + cluster.getClusterId() + "..."); } //It already has a entry in clusterToLoadBalancerConfigurationMap. @@ -82,15 +83,15 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //if the cluster contains at least one member if (!cluster.getMembers().isEmpty()) { - //that cluster contains at least one member - if (log.isDebugEnabled()) { log.debug("Cluster " + cluster.getClusterId() + " has one or more members"); } activeClusterIdList.add(cluster.getClusterId()); + if (log.isDebugEnabled()){ + log.debug("Cluster " + cluster.getClusterId() + " was added to active cluster id list"); + } - //***************detect member changes and update**************// - + //detect member changes and update //check for newly created members List membersToBeAddedToTargetPool = new ArrayList(); for (Member member : cluster.getMembers()) { @@ -106,7 +107,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (!membersToBeAddedToTargetPool.isEmpty()) { //we have new members log.info("New members in cluster" + cluster.getClusterId() + " found. Adding new members " + - "to cluster"); + "to cluster..."); //add them to configuration holder for (String memberId : membersToBeAddedToTargetPool) { @@ -139,7 +140,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio } if (!membersToBeRemovedFromTargetPool.isEmpty()) { //found terminated members - log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them"); + log.info("Terminated members found in cluster " + cluster.getClusterId() + ". Removing them..."); //remove them from configuration holder for (String memberId : membersToBeRemovedFromTargetPool) { @@ -151,12 +152,9 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio gceOperations.removeInstancesFromTargetPool(membersToBeRemovedFromTargetPool, gceClusterConfigurationHolder.getTargetPoolName()); } - } - } else { //doesn't have a GCEClusterConfigurationHolder object. So crate a new one and add to hash map - log.info("Found a new cluster: " + cluster.getClusterId()); if (cluster.getMembers().isEmpty()) { @@ -211,10 +209,8 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), gceClusterConfigurationHolder); createConfigurationForCluster(cluster.getClusterId()); - } } - } } @@ -222,7 +218,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //remove those clusters from map and remove the configuration from GCE too for (String clusterId : clusterToLoadBalancerConfigurationMap.keySet()) { if (!activeClusterIdList.contains(clusterId)) { - log.info("Removing the configuration for cluster " + clusterId); + log.info("Removing the configuration for cluster " + clusterId + "..."); deleteConfigurationForCluster(clusterId); clusterToLoadBalancerConfigurationMap.remove(clusterId); } @@ -238,7 +234,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio */ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { - log.info("Deleting configuration for cluster " + clusterId); + log.info("Deleting configuration for cluster " + clusterId + "..."); GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); //delete forwarding rule gceOperations.deleteForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName()); @@ -256,7 +252,7 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer */ private void createConfigurationForCluster(String clusterId) throws LoadBalancerExtensionException { - log.info("Creating configuration for cluster"); + log.info("Creating configuration for cluster " + clusterId + "..."); GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); @@ -278,9 +274,8 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer //if the ip list is empty if (ipList.isEmpty()) { log.warn("Ip list is null"); - //set all ports to be opened - portRange = "1-65535"; - + //set all default port range + portRange = Constants.DEFAULT_PORT_RANGE; } //else if ip list has only one value else if (ipList.size() == 1) { @@ -300,8 +295,8 @@ else if (ipList.size() == 1) { //create the forwarding rule gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), - gceClusterConfigurationHolder.getTargetPoolName(), PROTOCOL, portRange); - log.info("Created configuration for cluster"); + gceClusterConfigurationHolder.getTargetPoolName(), Constants.PROTOCOL, portRange); + log.info("Created configuration for cluster" + clusterId); } @Override @@ -314,7 +309,7 @@ public void start() throws LoadBalancerExtensionException { @Override public void stop() throws LoadBalancerExtensionException { - log.info("GCE Load Balancer is stopping"); + log.info("GCE Load Balancer is stopping..."); //iterate through hash map and remove all Iterator iterator = clusterToLoadBalancerConfigurationMap.entrySet().iterator(); @@ -331,10 +326,7 @@ public void stop() throws LoadBalancerExtensionException { */ @Override public void reload() throws LoadBalancerExtensionException { - //nothing to do here - log.info("Configuration reloaded"); - } /** @@ -350,8 +342,8 @@ private String targetPoolNameCreator(String clusterId) { String targetPoolName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" + clusterId.trim().toLowerCase().replace(".", "-"); //length should be les than 62 characters - if (targetPoolName.length() >= 62) { - targetPoolName = targetPoolName.substring(0, 62); + if (targetPoolName.length() >= Constants.MAX_NAME_LENGTH) { + targetPoolName = targetPoolName.substring(0, Constants.MAX_NAME_LENGTH); } return targetPoolName; } @@ -359,15 +351,16 @@ private String targetPoolNameCreator(String clusterId) { /** * Create a valid forwarding rule name * - * @param clusterID - Id of the cluster + * @param clusterId - Id of the cluster * @return - a proper name for forwarding rule */ - private String forwardingRuleNameCreator(String clusterID) { - String forwardingRuleName = GCEContext.getInstance().getNamePrefix() - + "-fr-" + clusterID.trim().toLowerCase().replace(".", "-"); + private String forwardingRuleNameCreator(String clusterId) { + String forwardingRuleName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" + + clusterId.trim().toLowerCase().replace(".", "-"); + //length should be les than 62 characters - if (forwardingRuleName.length() >= 62) { - forwardingRuleName = forwardingRuleName.substring(0, 62); + if (forwardingRuleName.length() >= Constants.MAX_NAME_LENGTH) { + forwardingRuleName = forwardingRuleName.substring(0, Constants.MAX_NAME_LENGTH); } return forwardingRuleName; } @@ -375,16 +368,16 @@ private String forwardingRuleNameCreator(String clusterID) { /** * create a valid health check name * - * @param clusterID - id of the cluster + * @param clusterId - id of the cluster * @return - a proper name for health check */ - private String healthCheckNameCreator(String clusterID) { - String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-hc-" + - clusterID.trim().toLowerCase().replace(".", "-"); + private String healthCheckNameCreator(String clusterId) { + String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" + + clusterId.trim().toLowerCase().replace(".", "-"); - //length should be les than 62 characters - if (healthCheckName.length() >= 62) { - healthCheckName = healthCheckName.substring(0, 62); + //length should be less than 62 characters + if (healthCheckName.length() >= Constants.MAX_NAME_LENGTH) { + healthCheckName = healthCheckName.substring(0, Constants.MAX_NAME_LENGTH); } return healthCheckName; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java index c78a569b79..649148465a 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCEStatisticsReader.java @@ -36,7 +36,6 @@ public GCEStatisticsReader(TopologyProvider topologyProvider) { this.topologyProvider = topologyProvider; this.clusterInstanceId = System.getProperty(StratosConstants. CLUSTER_INSTANCE_ID, StratosConstants.NOT_DEFINED); - } @Override @@ -46,7 +45,7 @@ public String getClusterInstanceId() { @Override public int getInFlightRequestCount(String clusterId) { - //There is no way in GCE API to get in flight request count! + // That is not possible to read the request count via the GCE API at the moment return 0; } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java index 0256d3e4da..66937c0a34 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/Main.java @@ -53,8 +53,7 @@ public static void main(String[] args) { GCEConfigParser.parse(documentElement); // Configure log4j properties - PropertyConfigurator.configure(getFilePathOfConfigFile(GCEContext.getInstance().getLog4jPropertiesFileName())); - + PropertyConfigurator.configure(System.getProperty("log4j.properties.file.path")); if (log.isInfoEnabled()) { log.info("GCE extension started"); } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 9232d6a8df..36577b034e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -53,5 +53,11 @@ public class Constants { //other properties public static final String OPERATION_TIMEOUT = "operationTimeout"; public static final String NAME_PREFIX = "namePrefix"; - public static final String LOG4J_PROPERTIES_FILE_NAME = "log4jPropertiesFileName"; + + //PROTOCOL should be TCP or UDP + public static final String PROTOCOL = "TCP"; + //set all ports to be opened if the application does not have any port defined + public static final String DEFAULT_PORT_RANGE="1-65535"; + //maximum length the name which allowed by GCE API + public static final int MAX_NAME_LENGTH = 62; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 598aac0f0d..1b8c34c5a7 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -52,7 +52,6 @@ public class GCEContext { //other properties private String namePrefix; private String operationTimeout; - private String log4jPropertiesFileName; //private constructor private GCEContext() { @@ -69,14 +68,6 @@ public static GCEContext getInstance() { return context; } - public String getLog4jPropertiesFileName() { - return log4jPropertiesFileName; - } - - public void setLog4jPropertiesFileName(String log4jPropertiesFileName) { - this.log4jPropertiesFileName = log4jPropertiesFileName; - } - public void validate() throws LoadBalancerExtensionException { validateProperty(Boolean.toString(cepStatsPublisherEnabled)); validateProperty(namePrefix); @@ -233,5 +224,4 @@ public void setThriftReceiverIp(String thriftReceiverIp) { public void setThriftReceiverPort(String thriftReceiverPort) { this.thriftReceiverPort = thriftReceiverPort; } - } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 3cb944ca96..845fb004a7 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -30,6 +30,9 @@ import javax.xml.namespace.QName; +/** + * parse the gce-configuration.xml + */ public class GCEConfigParser { private static final Log log = LogFactory.getLog(GCEConfigParser.class); private static GCEContext gceContext; @@ -239,8 +242,6 @@ private static void extractOtherProperties(OMElement documentElement) { OMElement operationTimeoutElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants. OPERATION_TIMEOUT); OMElement namePrefixElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX); - OMElement log4jPropertiesFileNameElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants. - LOG4J_PROPERTIES_FILE_NAME); //set extracted properties to gceContext object if (operationTimeoutElement != null) { @@ -256,12 +257,5 @@ private static void extractOtherProperties(OMElement documentElement) { log.debug("Name prefix: " + namePrefixElement.getText()); } } - - if (log4jPropertiesFileNameElement != null) { - gceContext.setLog4jPropertiesFileName(log4jPropertiesFileNameElement.getText()); - if (log.isDebugEnabled()) { - log.debug("log4j properties file name: " + log4jPropertiesFileNameElement.getText()); - } - } } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index e6b244d03f..45475b0c1d 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -113,10 +113,10 @@ private void buildComputeEngineObject() throws IOException, GeneralSecurityExcep } /** - * Get list of running instances in given project and zone.(This method can be used - * to check whether a given instance is available or not in a given project - * and zone) + * Get list of instances in given project and zone which matches the given filter * + * @param zoneName - name of the zone + * @param filter - a condition to filter the instances * @return instanceList - list of instances(members in Stratos side) */ public static InstanceList getInstanceList(String zoneName, String filter) { @@ -231,9 +231,10 @@ private static String createInstanceSelfLink(String instanceId) { } /** - * Creating a new target pool; name should be unique + * Creating a new target pool in IaaS * * @param targetPoolName - name of the target pool in IaaS + * @param healthCheckName - name of the health check in IaaS */ public void createTargetPool(String targetPoolName, String healthCheckName) { @@ -384,18 +385,22 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String List instanceReferenceList = new ArrayList(); - //add instance to instance reference list, we should use the instance URL + //add instance to instance reference list, it is required to use the instance URL for (String instanceId : instancesIdsList) { //for all instances String instanceUrl = createInstanceSelfLink(instanceId); instanceReferenceList.add(new InstanceReference(). setInstance(instanceUrl)); + if (log.isDebugEnabled()){ + log.debug("Instance " + instanceId + " was added to instance reference list"); + } } //create target pools add instance request and set instance to it TargetPoolsRemoveInstanceRequest targetPoolsRemoveInstanceRequest = new TargetPoolsRemoveInstanceRequest(); if (instanceReferenceList.isEmpty()) { - log.warn("Could not remove instances from target pool " + targetPoolName + " because instance reference list is null"); + log.warn("Could not remove instances from target pool " + targetPoolName + " because instance reference " + + "list is null"); return; } targetPoolsRemoveInstanceRequest.setInstances(instanceReferenceList); @@ -430,11 +435,13 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe //add instance to instance reference list, we should use the instance URL for (String instanceId : instancesIdsList) { //for all instances - String instanceUrl = getInstanceURLFromId(instanceId); if (instanceUrl != null) { instanceReferenceList.add(new InstanceReference(). setInstance(instanceUrl)); + if (log.isDebugEnabled()){ + log.debug("Instance " + instanceId + " was added to instance reference list"); + } } } From e02e0ce0944bc8c4234056e3033ca8f13c557615 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 18 Aug 2015 01:09:04 +0530 Subject: [PATCH 209/217] Read GCE API URL from configuration and make some other strings constant --- .../src/main/conf/gce-configuration.xml | 3 +-- .../gce/extension/config/Constants.java | 8 +++++++ .../gce/extension/config/GCEContext.java | 6 +++++ .../config/parser/GCEConfigParser.java | 8 +++++++ .../gce/extension/util/GCEOperations.java | 23 ++++++++++++------- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml index a1314ce238..f638b38f6d 100644 --- a/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml +++ b/extensions/load-balancer/gce-extension/src/main/conf/gce-configuration.xml @@ -26,7 +26,6 @@ 10000 lb - - log4j.properties + https://www.googleapis.com/compute/v1/projects/ \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 36577b034e..561a95a925 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -53,6 +53,8 @@ public class Constants { //other properties public static final String OPERATION_TIMEOUT = "operationTimeout"; public static final String NAME_PREFIX = "namePrefix"; + public static final String GCE_API_URL="gceApiUrl"; + //PROTOCOL should be TCP or UDP public static final String PROTOCOL = "TCP"; @@ -60,4 +62,10 @@ public class Constants { public static final String DEFAULT_PORT_RANGE="1-65535"; //maximum length the name which allowed by GCE API public static final int MAX_NAME_LENGTH = 62; + + //the forward slash character + public static final String FORWARD_SLASH="/"; + //strings + public static final String ZONES_STR="zones"; + public static final String INSTANCES_STR="instances"; } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 1b8c34c5a7..771424a7b4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -48,6 +48,7 @@ public class GCEContext { private String healthCheckIntervalSec; private String healthCheckUnhealthyThreshold; private String healthCheckHealthyThreshold; + private String gceApiUrl; //other properties private String namePrefix; @@ -84,6 +85,7 @@ public void validate() throws LoadBalancerExtensionException { validateProperty(healthCheckHealthyThreshold); validateProperty(networkName); validateProperty(operationTimeout); + validateProperty(gceApiUrl); if (cepStatsPublisherEnabled) { validateProperty(Constants.THRIFT_RECEIVER_IP); @@ -224,4 +226,8 @@ public void setThriftReceiverIp(String thriftReceiverIp) { public void setThriftReceiverPort(String thriftReceiverPort) { this.thriftReceiverPort = thriftReceiverPort; } + + public String getGceApiUrl() { return gceApiUrl; } + + public void setGceApiUrl(String gceApiUrl) { this.gceApiUrl = gceApiUrl; } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java index 845fb004a7..d235316467 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/parser/GCEConfigParser.java @@ -242,6 +242,7 @@ private static void extractOtherProperties(OMElement documentElement) { OMElement operationTimeoutElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants. OPERATION_TIMEOUT); OMElement namePrefixElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.NAME_PREFIX); + OMElement gceApiUrlElement = AxiomXpathParserUtil.getFirstChildElement(documentElement, Constants.GCE_API_URL); //set extracted properties to gceContext object if (operationTimeoutElement != null) { @@ -257,5 +258,12 @@ private static void extractOtherProperties(OMElement documentElement) { log.debug("Name prefix: " + namePrefixElement.getText()); } } + + if (gceApiUrlElement != null) { + gceContext.setGceApiUrl(gceApiUrlElement.getText()); + if (log.isDebugEnabled()) { + log.debug("GCE API URL: " + gceApiUrlElement.getText()); + } + } } } diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 45475b0c1d..2a5a86d4f9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -29,6 +29,7 @@ import com.google.api.services.compute.model.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.stratos.gce.extension.config.Constants; import org.apache.stratos.gce.extension.config.GCEContext; import org.apache.stratos.load.balancer.extension.api.exception.LoadBalancerExtensionException; @@ -66,6 +67,9 @@ public class GCEOperations { private static final int OPERATION_TIMEOUT = Integer.parseInt(GCEContext.getInstance().getOperationTimeout()); static Compute compute; + //the url of the GCE API + private static final String GCE_API_URL = GCEContext.getInstance().getGceApiUrl(); + /** * Constructor for GCE Operations Class */ @@ -116,7 +120,7 @@ private void buildComputeEngineObject() throws IOException, GeneralSecurityExcep * Get list of instances in given project and zone which matches the given filter * * @param zoneName - name of the zone - * @param filter - a condition to filter the instances + * @param filter - a condition to filter the instances * @return instanceList - list of instances(members in Stratos side) */ public static InstanceList getInstanceList(String zoneName, String filter) { @@ -226,14 +230,17 @@ private static HttpHealthCheckList getHealthCheckList() { * @return - the self link of the instance */ private static String createInstanceSelfLink(String instanceId) { - return "https://www.googleapis.com/compute/v1/projects/" + PROJECT_ID + - "/zones/" + getZoneNameFromInstanceId(instanceId) + "/instances/" + getInstanceNameFromInstanceId(instanceId); + + return GCE_API_URL + PROJECT_ID + + Constants.FORWARD_SLASH + Constants.ZONES_STR + Constants.FORWARD_SLASH + + getZoneNameFromInstanceId(instanceId) + Constants.FORWARD_SLASH + Constants.INSTANCES_STR + + Constants.FORWARD_SLASH + getInstanceNameFromInstanceId(instanceId); } /** * Creating a new target pool in IaaS * - * @param targetPoolName - name of the target pool in IaaS + * @param targetPoolName - name of the target pool in IaaS * @param healthCheckName - name of the health check in IaaS */ public void createTargetPool(String targetPoolName, String healthCheckName) { @@ -390,7 +397,7 @@ public void removeInstancesFromTargetPool(List instancesIdsList, String String instanceUrl = createInstanceSelfLink(instanceId); instanceReferenceList.add(new InstanceReference(). setInstance(instanceUrl)); - if (log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Instance " + instanceId + " was added to instance reference list"); } } @@ -439,7 +446,7 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe if (instanceUrl != null) { instanceReferenceList.add(new InstanceReference(). setInstance(instanceUrl)); - if (log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Instance " + instanceId + " was added to instance reference list"); } } @@ -536,7 +543,7 @@ private void waitForGlobalOperationCompletion(String operationName) throws LoadB timeout += 1000; } } catch (Exception e) { - log.error("Could not wait for global operation completion " + operationName , e); + log.error("Could not wait for global operation completion " + operationName, e); throw new LoadBalancerExtensionException(e); } } @@ -571,7 +578,7 @@ private void waitForRegionOperationCompletion(String operationName) throws LoadB timeout += 1000; } } catch (Exception e) { - log.error("Could not wait for region operation completion " + operationName , e); + log.error("Could not wait for region operation completion " + operationName, e); throw new LoadBalancerExtensionException(e); } } From 6e19dbba52b34f843f645551f38992d1c2034605 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 18 Aug 2015 01:09:44 +0530 Subject: [PATCH 210/217] fixing a log issue --- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 2a5a86d4f9..5a8dfd1300 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -107,11 +107,11 @@ private void buildComputeEngineObject() throws IOException, GeneralSecurityExcep } } catch (GeneralSecurityException e) { //Security exception occurred. Cant proceed further - log.error("Could not authenticate and build compute object"); + log.error("Could not authenticate and build compute object", e); throw new GeneralSecurityException(e); } catch (IOException e) { //IO exception occurred. Cant proceed further - log.error("Could not authenticate and build compute object"); + log.error("Could not authenticate and build compute object", e); throw new IOException(e); } } From 19acc9ee0e67f5988d8df7b56fd92b7b1bf96632 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Tue, 18 Aug 2015 22:45:21 +0530 Subject: [PATCH 211/217] fixing a concurrent modification exception issue --- .../stratos/gce/extension/GCELoadBalancer.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index fcafacc285..5a9efec2e1 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -87,7 +87,7 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio log.debug("Cluster " + cluster.getClusterId() + " has one or more members"); } activeClusterIdList.add(cluster.getClusterId()); - if (log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Cluster " + cluster.getClusterId() + " was added to active cluster id list"); } @@ -98,10 +98,10 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio if (member.getInstanceId() != null && !gceClusterConfigurationHolder.getMemberList(). contains(member.getInstanceId())) { - if (log.isDebugEnabled()) { - log.debug("New member found: " + member.getInstanceId()); - } - membersToBeAddedToTargetPool.add(member.getInstanceId()); + if (log.isDebugEnabled()) { + log.debug("New member found: " + member.getInstanceId()); + } + membersToBeAddedToTargetPool.add(member.getInstanceId()); } } @@ -216,13 +216,17 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio //if any cluster is removed from the topology or if any cluster does not have at least one member, //remove those clusters from map and remove the configuration from GCE too + List clustersToBeRemoved = new ArrayList(); for (String clusterId : clusterToLoadBalancerConfigurationMap.keySet()) { if (!activeClusterIdList.contains(clusterId)) { log.info("Removing the configuration for cluster " + clusterId + "..."); - deleteConfigurationForCluster(clusterId); - clusterToLoadBalancerConfigurationMap.remove(clusterId); + clustersToBeRemoved.add(clusterId); } } + for (String clusterId : clustersToBeRemoved) { + deleteConfigurationForCluster(clusterId); //remove from GCE + clusterToLoadBalancerConfigurationMap.remove(clusterId); //remove from local map + } activeClusterIdList.clear(); log.info("Load balancer was configured as given topology"); return true; From 619c97335fdf6c3467a0fe1962a7511e103eddec Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 19 Aug 2015 13:40:46 +0530 Subject: [PATCH 212/217] removing some blank lines --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 -- .../org/apache/stratos/gce/extension/util/GCEOperations.java | 1 - 2 files changed, 3 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 5a9efec2e1..91e8c36332 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -247,7 +247,6 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer //delete health check from GCE gceOperations.deleteHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); log.info("Deleted configuration for cluster " + clusterId); - } /** @@ -307,7 +306,6 @@ else if (ipList.size() == 1) { public void start() throws LoadBalancerExtensionException { //Configuration has completed log.info("GCE Load balancer instance started"); - } @Override diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index 5a8dfd1300..f9b6da0bb9 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -141,7 +141,6 @@ public static InstanceList getInstanceList(String zoneName, String filter) { } } - /** * Get instance resource URL from given instance name * From 39b853b916ff85c5ac49c250cfec7351bd2b8c94 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 19 Aug 2015 18:57:58 +0530 Subject: [PATCH 213/217] adding a install.md file --- .../load-balancer/gce-extension/INSTALL.md | 36 +++++++++++++++++++ .../load-balancer/gce-extension/README.md | 4 ++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 extensions/load-balancer/gce-extension/INSTALL.md diff --git a/extensions/load-balancer/gce-extension/INSTALL.md b/extensions/load-balancer/gce-extension/INSTALL.md new file mode 100644 index 0000000000..2876197c66 --- /dev/null +++ b/extensions/load-balancer/gce-extension/INSTALL.md @@ -0,0 +1,36 @@ + # + # Licensed to the Apache Software Foundation (ASF) under one + # or more contributor license agreements. See the NOTICE file + # distributed with this work for additional information + # regarding copyright ownership. The ASF licenses this file + # to you under the Apache License, Version 2.0 (the + # "License"); you may not use this file except in compliance + # with the License. You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, + # software distributed under the License is distributed on an + # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + # KIND, either express or implied. See the License for the + # specific language governing permissions and limitations + # under the License. + # + +# Installing Apache Stratos GCE Extension + +Apache Stratos GCE Extension could be used for integrating GCE load balancer with Apache Stratos. Please follow +below steps to proceed with a quick installation: + +1. Extract org.apache.stratos.gce.extension-.zip to a desired location: . + +2. Open /conf/gce-configuration file in text editor and update GCE credentials. + +3. Open /conf/jndi.properties file in a text editor and update message broker information: + ``` + java.naming.provider.url=tcp://localhost:61616 + ``` +4. Run /bin/gce-extension.sh as the root user. + +For a detailed installation refer following link: +https://docs.google.com/document/d/1a2ZptPScpjuavfpxVu1R1GC7R95jjzHo3L372zL2bRY/edit diff --git a/extensions/load-balancer/gce-extension/README.md b/extensions/load-balancer/gce-extension/README.md index c22387e192..8b55f2a921 100644 --- a/extensions/load-balancer/gce-extension/README.md +++ b/extensions/load-balancer/gce-extension/README.md @@ -12,6 +12,8 @@ the message broker. 4. Reconfigure the load balancer with the new topology configuration. ## Installation -Please refer bellow document for information on the installation process. +Please refer INSTALL.md for information on a quick installation process. + +Please refer bellow document for information on a detailed installation process. https://docs.google.com/document/d/1a2ZptPScpjuavfpxVu1R1GC7R95jjzHo3L372zL2bRY/edit \ No newline at end of file From a24999fdf9c1b682afd53ca63020135aa729a4da Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 19 Aug 2015 18:58:53 +0530 Subject: [PATCH 214/217] reformat code --- .../load-balancer/haproxy-extension/src/main/assembly/bin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/load-balancer/haproxy-extension/src/main/assembly/bin.xml b/extensions/load-balancer/haproxy-extension/src/main/assembly/bin.xml index 5bfa02edc6..9975d757df 100644 --- a/extensions/load-balancer/haproxy-extension/src/main/assembly/bin.xml +++ b/extensions/load-balancer/haproxy-extension/src/main/assembly/bin.xml @@ -78,7 +78,7 @@ INSTALL* - + ${project.basedir}/src/main/license / 0600 @@ -92,7 +92,7 @@ /lib - + *:icu4j* *:jaxen* *:jboss-transaction-api* From eb56b83fe2f0c5a773fe77d73cf39fbada3ea882 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Wed, 19 Aug 2015 19:13:18 +0530 Subject: [PATCH 215/217] add security folder --- .../src/main/security/client-truststore.jks | Bin 0 -> 35240 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 extensions/load-balancer/gce-extension/src/main/security/client-truststore.jks diff --git a/extensions/load-balancer/gce-extension/src/main/security/client-truststore.jks b/extensions/load-balancer/gce-extension/src/main/security/client-truststore.jks new file mode 100644 index 0000000000000000000000000000000000000000..be441f378e8496cf04c83bd55e1c150db4e668a2 GIT binary patch literal 35240 zcmeFa2Urx#wl)k5Ip-V(kSs7m2FXzn1SE=N7=q*+l^{_C0YRb!iGoOyoJAx^RFEW~ zWI+TK6%6qA44{LX?b-X@bI(2Z{GZPQQr*?vRo!b4?t+sHo@|C=gpH9s~yyq=$}4hNgZ7N&vxw7jVhY4RkaGpkxpdcoCZn*TBNV&feM9 z)5RG|3?YOc#3IAefmwKZI>HXG!XraJ>*5SMyb45y`?GZrFckqr3@QMHLIogVf?`J0 zL;?b00uXTl;e!MJx~7C=A-@Gw3=~jE3<@M98Z9IQrI2u@{u{Ph!`$VM8I5kFPHVw6 z{@DaeBMCw07$Pk_o+h3)N@bWf$-bPF{c+oHXGWkmj+j!5?=9DZ6g|s6{pPmks3PQ0jeT4eJgLHrgodl~oTk%09ArkNtcw~YK@F#->!CGFHj`mhy zEq8k-3wJ-T0wDYLHuhE)p7t)zU^y>OI~R9*Pd_j(SVaIT0TJ838p>(K1%`@?i-C{c zAE>76;tsahzsw(I4fgVYfnA&({h&+`hW%?P4=(}hx_fzeg3rP{eO%lfAdFN5;$jeC zs2BwC&xndZKnx-VfeHu;iwlbz{YUiicM8*II!t0>Y(G@;tp1{UD%1HCNGxSISlLNM zW+WUO_R6VhJ8vET9Tm~3ox&ZqvG&0*tM`FcgLhQkKfWLsYb}dz*B)GNO|RtBHSYW| ziAz#zMQF^Isi?t8AwKDbl7Z>v&ab_B=xeLVqPh^5MpP96!TuKp>DKlZ+vyDS(VE7# ze^3}eu;2=#tt|zcXY?%+ z%nBYc5L<{mJINur!i7^$V(r;i?U6-)`fig2>f1T00{nSd>{EoxYlmli8Wd*H8Qv<3Yg zBouue_|eY>p`oIop^Jgy-~OWhkdU6EYC;Yn-B%MlrTyFUIm0}mryf0_w)e%v#{iYvO!q) zWuE>(U&O&k4+5*h>%y#|f)FUY8iLLyW)B`FmAS4I@)CGD_6owc7 zqxu?h8~IBj=9z22pce_BXSyX)O`%k?_c&bQ0v2fYlyZe0PPG?lZrZJeeb4gp8*IO- zomkdo08+8eEDfbInhX;4RcRDWA-y&5nC#NVQ+$Z_UGYr4?XMNfkeMr$4btyMqfea* zZz%RWxhn&8E{jic#vH-YICD~8g&O_bBq8z5R;#%5SF_ib(DIfvO+Q~lLj~oAqP_$S zgBQRYk7FKj8Z}~D9QKnZZ0>B%2zEP9Pge zW*r7XbV~H&PvgU{Cqu`8fKXBQAT;|n-KR@fawzEd5L`NReIY&w2n{_BSpW|#37Pv> z-;LRTFfygTtkNqt=3Thqn?`y%b!SU>244gV&4E}Vnmi-}S`b(%S9x(63pMA=P8Qp# zTfM0r(mC4nA3FFHKbPAo7bh&9nxv;87lVw>-GQ?4y?di1w!V#N2=cHjCx+gTZMA-B zEZwQeG)bzkr@n;AUX)H#tSISSY5WE;Fd|uoaFeyqiS6_c3j$3XupWc~smnYV6VF^0 z4Mpw<+;q@8DuM?_EH*xxf*h0*LJqthbS!)V4HqwGPYZizu)aOa=kQzO;_n-`q!40w zH4r|Iql=Y=qn(R~CwzEQX75?v1fI<*4o%_w#Pkh2LTwZ*dq>&y zuQxDa%1xirF={{aW6a>s2mp|EBr86mMGk4 zh0;K%;D_L|eg1`rvawYrzU~aFK+F z0B+O1eF>j21%c9!;=i~xz{G(3I^dI9C@K*Opsl!Qp{S@RkNXxqmcEWOF7omU6wEG$ z$n^BHsn)o0cZ?d5LE)5}!*>d5Yz!^=Yt$epbuZ zAr*W3LDk7E{<2j~Nr72MUf8y#rFP49=bI_9gn7(G?0Eb~oN{_!pBP0`Ty|R#Zq;zd zk!q0;)4JdTrHiTRI-!(Sc+Uxi+z7q4fox41H$_g4Bq^*thmA4PgjNd=Oxh>c=!~Z=R(IyfzP4CFERJdmY6OG`_~Z;^ zaP2u5wc(D%{t#aw-C+;fZdE}YNnxkOM%%Em=IJ;xMI2iJ$&-iMyzsYAPm7uSVk{#| zGRg)M+kknBS!J8swz!pAz+0Bsp#ACx{|ORUtnio2Z%Wmf6Y9`2b@3|-Cu6I82d3tA z{M?=|GAE)=>P4oVu>N$_rf()gw7*EG!akj~JJXki$5mloPX%g0vtig7&VLs2DH}@3 z+PypnqZEA7N=uh5wcTra4SLNSJDL|C)A(HNqaECoVG6S>(w0CGE3sz9yr2bk9^6OC z_5`o5&$SU7)OCB4#_PR5Z9m?`jdp=ZaRdyV+G=oRH;FUPY&t`Q!~ft3qk>%z7DxM2 z(Bgk{PX;--3W_|0z7}EPOm+ zt}u5G7iSAcOA8Nss~@I!)K9f%1Js@wQ2VR4$pgFZHLR`XANX-_58^O*eI%+O#x7DV9zr3Ktl)xX6DY zQhDp+%d6c#g3 zYumzheJ!aNpmo_IEpDFmSrmyf$45LY!p7<0ATVxJy*?fveemSF`An`2@@8DcuXGov zhg(^1GVhNO0JiqWF#$=Z56m^*xm1U8DgWrP^LG+anRup2&*(fX4Js}~F^-otU{ez- z4s)%a2qwx8F#hWCxOwcVg)wNJm!pX4WmvfU3)A$+wUthdo@EO%PYP?xUz)V|USUgo zIu%0XhvlTXB~D><4mDs#;JJp_CsJcftyzo<&E#itX1N+p$;EuO($AS?*#~|woctVM zet@MWc};Xc<%bGk8bd-c4I!ZzvIjFKt{I62=mJ$d)zgg;&~=$p$QlK=+Wz%3rx-*C zu-^pWG7pDl1c0L8fdW8mkklJMpZ@+le&8sB$msuU9#@d#6@)ue$S>j#b7rdrE*CMA z>8_BdHug5-SC(~)7CZu1buBA)FN%7(sN|Z>Y>Gx~^Oy1~7+l1WB3C(KMH^5oPbZON zeokc@^e%2ccK_7T*bXPnY}3*vsrZNI158C6+jIs|umz-vtqqCE?7Q&aX2@%!>|iLq zJu%?Vw0@nWnY8Ew#TLCk)El0!Hyd@j!tA z|GS{r0KYv^>`?51BVZH-;HW!Lwg-;eqgbI>0Dr^lSphYjfg12Lp1{@cqwx9`z!@vx zZ&%=m1yBS2H}YNKB}L#GTj1yL-tebrq3|Pq>mcsojA9M^4{rs${yE^cBhX5F;C{A1 zSqr!`yiM?S%K=B+f%7mFC*a2!I0{DbLA2fq_zecGvj@(=+qnO?1&Sq5f*;+#9^OXy zv*34xKMVd0c;DQC9>9O^_ZMCR-WGTrcnvUc7x>fRWt)TJ`+em@pjP`95H&Q_Ffl?-9F`%d5!46Y(Z$Nc^@srt3Aq6m2`2QANJvN+L^fMGTQWl8pf=!` z3m&P>f2f>r8~cZet)ve(uodJGj{G0)AoO?dfb7s8YpwmX_Ow<#qNljN65q&NL!2I5g%M=kiZyI!@_`5p5LEa^IT+DXgb8NymE8ZGPutIe(9=&0=o(%j?ws zNE|O+&Q@jf7cJT+6F$(z2STx3=S1t zS)s1DR%rWnMOeg825Rx_Rej6>iPwbplRZtw+|uMd&1Pa00%u<9t=pqK!FcI!VIeq7 zqp^eiHe0-tO}Lil5mDvzyZlTewDIO(~wst1Sz-8FD~p002|~rUId&5nH%EQN3=KqQtdaUNE6` z!T*;R3km5xI_Upt$l)IW|9^}si2wDdf)YdlZUTbHB!5H|_5&LNe^cxEjZZ9im@ZYM*;<=n4HJRw<^`UG)`8tJufbv7exyo_<;M zp01`($W`s{NA0)kziZ!+yT(9}kq0hl&+Z&nR;O}$de27Y*7cWRBO-e&=R0>u%!|y> zFTJPz#3pY+^hm8vIvO#H{vz%Or%;HULb5GJLqV0H`89LGm`z6QOlRHDf{B?oOB?%6 zn1sa6_3E#0%-^jHpqF<~7lLj;KBUa%E#*OHpV8wfzi*W*ko z&n)DjZh6ruy_{W2&VKo3Pv_t%4#mO&MUxS_xD*0L`NRs8ljuX9xo8+HR#yF2s=u~7 zSvuHzeK&EHtN+*JqS;cif z##-W_GbF|pq%X0}$txAt#g(>T-?)n>Pn|gEF8-=Q;U(u_?Xr<0nS*N8-aK_+^ff_~ zdxB$yJChQ6J%+?P#T!O7gJ;gn?t?;9N1Z}fcbJpCm(wwW35XXMNVot?B;ilp!a<}V zOUN)cP**CDP2rbosPhb7+T6t%tQ z#DdGc?d3`JulfrTMJ|g1=g&=facZ5%-^Qa^xHnODD~4Zd3aew4sYLMQM;>VOKAL}M zWh3-S^4ha|Y(IQNPzRt-t-ufGzCPigM4fAPijymE{bj6z06~W%T$BTz2{swl0o(#* zgwVqUAD4{60AQzp)h(PIEWn&v-kw}wbx&(P=)OY@AS>89Fe@)O0RYMZ0q^Sy4dN12 zYalQRCkE)aIC>$t0)VOj@f&1Sp|C%w#A^-nmW5MT_*~p=5jdEtmd&Ubc*jaZ9S)cgAw<=ebhNF^E zDz~=ooOT6tf1+Ro^7wO>pPWcwfOAL~&Zi4|B;}JVmp@rYY2ZaEyRK|i4-YU=F<3wp zDAA30Ugkue^&uVeW|Jj~zJpUVtJV9daVPtIVTNt|!?P@zejWA)4j?K9;C!JXg}%mz zm@vXAPYs+xS4yRpgkVmwV>v)VhJgpbV9&}rh1D$MWr81>5z(#og^IErFDjni z@5Zy^oT!5Hgx(L9@Ee6N^w?omqH2q|>@H_3B(7^zX*IZg=dNASN^woN9eh%FE^on( zF5XR2FV^=x)!r?cCori;n<7~w8;wGS;$BIbG&;MA_;v^_C-$}gC^tZO1Ht||j{AeQ z2F#nwz>gLh@EwnK0}|4RP&7b)vB>E3fml$iE^}8DKu^bIP=+mKGv=UbmCNy zmWzv4Vydd8m>AQU?fh=(!qAXUJY6fD11l25p--q$Vl|qJ41;p~P^ueW$CSxU5DC3y z4xz~wQ03fu6stdaPVl?d=;c&L&_a*;wz}$b& z>wyRZY)%n~xX?bYXTK;2FG528BYOEeMo&NI6(L=^=nq6?qVdqZGN^e^(Mlz;-FnvY zO_6uF){QD3(WzuuRWv#|XhPWWb=?V~cqf?BNVA%%+@1x~$f(!^To>kiT8}$>Vlv~o zmS2d!(KFG{57oxG64zhfHOMjOT@nLPDPY2gu+dzvGb0!pm$C;PSv}bH@^SkOX<3$b)p?&xt&nRF-6VQdN7nC=Oq>!jeC%TMp48Su@9; zK05RNH6qV}Q4se6g7(GQ^I;)wejsy<5LMAv6~aBXz!);zuL~*F8`rlxi3vU@w7lyW z9ZkB3-gt6=T?Ez*eZ2fuX5PRn%%5aKS(AF}SxRG3q(FoFC&@XftTBd(4s(U;hJ-A) z_$_l!GBuQ9Y?KK2MrP}J&{P{^?3|N!;#I=?jC*r+9doA=F#yuQ+`Q~E&VX4D;}?vJm(qGx!AH1%LtTAo_4LbRDezbu>JCR1kl{b4vTq0mdQtgP?Gv7-0)A z96bSs$saTUaDsUSe$3lIoD(X9u-Xyx_F)n7&wk$TX3_<5@tch2FzGl&wkvbFI@e<> zNt$=pmLGUNys?L|JaHSdm9$%i@cr}Q6O|-0!yY(SM=DOH;1DosDOX-8P>Qj%YYe9Y zy9yM`_7~hTd*mi6gZ`mb?u0lNEhC?WVKyn=V*YGr$*QPZAAPr|M1AtP!h4+;Pb8kr z2pDX;_G; zgU|BkN~M*Fw_0Xe4?bO>b@9pfaj<`3s5g>Q9eetyQqdx_4Tfv_z|I{D`#mx#zu3@2^&grJ;1slqLtL@+@87iD6TTRsIgZ5B@veR?AOe=%Heit zoh*=I`Qy%d0zwlroa=%Pk4DC%NDWIa;qX3j{YZ8-F^41X zxof9WVs+1@+u2VaW2;Wsq!&Ef!h6xlZtyA|vfBT9t%4qC)lV7&S_Gg`p}-eiJHV^Z zkvj#aG3Xrqs`L=}cL1DdvR^a@!L&cnD-hXl^$Pk!ub@Cc^&qwi0qo(!;{VJ;f2Ujn z{4`BewLUX9@0uAAP-zO$;-_q}Oq?HiWT(9OK)5p;1b$qml+UcKB)3LsC?eo8r)6oq z^Ibcm_{7B4?JL}oxXjN;#e^JVP@IjjC*arJmosFDfg?Um2(Ff~(`zGGy6>69)dv86tltkn(>uL*(D6 zkH6E*!YEW`&y&lvpv{z5$&y6O*zYo?l3%BNdkEy5wV0jj?qfVjs(-Q$)&68(DpP6s zt^0oH@5#j515z5WPp&)+BRg4a{~Bkj>n>WJ{6khvwQ&H${0epKS#n9`!1}nfrS6;Q zw5A;Kr9PrZ_kHD~vJqu^qaF )aUWUP7mVAfG>TAl>NHz6(0E(>8x$`R;hrsX@#;o z$92+xPQ?fJ5gKzyR@(>eJrGXTF`gud2T&RgKxyI*M)@P~3WBUQfHchiy{H5Ogl>OE zAU}vF{3NS^t*riAe6@pk#G&(e3}0=(2Je2){}_}2GN}&eIso2!l&|)m*5Tjj&{GkS zi`T{;UdWsbk+ZxZ_Er^L@A=RMJzWx|$_DjmVTp5FJQp!c>0j-Py;~%Cb`GR%_qs+C>h3Q@teL-ocs1((Rq?Y%^5q3pLc$zSR%rs zMp?(OI~t?;3Q3)ZOfgo>mb}KY>}~q}w8Y%MNLgb)eUkE_;g=OkPyFIyGhLbYV?Dm+ zrl!uKRxCaumn*3r3DtkZ4*%AJDz>N5@}5#&VY$&r`D^=Q5~g=*<($er9gpNMHGL^L z?>t(o9Yr#q7f$04s-A~WTKYQgzRbH0Ran~f&TeV8+Qihx1OYd!%?Q(VEsg?$0@j_z zCk0sK@(9Huvh{>n`B?&RB_aU}U=#e3sEE1?7)=1>2-OM=4K){e;(@D^5|TCnpbU_x zv9BUTD!NJlnbY0X#T|iKLJ!O-5E&Wb4E%}v34(BX3BpVg0Wt{$1%PZR1O*LpP!tvi zivO&~{7!W0mNXltQUcuq%M@#$5h+htFWzjIkL_wujS=ScU%uA7hygwSxPl)S|7%vE z%pDw?FnvZ*F1pCqm+^bkvhssIQY7Y%-cb%6w^JV$rNFc+Yu+xe+T{9}WQ0R$;e*S< zHlnFi+||5zYj$U(C|17jL>pr~hg!80X0Vm`qdTTz`-agkuNQ7;lU8{>He+~Yp%;uY z5^^R0O2lflEcF4jvn5j0I5D4}tg*_&_44^ekC3Id=-g-TUgqbsh^ARRJPm#@_^U+)LyJzvwTh^qh?Z{7GcL}-cwzq}r?&PFMc>9B=XVIvT>TA=? z*AM((EgCU}K{B3Y<+F|N55EVHfUTp8rG?`!X?j0x7W7B}#Jd6v!EX*+SFy}b3%~RU z67t|rusd0ZG+cP_$VGp}?o7!P$)e)Qmjfegbgb2vh`t+yVDT6ouf$ z|Et~lol4yFd{DE{dFFYJU6AGIo6p(?RqkpjABUoQO0D`egtae*jgq-5B~_uQI8)T*ja8k3>2K{bXSmrGUJHNG!@yjO_Fv5- zF*x-tP)elVR@f=;F5CHLn~ysj3rV)mWfFo--wR#h2|skiGl9`3?KpoSWEv0{IKK@J z%|Sv2vqSo_LwfQ;9>a0e;{oD-Ya#m;2|!MqLvV9{iXR*rI4Xef6$y?_oC~|=`Mooy zZI8nVEUFZ^%RA8U>=KgWbnNM)&;SE6Gyue#>9F;M`5+R1o;-KfML77>@YRomh2ST= zFukFKt>v(4O!h0JVR-jWRVu!19+aH|6E--LuR>m)vJ4Em<`Ae>I4UgJQe?b(rtxNM zuuTaO*LMxxR@!vjxXzNv;i`xc{uAen{hc1a-(A$8g%y$;oLwAUZ0%tl2O&7%%OHj_GOnN14r6dfvl)KG-{5l~01}7@h(kpM z#i59tI^^QNuqC0WVB|r2pNLHWPhP@CBrnwpbnm`)D?kq~#V4_z9nje522n@Kq8LDD8%(fS-CRzUg;Xw`dC&mdSvd%PISJI*_1+j zsK|tkWJO(l==Tf>Y2xlv8<;Q~|8yE^sXaGsNeG`=iPdIx5eIZ)a zf($_!wqIzSh}3GvGvTTx``(Xzw^zPf$4~_eI-9DQr1mgIKDbTWHtI|!%xXHDZYH(y z{ImDNRp~}w0(yB{2lVmn=aVki-YaGUON0PP!6BWHkcUWG)M{2cJTT1^v2{W3-itBf zhlF>dmLVYtaGeBV@K=F!=3w&U>f|`)UHsR5+E9Q>d{niO5E3|E4iF1aFmB64-5&0t z)yuhO|KY>=$#m36T1|tyIes|YQ=j=O8T-0SFOFY{%t_u*6_)nFlryw!jWw*pwUv2O zHO*|p)T8^wy-!MAc08oaC-aJbX8q7^XB7+(@q1dMt)0tgG{+3S1Xdu&1xfU4&s4EixC&JxF3ss=qWWR6_Q=wCTm1 zlz4x$w3llR^?6Va%Yz#kqo&+r`86ZBPTRGzB+6+_euS2-M9FVn@-tB-A_kA65DgTG zP>W>lFao0oEnx1T0T9i#3tswRy5V>zgJoi;2P*QAH3$LG{Cks3q5pqk)c(EB{v$^1 zbl6D!gPp?h59q!bGg2=c$tWlMr%!0xv~{tcC%A`+{V;J@kZJRZFq1P~_e`-f#aUgB zjYm$jZ}8>`Hx=^@x?~L*b5)q!-k5)KO6;Z7dl=-!quw{U8=1FZ5>C>LW}LK-t5k*jOiY)%r!`wS#JNteP0?G*4M^UT+O9=-E_Lwtv;<3 ztagc#8s~B`qD@ROoq8}vq^}Y}fv#3|g=4tWFsgm}Q*mJ~^`u>~6N&b#R+vN9E$?Be zV}T?1KvH58Ggj5ml~%K)H-zyn3mRioJW;I7PUNTiK@b__(R9*@;QR{&5)_)9!Zuv=JPt*cj^S} zusOwG#;&aS=@s0`H~HXTd%GOX%dZ>;vE;s7iER>_F6SeuaHy2;OKaLW&ElsG{nk-=3 zN&<#kJ{qxW!vX{G1eZ{aSZ@HRui*%<6b-O+&5l~SKSRogxfchvttdoz-?ru3w`l+B zB2xz-4^#j^bm0Hs%+MoCK>d$5;CH@mkMa4;_jFfL$sZ8UqRURr8K%`yQ*AE0;)KPsDOX8u*D$e)zIf%cZp46H01>{T&feyYY7mlO%KUD)VsCkf*|6W9YF?2(gGNz2+W18V3Xy&cTI%|pI3@LkM&dlF zO#u+$yMgVM9_{N(mRU<#ZI^1@GkQcM9J0<9?O798BgQbo{j7jLhux_FBM5M%&;tJy zc7KERATr_u{Qf804iD!drH51P_mmgT;`I1iVEcbYH-D!n&+@dKyZ7`R zmIh5~R`Kn;RPGc%oD5_8R&YaG|k-3kY;8h+L8QzIPcY{bd@%W+O^obst->IyR*ADNwWvrIY+U$rev zTqv)5@gQJUMB-t!4GZb>NP>M(=r2O-SYOobjlU-KDZdTBqQMM_?VTucQKem))SfqY zbqup0$)W8&Eqz|$l4g=r&b3-R%M^dFtJ6_u&t}R_74->t*1Hfqp085Go4D$d#+9B* z&3S5gUY0Y>NOH7#8BBMrH?Jh-wf4lE`pNTmC+jP{=swB6-{^Wzy%XJ(yLXk9&s7DX zJp_l~DKh&J$%{w@yoe+~fp!l;({vI^WbXkHwrcnjJWB>5g&2*=MScZMb#&DKiJ0ks zlk^CT_drfLR1}V4!3X|>qAtZSG(C+w|4`Z<`G0s4TGKuCi7C=@q$#} zvS#PE>rgBy@>)W%6*9<#b+M#-EIpgXCKS~xW>XGvY~C&U7DI z{j@X=mefJLOp6J$xxku0F{~H!L7HjxAi3ZgFIzIatQ7;1ZW9!d85{CRXKyA=(d(gP z`?+qp@VxI()a+vc)Ok2S0RX7*)yg0tquC)(vqJ{+Li*qf%pDJ){vQyyzW}2iisBC# z6*#ajjDHHFK5=Ywm~WJR@{J{9_v^KUjPm!+EJy&*v8Rt>Eq@zEwVVoxALvf=k>`KY z%#o`@q(!%SHevH_+1>1h(-u!QdN4PbMz`M1>hmu3UZn9T)@ezo(n6~VXLq+6_tLWT zBCoB|qLt|-LBR`GvUjSCLWJRxGTmt%z%;hNkiI& z2#cZYB;yTp@wqP|I%MJ_rtCaZQbpv=0&CPD&U5H)izR|muf!U$M8YgH{8lL;TV`!M zD{c-8JNwhG4n+Hpi?aMo-EZ?xv5SfRT7qGXPjadF60EMb@9dFD2VP&ckO4k61HVezk z{M8zY(>T_vrkb9gF{Hb$p2MG_c+l*WzWBI8*Y57TeOygiK2cr04EWN0wd%Tz1%{fE zrNsR9t}CTeA2}ik(H%$krn61fBhS_HP@vrxFSzLWdh*e7lZFuEU1JSFvjiOeC>s-> z;?@kinQCao5b5v64CJqzpCPYnJo5qV6*?LWU+svKK{fyJ^SVA-(}WAH%Q+EeFMV9SXR`{C%p|a@mv1yP&o~Ik(1i&lVceDz zUQ1ZJHC=pO235x?RdaoDj@u}%z5Y=F#bCG6T7gMyhV-WO3Ge*=5?Ys<@c?ZL=YpWf z?z!4Up%-#dt2nYP9tlzo%lpZLC|H}a`MSUQ9rNO@@0z5Q|@b**Nk~_ zBA+`rnFlW3?~G%`H&z=et1$V{Rf9YAlHw-8G^nY|`)c*HW=A@iR~>5GQqKj4{JQ8D z_wuIQ*U#pB)@;Ijw%Tp&8SpSkE(7La_%1F@@?u3w&!fnuK_w@pIcFA`-6kTa@yh!N zgu)OVA=@7Vi-3Nm*bC2W4gS)bUn%bgX|}jzSOYJguAhII)W-%TKq*LY4ysA8%G634PIFlxnXw9YPI+6jXVm>n zuhPcNV5W_EO^UmaRTULILO$Tz+n_s?=c;XOpUF<0VmGYh^pUzx?ql)%3%3nNHo=!d z593wWcZtj}MYAv8Hn{BW-ih?v@Y~S5hvg%N&?O3h@8fCjB+%cAFdz>bZa@pJ((px*F=EsxRU!d#sSi z77q9ITE_4$-oPu+dRnB_!MXaege~%F+AaFKwskW2qn~%qk?}vI8+CQvywOJ5i}@t& z)kLqLzt8jSH}&uA6y;BoJ#BlKci+@}x26E&+kz=3Bjt!@p!wiRu3# ze06OEbl)^g+H8+v-M(o@T*TdL(C3`Shn~2T^-_yHtU5AGCsLS=u~NC3A4|Mhc8-v6 zNcOZ6Y__9@Zu-V}w|>ivHQ|mZ)QEe*L3^+?F0hynlC~_~J`V|1G3>kd1zT4nB0!=V zU1Rf@m9Id*taFC>i%cN`*5UXju?sHRcJdh6(~X)OY+<10&(`00#~|~0#8hjOTwFDN zGTxtP$XM%$ad!;!Ml4*L(Jd~LUZonvZSHJ>1U`R_&lVFQtNErc_p;byQ4-DdX*+1F z`qL^@&$lgJrdX$GgIxD0jlUyb!p^ zSp8OV^xJX>15L*X`Bf|NyZdh1kzl}28}aA*PsqUlUb=5;R57{nYs-5duPL?QA-~rD zPB7rFa_#@ef&qWI0l%9bYmBbt5?o}x66`Q29=XL#CWxudc4u9WG`X`dxcwc?!7<*og+(3Ca?PiNy zJgAW(_@?pNav!#%jC7USx4kottfN|??20t8tQ~HvG$&NhGrd~73s9K;EEsT=j^~Sb zyXTncIF0okLp5H}mx3xp_trlbPcbfB!!$PM=v6v5K)E4L1JHa+cG8> zr0Y=7viKH*+8n)AKKT1kQ4u5Rsn5B_Ww|ew*n?Rm>l8gdpbA zjofz)&}P)|qHjz-x8|p00xF;0eJN2`qRCQapq+t?F%%#S1}( z`1>4Cfc|L)f8-zbWcV!y6u#X2-{F7)fd6s(qj18X%!LqIabQkCfJOTz+m4&C}k^H-_HnY*MBm8-d6EDB0%Zk{v4t$1o0vFpL!`L?ybvTYvn-F9tLIy}>+ zb>1n$H?Ps&4kVKxWV%qxIJkI%oUtP0Zp@{+K8G`)cWC%8O7dk-pagj)=G?~Ss*1w< z80m9cuYaNA^4LY|l5p~fqzlOcS}s!E4L11m-P7}>^GYTRqf(iw^g3qPLgjY)R=W)AMBuJ zwzN@jeLmWT^=jW*^@O+|2caUTsOc?)43h-6j7QgF=R$XKPT)}1yCThbe{vcTc-r5T z;J4h$Lw?qIm3z!#SE+h3qIDP>g2QPaOP-ak$fyZ?oM1w2jW+)b6Pv^$&}yFNHWcLQ z{WO;|d#f?c%46MWk$Y;L{4UR95t1REHLPp-lbOaexAjRs>T-2stXGn9$83S<_LdWf zBg-YKJ8ol$lIC`8QPhv-iBqQQNU+AgD+;}HG0Lvp4~?a%xZwHy*>ZBTy2zpFz@UJ= zGWx-#DXdb{sqouFJOqMM=)+5@vSd8oU!`AXL=#aAP?v}MGHW_$5`Gb}?Zt;EQ#J*n`jp_DET^NOl+l1C8-x*2#q4k*Q4!+I_BKMQ( zoQ@n=(ZbVWKc5;{5$PZZ&IdV(2)mH6?I&9Qm31G4fYs=K#=e0x2Pj1Ja0$X+V&DJ# z285&|kHK(CXGk=VHyDm~86{!Bzy1CdX`|xkD+c%2P`&X>@5i1L9at0gwblhKhRJI8 zwBEp;yBdo9lrln8?{x(;TB)~PNE*hSGd*Y6Y*_Riqp)s#4ms}>h6QsabMux?_fenM ziq=m#UC&U+MN7t~Mshxbkz!O;_oRn}eP~6pc!ra!?dip7-sjzn0mn{tmr-ETmtR%B zDW8*g`NmB-jfSM|Sy%Q0kSsfzG)~4V(yC#jPonv?7ND97l=i0{D`MkE>EJsgt9D5X zzi_N?ES@!Pl;FQ2J<1H0kcL z+^cdg)@@GJnDbUp!&-V_?c}+AbmAP3*$0N=4$keLC`OBlWQs{KW1#nf z%7w;m2-!yA^plg!omJAeXYxf0o_wJa&($c>V`bd=a*Q`JAg5NKJOI+b%?~Ypn`=8c zb*z*DaFx1D-L=Pdvu_my2~A!XJi!Xn@E6=mpxY8D9ZzBru_JK|l<)hH!S@JDhP<3e zb1yEzduOgm?e&fR>|or_om}riSxo9GrbAeB1K22(A%2wGs~BezgBTvtchA>u5z9)F zb(k^ftejqmco2{yTpqyIQ1>jhL`Lj3iV#Z5hhevUswu^h6s%vOEJ)&J3W%E#AZ{H% zB33@Ke8B_6UP!+6ZxgXNAZ+_17vnF9Scgl!9dg)zE}!^I#e;y%kHjqiJpp!pfxvk^ z2cQ-d$m7~~yZ@J(^*dQiBFe7W)XG@#?~3Z5rXu7kPaL9?BK(xtb~UjJvpX)iyUv={ z|FWZ`&MQ$)5A&ePWF4$5ogF8`#HVF3PEoeOOY44PfK7lH}lp%u}Za`odskHqpy!fU)d${ZAU>Q=1F24s%82qO!Q~w}~z~_TQr%r2h zIIm47w5M!YEb_P|Py5Vg2NukD+#v^rOMNXNgmhk^6bvE5&I}MbJ1g7mIaYt^#g@0; zrF1J@>erjAAB-y|uE{gjwd_|eXyHTDfgve||5vD|Q>M<)sih>~t@JV_kS zWV&q}?$lL$Uz3TYx<9G3p|EeK1kXPRG3rtNgnL}9VemZ+fvp&RjD0_SNl-Ch;THe` z8T%9OIl?G|TlvVFX8s+#habYb9|UAS7Vl92S_X#idI&V_DEK1^6*@>CM1Vht*%c1{ z{L32hk1XkKw=`RWAQTc$r8OQoywQNzR4&$?m2~Whk!o0_)glnD> zoRb^dO7MDh2Ukl!vLzWWKro!Ro|F2m;Oc3Tu?z7k-Yg?;2ThiX&eGq$6+fNP?1@w4 zZc$v$Eb&h2BuF3UY5R+g>MmW;k|p*#mC9}&y(Cd@o0hFV50TJ%$QpI4o+PT>hzqg{ zMi;}QBRVzmF}vzv>?@%M!KqG}-XjTIvK2{BMe}S)gI-!T-WTpn6$w?WTk@qAv~at5 zfj1`0Hz{<@Y2T7If*2z90%Bl;@4|Jsk~y&0!OsX{x15kM1qJ$|?EB%8G?x=;j=MngeHxt}vu z%k?*J$HeR}wBzgBW$msFzv_XiydUW>T_wuRGMB?rTh76-UkuM zP7&9b=+$MD0wGSHBmxysoe|SeQ!48GNO>a*8RQ%&6nW1e>91unN&*(EWS! zt+j2%`wRP0?^E~=m$$V679n!7us?1!HV_n0ZD4g@v|IbCeawb0!$_0O-y`$=b2fZ| zuSAMq3D6xd`F?EpqI}RVfG&X8J_?D{M}OFN-owuSk=gf~ZD0Na`~16Ea>RaYq&(63 zg4=7AaeVEXRrmPvFw;xC1UCXmXT#aNI6WogPg-$gB?X+>xJ(nt5V4v&T|aQkn)V^N zv*NwLr5h_6L~cy7Vg)FX{W5yjU1`Hyj_{EGvY@8;H@EhP3 zoDft9L4X3nl7jH!p#}G^Z_z)RM4L#RWv&MLC!@Y$Y!o*_+wxVsbDAzTK=qt|U4Tke zSz@|N(FHbq%}v%zBZ-t?jFM@%X)PuUsc)9w4?p&&nkY@zy%qE*(7ZLg zm_nFAc9Nv&jV?1MFKbTG<{)qX^ta1IrmtXF`cJSPJk?(@g#uKeM-fkX!v}9BlsN6$ ziGQ8(XpY!kQ1)NV!hf+PP~_9Xs|^wwp8-GhCR;FBnPf7_!wg<$+4UIO1;57-q3K$d{aKV0~p z=G#`NKn5d%Xa(%6Mv6}CjjPHmrk*vk{YbUT%`N`OcC3e>lbpl|^@Yj08D{!du{ewG z?1c7aZf#+GER_6kPpu;TOTw4*^(6u3Vm0s17n)*=v!f9Uqut(@QpPI!Z)jAN@g|cRuYj8sk5xQ78ct0x!}?rbUC>mdRrjkQNA?Qfwb~HV^(W~9hQk{& z%}KJ)sb$hbgRuqfcd9xt(t0>9CG=fB7gJT@>XaFsrLjiq^)RJ)6peBW|7t7S!WwT= z%49`C-;~fjM5y>tCXV1gP6|xFjH#L{ zZCOA1Htw_=*M`Bb>i%!O&Bk9%?SSte{(pX(jlb8~e>6xvX~;PD&6kOm(S=Ubqj|f> zA(0fKxhbOZaVQ@5BUN|4MLVUe#@DMBaf{yIb`s1>B`2K=K9b1Ae&H?Uwm6?>%dS4O z(sb^ED;V8y*uN*wzUc~;bt%TRrXj;bJw|pWrF-*2GSH@8*Kiho2|tv{6)&io1}BQ z4{>?4m%Nv1m22k+3i^sV)X(chFRkbp)34s%w4}r<>@maNoO$RyQ1RjkLxqL$i zdn$JqjIyj}rkFJ&QiZ%l45o)D_&ZC3D40YoJ)}pL%?7AIQ^H?(rtX{Lm@%5&aBjqt zS~VhL#5Z@TZmVWx;lsjva@X^TN+U!2SiVCa|5N$zs?&whgE|e9C`O#Ep|jf!WDHsn zq2FU6H@K9`8Ks0L#VjeQ)k>FYv>j*4EZ0zn7*Fi_-yo$WwX6GTlS)pmWPE@5zCBe4 zkCAAPDfianxg2BN^a5R!!OeH=T`3USQzDd8xz4NKODi8vZlI}T&(gYMu#ud*y$z$z{PY7N{Utm5wC<$8cw zLm~Wds~L}s^T+A^3@(A+EmwTFCIPTA0UX{DJXn(eQT*35;vX$XFmros)qq+x=fc{U z+3ASYmg&8P4O{vxm|c~DTehiB<9fR4Yu8{YeQGOgm&x~iLoz{Vx-7cHnol%z`H8PgBk1KJw6pI>uj$|Jj=lyh-s+P%JZYGPb5a?NbivGj>ndnkxFG_V_?@9=flK+<@gzM&CNYK4uj}-%Or7bzl8sxBa31MW`X@PTzp#RHBkcb*oa(iRw{c?_yRz`mdl!_9SF$7IDXCcN4rXy^| zeRvr5a{=MQrA~ihb7+acxDf{c#XARM#~&8KLncE3UdHd2Iz6B{g8o2rJivjEtR(!8 zS3LcneD?1g+J>ZdsGt#zENDxRN;+OO(hYN+ zYVV92bXR&(biS=$@U~3ut+jALW_oExX>(`q4BPO|?hcE6=-g8Ay($9-J4Yl{KlU^dm;L}=hRmUA|9=6H0B`@Q$Le3&xzJ?~FxEcW4HQXkk&`DB zG4I6pEk*e3$G@UM4I{LY`56Fby#cSy;Bov~&t$~lmYC3^K;i+4? Date: Sun, 11 Oct 2015 18:54:22 +0530 Subject: [PATCH 216/217] create health checks using the application ports --- .../gce/extension/GCELoadBalancer.java | 65 +++++++++++++------ .../gce/extension/config/Constants.java | 2 +- .../config/GCEClusterConfigurationHolder.java | 19 ++++-- .../gce/extension/config/GCEContext.java | 2 +- .../gce/extension/util/GCEOperations.java | 18 +++-- 5 files changed, 72 insertions(+), 34 deletions(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 91e8c36332..82c09926a6 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -203,9 +203,20 @@ public boolean configure(Topology topology) throws LoadBalancerExtensionExceptio String forwardingRuleName = forwardingRuleNameCreator(cluster.getClusterId()); gceClusterConfigurationHolder.setForwardingRuleName(forwardingRuleName); - //set health check name - String healthCheckName = healthCheckNameCreator(cluster.getClusterId()); - gceClusterConfigurationHolder.setHealthCheckName(healthCheckName); + //set health check names + if (!ipList.isEmpty()) { + Collections.sort(ipList); + for (int port : ipList) { + String healthCheckName = healthCheckNameCreator(cluster.getClusterId(), port); + gceClusterConfigurationHolder.addHealthCheck(port, healthCheckName); + } + } else { + //the ip list is empty. So creating the default health check name + String healthCheckName = healthCheckNameCreator(cluster.getClusterId(), + Integer.parseInt(GCEContext.getInstance().getHealthCheckPort())); + gceClusterConfigurationHolder.addHealthCheck(Integer.parseInt(GCEContext. + getInstance().getHealthCheckPort()), healthCheckName); + } clusterToLoadBalancerConfigurationMap.put(cluster.getClusterId(), gceClusterConfigurationHolder); createConfigurationForCluster(cluster.getClusterId()); @@ -244,8 +255,12 @@ private void deleteConfigurationForCluster(String clusterId) throws LoadBalancer gceOperations.deleteForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName()); //delete target pool from GCE gceOperations.deleteTargetPool(gceClusterConfigurationHolder.getTargetPoolName()); - //delete health check from GCE - gceOperations.deleteHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); + + //delete health checks from GCE + Collection healthCheckNames = gceClusterConfigurationHolder.getHealthCheckNames(); + for (String healthCheckName : healthCheckNames) { + gceOperations.deleteHealthCheck(healthCheckName); + } log.info("Deleted configuration for cluster " + clusterId); } @@ -259,21 +274,11 @@ private void createConfigurationForCluster(String clusterId) throws LoadBalancer GCEClusterConfigurationHolder gceClusterConfigurationHolder = clusterToLoadBalancerConfigurationMap.get(clusterId); - //create a health check - gceOperations.createHealthCheck(gceClusterConfigurationHolder.getHealthCheckName()); - - //crate a target pool in GCE - gceOperations.createTargetPool(gceClusterConfigurationHolder.getTargetPoolName(), - gceClusterConfigurationHolder.getHealthCheckName()); - - //add instances to target pool - gceOperations.addInstancesToTargetPool(gceClusterConfigurationHolder.getMemberList(), - gceClusterConfigurationHolder.getTargetPoolName()); - - //create forwarding rules in GCE List ipList = gceClusterConfigurationHolder.getIpList(); - //need to create a port range String + + //create a port range String String portRange; + //if the ip list is empty if (ipList.isEmpty()) { log.warn("Ip list is null"); @@ -296,6 +301,22 @@ else if (ipList.size() == 1) { log.debug("Port range set as: " + portRange); } + //create all health checks + Map healthCheckMap = gceClusterConfigurationHolder.getHealthCheckMap(); + Iterator iterator = healthCheckMap.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry portMapNamePair = (Map.Entry) iterator.next(); + gceOperations.createHealthCheck((Integer) portMapNamePair.getKey(), (String) portMapNamePair.getValue()); + } + + //crate a target pool in GCE + gceOperations.createTargetPool(gceClusterConfigurationHolder.getTargetPoolName(), + gceClusterConfigurationHolder.getHealthCheckNames()); + + //add instances to target pool + gceOperations.addInstancesToTargetPool(gceClusterConfigurationHolder.getMemberList(), + gceClusterConfigurationHolder.getTargetPoolName()); + //create the forwarding rule gceOperations.createForwardingRule(gceClusterConfigurationHolder.getForwardingRuleName(), gceClusterConfigurationHolder.getTargetPoolName(), Constants.PROTOCOL, portRange); @@ -373,14 +394,18 @@ private String forwardingRuleNameCreator(String clusterId) { * @param clusterId - id of the cluster * @return - a proper name for health check */ - private String healthCheckNameCreator(String clusterId) { + private String healthCheckNameCreator(String clusterId, int port) { String healthCheckName = GCEContext.getInstance().getNamePrefix().toLowerCase() + "-" + clusterId.trim().toLowerCase().replace(".", "-"); //length should be less than 62 characters + //keep 6 characters to add the port at the end if (healthCheckName.length() >= Constants.MAX_NAME_LENGTH) { - healthCheckName = healthCheckName.substring(0, Constants.MAX_NAME_LENGTH); + healthCheckName = healthCheckName.substring(0, Constants.MAX_NAME_LENGTH - 6); } + + //add the port number at the end + healthCheckName.concat("-" + Integer.toString(port)); return healthCheckName; } } \ No newline at end of file diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java index 561a95a925..f919546264 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/Constants.java @@ -44,7 +44,7 @@ public class Constants { //health check configuration public static final String HEALTH_CHECK_PROPERTIES_ELEMENT = "healthCheckProperties"; public static final String HEALTH_CHECK_REQUEST_PATH = "healthCheckRequestPath"; - public static final String HEALTH_CHECK_PORT = "healthCheckPort"; + public static final String HEALTH_CHECK_PORT = "healthCheckPort"; //the default health check port public static final String HEALTH_CHECK_INTERVAL_SEC = "healthCheckIntervalSec"; public static final String HEALTH_CHECK_TIME_OUT_SEC = "healthCheckTimeoutSec"; public static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = "healthCheckUnhealthyThreshold"; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java index 324f096454..aeefd2cf43 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEClusterConfigurationHolder.java @@ -19,7 +19,10 @@ package org.apache.stratos.gce.extension.config; +import java.util.Collection; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Since GCE have separate target pools and forwarding rules, we need @@ -38,13 +41,15 @@ public class GCEClusterConfigurationHolder { private String clusterID; private String forwardingRuleName; private String targetPoolName; - private String healthCheckName; + //a map to hold the health check names and corresponding port values + private Map healthCheckMap; public GCEClusterConfigurationHolder(String clusterID, List memberList, List ipList) { this.clusterID = clusterID; this.memberList = memberList; this.ipList = ipList; + healthCheckMap = new HashMap(); } public List getIpList() { @@ -75,12 +80,16 @@ public void setTargetPoolName(String targetPoolName) { this.targetPoolName = targetPoolName; } - public String getHealthCheckName() { - return healthCheckName; + public Map getHealthCheckMap() { + return healthCheckMap; } - public void setHealthCheckName(String healthCheckName) { - this.healthCheckName = healthCheckName; + public Collection getHealthCheckNames() { + return healthCheckMap.values(); + } + + public void addHealthCheck(int port, String healthCheckName) { + this.healthCheckMap.put(port, healthCheckName); } public void addMember(String memberId) { diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java index 771424a7b4..b166bf454e 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/config/GCEContext.java @@ -43,7 +43,7 @@ public class GCEContext { //health check properties private String healthCheckRequestPath; - private String healthCheckPort; + private String healthCheckPort; // the default health check port private String healthCheckTimeOutSec; private String healthCheckIntervalSec; private String healthCheckUnhealthyThreshold; diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java index f9b6da0bb9..8f05be6d08 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/util/GCEOperations.java @@ -37,6 +37,7 @@ import java.io.IOException; import java.security.GeneralSecurityException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; @@ -57,7 +58,6 @@ public class GCEOperations { //health check private static final String HEALTH_CHECK_REQUEST_PATH = GCEContext.getInstance().getHealthCheckRequestPath(); - private static final String HEALTH_CHECK_PORT = GCEContext.getInstance().getHealthCheckPort(); private static final String HEALTH_CHECK_TIME_OUT_SEC = GCEContext.getInstance().getHealthCheckTimeOutSec(); private static final String HEALTH_CHECK_INTERVAL_SEC = GCEContext.getInstance().getHealthCheckIntervalSec(); private static final String HEALTH_CHECK_UNHEALTHY_THRESHOLD = GCEContext.getInstance().getHealthCheckUnhealthyThreshold(); @@ -239,16 +239,20 @@ private static String createInstanceSelfLink(String instanceId) { /** * Creating a new target pool in IaaS * - * @param targetPoolName - name of the target pool in IaaS - * @param healthCheckName - name of the health check in IaaS + * @param targetPoolName - name of the target pool in IaaS + * @param healthCheckNames - names of the health check in IaaS */ - public void createTargetPool(String targetPoolName, String healthCheckName) { + public void createTargetPool(String targetPoolName, Collection healthCheckNames) { log.info("Creating target pool: " + targetPoolName); TargetPool targetPool = new TargetPool(); targetPool.setName(targetPoolName); List httpHealthChecks = new ArrayList(); - httpHealthChecks.add(getHealthCheckURLFromName(healthCheckName)); + + //add all health checks to httpHealthChecks ArrayList + for (String healthCheckName : healthCheckNames) { + httpHealthChecks.add(getHealthCheckURLFromName(healthCheckName)); + } targetPool.setHealthChecks(httpHealthChecks); try { @@ -478,14 +482,14 @@ public void addInstancesToTargetPool(List instancesIdsList, String targe * * @param healthCheckName - name of the health check to be created */ - public void createHealthCheck(String healthCheckName) { + public void createHealthCheck(int port, String healthCheckName) { log.info("Creating health check: " + healthCheckName); HttpHealthCheck httpHealthCheck = new HttpHealthCheck(); httpHealthCheck.setName(healthCheckName); httpHealthCheck.setRequestPath(HEALTH_CHECK_REQUEST_PATH); - httpHealthCheck.setPort(Integer.parseInt(HEALTH_CHECK_PORT)); + httpHealthCheck.setPort(port); httpHealthCheck.setTimeoutSec(Integer.parseInt(HEALTH_CHECK_TIME_OUT_SEC)); httpHealthCheck.setCheckIntervalSec(Integer.parseInt(HEALTH_CHECK_INTERVAL_SEC)); httpHealthCheck.setUnhealthyThreshold(Integer.parseInt(HEALTH_CHECK_UNHEALTHY_THRESHOLD)); From 5ade51f2b058f0d27af252383b196fe04f4685a6 Mon Sep 17 00:00:00 2001 From: asanka sanjaya Date: Sun, 11 Oct 2015 19:05:47 +0530 Subject: [PATCH 217/217] fixing an issue in health check name creation --- .../java/org/apache/stratos/gce/extension/GCELoadBalancer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java index 82c09926a6..e31af5a4b4 100644 --- a/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java +++ b/extensions/load-balancer/gce-extension/src/main/java/org/apache/stratos/gce/extension/GCELoadBalancer.java @@ -405,7 +405,7 @@ private String healthCheckNameCreator(String clusterId, int port) { } //add the port number at the end - healthCheckName.concat("-" + Integer.toString(port)); + healthCheckName = healthCheckName.concat("-" + Integer.toString(port)); return healthCheckName; } } \ No newline at end of file