You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sm...@apache.org on 2014/01/16 08:23:50 UTC
git commit: AMBARI-4308. Add optional parameter options and minor
fixes to custom action support
Updated Branches:
refs/heads/trunk 067b1b60c -> ad77a8afd
AMBARI-4308. Add optional parameter options and minor fixes to custom action support
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ad77a8af
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ad77a8af
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ad77a8af
Branch: refs/heads/trunk
Commit: ad77a8afd5d914c9e5801110abc0e524070946a0
Parents: 067b1b6
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Wed Jan 15 23:23:23 2014 -0800
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Wed Jan 15 23:23:23 2014 -0800
----------------------------------------------------------------------
ambari-agent/conf/unix/ambari-agent.ini | 2 +-
ambari-agent/pom.xml | 2 +-
.../controller/AmbariActionExecutionHelper.java | 13 +++-
.../resources/Ambari-DDL-Postgres-CREATE.sql | 4 ++
.../custom_actions/ambari_hdfs_rebalance.py | 58 ++++++++++++++++++
.../resources/custom_actions/hdfs_rebalance.py | 63 --------------------
.../AmbariManagementControllerTest.java | 3 +-
7 files changed, 75 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad77a8af/ambari-agent/conf/unix/ambari-agent.ini
----------------------------------------------------------------------
diff --git a/ambari-agent/conf/unix/ambari-agent.ini b/ambari-agent/conf/unix/ambari-agent.ini
index e663a25..95944d2 100644
--- a/ambari-agent/conf/unix/ambari-agent.ini
+++ b/ambari-agent/conf/unix/ambari-agent.ini
@@ -35,7 +35,7 @@ facter_home=/usr/lib/ambari-agent/lib/facter-1.6.10
timeout_seconds = 600
[python]
-custom_actions_dir = /var/lib/ambari-agent/resources
+custom_actions_dir = /var/lib/ambari-agent/resources/custom_actions
[command]
maxretries=2
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad77a8af/ambari-agent/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-agent/pom.xml b/ambari-agent/pom.xml
index 3be0a1e..d037d46 100644
--- a/ambari-agent/pom.xml
+++ b/ambari-agent/pom.xml
@@ -346,7 +346,7 @@
</mapping>
<mapping>
<!-- custom actions root-->
- <directory>/var/lib/ambari-agent/resources</directory>
+ <directory>/var/lib/ambari-agent/resources/custom_actions</directory>
<filemode>755</filemode>
<username>root</username>
<groupname>root</groupname>
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad77a8af/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
index 4e32f2a..d985d9f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariActionExecutionHelper.java
@@ -150,9 +150,16 @@ public class AmbariActionExecutionHelper {
if (actionDef.getInputs() != null) {
String[] inputs = actionDef.getInputs().split(",");
for (String input : inputs) {
- if (!input.trim().isEmpty() && !actionRequest.getParameters().containsKey(input.trim())) {
- throw new AmbariException("Action " + actionRequest.getActionName() + " requires input '" +
- input.trim() + "' that is not provided.");
+ String inputName = input.trim();
+ if (!inputName.isEmpty()) {
+ boolean mandatory = true;
+ if (inputName.startsWith("[") && inputName.endsWith("]")) {
+ mandatory = false;
+ }
+ if (mandatory && !actionRequest.getParameters().containsKey(inputName)) {
+ throw new AmbariException("Action " + actionRequest.getActionName() + " requires input '" +
+ input.trim() + "' that is not provided.");
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad77a8af/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index ff2b480..5228121 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -362,6 +362,10 @@ create index idx_qrtz_ft_tg on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_GRO
commit;
+-- Insert data into the table
+INSERT INTO ambari.action (action_name, action_type, inputs, target_service, target_component, default_timeout, description, target_type)
+ SELECT 'ambari_hdfs_rebalance', 'SYSTEM', 'threshold,[principal],[keytab]', 'HDFS', 'NAMENODE', 600, 'HDFS Rebalance', 'ANY';
+
-- ambari log4j DDL
--------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad77a8af/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalance.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalance.py b/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalance.py
new file mode 100644
index 0000000..710c9c6
--- /dev/null
+++ b/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalance.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+"""
+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.
+
+Ambari Agent
+
+"""
+
+from resource_management import *
+
+
+class HdfsRebalance(Script):
+ def actionexecute(self, env):
+ config = Script.get_config()
+
+ hdfs_user = config['configurations']['global']['hdfs_user']
+ conf_dir = "/etc/hadoop/conf"
+
+ security_enabled = config['configurations']['global']['security_enabled']
+
+ threshold = config['commandParams']['threshold']
+
+ if security_enabled:
+ kinit_path_local = functions.get_kinit_path(
+ [default('kinit_path_local', None), "/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
+ principal = config['commandParams']['principal']
+ keytab = config['commandParams']['keytab']
+ Execute(format("{kinit_path_local} -kt {keytab} {principal}"))
+
+ ExecuteHadoop(format('balancer -threshold {threshold}'),
+ user=hdfs_user,
+ conf_dir=conf_dir,
+ logoutput=True
+ )
+
+ structured_output_example = {
+ 'result': 'Rebalancer completed.'
+ }
+
+ self.put_structured_out(structured_output_example)
+
+
+if __name__ == "__main__":
+ HdfsRebalance().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad77a8af/ambari-server/src/main/resources/custom_actions/hdfs_rebalance.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/hdfs_rebalance.py b/ambari-server/src/main/resources/custom_actions/hdfs_rebalance.py
deleted file mode 100644
index 6426855..0000000
--- a/ambari-server/src/main/resources/custom_actions/hdfs_rebalance.py
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/env python
-"""
-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.
-
-Ambari Agent
-
-"""
-
-from resource_management import *
-import os
-import json
-
-
-class HdfsRebalance(Script):
- def actionexecute(self, env):
-
- config = Script.get_config()
-
- hdfs_user = config['configurations']['global']['hdfs_user']
- conf_dir = config['configurations']['global']['hadoop_conf_dir']
-
- security_enabled = config['configurations']['global']['security_enabled']
- kinit_path_local = functions.get_kinit_path(
- [default('kinit_path_local'), "/usr/bin", "/usr/kerberos/bin", "/usr/sbin"])
-
- threshold = config['commandParams']['threshold']
- principal = config['commandParams']['principal']
- keytab = config['commandParams']['keytab']
-
- if security_enabled:
- Execute(format("{kinit_path_local} -kt {keytab} {principal}"))
-
- ExecuteHadoop(format('balancer -threshold {threshold}'),
- user=hdfs_user,
- conf_dir=conf_dir
- )
-
- structured_output_example = {
- 'user' : hdfs_user,
- 'conf_dir' : conf_dir,
- 'principal' : principal,
- 'keytab' : keytab
- }
-
- self.put_structured_out(structured_output_example)
-
-if __name__ == "__main__":
-
- HdfsRebalance().execute()
http://git-wip-us.apache.org/repos/asf/ambari/blob/ad77a8af/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
index 82a66e1..8f92c09 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
@@ -3663,7 +3663,7 @@ public class AmbariManagementControllerTest {
hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost("h2").persist();
controller.getActionManager().createActionDefinition(
- "a1", ActionType.SYSTEM, "test", "Does file exist", "", "",
+ "a1", ActionType.SYSTEM, "test,[optional1]", "Does file exist", "", "",
TargetHostType.SPECIFIC, Short.valueOf("100"));
controller.getActionManager().createActionDefinition(
@@ -3676,7 +3676,6 @@ public class AmbariManagementControllerTest {
Map<String, String> requestProperties = new HashMap<String, String>();
requestProperties.put(REQUEST_CONTEXT_PROPERTY, "Called from a test");
- long now = System.currentTimeMillis();
ArrayList<String> hosts = new ArrayList<String>() {{add("h1");}};