Skip to content

Commit

Permalink
Merge pull request #56 from ggear/graham-patch-CDH-19550
Browse files Browse the repository at this point in the history
CDH-9550: Whirr-CM to implement reverse proxy service
  • Loading branch information
ggear committed Jun 6, 2014
2 parents 05b981d + 1677396 commit 50abff0
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 32 deletions.
3 changes: 2 additions & 1 deletion cm-ec2.properties
Expand Up @@ -50,6 +50,7 @@ cm-agent,\
\
1 \
cm-java+\
cm-balancer+\
cm-cdh-jobtracker+\
cm-cdh-resourcemanager+\
cm-cdh-jobhistory+\
Expand Down Expand Up @@ -119,7 +120,7 @@ whirr.location-id=ap-southeast-1a
# Define the CM repository version in 'cm$MAJOR_VERSION.$MINOR_VERSION.$VERSION'
# format (major version mandatory, minor and incremental optional), defaults to
# latest available
whirr.env.repocm=cm5.0.0
whirr.env.repocm=cm5.0.1

# Define the CM API version in 'v$MAJOR_VERSION' format, defaults to most
# advanced available from CM version
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -61,7 +61,7 @@
<skipASs>true</skipASs>

<whirr.version>0.9.0-cdh5.0.0</whirr.version>
<cm.version>5.0.0</cm.version>
<cm.version>5.0.1</cm.version>
<log4j.version>1.2.16</log4j.version>
<slf4j.version>1.6.4</slf4j.version>
<hamcrest-all.version>1.1</hamcrest-all.version>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cloudera/whirr/cm/CmConstants.java
Expand Up @@ -17,6 +17,7 @@
*/
package com.cloudera.whirr.cm;

import com.cloudera.whirr.cm.handler.CmBalancerHandler;
import com.cloudera.whirr.cm.handler.CmServerHandler;
import com.cloudera.whirr.cm.server.CmServerConstants;

Expand Down Expand Up @@ -51,6 +52,7 @@ public interface CmConstants extends CmServerConstants {
public static final String CONFIG_WHIRR_INTERNAL_PORT_NAV = CmServerHandler.ROLE + ".port.nav";
public static final String CONFIG_WHIRR_INTERNAL_PORT_HUE = CmServerHandler.ROLE + ".port.hue";
public static final String CONFIG_WHIRR_INTERNAL_PORT_COMMS = CmServerHandler.ROLE + ".port.comms";
public static final String CONFIG_WHIRR_INTERNAL_PORT_BALANCER_IMPALA = CmBalancerHandler.ROLE + ".port.impala";

public static final String CONFIG_WHIRR_NAME_DEFAULT = "whirr";

Expand Down
36 changes: 19 additions & 17 deletions src/main/java/com/cloudera/whirr/cm/CmServerClusterInstance.java
Expand Up @@ -42,6 +42,7 @@
import org.apache.whirr.service.hadoop.VolumeManager;

import com.cloudera.whirr.cm.handler.CmAgentHandler;
import com.cloudera.whirr.cm.handler.CmBalancerHandler;
import com.cloudera.whirr.cm.handler.CmNodeHandler;
import com.cloudera.whirr.cm.handler.CmServerHandler;
import com.cloudera.whirr.cm.handler.cdh.BaseHandlerCmCdh;
Expand Down Expand Up @@ -444,19 +445,22 @@ public static boolean logCluster(CmServerLog logger, String label, Configuration
}
}
}
if (!cluster.getNodes().isEmpty()) {
logger.logOperationInProgressSync(label, "CM NODES");
}
SortedSet<String> cmNodesSorted = new TreeSet<String>();
for (CmServerService cmNode : cluster.getNodes()) {
cmNodesSorted.add(" ssh -o StrictHostKeyChecking=no -i "
+ configuration.getString(ClusterSpec.Property.PRIVATE_KEY_FILE.getConfigName()) + " "
+ configuration.getString(ClusterSpec.Property.CLUSTER_USER.getConfigName()) + "@" + cmNode.getIp());
Set<Instance> balancerInstances = new HashSet<Cluster.Instance>();
for (Instance instance : instances) {
if (instance.getRoles().contains(CmBalancerHandler.ROLE)) {
balancerInstances.add(instance);
}
}
for (String cmNodeSorted : cmNodesSorted) {
logger.logOperationInProgressSync(label, cmNodeSorted);
if (!balancerInstances.isEmpty()) {
logger.logOperationInProgressSync(label, "BALANCER IMPALA");
for (Instance instance : balancerInstances) {
logger.logOperationInProgressSync(
label,
" impala-shell://" + instance.getPrivateIp() + ":"
+ configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_BALANCER_IMPALA));
}
}
logger.logOperationInProgressSync(label, "MANAGER CONSOLE");
logger.logOperationInProgressSync(label, "CONSOLE MANAGER");
if (cluster.getServer() != null) {
logger.logOperationInProgressSync(
label,
Expand All @@ -465,7 +469,7 @@ public static boolean logCluster(CmServerLog logger, String label, Configuration
} else {
logger.logOperationInProgressSync(label, "NO CM SERVER");
}
logger.logOperationInProgressSync(label, "NAVIGATOR CONSOLE");
logger.logOperationInProgressSync(label, "CONSOLE NAVIGATOR");
if (cluster.getServer() != null) {
logger.logOperationInProgressSync(
label,
Expand All @@ -474,7 +478,7 @@ public static boolean logCluster(CmServerLog logger, String label, Configuration
} else {
logger.logOperationInProgressSync(label, "NO NAVIGATOR SERVER");
}
logger.logOperationInProgressSync(label, "HUE CONSOLE");
logger.logOperationInProgressSync(label, "CONSOLE HUE");
if (cluster.getServiceTypes(CmServerServiceType.HUE) != null) {
String hueHost = null;
for (Instance instance : instances) {
Expand All @@ -483,10 +487,8 @@ public static boolean logCluster(CmServerLog logger, String label, Configuration
break;
}
}
logger.logOperationInProgressSync(
label,
" http://" + hueHost + ":"
+ configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_HUE));
logger.logOperationInProgressSync(label,
" http://" + hueHost + ":" + configuration.getString(CmConstants.CONFIG_WHIRR_INTERNAL_PORT_HUE));
} else {
logger.logOperationInProgressSync(label, "NO HUE SERVER");
}
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/com/cloudera/whirr/cm/handler/CmBalancerHandler.java
@@ -0,0 +1,79 @@
/**
* Licensed to Cloudera, Inc. under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Cloudera, Inc. 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 com.cloudera.whirr.cm.handler;

import static org.apache.whirr.RolePredicates.role;
import static org.jclouds.scriptbuilder.domain.Statements.call;

import java.io.IOException;

import org.apache.whirr.Cluster;
import org.apache.whirr.RolePredicates;
import org.apache.whirr.service.ClusterActionEvent;
import org.apache.whirr.service.ClusterActionHandlerSupport;
import org.apache.whirr.service.FirewallManager.Rule;
import org.jclouds.scriptbuilder.domain.Statement;

import com.cloudera.whirr.cm.CmConstants;
import com.cloudera.whirr.cm.CmServerClusterInstance;
import com.cloudera.whirr.cm.handler.cdh.CmCdhImpalaDaemonHandler;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;

public class CmBalancerHandler extends ClusterActionHandlerSupport implements CmConstants {

public static final String ROLE = "cm-balancer";

@Override
public String getRole() {
return ROLE;
}

@Override
protected void beforeStart(ClusterActionEvent event) throws IOException, InterruptedException {
super.beforeStart(event);
final String portBalancerImpala = CmServerClusterInstance.getConfiguration(event.getClusterSpec()).getString(
CmConstants.CONFIG_WHIRR_INTERNAL_PORT_BALANCER_IMPALA);
addStatement(event, call("retry_helpers"));
addStatement(
event,
call(
"configure_cm_balancer",
"-b",
portBalancerImpala,
"-h",
Joiner.on(',').join(
Lists.transform(
Lists.newArrayList(event.getCluster().getInstancesMatching(
RolePredicates.role(CmCdhImpalaDaemonHandler.ROLE))), new Function<Cluster.Instance, String>() {
@Override
public String apply(Cluster.Instance input) {
return input.getPrivateIp() + ":" + portBalancerImpala;
}
}))));
if (CmServerClusterInstance.getConfiguration(event.getClusterSpec()).getBoolean(CONFIG_WHIRR_FIREWALL_ENABLE, true)) {
event.getFirewallManager().addRules(Rule.create().destination(role(getRole())).ports(Integer.parseInt(portBalancerImpala)));
for (Statement portIngressStatement : event.getFirewallManager().getRulesAsStatements()) {
addStatement(event, portIngressStatement);
}
}
}

}
Expand Up @@ -19,6 +19,7 @@ com.cloudera.whirr.cm.handler.CmJavaHandler
com.cloudera.whirr.cm.handler.CmNodeHandler
com.cloudera.whirr.cm.handler.CmAgentHandler
com.cloudera.whirr.cm.handler.CmServerHandler
com.cloudera.whirr.cm.handler.CmBalancerHandler

com.cloudera.whirr.cm.handler.cdh.CmCdhHdfsNameNodeHandler
com.cloudera.whirr.cm.handler.cdh.CmCdhHdfsSecondaryNameNodeHandler
Expand Down
56 changes: 56 additions & 0 deletions src/main/resources/functions/configure_cm_balancer.sh
@@ -0,0 +1,56 @@
#
# Licensed to Cloudera, Inc. under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# Cloudera, Inc. 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 -x

function configure_cm_balancer() {
local OPTIND
local OPTARG
CM_BALANCER_BIND_PORT=9090
CM_BALANCER_HOSTS=
while getopts "b:h:" OPTION; do
case $OPTION in
b)
CM_BALANCER_BIND_PORT="$OPTARG"
;;
h)
CM_BALANCER_HOSTS="$OPTARG"
;;
esac
done
export IFS=,
CM_BALANCER_HOSTS_ARRAY=($CM_BALANCER_HOSTS)
if which dpkg &> /dev/null; then
retry_apt_get update
retry_apt_get -y install haproxy
elif which rpm &> /dev/null; then
retry_yum install -y haproxy
fi
CM_BALANCER_CONFIG='
listen '$(hostname)' :'$CM_BALANCER_BIND_PORT'
mode tcp
option tcplog
balance leastconn
'
for i in "${!CM_BALANCER_HOSTS_ARRAY[@]}"; do
CM_BALANCER_CONFIG=$CM_BALANCER_CONFIG'
server host'$i' '${CM_BALANCER_HOSTS_ARRAY[$i]}
done
echo $CM_BALANCER_CONFIG >> /etc/haproxy/haproxy.cfg
service haproxy start
}
2 changes: 1 addition & 1 deletion src/main/resources/functions/configure_cm_cdh_pre.sh
Expand Up @@ -41,7 +41,7 @@ function configure_cm_cdh_pre() {
if [ "$CM_CDH_ROLE" = "cm-cdh-jobtracker" ]; then
mkdir -p "${CM_CDH_DIRS_ARRAY[0]}/mapreduce/jobtracker/history"
chmod 777 "${CM_CDH_DIRS_ARRAY[0]}/mapreduce/jobtracker/history"
elif [ "$CM_CDH_ROLE" = "cm-cdh-impala" -o "$CM_CDH_ROLE" = "cm-cdh-impalastatestore" -o "$CM_CDH_ROLE" = "cm-cdh-impalacatalog" ]; then
elif [ "$CM_CDH_ROLE" = "cm-cdh-impala" -o "$CM_CDH_ROLE" = "cm-cdh-impalastatestore" -o "$CM_CDH_ROLE" = "cm-cdh-impalacatalog" ]; then
JAVA_HOME=$(grep "export JAVA_HOME" /etc/profile | cut -d= -f 2)
REPOCDH=${REPOCDH:-cdh5}
CDH_MAJOR_VERSION=$(echo $REPOCDH | sed -e 's/cdh\([0-9]\).*/\1/')
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/functions/install_cm.sh
Expand Up @@ -44,16 +44,16 @@ function install_cm() {
if [ $CM_MAJOR_VERSION -ge 4 ]; then
if which dpkg &> /dev/null; then
cat > /etc/apt/sources.list.d/cloudera-$REPOCM.list <<EOF
deb [arch=amd64] $CM_REPO_ROOT/$OS_DISTID/$OS_CODENAME/amd64/cm $OS_CODENAME-cm$CM_MAJOR_VERSION contrib
deb-src $CM_REPO_ROOT/$OS_DISTID/$OS_CODENAME/amd64/cm $OS_CODENAME-cm$CM_MAJOR_VERSION contrib
deb [arch=amd64] $CM_REPO_ROOT/$OS_DISTID/$OS_CODENAME/amd64/cm $OS_CODENAME-cm$CM_VERSION contrib
deb-src $CM_REPO_ROOT/$OS_DISTID/$OS_CODENAME/amd64/cm $OS_CODENAME-cm$CM_VERSION contrib
EOF
curl -s $CM_REPO_ROOT/$OS_DISTID/$OS_CODENAME/amd64/cm/archive.key | apt-key add -
elif which rpm &> /dev/null; then
RHEL_VERSION=$(lsb_release -sr | sed -e 's/\([0-9]*\)\..*/\1/')
cat > /etc/yum.repos.d/cloudera-$REPOCM.repo <<EOF
[cloudera-manager-$REPOCM]
name=Cloudera Manager, Version $CM_VERSION
baseurl=$CM_REPO_ROOT/redhat/$RHEL_VERSION/\$basearch/cm/$CM_MAJOR_VERSION/
baseurl=$CM_REPO_ROOT/redhat/$RHEL_VERSION/\$basearch/cm/$CM_VERSION/
gpgkey=$CM_REPO_ROOT/redhat/$RHEL_VERSION/\$basearch/cm/RPM-GPG-KEY-cloudera
gpgcheck=1
EOF
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/whirr-cm-default.properties
Expand Up @@ -187,6 +187,8 @@ whirr.cm.config.navigator.navigator_database_name=cm_navr
database.port.mysql=3306
database.port.postgres=5432

cm-balancer.port.impala=21000

cm-server.port.web=7180
cm-server.port.nav=7187
cm-server.port.hue=8888
Expand Down
Expand Up @@ -66,18 +66,19 @@
public class CmServerHandlerTest extends BaseTestHandler {

private static final int WHIRR_INSTANCE_TEMPLATE_NUM_SLAVES = 3;
private static final String[] WHIRR_INSTANCE_TEMPLATE_ROLES_MASTER = { CmCdhHdfsNameNodeHandler.ROLE,
CmCdhHdfsSecondaryNameNodeHandler.ROLE, CmCdhHueServerHandler.ROLE, CmCdhHueBeeswaxServerHandler.ROLE,
CmCdhMapReduceJobTrackerHandler.ROLE, CmCdhSparkMasterHandler.ROLE, CmCdhHBaseMasterHandler.ROLE,
CmCdhHiveMetaStoreHandler.ROLE, CmCdhImpalaStateStoreHandler.ROLE, CmCdhImpalaCatalogServerHandler.ROLE,
CmCdhOozieServerHandler.ROLE, CmCdhHiveServer2Handler.ROLE, CmCdhHiveHCatalogHandler.ROLE,
CmCdhSqoopServerHandler.ROLE, CmCdhSolrServerHandler.ROLE, CmCdhHdfsHttpFsHandler.ROLE };
private static final String[] WHIRR_INSTANCE_TEMPLATE_ROLES_MASTER = { CmBalancerHandler.ROLE,
CmCdhHdfsNameNodeHandler.ROLE, CmCdhHdfsSecondaryNameNodeHandler.ROLE, CmCdhHueServerHandler.ROLE,
CmCdhHueBeeswaxServerHandler.ROLE, CmCdhMapReduceJobTrackerHandler.ROLE, CmCdhSparkMasterHandler.ROLE,
CmCdhHBaseMasterHandler.ROLE, CmCdhHiveMetaStoreHandler.ROLE, CmCdhImpalaStateStoreHandler.ROLE,
CmCdhImpalaCatalogServerHandler.ROLE, CmCdhOozieServerHandler.ROLE, CmCdhHiveServer2Handler.ROLE,
CmCdhHiveHCatalogHandler.ROLE, CmCdhSqoopServerHandler.ROLE, CmCdhSolrServerHandler.ROLE,
CmCdhHdfsHttpFsHandler.ROLE };
private static final String[] WHIRR_INSTANCE_TEMPLATE_ROLES_SLAVES = { CmCdhHdfsDataNodeHandler.ROLE,
CmCdhMapReduceTaskTrackerHandler.ROLE, CmCdhSparkWorkerHandler.ROLE, CmCdhZookeeperServerHandler.ROLE,
CmCdhHBaseRegionServerHandler.ROLE, CmCdhImpalaDaemonHandler.ROLE, CmCdhFlumeAgentHandler.ROLE,
CmCdhSolrIndexerHBaseHandler.ROLE, CmCdhHdfsHttpFsHandler.ROLE };
private static final int WHIRR_INSTANCE_TEMPLATE_NUM_ROLES = WHIRR_INSTANCE_TEMPLATE_ROLES_MASTER.length
+ WHIRR_INSTANCE_TEMPLATE_NUM_SLAVES * WHIRR_INSTANCE_TEMPLATE_ROLES_SLAVES.length;
+ WHIRR_INSTANCE_TEMPLATE_NUM_SLAVES * WHIRR_INSTANCE_TEMPLATE_ROLES_SLAVES.length - 1;
private static String WHIRR_INSTANCE_TEMPLATE_ALL = "1 " + CmServerHandler.ROLE + "+" + CmAgentHandler.ROLE + ",1 "
+ CmAgentHandler.ROLE;
static {
Expand Down
Expand Up @@ -12,8 +12,8 @@
public class CmServerSmokeSuiteIT extends CmServerSmokeIT {

public static String[] OS_VERSION_MATRIX = new String[] { "centos", "ubuntu" };
public static String[][] CM_VERSION_MATRIX = new String[][] { { "cm5.0.0", "v6", "cdh5" },
{ "cm5.0.0", "v6", "cdh4" } };
public static String[][] CM_VERSION_MATRIX = new String[][] { { "cm5.0.0", "v6", "cdh5" }, { "cm5", "v6", "cdh5" },
{ "cm5", "v6", "cdh4" } };

@Parameters
public static Collection<String[]> data() {
Expand Down

0 comments on commit 50abff0

Please sign in to comment.