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/22 20:26:22 UTC
[1/2] AMBARI-4365. Action definitions should be provided as
declarative resources - read from XML files
Updated Branches:
refs/heads/trunk 241f059cb -> 8e8a9a47f
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionXml.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionXml.java b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionXml.java
new file mode 100644
index 0000000..829c4ba
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionXml.java
@@ -0,0 +1,42 @@
+/**
+ * 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.ambari.server.customactions;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * The elements within a service's configuration file.
+ */
+@XmlRootElement(name="actionDefinitions")
+public class ActionDefinitionXml {
+
+ @XmlElement(name="actionDefinition")
+ private List<ActionDefinitionSpec> actionDefinitions = new ArrayList<ActionDefinitionSpec>();
+
+ /**
+ * @return the list of properties contained in a configuration file
+ */
+ public List<ActionDefinitionSpec> actionDefinitions() {
+ return actionDefinitions;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAO.java
deleted file mode 100644
index df1f71a..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAO.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.ambari.server.orm.dao;
-
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.persist.Transactional;
-import org.apache.ambari.server.orm.entities.ActionEntity;
-
-import javax.persistence.EntityManager;
-import javax.persistence.NoResultException;
-import javax.persistence.TypedQuery;
-import java.util.List;
-
-public class ActionDefinitionDAO {
-
- @Inject
- Provider<EntityManager> entityManagerProvider;
-
- @Transactional
- public ActionEntity findByPK(String actionName) {
- return entityManagerProvider.get().find(ActionEntity.class, actionName);
- }
-
- @Transactional
- public List<ActionEntity> findAll() {
- TypedQuery<ActionEntity> query = entityManagerProvider.get().createNamedQuery("allActions",
- ActionEntity.class);
- try {
- return query.getResultList();
- } catch (NoResultException ignored) {
- }
- return null;
- }
-
- @Transactional
- public void create(ActionEntity actionDefinition) {
- entityManagerProvider.get().persist(actionDefinition);
- }
-
- @Transactional
- public ActionEntity merge(ActionEntity actionDefinition) {
- return entityManagerProvider.get().merge(actionDefinition);
- }
-
- @Transactional
- public void remove(ActionEntity actionDefinition) {
- entityManagerProvider.get().remove(merge(actionDefinition));
- }
-
- @Transactional
- public void removeByPK(String actionName) {
- remove(findByPK(actionName));
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionEntity.java
deleted file mode 100644
index 7f1d031..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ActionEntity.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * 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.ambari.server.orm.entities;
-
-import org.apache.ambari.server.actionmanager.ActionType;
-import org.apache.ambari.server.actionmanager.TargetHostType;
-
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.EnumType;
-import javax.persistence.Enumerated;
-import javax.persistence.Id;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-
-@NamedQueries({
- @NamedQuery(name = "allActions", query =
- "SELECT actions " +
- "FROM ActionEntity actions")
-})
-@Table(name = "action")
-@Entity
-public class ActionEntity {
-
- @Id
- @Column(name = "action_name")
- private String actionName;
-
- @Column(name = "action_type")
- @Enumerated(EnumType.STRING)
- private ActionType actionType = ActionType.DISABLED;
-
- @Column(name = "inputs")
- @Basic
- private String inputs;
-
- @Column(name = "target_service")
- @Basic
- private String targetService;
-
- @Column(name = "target_component")
- @Basic
- private String targetComponent;
-
- @Column(name = "description", nullable = false)
- @Basic
- private String description = "";
-
- @Column(name = "target_type", nullable = false)
- @Enumerated(EnumType.STRING)
- private TargetHostType targetType = TargetHostType.ANY;
-
- @Basic
- @Column(name = "default_timeout", nullable = false)
- private Short defaultTimeout = 600;
-
- public String getActionName() {
- return actionName;
- }
-
- public void setActionName(String actionName) {
- this.actionName = actionName;
- }
-
- public ActionType getActionType() {
- return actionType;
- }
-
- public void setActionType(ActionType actionType) {
- this.actionType = actionType;
- }
-
- public String getInputs() {
- return inputs;
- }
-
- public void setInputs(String inputs) {
- this.inputs = inputs;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public TargetHostType getTargetType() {
- return targetType;
- }
-
- public void setTargetType(TargetHostType targetType) {
- this.targetType = targetType;
- }
-
- public String getTargetService() {
- return targetService;
- }
-
- public void setTargetService(String targetService) {
- this.targetService = targetService;
- }
-
- public String getTargetComponent() {
- return targetComponent;
- }
-
- public void setTargetComponent(String targetComponent) {
- this.targetComponent = targetComponent;
- }
-
- public Short getDefaultTimeout() {
- return defaultTimeout;
- }
-
- public void setDefaultTimeout(Short defaultTimeout) {
- this.defaultTimeout = defaultTimeout;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- ActionEntity that = (ActionEntity) o;
-
- if (actionName != null ? !actionName.equals(that.actionName) : that.actionName != null) {
- return false;
- }
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = actionName != null ? actionName.hashCode() : 0;
- return result;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index 561ac73..4f6068e 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -55,7 +55,6 @@ CREATE TABLE configgroup (group_id BIGINT, cluster_id BIGINT NOT NULL, group_nam
CREATE TABLE configgrouphostmapping (config_group_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, PRIMARY KEY(config_group_id, host_name));
CREATE TABLE requestschedule (schedule_id bigint, cluster_id BIGINT NOT NULL, description varchar(255), status varchar(255), batch_separation_seconds smallint, batch_toleration_limit smallint, create_user varchar(255), create_timestamp bigint, update_user varchar(255), update_timestamp bigint, minutes varchar(10), hours varchar(10), days_of_month varchar(10), month varchar(10), day_of_week varchar(10), yearToSchedule varchar(10), startTime varchar(50), endTime varchar(50), last_execution_status varchar(255), PRIMARY KEY(schedule_id));
CREATE TABLE requestschedulebatchrequest (schedule_id bigint, batch_id bigint, request_id bigint, request_type varchar(255), request_uri varchar(1024), request_body LONGBLOB, request_status varchar(255), return_code smallint, return_message varchar(2000), PRIMARY KEY(schedule_id, batch_id));
-CREATE TABLE action (action_name VARCHAR(255) NOT NULL, action_type VARCHAR(32) NOT NULL, inputs VARCHAR(1000), target_service VARCHAR(255), target_component VARCHAR(255), default_timeout SMALLINT NOT NULL, description VARCHAR(1000), target_type VARCHAR(32), PRIMARY KEY (action_name));
ALTER TABLE users ADD CONSTRAINT UNQ_users_0 UNIQUE (user_name, ldap_user);
ALTER TABLE clusterconfig ADD CONSTRAINT FK_clusterconfig_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index 5aa356a..e125e2a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -43,7 +43,6 @@ CREATE TABLE ambari_sequences (sequence_name VARCHAR2(50) NOT NULL, value NUMBER
CREATE TABLE configgroup (group_id NUMBER(19), cluster_id NUMBER(19) NOT NULL, group_name VARCHAR2(255) NOT NULL, tag VARCHAR2(1024) NOT NULL, description VARCHAR2(1024), create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY(group_id));
CREATE TABLE confgroupclusterconfigmapping (config_group_id NUMBER(19) NOT NULL, cluster_id NUMBER(19) NOT NULL, config_type VARCHAR2(255) NOT NULL, version_tag VARCHAR2(255) NOT NULL, user_name VARCHAR2(255) DEFAULT '_db', create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY(config_group_id, cluster_id, config_type));
CREATE TABLE configgrouphostmapping (config_group_id NUMBER(19) NOT NULL, host_name VARCHAR2(255) NOT NULL, PRIMARY KEY(config_group_id, host_name));
-CREATE TABLE action (action_name VARCHAR2(255) NOT NULL, action_type VARCHAR2(255) NOT NULL, inputs VARCHAR2(1024), target_service VARCHAR2(255), target_component VARCHAR2(255), default_timeout NUMBER(10) NOT NULL, description VARCHAR2(1024), target_type VARCHAR2(255), PRIMARY KEY (action_name));
CREATE TABLE requestschedule (schedule_id NUMBER(19), cluster_id NUMBER(19) NOT NULL, description VARCHAR2(255), status VARCHAR2(255), batch_separation_seconds smallint, batch_toleration_limit smallint, create_user VARCHAR2(255), create_timestamp NUMBER(19), update_user VARCHAR2(255), update_timestamp NUMBER(19), minutes VARCHAR2(10), hours VARCHAR2(10), days_of_month VARCHAR2(10), month VARCHAR2(10), day_of_week VARCHAR2(10), yearToSchedule VARCHAR2(10), startTime VARCHAR2(50), endTime VARCHAR2(50), last_execution_status VARCHAR2(255), PRIMARY KEY(schedule_id));
CREATE TABLE requestschedulebatchrequest (schedule_id NUMBER(19), batch_id NUMBER(19), request_id NUMBER(19), request_type VARCHAR2(255), request_uri VARCHAR2(1024), request_body BLOB, request_status VARCHAR2(255), return_code smallint, return_message VARCHAR2(2000), PRIMARY KEY(schedule_id, batch_id));
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/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 63c5f4b..f15ccd1 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -110,9 +110,6 @@ GRANT ALL PRIVILEGES ON TABLE ambari.confgroupclusterconfigmapping TO :username;
CREATE TABLE ambari.configgrouphostmapping (config_group_id BIGINT NOT NULL, host_name VARCHAR(255) NOT NULL, PRIMARY KEY(config_group_id, host_name));
GRANT ALL PRIVILEGES ON TABLE ambari.configgrouphostmapping TO :username;
-CREATE TABLE ambari.action (action_name VARCHAR(255) NOT NULL, action_type VARCHAR(32) NOT NULL, inputs VARCHAR(1000), target_service VARCHAR(255), target_component VARCHAR(255), default_timeout SMALLINT NOT NULL, description VARCHAR(1000), target_type VARCHAR(32), PRIMARY KEY (action_name));
-GRANT ALL PRIVILEGES ON TABLE ambari.action TO :username;
-
CREATE TABLE ambari.requestschedule (schedule_id bigint, cluster_id bigint NOT NULL, description varchar(255), status varchar(255), batch_separation_seconds smallint, batch_toleration_limit smallint, create_user varchar(255), create_timestamp bigint, update_user varchar(255), update_timestamp bigint, minutes varchar(10), hours varchar(10), days_of_month varchar(10), month varchar(10), day_of_week varchar(10), yearToSchedule varchar(10), startTime varchar(50), endTime varchar(50), last_execution_status varchar(255), PRIMARY KEY(schedule_id));
GRANT ALL PRIVILEGES ON TABLE ambari.requestschedule TO :username;
@@ -361,10 +358,6 @@ create index idx_qrtz_ft_jg on ambari.qrtz_fired_triggers(SCHED_NAME,JOB_GROUP);
create index idx_qrtz_ft_t_g on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_NAME,TRIGGER_GROUP);
create index idx_qrtz_ft_tg on ambari.qrtz_fired_triggers(SCHED_NAME,TRIGGER_GROUP);
--- 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/8e8a9a47/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml b/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml
new file mode 100644
index 0000000..ee07900
--- /dev/null
+++ b/ambari-server/src/main/resources/custom_action_definitions/system_action_definitions.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="action_definition.xsl"?>
+
+<!--
+ 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.
+-->
+
+<actionDefinitions>
+ <actionDefinition>
+ <actionName>ambari_hdfs_rebalancer</actionName>
+ <actionType>SYSTEM</actionType>
+ <inputs>threshold,[principal],[keytab]</inputs>
+ <targetService>HDFS</targetService>
+ <targetComponent>NAMENODE</targetComponent>
+ <defaultTimeout>600</defaultTimeout>
+ <description>HDFS Rebalance</description>
+ <targetType>ANY</targetType>
+ </actionDefinition>
+</actionDefinitions>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/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
deleted file mode 100644
index 710c9c6..0000000
--- a/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalance.py
+++ /dev/null
@@ -1,58 +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 *
-
-
-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/8e8a9a47/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalancer.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalancer.py b/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalancer.py
new file mode 100644
index 0000000..710c9c6
--- /dev/null
+++ b/ambari-server/src/main/resources/custom_actions/ambari_hdfs_rebalancer.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/8e8a9a47/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
index 19768e7..53b2b7a 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
+++ b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql
@@ -43,7 +43,6 @@ INSERT INTO ambari_sequences(sequence_name, value) values ('configgroup_id_seq',
CREATE TABLE configgroup (group_id NUMBER(19), cluster_id NUMBER(19) NOT NULL, group_name VARCHAR2(255) NOT NULL, tag VARCHAR2(1024) NOT NULL, description VARCHAR2(1024), create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY(group_id), UNIQUE(group_name));
CREATE TABLE confgroupclusterconfigmapping (config_group_id NUMBER(19) NOT NULL, cluster_id NUMBER(19) NOT NULL, config_type VARCHAR2(255) NOT NULL, version_tag VARCHAR2(255) NOT NULL, user_name VARCHAR2(255) DEFAULT '_db', create_timestamp NUMBER(19) NOT NULL, PRIMARY KEY(config_group_id, cluster_id, config_type));
CREATE TABLE configgrouphostmapping (config_group_id NUMBER(19) NOT NULL, host_name VARCHAR2(255) NOT NULL, PRIMARY KEY(config_group_id, host_name));
-CREATE TABLE action (action_name VARCHAR2(255) NOT NULL, action_type VARCHAR2(255) NOT NULL, inputs VARCHAR2(1024), target_service VARCHAR2(255), target_component VARCHAR2(255), default_timeout NUMBER(10) NOT NULL, description VARCHAR2(1024), target_type VARCHAR2(255), PRIMARY KEY (action_name));
ALTER TABLE configgroup ADD CONSTRAINT FK_configgroup_cluster_id FOREIGN KEY (cluster_id) REFERENCES clusters (cluster_id);
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
index bb02aba..6ebb61b 100644
--- a/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
+++ b/ambari-server/src/main/resources/upgrade/ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql
@@ -132,11 +132,6 @@ ALTER TABLE ambari.confgroupclusterconfigmapping ADD CONSTRAINT FK_confgroupclus
ALTER TABLE ambari.configgrouphostmapping ADD CONSTRAINT FK_configgrouphostmapping_configgroup_id FOREIGN KEY (config_group_id) REFERENCES ambari.configgroup (group_id);
ALTER TABLE ambari.configgrouphostmapping ADD CONSTRAINT FK_configgrouphostmapping_host_name FOREIGN KEY (host_name) REFERENCES ambari.hosts (host_name);
--- required for custom action
-CREATE TABLE ambari.action (action_name VARCHAR(255) NOT NULL, action_type VARCHAR(32) NOT NULL, inputs VARCHAR(1000),
-target_service VARCHAR(255), target_component VARCHAR(255), default_timeout SMALLINT NOT NULL, description VARCHAR(1000), target_type VARCHAR(32), PRIMARY KEY (action_name));
-GRANT ALL PRIVILEGES ON TABLE ambari.action TO :username;
-
-- add decommission state
ALTER TABLE ambari.hostcomponentdesiredstate ADD COLUMN admin_state VARCHAR(32);
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
index c09c8bb..d052673 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionDBAccessorImpl.java
@@ -62,7 +62,6 @@ public class TestActionDBAccessorImpl {
private Injector injector;
ActionDBAccessor db;
ActionManager am;
- CustomActionDBAccessor cdb;
@Inject
private Clusters clusters;
@@ -80,10 +79,9 @@ public class TestActionDBAccessorImpl {
clusters.getHost(hostName).persist();
clusters.addCluster(clusterName);
db = injector.getInstance(ActionDBAccessorImpl.class);
- cdb = injector.getInstance(CustomActionDBAccessor.class);
am = new ActionManager(5000, 1200000, new ActionQueue(), clusters, db,
- new HostsMap((String) null), null, injector.getInstance(UnitOfWork.class), cdb,
+ new HostsMap((String) null), null, injector.getInstance(UnitOfWork.class),
injector.getInstance(RequestFactory.class), null);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
index 648e935..b749ea0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionManager.java
@@ -84,7 +84,7 @@ public class TestActionManager {
public void testActionResponse() {
ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(),
- clusters, db, new HostsMap((String) null), null, unitOfWork, null,
+ clusters, db, new HostsMap((String) null), null, unitOfWork,
injector.getInstance(RequestFactory.class), null);
populateActionDB(db, hostname);
Stage stage = db.getAllStages(requestId).get(0);
@@ -125,7 +125,7 @@ public class TestActionManager {
public void testLargeLogs() {
ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(),
- clusters, db, new HostsMap((String) null), null, unitOfWork, null,
+ clusters, db, new HostsMap((String) null), null, unitOfWork,
injector.getInstance(RequestFactory.class), null);
populateActionDB(db, hostname);
Stage stage = db.getAllStages(requestId).get(0);
@@ -215,7 +215,7 @@ public class TestActionManager {
replay(queue, db, clusters);
- ActionManager manager = new ActionManager(0, 0, queue, clusters, db, null, null, unitOfWork, null,
+ ActionManager manager = new ActionManager(0, 0, queue, clusters, db, null, null, unitOfWork,
injector.getInstance(RequestFactory.class), null);
assertSame(listStages, manager.getActions(requestId));
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
index 5925fbb..696d2a6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java
@@ -466,7 +466,7 @@ public class TestActionScheduler {
ActionManager am = new ActionManager(
2, 2, aq, fsm, db, new HostsMap((String) null),
- new ServerActionManagerImpl(fsm), unitOfWork, null, requestFactory, conf);
+ new ServerActionManagerImpl(fsm), unitOfWork, requestFactory, conf);
scheduler.doWork();
@@ -538,7 +538,7 @@ public class TestActionScheduler {
ActionManager am = new ActionManager(
2, 2, aq, fsm, db, new HostsMap((String) null),
- new ServerActionManagerImpl(fsm), unitOfWork, null,
+ new ServerActionManagerImpl(fsm), unitOfWork,
requestFactory, conf);
scheduler.doWork();
@@ -643,7 +643,7 @@ public class TestActionScheduler {
new HostsMap((String) null), new ServerActionManagerImpl(fsm),
unitOfWork, conf);
ActionManager am = new ActionManager(
- 2, 2, aq, fsm, db, new HostsMap((String) null), new ServerActionManagerImpl(fsm), unitOfWork, null, requestFactory, conf);
+ 2, 2, aq, fsm, db, new HostsMap((String) null), new ServerActionManagerImpl(fsm), unitOfWork, requestFactory, conf);
scheduler.doWork();
@@ -790,7 +790,7 @@ public class TestActionScheduler {
new HostsMap((String) null), new ServerActionManagerImpl(fsm),
unitOfWork, conf);
ActionManager am = new ActionManager(
- 2, 10000, aq, fsm, db, new HostsMap((String) null), new ServerActionManagerImpl(fsm), unitOfWork, null, requestFactory, conf);
+ 2, 10000, aq, fsm, db, new HostsMap((String) null), new ServerActionManagerImpl(fsm), unitOfWork, requestFactory, conf);
scheduler.doWork();
@@ -962,7 +962,7 @@ public class TestActionScheduler {
new HostsMap((String) null),
new ServerActionManagerImpl(fsm), unitOfWork, conf);
ActionManager am = new ActionManager(
- 2, 2, aq, fsm, db, new HostsMap((String) null), new ServerActionManagerImpl(fsm), unitOfWork, null, requestFactory, conf);
+ 2, 2, aq, fsm, db, new HostsMap((String) null), new ServerActionManagerImpl(fsm), unitOfWork, requestFactory, conf);
scheduler.doWork();
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestCustomActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestCustomActionDBAccessorImpl.java b/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestCustomActionDBAccessorImpl.java
deleted file mode 100644
index 55d2021..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestCustomActionDBAccessorImpl.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * 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.ambari.server.actionmanager;
-
-import com.google.inject.Guice;
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
-import junit.framework.Assert;
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.dao.ActionDefinitionDAO;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.List;
-
-public class TestCustomActionDBAccessorImpl {
- private static final Logger log = LoggerFactory.getLogger(TestCustomActionDBAccessorImpl.class);
- CustomActionDBAccessor db;
- private Injector injector;
- @Inject
- private ActionDefinitionDAO actions;
-
- @Before
- public void setup() throws AmbariException {
- injector = Guice.createInjector(new InMemoryDefaultTestModule());
- injector.getInstance(GuiceJpaInitializer.class);
- injector.injectMembers(this);
- db = injector.getInstance(CustomActionDBAccessorImpl.class);
- }
-
- @After
- public void tearDown() throws AmbariException {
- injector.getInstance(PersistService.class).stop();
- }
-
- @Test
- public void testActionLifeCycle() throws Exception {
- try {
- db.createActionDefinition(
- "a1", ActionType.SYSTEM, "a,b,,c", "desc", TargetHostType.ANY, "HDFS", "DATANODE", Short.parseShort("70"));
- Assert.fail("createActionDefinition must throw exception.");
- } catch (AmbariException ex) {
- Assert.assertTrue(ex.getMessage().contains("Empty parameter cannot be specified as an input parameter"));
- }
-
- db.createActionDefinition(
- "a1", ActionType.SYSTEM, "fileName", "desc", TargetHostType.ANY, "HDFS", "DATANODE", Short.parseShort("70"));
- ActionDefinition ad = db.getActionDefinition("a1");
- assertContent(
- ad, "a1", ActionType.SYSTEM, "fileName", "desc", TargetHostType.ANY, "HDFS", "DATANODE", Short.parseShort("70"));
-
- ad = db.getActionDefinition("a2");
- Assert.assertNull(ad);
-
- try {
- db.createActionDefinition(
- "a1", ActionType.SYSTEM, "fileName", "desc", TargetHostType.ANY, "HDFS", "DATANODE", Short.parseShort("70"));
- Assert.fail("updateActionDefinition must throw exception.");
- } catch (AmbariException ex) {
- Assert.assertTrue(ex.getMessage().contains("Action definition a1 already exists"));
- }
-
- db.createActionDefinition(
- "a2", ActionType.SYSTEM, "dirName", "desc2", TargetHostType.ANY, "HDFS", "DATANODE", Short.parseShort("70"));
- ad = db.getActionDefinition("a2");
- assertContent(ad, "a2", ActionType.SYSTEM, "dirName", "desc2", TargetHostType.ANY,
- "HDFS", "DATANODE", Short.parseShort("70"));
-
- db.updateActionDefinition("a2", ActionType.USER, "desc3", TargetHostType.ALL, Short.parseShort("100"));
- ad = db.getActionDefinition("a2");
- assertContent(ad, "a2", ActionType.USER, "dirName", "desc3", TargetHostType.ALL,
- "HDFS", "DATANODE", Short.parseShort("100"));
-
- List<ActionDefinition> ads = db.getActionDefinitions();
- Assert.assertEquals(2, ads.size());
-
- db.deleteActionDefinition("a1");
- ads = db.getActionDefinitions();
- Assert.assertEquals(1, ads.size());
-
- db.deleteActionDefinition("a1");
-
- try {
- db.updateActionDefinition("a1", ActionType.USER, "desc3", TargetHostType.ALL, Short.parseShort("100"));
- Assert.fail("updateActionDefinition must throw exception.");
- } catch (AmbariException ex) {
- Assert.assertTrue(ex.getMessage().contains("Action definition a1 does not exist"));
- }
- }
-
- private void assertContent(ActionDefinition ad, String actionName, ActionType actionType, String inputs,
- String description, TargetHostType targetType, String serviceType, String componentType,
- Short defaultTimeout) {
- Assert.assertEquals(actionName, ad.getActionName());
- Assert.assertEquals(actionType, ad.getActionType());
- Assert.assertEquals(description, ad.getDescription());
- Assert.assertEquals(inputs, ad.getInputs());
- Assert.assertEquals(serviceType, ad.getTargetService());
- Assert.assertEquals(componentType, ad.getTargetComponent());
- Assert.assertEquals(defaultTimeout, ad.getDefaultTimeout());
- Assert.assertEquals(targetType, ad.getTargetType());
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
index 7b07062..afec756 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
@@ -413,7 +413,7 @@ public class TestHeartbeatHandler {
clusters.addCluster(DummyCluster);
ActionDBAccessor db = injector.getInstance(ActionDBAccessorImpl.class);
ActionManager am = new ActionManager(5000, 1200000, new ActionQueue(), clusters, db,
- new HostsMap((String) null), null, unitOfWork, null, injector.getInstance(RequestFactory.class), null);
+ new HostsMap((String) null), null, unitOfWork, injector.getInstance(RequestFactory.class), null);
populateActionDB(db, DummyHostname1);
Stage stage = db.getAllStages(requestId).get(0);
Assert.assertEquals(stageId, stage.getStageId());
@@ -1511,7 +1511,8 @@ public class TestHeartbeatHandler {
private ActionManager getMockActionManager() {
return new ActionManager(0, 0, null, null,
- actionDBAccessor, new HostsMap((String) null), null, unitOfWork, null, injector.getInstance(RequestFactory.class), null);
+ actionDBAccessor, new HostsMap((String) null), null, unitOfWork,
+ injector.getInstance(RequestFactory.class), null);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/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 1ecb9ca..bc2039e 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
@@ -51,6 +51,7 @@ import org.apache.ambari.server.controller.internal.ActionResourceProviderTest;
import org.apache.ambari.server.controller.internal.ComponentResourceProviderTest;
import org.apache.ambari.server.controller.internal.HostResourceProviderTest;
import org.apache.ambari.server.controller.internal.ServiceResourceProviderTest;
+import org.apache.ambari.server.customactions.ActionDefinition;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.dao.ExecutionCommandDAO;
@@ -3669,13 +3670,13 @@ public class AmbariManagementControllerTest {
hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost("h1").persist();
hdfs.getServiceComponent(Role.DATANODE.name()).addServiceComponentHost("h2").persist();
- controller.getActionManager().createActionDefinition(
- "a1", ActionType.SYSTEM, "test,[optional1]", "Does file exist", "", "",
- TargetHostType.SPECIFIC, Short.valueOf("100"));
+ controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
+ "a1", ActionType.SYSTEM, "test,[optional1]", "", "", "Does file exist",
+ TargetHostType.SPECIFIC, Short.valueOf("100")));
- controller.getActionManager().createActionDefinition(
- "a2", ActionType.SYSTEM, "", "Does file exist", "HDFS", "DATANODE",
- TargetHostType.ALL, Short.valueOf("100"));
+ controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
+ "a2", ActionType.SYSTEM, "", "HDFS", "DATANODE", "Does file exist",
+ TargetHostType.ALL, Short.valueOf("100")));
Map<String, String> params = new HashMap<String, String>() {{
put("test", "test");
@@ -3843,21 +3844,21 @@ public class AmbariManagementControllerTest {
expectActionCreationErrorWithMessage(actionRequest, requestProperties,
"Component DATANODE on host h1 cannot be decommissioned as its not in STARTED state");
- controller.getActionManager().createActionDefinition(
- "a1", ActionType.SYSTEM, "test,dirName", "Does file exist", "", "",
- TargetHostType.SPECIFIC, Short.valueOf("100"));
+ controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
+ "a1", ActionType.SYSTEM, "test,dirName", "", "", "Does file exist",
+ TargetHostType.SPECIFIC, Short.valueOf("100")));
- controller.getActionManager().createActionDefinition(
- "a2", ActionType.SYSTEM, "", "Does file exist", "HDFS", "DATANODE",
- TargetHostType.ANY, Short.valueOf("100"));
+ controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
+ "a2", ActionType.SYSTEM, "", "HDFS", "DATANODE", "Does file exist",
+ TargetHostType.ANY, Short.valueOf("100")));
- controller.getActionManager().createActionDefinition(
- "a3", ActionType.SYSTEM, "", "Does file exist", "MAPREDUCE", "MAPREDUCE_CLIENT",
- TargetHostType.ANY, Short.valueOf("100"));
+ controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
+ "a3", ActionType.SYSTEM, "", "MAPREDUCE", "MAPREDUCE_CLIENT", "Does file exist",
+ TargetHostType.ANY, Short.valueOf("100")));
- controller.getActionManager().createActionDefinition(
- "a4", ActionType.SYSTEM, "", "Does file exist", "HIVE", "",
- TargetHostType.ANY, Short.valueOf("100"));
+ controller.getAmbariMetaInfo().addActionDefinition(new ActionDefinition(
+ "a4", ActionType.SYSTEM, "", "HIVE", "", "Does file exist",
+ TargetHostType.ANY, Short.valueOf("100")));
actionRequest = new ExecuteActionRequest("c1", null, "a1", null, null, null, null);
expectActionCreationErrorWithMessage(actionRequest, requestProperties,
@@ -8528,129 +8529,6 @@ public class AmbariManagementControllerTest {
}
}
- @Test
- public void testActionDefinitionLifeCycle() throws Exception {
- ActionRequest createRequest1 =
- new ActionRequest("a1", "SYSTEM", "fileName", "HDFS", "DATANODE", "Does file exist", "ANY", "100");
- ActionResourceProviderTest.createAction(controller, createRequest1);
-
- ActionRequest getAllRequest = ActionRequest.getAllRequest();
- Set<ActionResponse> responses = ActionResourceProviderTest.getActions(controller,
- Collections.singleton(getAllRequest));
- Assert.assertEquals(1, responses.size());
-
- ActionRequest createRequest2 =
- new ActionRequest("a2", "USER", "fileName", "YARN", "NODEMANAGER", "Does file exist", "ANY", "100");
- ActionResourceProviderTest.createAction(controller, createRequest2);
-
- responses = ActionResourceProviderTest.getActions(controller, Collections.singleton
- (getAllRequest));
- Assert.assertEquals(2, responses.size());
-
- ActionRequest updateRequest =
- new ActionRequest("a2", "USER", null, null, null, "Does file really exist", "ANY", "100");
- RequestStatusResponse response = ActionResourceProviderTest.updateAction(controller,
- Collections.singleton(updateRequest), null);
- Assert.assertNull(response);
-
- ActionRequest getOneRequest =
- new ActionRequest("a2", null, null, null, null, null, null, null);
- responses = ActionResourceProviderTest.getActions(controller, Collections.singleton
- (getOneRequest));
- Assert.assertEquals(1, responses.size());
- Assert.assertEquals("Does file really exist", responses.iterator().next().getDescription());
-
- ActionResourceProviderTest.deleteAction(controller, getOneRequest);
- responses = ActionResourceProviderTest.getActions(controller, Collections.singleton
- (getOneRequest));
- Assert.assertEquals(0, responses.size());
- }
-
- @Test
- public void testActionDefinitionErrors() throws Exception {
- ActionRequest createRequest =
- new ActionRequest(null, "SYSTEM", "fileName", "HDFS", "DATANODE", "Does file exist", "ANY", "100");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("Action name should be provided"));
- }
-
- createRequest =
- new ActionRequest("a1", "SYSTEM", "fileName", "HDFS", "DATANODE", "Does file exist", "ANY", "10000");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("Default timeout should be between 60 and 600"));
- }
-
- createRequest =
- new ActionRequest("a1", "Favorite", "", "HDFS", "", "Does file exist", "ANY", "100");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("No enum const class"));
- }
-
- createRequest =
- new ActionRequest("a1", "SYSTEM", "", "HDFS", "", "", "ANY", "100");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("Action description cannot be empty"));
- }
-
- createRequest =
- new ActionRequest("a1", "SYSTEM", "", "", "", "SS", "ANY", "10");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("Default timeout should be between 60 and 600"));
- }
-
- createRequest =
- new ActionRequest("a1", "SYSTEM", "", "HDFS", "", "SS", "ANY", "100");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("Action definition a1 already exists"));
- }
-
- createRequest =
- new ActionRequest("a1", "SYSTEM", "", "HDFS", "", "SS", "Any", "100");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("No enum const class"));
- }
-
- createRequest =
- new ActionRequest("a1", "SYSTEM", "", "", "DATANODE", "SS", "SPECIFIC", "100");
- try {
- ActionResourceProviderTest.createAction(controller, createRequest);
- Assert.fail("Exception must be thrown");
- } catch (Exception ex) {
- LOG.info(ex.getMessage());
- Assert.assertTrue(ex.getMessage().contains("Target component cannot be specified unless target service is " +
- "specified"));
- }
- }
-
@Test
public void testScheduleSmokeTest() throws Exception {
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
index 271187b..96995b4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ActionResourceProviderTest.java
@@ -23,20 +23,19 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.persist.PersistService;
import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.actionmanager.ActionDefinition;
-import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.ActionType;
import org.apache.ambari.server.actionmanager.TargetHostType;
-import org.apache.ambari.server.controller.ActionResponse;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ActionRequest;
+import org.apache.ambari.server.controller.ActionResponse;
import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.RequestStatusResponse;
import org.apache.ambari.server.controller.spi.Predicate;
import org.apache.ambari.server.controller.spi.Request;
import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.customactions.ActionDefinition;
import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.junit.After;
@@ -45,17 +44,11 @@ import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
-import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
@@ -64,6 +57,24 @@ public class ActionResourceProviderTest {
private Injector injector;
+ public static ActionResourceProvider getActionDefinitionResourceProvider(
+ AmbariManagementController managementController) {
+ Resource.Type type = Resource.Type.Action;
+
+ return (ActionResourceProvider) AbstractControllerResourceProvider.getResourceProvider(
+ type,
+ PropertyHelper.getPropertyIds(type),
+ PropertyHelper.getKeyPropertyIds(type),
+ managementController);
+ }
+
+ public static Set<ActionResponse> getActions(AmbariManagementController controller,
+ Set<ActionRequest> requests)
+ throws AmbariException {
+ ActionResourceProvider provider = getActionDefinitionResourceProvider(controller);
+ return provider.getActionDefinitions(requests);
+ }
+
@Before
public void setup() throws Exception {
InMemoryDefaultTestModule module = new InMemoryDefaultTestModule();
@@ -79,9 +90,9 @@ public class ActionResourceProviderTest {
@Test
public void testGetResources() throws Exception {
Resource.Type type = Resource.Type.Action;
- ActionManager am = createNiceMock(ActionManager.class);
+ AmbariMetaInfo am = createNiceMock(AmbariMetaInfo.class);
AmbariManagementController managementController = createNiceMock(AmbariManagementController.class);
- expect(managementController.getActionManager()).andReturn(am).anyTimes();
+ expect(managementController.getAmbariMetaInfo()).andReturn(am).anyTimes();
List<ActionDefinition> allDefinition = new ArrayList<ActionDefinition>();
allDefinition.add(new ActionDefinition(
@@ -96,7 +107,7 @@ public class ActionResourceProviderTest {
Set<ActionResponse> allResponse = new HashSet<ActionResponse>();
for (ActionDefinition definition : allDefinition) {
- allResponse.add(new ActionResponse(definition));
+ allResponse.add(definition.convertToResponse());
}
ActionDefinition namedDefinition = new ActionDefinition(
@@ -104,7 +115,7 @@ public class ActionResourceProviderTest {
Short.valueOf("100"));
Set<ActionResponse> nameResponse = new HashSet<ActionResponse>();
- nameResponse.add(new ActionResponse(namedDefinition));
+ nameResponse.add(namedDefinition.convertToResponse());
expect(am.getAllActionDefinition()).andReturn(allDefinition).once();
expect(am.getActionDefinition("a1")).andReturn(namedDefinition).once();
@@ -163,178 +174,4 @@ public class ActionResourceProviderTest {
// verify
verify(managementController);
}
-
- @Test
- public void testCreateResources() throws Exception {
- Resource.Type type = Resource.Type.Action;
-
- AmbariManagementController managementController = createNiceMock(AmbariManagementController.class);
- ActionManager am = createMock(ActionManager.class);
- RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
- expect(managementController.getActionManager()).andReturn(am).anyTimes();
-
- am.createActionDefinition(eq("a1"), eq(ActionType.SYSTEM), eq("fileName"), eq("desc"), eq((String)null),
- eq((String)null), eq(TargetHostType.ANY), eq(Short.valueOf("60")));
- // replay
- replay(managementController, am, response);
-
- ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
- type,
- PropertyHelper.getPropertyIds(type),
- PropertyHelper.getKeyPropertyIds(type),
- managementController);
- ((ActionResourceProvider) provider).setEnableExperimental(true);
-
- AbstractResourceProviderTest.TestObserver observer = new AbstractResourceProviderTest.TestObserver();
-
- ((ObservableResourceProvider) provider).addObserver(observer);
-
- // add the property map to a set for the request. add more maps for multiple creates
- Set<Map<String, Object>> propertySet = new LinkedHashSet<Map<String, Object>>();
-
- // Cluster 1: create a map of properties for the request
- Map<String, Object> properties = new LinkedHashMap<String, Object>();
-
- properties.put(ActionResourceProvider.ACTION_NAME_PROPERTY_ID, "a1");
- properties.put(ActionResourceProvider.ACTION_TYPE_PROPERTY_ID, "SYSTEM");
- properties.put(ActionResourceProvider.TARGET_HOST_PROPERTY_ID, "ANY");
- properties.put(ActionResourceProvider.DESCRIPTION_PROPERTY_ID, "desc");
- properties.put(ActionResourceProvider.INPUTS_PROPERTY_ID, "fileName");
-
- propertySet.add(properties);
-
- // create the request
- Request request = PropertyHelper.getCreateRequest(propertySet, null);
-
- provider.createResources(request);
-
- ResourceProviderEvent lastEvent = observer.getLastEvent();
- Assert.assertNotNull(lastEvent);
- Assert.assertEquals(Resource.Type.Action, lastEvent.getResourceType());
- Assert.assertEquals(ResourceProviderEvent.Type.Create, lastEvent.getType());
- Assert.assertEquals(request, lastEvent.getRequest());
- Assert.assertNull(lastEvent.getPredicate());
-
- // verify
- verify(managementController, response);
- }
-
- @Test
- public void testUpdateResources() throws Exception {
- Resource.Type type = Resource.Type.Action;
-
- AmbariManagementController managementController = createNiceMock(AmbariManagementController.class);
- ActionManager am = createMock(ActionManager.class);
- RequestStatusResponse response = createNiceMock(RequestStatusResponse.class);
- expect(managementController.getActionManager()).andReturn(am).anyTimes();
- am.updateActionDefinition(eq("a2"), eq((ActionType) null), eq("Updated description"),
- eq((TargetHostType) null), eq((Short)null));
-
- Map<String, String> mapRequestProps = new HashMap<String, String>();
- mapRequestProps.put("context", "Called from a test");
-
- // replay
- replay(managementController, response, am);
-
- ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
- type,
- PropertyHelper.getPropertyIds(type),
- PropertyHelper.getKeyPropertyIds(type),
- managementController);
- ((ActionResourceProvider) provider).setEnableExperimental(true);
-
- Map<String, Object> properties = new LinkedHashMap<String, Object>();
-
- properties.put(ActionResourceProvider.DESCRIPTION_PROPERTY_ID, "Updated description");
-
- // create the request
- Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps);
-
- // update the action named a2
- Predicate predicate = new PredicateBuilder().property(
- ActionResourceProvider.ACTION_NAME_PROPERTY_ID).equals("a2").toPredicate();
- provider.updateResources(request, predicate);
-
- // verify
- verify(managementController, response, am);
- }
-
- @Test
- public void testEnsureLockedOperations() throws Exception {
- Resource.Type type = Resource.Type.Action;
-
- AmbariManagementController managementController = createMock(AmbariManagementController.class);
- ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
- type,
- PropertyHelper.getPropertyIds(type),
- PropertyHelper.getKeyPropertyIds(type),
- managementController);
-
- Map<String, Object> properties = new LinkedHashMap<String, Object>();
- Map<String, String> mapRequestProps = new HashMap<String, String>();
- mapRequestProps.put("context", "Called from a test");
- // create the request
- Request request = PropertyHelper.getUpdateRequest(properties, mapRequestProps);
-
- Predicate predicate = new PredicateBuilder().property(
- ActionResourceProvider.ACTION_NAME_PROPERTY_ID).equals("a2").toPredicate();
- try {
- provider.updateResources(request, predicate);
- Assert.fail("Update call must fail.");
- } catch (UnsupportedOperationException ex) {
- Assert.assertTrue(ex.getMessage().contains("Not currently supported"));
- }
-
- try {
- provider.createResources(request);
- Assert.fail("Create call must fail.");
- } catch (UnsupportedOperationException ex) {
- Assert.assertTrue(ex.getMessage().contains("Not currently supported"));
- }
-
- try {
- provider.deleteResources(predicate);
- Assert.fail("Delete call must fail.");
- } catch (UnsupportedOperationException ex) {
- Assert.assertTrue(ex.getMessage().contains("Not currently supported"));
- }
- }
-
- public static ActionResourceProvider getActionDefinitionResourceProvider(
- AmbariManagementController managementController) {
- Resource.Type type = Resource.Type.Action;
-
- return (ActionResourceProvider) AbstractControllerResourceProvider.getResourceProvider(
- type,
- PropertyHelper.getPropertyIds(type),
- PropertyHelper.getKeyPropertyIds(type),
- managementController);
- }
-
- public static void createAction(AmbariManagementController controller, ActionRequest request)
- throws AmbariException {
- ActionResourceProvider provider = getActionDefinitionResourceProvider(controller);
- provider.createActionDefinition(request);
- }
-
- public static Set<ActionResponse> getActions(AmbariManagementController controller,
- Set<ActionRequest> requests)
- throws AmbariException {
- ActionResourceProvider provider = getActionDefinitionResourceProvider(controller);
- return provider.getActionDefinitions(requests);
- }
-
- public static RequestStatusResponse updateAction(AmbariManagementController controller,
- Set<ActionRequest> requests,
- Map<String, String> requestProperties)
- throws AmbariException {
- ActionResourceProvider provider = getActionDefinitionResourceProvider(controller);
- return provider.updateActionDefinitions(requests, requestProperties);
- }
-
- public static void deleteAction(AmbariManagementController controller, ActionRequest request)
- throws AmbariException {
- ActionResourceProvider provider = getActionDefinitionResourceProvider(controller);
- provider.deleteActionDefinition(request);
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/customactions/ActionDefinitionManagerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/customactions/ActionDefinitionManagerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/customactions/ActionDefinitionManagerTest.java
new file mode 100644
index 0000000..7108be2
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/customactions/ActionDefinitionManagerTest.java
@@ -0,0 +1,73 @@
+/**
+ * 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.ambari.server.customactions;
+
+import java.io.File;
+
+import junit.framework.Assert;
+import org.apache.ambari.server.actionmanager.ActionType;
+import org.apache.ambari.server.actionmanager.TargetHostType;
+import org.junit.Test;
+
+public class ActionDefinitionManagerTest {
+
+ private final String customActionDefinitionRoot = "./src/test/resources/custom_action_definitions/".
+ replaceAll("/", File.separator);
+
+ @Test
+ public void testReadCustomActionDefinitions() throws Exception {
+ ActionDefinitionManager manager = new ActionDefinitionManager();
+ manager.readCustomActionDefinitions(new File(customActionDefinitionRoot));
+
+ Assert.assertEquals(3, manager.getAllActionDefinition().size());
+ ActionDefinition ad = manager.getActionDefinition("ambari_hdfs_rebalancer");
+ Assert.assertNotNull(ad);
+ Assert.assertEquals("ambari_hdfs_rebalancer", ad.getActionName());
+ Assert.assertEquals("HDFS Rebalance", ad.getDescription());
+ Assert.assertEquals("threshold,[principal],[keytab]", ad.getInputs());
+ Assert.assertEquals("NAMENODE", ad.getTargetComponent());
+ Assert.assertEquals("HDFS", ad.getTargetService());
+ Assert.assertEquals(600, (int)ad.getDefaultTimeout());
+ Assert.assertEquals(TargetHostType.ANY, ad.getTargetType());
+ Assert.assertEquals(ActionType.SYSTEM, ad.getActionType());
+
+ ad = manager.getActionDefinition("customAction1");
+ Assert.assertNotNull(ad);
+ Assert.assertEquals("customAction1", ad.getActionName());
+ Assert.assertEquals("A random test", ad.getDescription());
+ Assert.assertEquals("threshold", ad.getInputs());
+ Assert.assertEquals("TASKTRACKER", ad.getTargetComponent());
+ Assert.assertEquals("MAPREDUCE", ad.getTargetService());
+ Assert.assertEquals(60, (int)ad.getDefaultTimeout());
+ Assert.assertEquals(TargetHostType.ALL, ad.getTargetType());
+ Assert.assertEquals(ActionType.USER, ad.getActionType());
+
+ ad = manager.getActionDefinition("customAction2");
+ Assert.assertNotNull(ad);
+ Assert.assertEquals("customAction2", ad.getActionName());
+ Assert.assertEquals("A random test", ad.getDescription());
+ Assert.assertEquals(null, ad.getInputs());
+ Assert.assertEquals("TASKTRACKER", ad.getTargetComponent());
+ Assert.assertEquals("MAPREDUCE", ad.getTargetService());
+ Assert.assertEquals(60, (int)ad.getDefaultTimeout());
+ Assert.assertEquals(null, ad.getTargetType());
+ Assert.assertEquals(ActionType.USER, ad.getActionType());
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAOTest.java
deleted file mode 100644
index cf87023..0000000
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/ActionDefinitionDAOTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/**
- * 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.ambari.server.orm.dao;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.persist.PersistService;
-import junit.framework.Assert;
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.Role;
-import org.apache.ambari.server.actionmanager.ActionType;
-import org.apache.ambari.server.actionmanager.TargetHostType;
-import org.apache.ambari.server.orm.GuiceJpaInitializer;
-import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
-import org.apache.ambari.server.orm.entities.ActionEntity;
-import org.apache.ambari.server.state.Service;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import javax.persistence.RollbackException;
-import java.util.List;
-
-public class ActionDefinitionDAOTest {
- private Injector injector;
- private ActionDefinitionDAO actionDefinitionDAO;
-
- @Before
- public void setup() throws Exception {
- injector = Guice.createInjector(new InMemoryDefaultTestModule());
- injector.getInstance(GuiceJpaInitializer.class);
-
- actionDefinitionDAO = injector.getInstance(ActionDefinitionDAO.class);
- }
-
- @After
- public void teardown() throws AmbariException {
- injector.getInstance(PersistService.class).stop();
- }
-
- private ActionEntity createActionDefinition(
- String actionName, ActionType actionType, String inputs, String targetService, Role targetComponent,
- Short defaultTimeout, String description, TargetHostType targetType, Boolean addToDAO) throws Exception {
- ActionEntity actionDefinitionEntity = new ActionEntity();
-
- actionDefinitionEntity.setActionName(actionName);
- actionDefinitionEntity.setActionType(actionType);
- actionDefinitionEntity.setDefaultTimeout(defaultTimeout);
- actionDefinitionEntity.setDescription(description);
- actionDefinitionEntity.setInputs(inputs);
- actionDefinitionEntity.setTargetComponent(targetComponent.toString());
- actionDefinitionEntity.setTargetService(targetService);
- actionDefinitionEntity.setTargetType(targetType);
-
- if (addToDAO) {
- actionDefinitionDAO.create(actionDefinitionEntity);
- }
-
- return actionDefinitionEntity;
- }
-
- @Test
- public void testFindAll() throws Exception {
- createActionDefinition("a1", ActionType.SYSTEM, "fileName", Service.Type.HDFS.toString(), Role.DATANODE,
- Short.parseShort("10"), "a1", TargetHostType.ANY, true);
- createActionDefinition("a2", ActionType.SYSTEM, "fileName", Service.Type.HDFS.toString(), Role.DATANODE,
- Short.parseShort("10"), "a2", TargetHostType.ANY, true);
-
- List<ActionEntity> actionDefinitionEntities = actionDefinitionDAO.findAll();
-
- Assert.assertNotNull(actionDefinitionEntities);
- Assert.assertEquals(2, actionDefinitionEntities.size());
- }
-
- @Test
- public void testFindByPK() throws Exception {
- createActionDefinition("c1", ActionType.SYSTEM, "fileName", Service.Type.HDFS.toString(), Role.DATANODE,
- Short.parseShort("10"), "a1", TargetHostType.ANY, true);
- createActionDefinition("c2", ActionType.SYSTEM, "fileName", Service.Type.HDFS.toString(), Role.DATANODE,
- Short.parseShort("10"), "a2", TargetHostType.ANY, true);
-
- ActionEntity actionDefinitionEntity = actionDefinitionDAO.findByPK("c1");
-
- Assert.assertNotNull(actionDefinitionEntity);
- Assert.assertEquals("c1", actionDefinitionEntity.getActionName());
- }
-
- @Test
- public void testDuplicate() throws Exception {
- createActionDefinition("b1", ActionType.SYSTEM, "fileName", Service.Type.HDFS.toString(), Role.DATANODE,
- Short.parseShort("10"), "a1", TargetHostType.ANY, true);
- try {
- createActionDefinition("b1", ActionType.SYSTEM, "fileName", Service.Type.HDFS.toString(), Role.DATANODE,
- Short.parseShort("10"), "a1", TargetHostType.ANY, true);
- Assert.fail("Should throw exception");
- } catch (RollbackException rbe) {
- Assert.assertTrue(rbe.getMessage().contains("duplicate"));
- }
- }
-
- @Test
- public void testUpdate() throws Exception {
- createActionDefinition("d1", ActionType.SYSTEM, "fileName", Service.Type.HDFS.toString(), Role.DATANODE,
- Short.parseShort("101"), "a1", TargetHostType.ANY, true);
- ActionEntity newOne = createActionDefinition("d1", ActionType.SYSTEM, "fileValue", Service.Type.HDFS.toString(),
- Role.DATANODE, Short.parseShort("101"), "a1", TargetHostType.ANY, false);
- actionDefinitionDAO.merge(newOne);
- ActionEntity actionDefinitionEntity = actionDefinitionDAO.findByPK("d1");
- Assert.assertEquals("fileValue", actionDefinitionEntity.getInputs());
-
- actionDefinitionDAO.remove(newOne);
- actionDefinitionEntity = actionDefinitionDAO.findByPK("d1");
- Assert.assertNull(actionDefinitionEntity);
- }
-
- @Test
- public void testDeleteNonExistent() throws Exception {
- ActionEntity newOne = createActionDefinition("d1", ActionType.SYSTEM, "fileValue", Service.Type.HDFS.toString(),
- Role.DATANODE, Short.parseShort("101"), "a1", TargetHostType.ANY, false);
- actionDefinitionDAO.remove(newOne);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions1.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions1.xml b/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions1.xml
new file mode 100644
index 0000000..a4db87d
--- /dev/null
+++ b/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions1.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="action_definition.xsl"?>
+
+<!--
+ 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.
+-->
+
+<actionDefinitions>
+ <actionDefinition>
+ <actionName>customAction1</actionName>
+ <actionType>USER</actionType>
+ <inputs>threshold</inputs>
+ <targetService>MAPREDUCE</targetService>
+ <targetComponent>TASKTRACKER</targetComponent>
+ <description>A random test</description>
+ <targetType>ALL</targetType>
+ </actionDefinition>
+ <actionDefinition>
+ <actionName>customAction2</actionName>
+ <actionType>USER</actionType>
+ <targetService>MAPREDUCE</targetService>
+ <targetComponent>TASKTRACKER</targetComponent>
+ <description>A random test</description>
+ </actionDefinition>
+ <actionDefinition>
+ <actionName>customAction3</actionName>
+ <actionType>USERS_OWN</actionType>
+ <targetService>MAPREDUCE</targetService>
+ <targetComponent>TASKTRACKER</targetComponent>
+ <description>A random test</description>
+ </actionDefinition>
+ <actionDefinition>
+ <actionName>ambari_hdfs_rebalancer</actionName>
+ <actionType>SYSTEM</actionType>
+ <inputs>threshold,[principal],[keytab]</inputs>
+ <targetService>HDFS</targetService>
+ <targetComponent>NAMENODE</targetComponent>
+ <description>HDFS Rebalance</description>
+ <targetType>ANY</targetType>
+ <defaultTimeout>600</defaultTimeout>
+ </actionDefinition>
+</actionDefinitions>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions2.txt
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions2.txt b/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions2.txt
new file mode 100644
index 0000000..f99105d
--- /dev/null
+++ b/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions2.txt
@@ -0,0 +1,18 @@
+<!--
+ 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.
+-->
+
+This is random text.
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions3.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions3.xml b/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions3.xml
new file mode 100644
index 0000000..01fa746
--- /dev/null
+++ b/ambari-server/src/test/resources/custom_action_definitions/cust_action_definitions3.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="action_definition.xsl"?>
+
+<!--
+ 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.
+-->
+
+<randomFile></randomFile>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/test/resources/custom_action_definitions/system_action_definitions.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/resources/custom_action_definitions/system_action_definitions.xml b/ambari-server/src/test/resources/custom_action_definitions/system_action_definitions.xml
new file mode 100644
index 0000000..ee07900
--- /dev/null
+++ b/ambari-server/src/test/resources/custom_action_definitions/system_action_definitions.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/xsl" href="action_definition.xsl"?>
+
+<!--
+ 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.
+-->
+
+<actionDefinitions>
+ <actionDefinition>
+ <actionName>ambari_hdfs_rebalancer</actionName>
+ <actionType>SYSTEM</actionType>
+ <inputs>threshold,[principal],[keytab]</inputs>
+ <targetService>HDFS</targetService>
+ <targetComponent>NAMENODE</targetComponent>
+ <defaultTimeout>600</defaultTimeout>
+ <description>HDFS Rebalance</description>
+ <targetType>ANY</targetType>
+ </actionDefinition>
+</actionDefinitions>
\ No newline at end of file
[2/2] git commit: AMBARI-4365. Action definitions should be provided
as declarative resources - read from XML files
Posted by sm...@apache.org.
AMBARI-4365. Action definitions should be provided as declarative resources - read from XML files
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8e8a9a47
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8e8a9a47
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8e8a9a47
Branch: refs/heads/trunk
Commit: 8e8a9a47fd5d9afb0fcc4bd41b283c409d5bc355
Parents: 241f059
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Wed Jan 22 09:42:45 2014 -0800
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Wed Jan 22 11:14:09 2014 -0800
----------------------------------------------------------------------
ambari-server/conf/unix/ambari.properties | 1 +
ambari-server/pom.xml | 8 +
.../server/actionmanager/ActionDefinition.java | 138 -----------
.../server/actionmanager/ActionManager.java | 35 +--
.../actionmanager/CustomActionDBAccessor.java | 82 -------
.../CustomActionDBAccessorImpl.java | 230 -------------------
.../server/api/services/AmbariMetaInfo.java | 78 +++++--
.../server/configuration/Configuration.java | 165 ++++++-------
.../server/controller/ActionResponse.java | 11 -
.../controller/AmbariActionExecutionHelper.java | 19 +-
.../server/controller/ControllerModule.java | 62 +++--
.../internal/ActionResourceProvider.java | 144 +-----------
.../server/customactions/ActionDefinition.java | 132 +++++++++++
.../customactions/ActionDefinitionManager.java | 202 ++++++++++++++++
.../customactions/ActionDefinitionSpec.java | 139 +++++++++++
.../customactions/ActionDefinitionXml.java | 42 ++++
.../server/orm/dao/ActionDefinitionDAO.java | 71 ------
.../server/orm/entities/ActionEntity.java | 162 -------------
.../main/resources/Ambari-DDL-MySQL-CREATE.sql | 1 -
.../main/resources/Ambari-DDL-Oracle-CREATE.sql | 1 -
.../resources/Ambari-DDL-Postgres-CREATE.sql | 7 -
.../system_action_definitions.xml | 32 +++
.../custom_actions/ambari_hdfs_rebalance.py | 58 -----
.../custom_actions/ambari_hdfs_rebalancer.py | 58 +++++
.../upgrade/ddl/Ambari-DDL-Oracle-UPGRADE.sql | 1 -
.../ddl/Ambari-DDL-Postgres-UPGRADE-1.3.0.sql | 5 -
.../actionmanager/TestActionDBAccessorImpl.java | 4 +-
.../server/actionmanager/TestActionManager.java | 6 +-
.../actionmanager/TestActionScheduler.java | 10 +-
.../TestCustomActionDBAccessorImpl.java | 124 ----------
.../server/agent/TestHeartbeatHandler.java | 5 +-
.../AmbariManagementControllerTest.java | 160 ++-----------
.../internal/ActionResourceProviderTest.java | 213 ++---------------
.../ActionDefinitionManagerTest.java | 73 ++++++
.../server/orm/dao/ActionDefinitionDAOTest.java | 137 -----------
.../cust_action_definitions1.xml | 55 +++++
.../cust_action_definitions2.txt | 18 ++
.../cust_action_definitions3.xml | 21 ++
.../system_action_definitions.xml | 32 +++
39 files changed, 1057 insertions(+), 1685 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/conf/unix/ambari.properties
----------------------------------------------------------------------
diff --git a/ambari-server/conf/unix/ambari.properties b/ambari-server/conf/unix/ambari.properties
index 978cdc6..74eed1b 100644
--- a/ambari-server/conf/unix/ambari.properties
+++ b/ambari-server/conf/unix/ambari.properties
@@ -18,6 +18,7 @@
security.server.keys_dir = /var/lib/ambari-server/keys
resources.dir = /var/lib/ambari-server/resources
+custom.action.definitions = /var/lib/ambari-server/resources/custom_action_definitions
jdk1.6.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jdk-6u31-linux-x64.bin
jce_policy1.6.url=http://public-repo-1.hortonworks.com/ARTIFACTS/jce_policy-6.zip
jdk1.7.url=http://www.reucon.com/cdn/java/jdk-7u45-linux-x64.tar.gz
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/pom.xml
----------------------------------------------------------------------
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index 2972e94..b494b7b 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -426,6 +426,14 @@
</source>
</sources>
</mapping>
+ <mapping>
+ <directory>/var/lib/ambari-server/resources/custom_action_definitions</directory>
+ <sources>
+ <source>
+ <location>src/main/resources/custom_action_definitions</location>
+ </source>
+ </sources>
+ </mapping>
</mappings>
</configuration>
</plugin>
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDefinition.java
deleted file mode 100644
index fdd57dd..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDefinition.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/**
- * 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.ambari.server.actionmanager;
-
-import org.apache.ambari.server.orm.entities.ActionEntity;
-
-/**
- * The resource describing the definition of an action
- */
-public class ActionDefinition {
- private String actionName;
- private ActionType actionType;
- private String inputs;
- private String targetService;
- private String targetComponent;
- private String description;
- private TargetHostType targetType;
- private Short defaultTimeout;
-
- /**
- * Create an instance of ActionDefinition
- * @param actionName The name of the action
- * @param actionType The type fo the action
- * @param inputs Expected input of the action
- * @param targetService Target service type (e.g. HDFS)
- * @param targetComponent Target component type (e.g. DATANODE)
- * @param description Short description of the action
- * @param targetType Selection criteria for target hosts
- * @param defaultTimeout The timeout value for this action when executed
- */
- public ActionDefinition(String actionName, ActionType actionType, String inputs,
- String targetService, String targetComponent, String description,
- TargetHostType targetType, Short defaultTimeout) {
- setActionName(actionName);
- setActionType(actionType);
- setInputs(inputs);
- setTargetService(targetService);
- setTargetComponent(targetComponent);
- setDescription(description);
- setTargetType(targetType);
- setDefaultTimeout(defaultTimeout);
- }
-
- /**
- * Create an instance of ActionDefinition
- * @param entity The entity corresponding to the action
- */
- public ActionDefinition(ActionEntity entity) {
- setActionName(entity.getActionName());
- setActionType(entity.getActionType());
- setInputs(entity.getInputs());
- setTargetService(entity.getTargetService());
- setTargetComponent(entity.getTargetComponent());
- setDescription(entity.getDescription());
- setTargetType(entity.getTargetType());
- setDefaultTimeout(entity.getDefaultTimeout());
- }
-
- public String getActionName() {
- return actionName;
- }
-
- public void setActionName(String actionName) {
- this.actionName = actionName;
- }
-
- public ActionType getActionType() {
- return actionType;
- }
-
- public void setActionType(ActionType actionType) {
- this.actionType = actionType;
- }
-
- public String getInputs() {
- return inputs;
- }
-
- public void setInputs(String inputs) {
- this.inputs = inputs;
- }
-
- public String getTargetService() {
- return targetService;
- }
-
- public void setTargetService(String targetService) {
- this.targetService = targetService;
- }
-
- public String getTargetComponent() {
- return targetComponent;
- }
-
- public void setTargetComponent(String targetComponent) {
- this.targetComponent = targetComponent;
- }
-
- public String getDescription() {
- return description;
- }
-
- public void setDescription(String description) {
- this.description = description;
- }
-
- public TargetHostType getTargetType() {
- return targetType;
- }
-
- public void setTargetType(TargetHostType targetType) {
- this.targetType = targetType;
- }
-
- public Short getDefaultTimeout() {
- return defaultTimeout;
- }
-
- public void setDefaultTimeout(Short defaultTimeout) {
- this.defaultTimeout = defaultTimeout;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
index 8e6fb13..3788d75 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
@@ -50,7 +50,6 @@ public class ActionManager {
private final ActionDBAccessor db;
private final ActionQueue actionQueue;
private final AtomicLong requestCounter;
- private final CustomActionDBAccessor cdb;
private final RequestFactory requestFactory;
@@ -58,7 +57,7 @@ public class ActionManager {
public ActionManager(@Named("schedulerSleeptime") long schedulerSleepTime,
@Named("actionTimeout") long actionTimeout,
ActionQueue aq, Clusters fsm, ActionDBAccessor db, HostsMap hostsMap,
- ServerActionManager serverActionManager, UnitOfWork unitOfWork, CustomActionDBAccessor cdb,
+ ServerActionManager serverActionManager, UnitOfWork unitOfWork,
RequestFactory requestFactory, Configuration configuration) {
this.actionQueue = aq;
this.db = db;
@@ -66,7 +65,6 @@ public class ActionManager {
actionQueue, fsm, 2, hostsMap, serverActionManager, unitOfWork, configuration);
requestCounter = new AtomicLong(
db.getLastPersistedRequestIdWhenInitialized());
- this.cdb = cdb;
this.requestFactory = requestFactory;
}
@@ -207,35 +205,4 @@ public class ActionManager {
public String getRequestContext(long requestId) {
return db.getRequestContext(requestId);
}
-
- /** CRUD operations of Action resources **/
-
- public ActionDefinition getActionDefinition(String actionName)
- throws AmbariException {
- return cdb.getActionDefinition(actionName);
- }
-
- public List<ActionDefinition> getAllActionDefinition()
- throws AmbariException {
- return cdb.getActionDefinitions();
- }
-
- public void deleteActionDefinition(String actionName)
- throws AmbariException {
- cdb.deleteActionDefinition(actionName);
- }
-
- public void updateActionDefinition(String actionName, ActionType actionType, String description,
- TargetHostType targetType, Short defaultTimeout)
- throws AmbariException {
- cdb.updateActionDefinition(actionName, actionType, description, targetType, defaultTimeout);
- }
-
- public void createActionDefinition(String actionName, ActionType actionType, String inputs, String description,
- String serviceType, String componentType, TargetHostType targetType,
- Short defaultTimeout)
- throws AmbariException {
- cdb.createActionDefinition(actionName, actionType, inputs, description, targetType, serviceType,
- componentType, defaultTimeout);
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessor.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessor.java
deleted file mode 100644
index b861e76..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessor.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * 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.ambari.server.actionmanager;
-
-import org.apache.ambari.server.AmbariException;
-
-import java.util.List;
-
-/**
- * The DB accessor implementation for Action definitions
- */
-public interface CustomActionDBAccessor {
-
- /**
- * Given an actionName, get the Action resource
- *
- * @param actionName name of the action
- * @return
- * @throws AmbariException
- */
- public ActionDefinition getActionDefinition(String actionName) throws AmbariException;
-
- /**
- * Get all action definition resources
- *
- * @return
- */
- public List<ActionDefinition> getActionDefinitions();
-
- /**
- * Create an action definition resource
- *
- * @param actionName name of the action
- * @param actionType type of the action
- * @param inputs inputs required by the action
- * @param description a short description of the action
- * @param targetType the host target type
- * @param serviceType the service type on which the action must be executed
- * @param componentType the component type on which the action must be executed
- * @param defaultTimeout the default timeout for this action
- * @throws AmbariException
- */
- public void createActionDefinition(String actionName, ActionType actionType, String inputs, String description,
- TargetHostType targetType, String serviceType, String componentType,
- Short defaultTimeout) throws AmbariException;
-
- /**
- * Update an action definition
- *
- * @param actionName name of the action
- * @param actionType type of the action
- * @param description a short description of the action
- * @param targetType the host target type
- * @param defaultTimeout the default timeout for this action
- * @throws AmbariException
- */
- public void updateActionDefinition(String actionName, ActionType actionType, String description,
- TargetHostType targetType, Short defaultTimeout) throws AmbariException;
-
- /**
- * Delete an action definition
- *
- * @param actionName
- * @throws AmbariException
- */
- public void deleteActionDefinition(String actionName) throws AmbariException;
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessorImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessorImpl.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessorImpl.java
deleted file mode 100644
index 38bc371..0000000
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/CustomActionDBAccessorImpl.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/**
- * 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.ambari.server.actionmanager;
-
-import com.google.inject.Inject;
-import com.google.inject.Injector;
-import com.google.inject.Singleton;
-import com.google.inject.persist.Transactional;
-import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.orm.dao.ActionDefinitionDAO;
-import org.apache.ambari.server.orm.entities.ActionEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * An implementation of DB accessor for Custom Action
- */
-@Singleton
-public class CustomActionDBAccessorImpl implements CustomActionDBAccessor {
- public static final Short MIN_TIMEOUT = 60;
- private static final Logger LOG = LoggerFactory.getLogger(CustomActionDBAccessorImpl.class);
- private static final Short MAX_TIMEOUT = 600;
- @Inject
- private ActionDefinitionDAO actionDefinitionDAO;
-
- @Inject
- public CustomActionDBAccessorImpl(Injector injector) {
- injector.injectMembers(this);
- }
-
- /**
- * Given an actionName, get the Action resource
- *
- * @param actionName name of the action
- * @return
- * @throws AmbariException
- */
- @Override
- public ActionDefinition getActionDefinition(String actionName) {
- ActionEntity action =
- actionDefinitionDAO.findByPK(actionName);
- if (action != null) {
- return new ActionDefinition(action);
- }
-
- return null;
- }
-
- /**
- * Get all action definition resources
- *
- * @return
- */
- @Override
- public List<ActionDefinition> getActionDefinitions() {
- List<ActionDefinition> result = new ArrayList<ActionDefinition>();
- List<ActionEntity> entities = actionDefinitionDAO.findAll();
- for (ActionEntity entity : entities) {
- result.add(new ActionDefinition(entity));
- }
- return result;
- }
-
- /**
- * Create an action definition resource
- *
- * @param actionName name of the action
- * @param actionType type of the action
- * @param inputs inputs required by the action
- * @param description a short description of the action
- * @param targetType the host target type
- * @param serviceType the service type on which the action must be executed
- * @param componentType the component type on which the action must be executed
- * @param defaultTimeout the default timeout for this action
- * @throws AmbariException
- */
- @Override
- @Transactional
- public void createActionDefinition(String actionName, ActionType actionType, String inputs, String description,
- TargetHostType targetType, String serviceType, String componentType,
- Short defaultTimeout)
- throws AmbariException {
- validateCreateInput(actionName, actionType, inputs, description, defaultTimeout,
- targetType, serviceType, componentType);
- ActionEntity entity =
- actionDefinitionDAO.findByPK(actionName);
- if (entity == null) {
- entity = new ActionEntity();
- entity.setActionName(actionName);
- entity.setActionType(actionType);
- entity.setInputs(inputs);
- entity.setTargetService(serviceType);
- entity.setTargetComponent(componentType);
- entity.setDescription(description);
- entity.setTargetType(targetType);
- entity.setDefaultTimeout(defaultTimeout);
- actionDefinitionDAO.merge(entity);
- } else {
- throw new AmbariException("Action definition " + actionName + " already exists");
- }
- }
-
- /**
- * Update an action definition
- *
- * @param actionName name of the action
- * @param actionType type of the action
- * @param description a short description of the action
- * @param targetType the host target type
- * @param defaultTimeout the default timeout for this action
- * @throws AmbariException
- */
- @Override
- @Transactional
- public void updateActionDefinition(String actionName, ActionType actionType, String description,
- TargetHostType targetType, Short defaultTimeout)
- throws AmbariException {
- ActionEntity entity = actionDefinitionDAO.findByPK(actionName);
- if (entity != null) {
- if (actionType != null) {
- if (actionType == ActionType.SYSTEM_DISABLED) {
- throw new AmbariException("Action type cannot be " + actionType);
- }
- entity.setActionType(actionType);
- }
- if (description != null) {
- if (description.isEmpty()) {
- throw new AmbariException("Action description cannot be empty");
- }
- entity.setDescription(description);
- }
- if (targetType != null) {
- entity.setTargetType(targetType);
- }
- if (defaultTimeout != null) {
- if (defaultTimeout < MIN_TIMEOUT || defaultTimeout > MAX_TIMEOUT) {
- throw new AmbariException("Default timeout should be between " + MIN_TIMEOUT + " and " + MAX_TIMEOUT);
- }
- entity.setDefaultTimeout(defaultTimeout);
- }
- actionDefinitionDAO.merge(entity);
- } else {
- throw new AmbariException("Action definition " + actionName + " does not exist");
- }
- }
-
- /**
- * Delete an action definition
- *
- * @param actionName
- * @throws AmbariException
- */
- @Override
- public void deleteActionDefinition(String actionName)
- throws AmbariException {
- validateActionName(actionName);
- ActionDefinition ad = getActionDefinition(actionName);
- if (ad != null) {
- actionDefinitionDAO.removeByPK(actionName);
- }
- }
-
- private void validateCreateInput(String actionName, ActionType actionType, String inputs,
- String description, Short defaultTimeout,
- TargetHostType targetType, String serviceType, String componentType)
- throws AmbariException {
-
- validateActionName(actionName);
-
- if (defaultTimeout < MIN_TIMEOUT || defaultTimeout > MAX_TIMEOUT) {
- throw new AmbariException("Default timeout should be between " + MIN_TIMEOUT + " and " + MAX_TIMEOUT);
- }
-
- if (actionType == ActionType.SYSTEM_DISABLED) {
- throw new AmbariException("Action type cannot be " + actionType);
- }
-
- if (description == null || description.isEmpty()) {
- throw new AmbariException("Action description cannot be empty");
- }
-
- if (actionType == null || actionType == ActionType.SYSTEM_DISABLED) {
- throw new AmbariException("Action type cannot be " + actionType);
- }
-
- if (serviceType == null || serviceType.isEmpty()) {
- if (componentType != null && !componentType.isEmpty()) {
- throw new AmbariException("Target component cannot be specified unless target service is specified");
- }
- }
-
- if (inputs != null && !inputs.isEmpty()) {
- String[] parameters = inputs.split(",");
- for (String parameter : parameters) {
- if (parameter.trim().isEmpty()) {
- throw new AmbariException("Empty parameter cannot be specified as an input parameter");
- }
- }
- }
- }
-
- private void validateActionName(String actionName)
- throws AmbariException {
- if (actionName == null || actionName.isEmpty()) {
- throw new AmbariException("Action name cannot be empty");
- }
- String trimmedName = actionName.replaceAll("\\s+", "");
- if (actionName.length() > trimmedName.length()) {
- throw new AmbariException("Action name cannot contain white spaces");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
index 56bd5e9..78131f2 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java
@@ -39,6 +39,8 @@ import org.apache.ambari.server.ObjectNotFoundException;
import org.apache.ambari.server.StackAccessException;
import org.apache.ambari.server.api.util.StackExtensionHelper;
import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.customactions.ActionDefinition;
+import org.apache.ambari.server.customactions.ActionDefinitionManager;
import org.apache.ambari.server.orm.dao.MetainfoDAO;
import org.apache.ambari.server.orm.entities.MetainfoEntity;
import org.apache.ambari.server.state.ComponentInfo;
@@ -67,57 +69,52 @@ import com.google.inject.Singleton;
@Singleton
public class AmbariMetaInfo {
- private final static Logger LOG = LoggerFactory.getLogger(AmbariMetaInfo.class);
-
public static final String STACK_METAINFO_FILE_NAME = "metainfo.xml";
public static final String SERVICES_FOLDER_NAME = "services";
public static final String SERVICE_METAINFO_FILE_NAME = "metainfo.xml";
public static final String SERVICE_CONFIG_FOLDER_NAME = "configuration";
public static final String SERVICE_CONFIG_FILE_NAME_POSTFIX = ".xml";
public static final String RCO_FILE_NAME = "role_command_order.json";
- private static final String REPOSITORY_FILE_NAME = "repoinfo.xml";
- private static final String REPOSITORY_FOLDER_NAME = "repos";
- private static final String REPOSITORY_XML_PROPERTY_BASEURL = "baseurl";
- // all the supported OS'es
- private static final List<String> ALL_SUPPORTED_OS = Arrays.asList(
- "centos5", "redhat5", "centos6", "redhat6", "oraclelinux5",
- "oraclelinux6", "suse11", "sles11", "ubuntu12");
-
public static final String SERVICE_METRIC_FILE_NAME = "metrics.json";
- private final static String HOOKS_DIR = "hooks";
-
/**
* This string is used in placeholder in places that are common for
* all operating systems or in situations where os type is not important.
*/
public static final String ANY_OS = "any";
-
/**
* Value for legacy xml files that don't contain schema property
*/
public static final String SCHEMA_VERSION_LEGACY = "1.0";
-
/**
* Version of XML files with support of custom services and custom commands
*/
public static final String SCHEMA_VERSION_2 = "2.0";
-
-
public static final FilenameFilter FILENAME_FILTER = new FilenameFilter() {
@Override
public boolean accept(File dir, String s) {
if (s.equals(".svn") || s.equals(".git") ||
- s.equals(HOOKS_DIR)) // Hooks dir is not a service
+ s.equals(HOOKS_DIR)) // Hooks dir is not a service
+ {
return false;
+ }
return true;
}
};
-
+ private final static Logger LOG = LoggerFactory.getLogger(AmbariMetaInfo.class);
+ private static final String REPOSITORY_FILE_NAME = "repoinfo.xml";
+ private static final String REPOSITORY_FOLDER_NAME = "repos";
+ private static final String REPOSITORY_XML_PROPERTY_BASEURL = "baseurl";
+ // all the supported OS'es
+ private static final List<String> ALL_SUPPORTED_OS = Arrays.asList(
+ "centos5", "redhat5", "centos6", "redhat6", "oraclelinux5",
+ "oraclelinux6", "suse11", "sles11", "ubuntu12");
+ private final static String HOOKS_DIR = "hooks";
+ private final ActionDefinitionManager adManager = new ActionDefinitionManager();
private String serverVersion = "undefined";
private List<StackInfo> stacksResult = new ArrayList<StackInfo>();
private File stackRoot;
private File serverVersionFile;
-
+ private File customActionRoot;
@Inject
private MetainfoDAO metainfoDAO;
@@ -133,6 +130,7 @@ public class AmbariMetaInfo {
String serverVersionFilePath = conf.getServerVersionFilePath();
this.stackRoot = new File(stackPath);
this.serverVersionFile = new File(serverVersionFilePath);
+ this.customActionRoot = new File(conf.getCustomActionDefinitionPath());
}
public AmbariMetaInfo(File stackRoot, File serverVersionFile) throws Exception {
@@ -150,6 +148,7 @@ public class AmbariMetaInfo {
stacksResult = new ArrayList<StackInfo>();
readServerVersion();
getConfigurationInformation(stackRoot);
+ getCustomActionDefinitions(customActionRoot);
}
/**
@@ -464,11 +463,11 @@ public class AmbariMetaInfo {
}
public List<ServiceInfo> getSupportedServices(String stackName, String version) throws AmbariException {
- List<ServiceInfo> servicesResulr = null;
+ List<ServiceInfo> servicesResult = null;
StackInfo stack = getStackInfo(stackName, version);
if (stack != null)
- servicesResulr = stack.getServices();
- return servicesResulr;
+ servicesResult = stack.getServices();
+ return servicesResult;
}
public List<StackInfo> getSupportedStacks() {
@@ -622,6 +621,41 @@ public class AmbariMetaInfo {
serverVersion = new Scanner(versionFile).useDelimiter("\\Z").next();
}
+ private void getCustomActionDefinitions(File customActionDefinitionRoot) throws JAXBException, AmbariException {
+ if (customActionDefinitionRoot != null) {
+ LOG.debug("Loading custom action definitions from "
+ + customActionDefinitionRoot.getAbsolutePath());
+
+ if (customActionDefinitionRoot.exists() && customActionDefinitionRoot.isDirectory()) {
+ adManager.readCustomActionDefinitions(customActionDefinitionRoot);
+ } else {
+ LOG.debug("No action definitions found at " + customActionDefinitionRoot.getAbsolutePath());
+ }
+ }
+ }
+
+ /**
+ * Get all action definitions
+ */
+ public List<ActionDefinition> getAllActionDefinition(){
+ return adManager.getAllActionDefinition();
+ }
+
+ /**
+ * Get action definitions based on the supplied name
+ */
+ public ActionDefinition getActionDefinition(String name){
+ return adManager.getActionDefinition(name);
+ }
+
+
+ /**
+ * Used for test purposes
+ */
+ public void addActionDefinition(ActionDefinition ad) throws AmbariException {
+ adManager.addActionDefinition(ad);
+ }
+
private void getConfigurationInformation(File stackRoot) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("Loading stack information"
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 7c8bbdf..b070d98 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -52,7 +52,7 @@ public class Configuration {
public static final String BOOTSTRAP_DIR_DEFAULT = "/var/run/ambari-server/bootstrap";
public static final String WEBAPP_DIR = "webapp.dir";
public static final String BOOTSTRAP_SCRIPT = "bootstrap.script";
- public static final String BOOTSTRAP_SCRIPT_DEFAULT = "/usr/bin/ambari_bootstrap";
+ public static final String BOOTSTRAP_SCRIPT_DEFAULT = "/usr/bin/ambari_bootstrap";
public static final String BOOTSTRAP_SETUP_AGENT_SCRIPT = "bootstrap.setup_agent.script";
public static final String BOOTSTRAP_SETUP_AGENT_PASSWORD = "bootstrap.setup_agent.password";
public static final String BOOTSTRAP_MASTER_HOSTNAME = "bootstrap.master_host_name";
@@ -81,7 +81,6 @@ public class Configuration {
public static final String JAVA_HOME_KEY = "java.home";
public static final String JDK_NAME_KEY = "jdk.name";
public static final String JCE_NAME_KEY = "jce.name";
-
public static final String CLIENT_SECURITY_KEY = "client.security";
public static final String CLIENT_API_PORT_KEY = "client.api.port";
public static final String CLIENT_API_SSL_PORT_KEY = "client.api.ssl.port";
@@ -96,7 +95,6 @@ public class Configuration {
public static final String POSTGRES_DB_NAME = "postgres";
public static final String ORACLE_DB_NAME = "oracle";
public static final String MYSQL_DB_NAME = "mysql";
-
public static final String OJDBC_JAR_NAME_KEY = "db.oracle.jdbc.name";
public static final String OJDBC_JAR_NAME_DEFAULT = "ojdbc6.jar";
public static final String MYSQL_JAR_NAME_KEY = "db.mysql.jdbc.name";
@@ -128,99 +126,119 @@ public class Configuration {
"authorization.ldap.adminGroupMappingRules";
public static final String LDAP_GROUP_SEARCH_FILTER_KEY =
"authorization.ldap.groupSearchFilter";
-
public static final String USER_ROLE_NAME_KEY =
"authorization.userRoleName";
public static final String ADMIN_ROLE_NAME_KEY =
"authorization.adminRoleName";
-
public static final String SERVER_EC_CACHE_SIZE = "server.ecCacheSize";
- private static final long SERVER_EC_CACHE_SIZE_DEFAULT = 10000L;
-
public static final String SERVER_PERSISTENCE_TYPE_KEY = "server.persistence.type";
public static final String SERVER_JDBC_USER_NAME_KEY = "server.jdbc.user.name";
public static final String SERVER_JDBC_USER_PASSWD_KEY = "server.jdbc.user.passwd";
public static final String SERVER_JDBC_DRIVER_KEY = "server.jdbc.driver";
public static final String SERVER_JDBC_URL_KEY = "server.jdbc.url";
public static final String SERVER_JDBC_PROPERTIES_PREFIX = "server.jdbc.properties.";
-
-// public static final String SERVER_RCA_PERSISTENCE_TYPE_KEY = "server.rca.persistence.type";
+ // public static final String SERVER_RCA_PERSISTENCE_TYPE_KEY = "server.rca.persistence.type";
public static final String SERVER_JDBC_RCA_USER_NAME_KEY = "server.jdbc.rca.user.name";
public static final String SERVER_JDBC_RCA_USER_PASSWD_KEY = "server.jdbc.rca.user.passwd";
public static final String SERVER_JDBC_RCA_DRIVER_KEY = "server.jdbc.rca.driver";
public static final String SERVER_JDBC_RCA_URL_KEY = "server.jdbc.rca.url";
-
public static final String SERVER_JDBC_GENERATE_TABLES_KEY = "server.jdbc.generateTables";
-
public static final String JDBC_UNIT_NAME = "ambari-server";
-
public static final String JDBC_LOCAL_URL = "jdbc:postgresql://localhost/";
public static final String JDBC_LOCAL_DRIVER = "org.postgresql.Driver";
-
public static final String JDBC_IN_MEMORY_URL = "jdbc:derby:memory:myDB/ambari;create=true";
public static final String JDBC_IN_MEMROY_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
-
public static final String HOSTNAME_MACRO = "{hostname}";
public static final String JDBC_RCA_LOCAL_URL = "jdbc:postgresql://" + HOSTNAME_MACRO + "/ambarirca";
public static final String JDBC_RCA_LOCAL_DRIVER = "org.postgresql.Driver";
-
- private static final String SERVER_JDBC_USER_NAME_DEFAULT = "ambari-server";
- private static final String SERVER_JDBC_USER_PASSWD_DEFAULT = "bigdata";
-
- private static final String SERVER_JDBC_RCA_USER_NAME_DEFAULT = "mapred";
- private static final String SERVER_JDBC_RCA_USER_PASSWD_DEFAULT = "mapred";
-
public static final String OS_VERSION_KEY =
"server.os_type";
-
public static final String SRVR_HOSTS_MAPPING =
"server.hosts.mapping";
-
// Command parameter names
public static final String UPGRADE_FROM_STACK = "source_stack_version";
public static final String UPGRADE_TO_STACK = "target_stack_version";
-
public static final String SSL_TRUSTSTORE_PATH_KEY = "ssl.trustStore.path";
public static final String SSL_TRUSTSTORE_PASSWORD_KEY = "ssl.trustStore.password";
public static final String SSL_TRUSTSTORE_TYPE_KEY = "ssl.trustStore.type";
public static final String JAVAX_SSL_TRUSTSTORE = "javax.net.ssl.trustStore";
public static final String JAVAX_SSL_TRUSTSTORE_PASSWORD = "javax.net.ssl.trustStorePassword";
public static final String JAVAX_SSL_TRUSTSTORE_TYPE = "javax.net.ssl.trustStoreType";
-
public static final String GANGLIA_HTTPS_KEY = "ganglia.https";
- public static final String NAGIOS_HTTPS_KEY = "nagios.https";
-
- private static final String SRVR_TWO_WAY_SSL_DEFAULT = "false";
+ public static final String NAGIOS_HTTPS_KEY = "nagios.https";
public static final String SRVR_TWO_WAY_SSL_PORT_DEFAULT = "8441";
public static final String SRVR_ONE_WAY_SSL_PORT_DEFAULT = "8440";
- private static final String SRVR_KSTR_DIR_DEFAULT = ".";
public static final String SRVR_CRT_NAME_DEFAULT = "ca.crt";
public static final String SRVR_KEY_NAME_DEFAULT = "ca.key";
public static final String KSTR_NAME_DEFAULT = "keystore.p12";
-
public static final String CLIENT_API_SSL_KSTR_NAME_DEFAULT = "https.keystore.p12";
public static final String CLIENT_API_SSL_CRT_PASS_FILE_NAME_DEFAULT = "https.pass.txt";
public static final String CLIENT_API_SSL_KEY_NAME_DEFAULT = "https.key";
public static final String CLIENT_API_SSL_CRT_NAME_DEFAULT = "https.crt";
+ public static final String GLOBAL_CONFIG_TAG = "global";
+ public static final String RCA_ENABLED_PROPERTY = "rca_enabled";
+ public static final String HIVE_CONFIG_TAG = "hive-site";
+ public static final String HIVE_METASTORE_PASSWORD_PROPERTY =
+ "javax.jdo.option.ConnectionPassword";
+ public static final String MASTER_KEY_PERSISTED = "security.master" +
+ ".key.ispersisted";
+ public static final String MASTER_KEY_LOCATION = "security.master.key" +
+ ".location";
+ public static final String MASTER_KEY_ENV_PROP =
+ "AMBARI_SECURITY_MASTER_KEY";
+ public static final String MASTER_KEY_FILENAME_DEFAULT = "master";
+ /**
+ * Key for repo validation suffixes.
+ */
+ public static final String REPO_SUFFIX_KEY = "repo.validation.suffixes";
+ public static final String EXECUTION_SCHEDULER_CLUSTERED =
+ "server.execution.scheduler.isClustered";
+ public static final String EXECUTION_SCHEDULER_THREADS =
+ "server.execution.scheduler.maxThreads";
+ public static final String EXECUTION_SCHEDULER_CONNECTIONS =
+ "server.execution.scheduler.maxDbConnections";
+ public static final String EXECUTION_SCHEDULER_MISFIRE_TOLERATION =
+ "server.execution.scheduler.misfire.toleration.minutes";
+ public static final String EXECUTION_SCHEDULER_START_DELAY =
+ "server.execution.scheduler.start.delay.seconds";
+ public static final String DEFAULT_SCHEDULER_THREAD_COUNT = "5";
+ public static final String DEFAULT_SCHEDULER_MAX_CONNECTIONS = "5";
+ public static final String DEFAULT_EXECUTION_SCHEDULER_MISFIRE_TOLERATION = "480";
+ public static final String DEFAULT_SCHEDULER_START_DELAY_SECONDS = "120";
+ /**
+ * This key defines whether stages of parallel requests are executed in
+ * parallel or sequentally. Only stages from different requests
+ * running on not interfering host sets may be executed in parallel.
+ */
+ public static final String PARALLEL_STAGE_EXECUTION_KEY =
+ "server.stages.parallel";
+ public static final String AGENT_TASK_TIMEOUT_KEY = "agent.task.timeout";
+ public static final String AGENT_TASK_TIMEOUT_DEFAULT = "600";
- private static final String API_CSRF_PREVENTION_DEFAULT = "true";
+ public static final String CUSTOM_ACTION_DEFINITION_KEY = "custom.action.definitions";
+ private static final String CUSTOM_ACTION_DEFINITION_DEF_VALUE =
+ "/var/lib/ambari-server/resources/custom_action_definitions";
- private static final String SRVR_CRT_PASS_FILE_DEFAULT ="pass.txt";
+ private static final long SERVER_EC_CACHE_SIZE_DEFAULT = 10000L;
+ private static final String SERVER_JDBC_USER_NAME_DEFAULT = "ambari-server";
+ private static final String SERVER_JDBC_USER_PASSWD_DEFAULT = "bigdata";
+ private static final String SERVER_JDBC_RCA_USER_NAME_DEFAULT = "mapred";
+ private static final String SERVER_JDBC_RCA_USER_PASSWD_DEFAULT = "mapred";
+ private static final String SRVR_TWO_WAY_SSL_DEFAULT = "false";
+ private static final String SRVR_KSTR_DIR_DEFAULT = ".";
+ private static final String API_CSRF_PREVENTION_DEFAULT = "true";
+ private static final String SRVR_CRT_PASS_FILE_DEFAULT = "pass.txt";
private static final String SRVR_CRT_PASS_LEN_DEFAULT = "50";
private static final String PASSPHRASE_ENV_DEFAULT = "AMBARI_PASSPHRASE";
private static final String RESOURCES_DIR_DEFAULT =
"/var/share/ambari/resources/";
-
- private static final String ANONYMOUS_AUDIT_NAME_KEY = "anonymous.audit.name";
-
+ private static final String ANONYMOUS_AUDIT_NAME_KEY = "anonymous.audit.name";
private static final String CLIENT_SECURITY_DEFAULT = "local";
private static final int CLIENT_API_PORT_DEFAULT = 8080;
private static final int CLIENT_API_SSL_PORT_DEFAULT = 8443;
-
private static final String USER_ROLE_NAME_DEFAULT = "user";
private static final String ADMIN_ROLE_NAME_DEFAULT = "admin";
private static final String LDAP_BIND_ANONYMOUSLY_DEFAULT = "true";
-
//TODO For embedded server only - should be removed later
private static final String LDAP_PRIMARY_URL_DEFAULT = "localhost:33389";
private static final String LDAP_BASE_DN_DEFAULT = "dc=ambari,dc=apache,dc=org";
@@ -233,75 +251,22 @@ public class Configuration {
private static final String LDAP_ADMIN_GROUP_MAPPING_RULES_DEFAULT =
"Ambari Administrators";
private static final String LDAP_GROUP_SEARCH_FILTER_DEFAULT = "";
-
//TODO for development purposes only, should be changed to 'false'
private static final String SERVER_PERSISTENCE_TYPE_DEFAULT = "local";
-
private static final String SERVER_CONNECTION_MAX_IDLE_TIME =
- "server.connection.max.idle.millis";
-
- public static final String GLOBAL_CONFIG_TAG = "global";
- public static final String RCA_ENABLED_PROPERTY = "rca_enabled";
- public static final String HIVE_CONFIG_TAG = "hive-site";
- public static final String HIVE_METASTORE_PASSWORD_PROPERTY =
- "javax.jdo.option.ConnectionPassword";
-
- public static final String MASTER_KEY_PERSISTED = "security.master" +
- ".key.ispersisted";
- public static final String MASTER_KEY_LOCATION = "security.master.key" +
- ".location";
- public static final String MASTER_KEY_ENV_PROP =
- "AMBARI_SECURITY_MASTER_KEY";
- public static final String MASTER_KEY_FILENAME_DEFAULT = "master";
-
- /**
- * Key for repo validation suffixes.
- */
- public static final String REPO_SUFFIX_KEY = "repo.validation.suffixes";
+ "server.connection.max.idle.millis";
/**
* Default for repo validation suffixes.
*/
private static final String REPO_SUFFIX_DEFAULT = "/repodata/repomd.xml";
-
- public static final String EXECUTION_SCHEDULER_CLUSTERED =
- "server.execution.scheduler.isClustered";
- public static final String EXECUTION_SCHEDULER_THREADS =
- "server.execution.scheduler.maxThreads";
- public static final String EXECUTION_SCHEDULER_CONNECTIONS =
- "server.execution.scheduler.maxDbConnections";
- public static final String EXECUTION_SCHEDULER_MISFIRE_TOLERATION =
- "server.execution.scheduler.misfire.toleration.minutes";
- public static final String EXECUTION_SCHEDULER_START_DELAY =
- "server.execution.scheduler.start.delay.seconds";
-
- public static final String DEFAULT_SCHEDULER_THREAD_COUNT = "5";
- public static final String DEFAULT_SCHEDULER_MAX_CONNECTIONS = "5";
- public static final String DEFAULT_EXECUTION_SCHEDULER_MISFIRE_TOLERATION = "480";
- public static final String DEFAULT_SCHEDULER_START_DELAY_SECONDS = "120";
-
-
- /**
- * This key defines whether stages of parallel requests are executed in
- * parallel or sequentally. Only stages from different requests
- * running on not interfering host sets may be executed in parallel.
- */
- public static final String PARALLEL_STAGE_EXECUTION_KEY =
- "server.stages.parallel";
private static final String PARALLEL_STAGE_EXECUTION_DEFAULT = "true";
-
- public static final String AGENT_TASK_TIMEOUT_KEY = "agent.task.timeout";
- public static final String AGENT_TASK_TIMEOUT_DEFAULT = "600";
-
private static final Logger LOG = LoggerFactory.getLogger(
Configuration.class);
-
private Properties properties;
-
private Map<String, String> configsMap;
-
private CredentialProvider credentialProvider = null;
private volatile boolean credentialProviderInitialized = false;
- private Map<String,String> customDbProperties = null;
+ private Map<String, String> customDbProperties = null;
public Configuration() {
this(readConfigFile());
@@ -929,18 +894,26 @@ public class Configuration {
return "true".equalsIgnoreCase(configsMap.get(PARALLEL_STAGE_EXECUTION_KEY));
}
+ public String getCustomActionDefinitionPath() {
+ String value = configsMap.get(CUSTOM_ACTION_DEFINITION_KEY);
+ if (value == null) {
+ value = CUSTOM_ACTION_DEFINITION_DEF_VALUE;
+ }
+ return value;
+ }
+
/**
* @return default task timeout in seconds (string representation). This value
- * is used at python (agent) code.
+ * is used at python (agent) code.
*/
public String getDefaultAgentTaskTimeout() {
- String value = properties.getProperty(AGENT_TASK_TIMEOUT_KEY, AGENT_TASK_TIMEOUT_DEFAULT);
+ String value = properties.getProperty(AGENT_TASK_TIMEOUT_KEY, AGENT_TASK_TIMEOUT_DEFAULT);
if (StringUtils.isNumeric(value)) {
return value;
} else {
LOG.warn(String.format("Value of %s (%s) should be a number, " +
- "falling back to default value (%s)",
- AGENT_TASK_TIMEOUT_KEY, value, AGENT_TASK_TIMEOUT_DEFAULT));
+ "falling back to default value (%s)",
+ AGENT_TASK_TIMEOUT_KEY, value, AGENT_TASK_TIMEOUT_DEFAULT));
return AGENT_TASK_TIMEOUT_DEFAULT;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionResponse.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionResponse.java
index f85f640..e7edafb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ActionResponse.java
@@ -18,8 +18,6 @@
package org.apache.ambari.server.controller;
-import org.apache.ambari.server.actionmanager.ActionDefinition;
-
/**
* Used to respond to GET requests for actions
*/
@@ -47,15 +45,6 @@ public class ActionResponse {
setDefaultTimeout(defaultTimeout);
}
- public ActionResponse(ActionDefinition ad) {
- this(ad.getActionName(), ad.getActionType().toString(), ad.getInputs(),
- null == ad.getTargetService() ? "" : ad.getTargetService().toString(),
- null == ad.getTargetComponent() ? "" : ad.getTargetComponent().toString(),
- ad.getDescription(),
- null == ad.getTargetType() ? "" : ad.getTargetType().toString(),
- ad.getDefaultTimeout().toString());
- }
-
public String getActionName() {
return actionName;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/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 d985d9f..70f9e58 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
@@ -22,13 +22,13 @@ import org.apache.ambari.server.AmbariException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.StackAccessException;
-import org.apache.ambari.server.actionmanager.ActionDefinition;
import org.apache.ambari.server.actionmanager.ActionManager;
import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.actionmanager.TargetHostType;
import org.apache.ambari.server.agent.ExecutionCommand;
import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.configuration.Configuration;
+import org.apache.ambari.server.customactions.ActionDefinition;
import org.apache.ambari.server.metadata.ActionMetadata;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
@@ -41,9 +41,15 @@ import org.apache.ambari.server.utils.StageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.*;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
-import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.*;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.COMMAND_TIMEOUT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCHEMA_VERSION;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT;
+import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.SCRIPT_TYPE;
/**
* Helper class containing logic to process custom action execution requests
@@ -51,14 +57,13 @@ import static org.apache.ambari.server.agent.ExecutionCommand.KeyNames.*;
public class AmbariActionExecutionHelper {
private final static Logger LOG =
LoggerFactory.getLogger(AmbariActionExecutionHelper.class);
+ private static final String TYPE_PYTHON = "PYTHON";
private ActionMetadata actionMetadata;
private Clusters clusters;
private AmbariManagementControllerImpl amcImpl;
private ActionManager actionManager;
private AmbariMetaInfo ambariMetaInfo;
- private static final String TYPE_PYTHON = "PYTHON";
-
public AmbariActionExecutionHelper(ActionMetadata actionMetadata, Clusters clusters,
AmbariManagementControllerImpl amcImpl) {
this.amcImpl = amcImpl;
@@ -82,7 +87,7 @@ public class AmbariActionExecutionHelper {
throw new AmbariException("Action name must be specified");
}
- ActionDefinition actionDef = actionManager.getActionDefinition(actionRequest.getActionName());
+ ActionDefinition actionDef = ambariMetaInfo.getActionDefinition(actionRequest.getActionName());
if (actionDef == null) {
throw new AmbariException("Action " + actionRequest.getActionName() + " does not exist");
}
@@ -164,7 +169,7 @@ public class AmbariActionExecutionHelper {
}
}
- if (actionDef.getTargetType() == TargetHostType.SPECIFIC
+ if (TargetHostType.SPECIFIC.name().equals(actionDef.getTargetType())
|| (targetService.isEmpty() && targetService.isEmpty())) {
if (actionRequest.getHosts().size() == 0) {
throw new AmbariException("Action " + actionRequest.getActionName() + " requires explicit target host(s)" +
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
index 7aa39a8..2b93e54 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/ControllerModule.java
@@ -18,12 +18,19 @@
package org.apache.ambari.server.controller;
-import java.security.SecureRandom;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-
-import org.apache.ambari.server.actionmanager.*;
+import com.google.gson.Gson;
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+import com.google.inject.assistedinject.FactoryModuleBuilder;
+import com.google.inject.name.Names;
+import com.google.inject.persist.jpa.JpaPersistModule;
+import org.apache.ambari.server.actionmanager.ActionDBAccessor;
+import org.apache.ambari.server.actionmanager.ActionDBAccessorImpl;
+import org.apache.ambari.server.actionmanager.ExecutionCommandWrapper;
+import org.apache.ambari.server.actionmanager.HostRoleCommandFactory;
+import org.apache.ambari.server.actionmanager.HostRoleCommandFactoryImpl;
+import org.apache.ambari.server.actionmanager.RequestFactory;
+import org.apache.ambari.server.actionmanager.StageFactory;
import org.apache.ambari.server.configuration.Configuration;
import org.apache.ambari.server.controller.internal.ComponentResourceProvider;
import org.apache.ambari.server.controller.internal.HostComponentResourceProvider;
@@ -64,14 +71,24 @@ import org.apache.ambari.server.state.svccomphost.ServiceComponentHostImpl;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.StandardPasswordEncoder;
-import com.google.gson.Gson;
-import com.google.inject.AbstractModule;
-import com.google.inject.Scopes;
-import com.google.inject.assistedinject.FactoryModuleBuilder;
-import com.google.inject.name.Names;
-import com.google.inject.persist.jpa.JpaPersistModule;
+import java.security.SecureRandom;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
-import static org.eclipse.persistence.config.PersistenceUnitProperties.*;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_JDBC_DDL_FILE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_ONLY;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.CREATE_OR_EXTEND;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_BOTH_GENERATION;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_GENERATION;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DDL_GENERATION_MODE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DROP_AND_CREATE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.DROP_JDBC_DDL_FILE;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_DRIVER;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_PASSWORD;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_URL;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.JDBC_USER;
+import static org.eclipse.persistence.config.PersistenceUnitProperties.THROW_EXCEPTIONS;
/**
* Used for injection purposes.
@@ -108,7 +125,6 @@ public class ControllerModule extends AbstractModule {
bind(Clusters.class).to(ClustersImpl.class);
bind(AmbariCustomCommandExecutionHelper.class);
bind(ActionDBAccessor.class).to(ActionDBAccessorImpl.class);
- bind(CustomActionDBAccessor.class).to(CustomActionDBAccessorImpl.class);
bindConstant().annotatedWith(Names.named("schedulerSleeptime")).to(10000L);
// This time is added to summary timeout time of all tasks in stage
@@ -141,13 +157,13 @@ public class ControllerModule extends AbstractModule {
// custom jdbc properties
Map<String, String> custom = configuration.getDatabaseCustomProperties();
-
+
if (0 != custom.size()) {
for (Entry<String, String> entry : custom.entrySet()) {
properties.setProperty("eclipselink.jdbc.property." + entry.getKey(),
- entry.getValue());
+ entry.getValue());
}
- }
+ }
switch (persistenceType) {
case IN_MEMORY:
@@ -202,16 +218,16 @@ public class ControllerModule extends AbstractModule {
Host.class, HostImpl.class).build(HostFactory.class));
install(new FactoryModuleBuilder().implement(
Service.class, ServiceImpl.class).build(ServiceFactory.class));
-
-
+
+
install(new FactoryModuleBuilder()
.implement(ResourceProvider.class, Names.named("host"), HostResourceProvider.class)
.implement(ResourceProvider.class, Names.named("hostComponent"), HostComponentResourceProvider.class)
.implement(ResourceProvider.class, Names.named("service"), ServiceResourceProvider.class)
.implement(ResourceProvider.class, Names.named("component"), ComponentResourceProvider.class)
- .build(ResourceProviderFactory.class));
+ .build(ResourceProviderFactory.class));
+
-
install(new FactoryModuleBuilder().implement(
ServiceComponent.class, ServiceComponentImpl.class).build(
ServiceComponentFactory.class));
@@ -221,9 +237,9 @@ public class ControllerModule extends AbstractModule {
install(new FactoryModuleBuilder().implement(
Config.class, ConfigImpl.class).build(ConfigFactory.class));
install(new FactoryModuleBuilder().implement(
- ConfigGroup.class, ConfigGroupImpl.class).build(ConfigGroupFactory.class));
+ ConfigGroup.class, ConfigGroupImpl.class).build(ConfigGroupFactory.class));
install(new FactoryModuleBuilder().implement(RequestExecution.class,
- RequestExecutionImpl.class).build(RequestExecutionFactory.class));
+ RequestExecutionImpl.class).build(RequestExecutionFactory.class));
install(new FactoryModuleBuilder().build(StageFactory.class));
install(new FactoryModuleBuilder().build(RequestFactory.class));
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java
index 54ab41c..faef86c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ActionResourceProvider.java
@@ -20,15 +20,11 @@
package org.apache.ambari.server.controller.internal;
import org.apache.ambari.server.AmbariException;
-import org.apache.ambari.server.actionmanager.ActionDefinition;
import org.apache.ambari.server.actionmanager.ActionManager;
-import org.apache.ambari.server.actionmanager.ActionType;
-import org.apache.ambari.server.actionmanager.CustomActionDBAccessorImpl;
-import org.apache.ambari.server.actionmanager.TargetHostType;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
import org.apache.ambari.server.controller.ActionRequest;
import org.apache.ambari.server.controller.ActionResponse;
import org.apache.ambari.server.controller.AmbariManagementController;
-import org.apache.ambari.server.controller.RequestStatusResponse;
import org.apache.ambari.server.controller.spi.NoSuchParentResourceException;
import org.apache.ambari.server.controller.spi.NoSuchResourceException;
import org.apache.ambari.server.controller.spi.Predicate;
@@ -40,6 +36,7 @@ import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.customactions.ActionDefinition;
import java.util.Arrays;
import java.util.HashSet;
@@ -67,7 +64,6 @@ public class ActionResourceProvider extends AbstractControllerResourceProvider {
.getPropertyId("Actions", "default_timeout");
private static Set<String> pkPropertyIds = new HashSet<String>(
Arrays.asList(new String[]{ACTION_NAME_PROPERTY_ID}));
- private Boolean enableExperimental = false;
public ActionResourceProvider(Set<String> propertyIds,
Map<Type, String> keyPropertyIds,
@@ -75,14 +71,6 @@ public class ActionResourceProvider extends AbstractControllerResourceProvider {
super(propertyIds, keyPropertyIds, managementController);
}
- public Boolean getEnableExperimental() {
- return enableExperimental;
- }
-
- public void setEnableExperimental(Boolean enabled) {
- enableExperimental = enabled;
- }
-
@Override
public RequestStatus createResources(Request request)
throws SystemException,
@@ -90,29 +78,8 @@ public class ActionResourceProvider extends AbstractControllerResourceProvider {
ResourceAlreadyExistsException,
NoSuchParentResourceException {
- if (!getEnableExperimental()) {
- throw new UnsupportedOperationException("Not currently supported.");
- }
-
- for (final Map<String, Object> properties : request.getProperties()) {
- createResources(new Command<Void>() {
- @Override
- public Void invoke() throws AmbariException {
- ActionRequest actionReq = getRequest(properties);
- LOG.info("Received a create request for Action with"
- + ", actionName = " + actionReq.getActionName()
- + ", actionType = " + actionReq.getActionType()
- + ", description = " + actionReq.getDescription()
- + ", service = " + actionReq.getTargetService());
+ throw new UnsupportedOperationException("Not currently supported.");
- createActionDefinition(actionReq);
- return null;
- }
- });
- }
- notifyCreate(Type.Action, request);
-
- return getRequestStatus(null);
}
@Override
@@ -120,34 +87,8 @@ public class ActionResourceProvider extends AbstractControllerResourceProvider {
throws SystemException, UnsupportedPropertyException,
NoSuchResourceException, NoSuchParentResourceException {
- if (!getEnableExperimental()) {
- throw new UnsupportedOperationException("Not currently supported.");
- }
+ throw new UnsupportedOperationException("Not currently supported.");
- final Set<ActionRequest> requests = new HashSet<ActionRequest>();
- RequestStatusResponse response;
-
- for (Map<String, Object> requestPropertyMap : request.getProperties()) {
- Set<Map<String, Object>> propertyMaps = getPropertyMaps(requestPropertyMap, predicate);
- for (Map<String, Object> propertyMap : propertyMaps) {
- ActionRequest actionReq = getRequest(propertyMap);
- LOG.info("Received a update request for Action with"
- + ", actionName = " + actionReq.getActionName()
- + ", actionType = " + actionReq.getActionType()
- + ", description = " + actionReq.getDescription()
- + ", timeout = " + actionReq.getDefaultTimeout());
-
- requests.add(actionReq);
- }
- }
- response = modifyResources(new Command<RequestStatusResponse>() {
- @Override
- public RequestStatusResponse invoke() throws AmbariException {
- return updateActionDefinitions(requests, request.getRequestInfoProperties());
- }
- });
- notifyUpdate(Type.Action, request, predicate);
- return getRequestStatus(response);
}
@Override
@@ -205,23 +146,7 @@ public class ActionResourceProvider extends AbstractControllerResourceProvider {
public RequestStatus deleteResources(Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException, NoSuchParentResourceException {
- if (!getEnableExperimental()) {
- throw new UnsupportedOperationException("Not currently supported.");
- }
-
- for (Map<String, Object> propertyMap : getPropertyMaps(predicate)) {
- final ActionRequest request = getRequest(propertyMap);
- try {
- LOG.info("Received a delete request for Action with"
- + ", actionName = " + request.getActionName());
-
- deleteActionDefinition(request);
- } catch (AmbariException ex) {
- throw new NoSuchResourceException(ex.getMessage());
- }
- }
- notifyDelete(Type.Action, predicate);
- return getRequestStatus(null);
+ throw new UnsupportedOperationException("Not currently supported.");
}
private ActionRequest getRequest(Map<String, Object> properties) {
@@ -247,28 +172,8 @@ public class ActionResourceProvider extends AbstractControllerResourceProvider {
return getManagementController().getActionManager();
}
- protected synchronized void createActionDefinition(ActionRequest request)
- throws AmbariException {
- if (request.getActionName() == null
- || request.getActionName().isEmpty()) {
- throw new IllegalArgumentException("Action name should be provided");
- }
-
- LOG.info("Received a createActionDefinition request = " + request.toString());
- if (request.getTargetType() == null || request.getActionType() == null) {
- throw new AmbariException("Both target_type and action_type must be specified.");
- }
- TargetHostType targetType = TargetHostType.valueOf(request.getTargetType());
- ActionType actionType = ActionType.valueOf(request.getActionType());
-
- Short defaultTimeout = CustomActionDBAccessorImpl.MIN_TIMEOUT;
- if (request.getDefaultTimeout() != null && !request.getDefaultTimeout().isEmpty()) {
- defaultTimeout = Short.parseShort(request.getDefaultTimeout());
- }
-
- getActionManager().createActionDefinition(request.getActionName(), actionType, request.getInputs(),
- request.getDescription(), request.getTargetService(), request.getTargetComponent(),
- targetType, defaultTimeout);
+ private AmbariMetaInfo getAmbariMetaInfo() {
+ return getManagementController().getAmbariMetaInfo();
}
protected synchronized Set<ActionResponse> getActionDefinitions(Set<ActionRequest> requests)
@@ -276,45 +181,18 @@ public class ActionResourceProvider extends AbstractControllerResourceProvider {
Set<ActionResponse> responses = new HashSet<ActionResponse>();
for (ActionRequest request : requests) {
if (request.getActionName() == null) {
- List<ActionDefinition> ads = getActionManager().getAllActionDefinition();
+ List<ActionDefinition> ads = getAmbariMetaInfo().getAllActionDefinition();
for (ActionDefinition ad : ads) {
- responses.add(new ActionResponse(ad));
+ responses.add(ad.convertToResponse());
}
} else {
- ActionDefinition ad = getActionManager().getActionDefinition(request.getActionName());
+ ActionDefinition ad = getAmbariMetaInfo().getActionDefinition(request.getActionName());
if (ad != null) {
- responses.add(new ActionResponse(ad));
+ responses.add(ad.convertToResponse());
}
}
}
return responses;
}
-
- protected synchronized RequestStatusResponse updateActionDefinitions(Set<ActionRequest> requests,
- Map<String, String> requestProperties)
- throws AmbariException {
- RequestStatusResponse response = null;
- for (ActionRequest request : requests) {
- if (null != request.getInputs() || null != request.getTargetService()
- || null != request.getTargetComponent()) {
- throw new AmbariException("Cannot update inputs, target_service, or target_component");
- }
- TargetHostType targetType = request.getTargetType() == null ? null
- : TargetHostType.valueOf(request.getTargetType());
- ActionType actionType = request.getActionType() == null ? null : ActionType.valueOf(request.getActionType());
- Short defaultTimeout = null;
- if (request.getDefaultTimeout() != null && !request.getDefaultTimeout().isEmpty()) {
- defaultTimeout = Short.parseShort(request.getDefaultTimeout());
- }
- getActionManager().updateActionDefinition(request.getActionName(), actionType,
- request.getDescription(), targetType, defaultTimeout);
- }
- return response;
- }
-
- protected synchronized void deleteActionDefinition(ActionRequest request)
- throws AmbariException {
- getActionManager().deleteActionDefinition(request.getActionName());
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinition.java
new file mode 100644
index 0000000..1f189a3
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinition.java
@@ -0,0 +1,132 @@
+/**
+ * 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.ambari.server.customactions;
+
+import org.apache.ambari.server.actionmanager.ActionType;
+import org.apache.ambari.server.actionmanager.TargetHostType;
+import org.apache.ambari.server.controller.ActionResponse;
+
+/**
+ * The resource describing the definition of an action
+ */
+public class ActionDefinition {
+ private String actionName;
+ private ActionType actionType;
+ private String inputs;
+ private String targetService;
+ private String targetComponent;
+ private String description;
+ private TargetHostType targetType;
+ private Short defaultTimeout;
+
+ /**
+ * Create an instance of ActionDefinition
+ *
+ * @param actionName The name of the action
+ * @param actionType The type fo the action
+ * @param inputs Expected input of the action
+ * @param targetService Target service type (e.g. HDFS)
+ * @param targetComponent Target component type (e.g. DATANODE)
+ * @param description Short description of the action
+ * @param targetType Selection criteria for target hosts
+ * @param defaultTimeout The timeout value for this action when executed
+ */
+ public ActionDefinition(String actionName, ActionType actionType, String inputs,
+ String targetService, String targetComponent, String description,
+ TargetHostType targetType, Short defaultTimeout) {
+ setActionName(actionName);
+ setActionType(actionType);
+ setInputs(inputs);
+ setTargetService(targetService);
+ setTargetComponent(targetComponent);
+ setDescription(description);
+ setTargetType(targetType);
+ setDefaultTimeout(defaultTimeout);
+ }
+
+ public String getActionName() {
+ return actionName;
+ }
+
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
+ public ActionType getActionType() {
+ return actionType;
+ }
+
+ public void setActionType(ActionType actionType) {
+ this.actionType = actionType;
+ }
+
+ public String getInputs() {
+ return inputs;
+ }
+
+ public void setInputs(String inputs) {
+ this.inputs = inputs;
+ }
+
+ public String getTargetService() {
+ return targetService;
+ }
+
+ public void setTargetService(String targetService) {
+ this.targetService = targetService;
+ }
+
+ public String getTargetComponent() {
+ return targetComponent;
+ }
+
+ public void setTargetComponent(String targetComponent) {
+ this.targetComponent = targetComponent;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public TargetHostType getTargetType() {
+ return targetType;
+ }
+
+ public void setTargetType(TargetHostType targetType) {
+ this.targetType = targetType;
+ }
+
+ public Short getDefaultTimeout() {
+ return defaultTimeout;
+ }
+
+ public void setDefaultTimeout(Short defaultTimeout) {
+ this.defaultTimeout = defaultTimeout;
+ }
+
+ public ActionResponse convertToResponse() {
+ return new ActionResponse(getActionName(), getActionType().name(), getInputs(),
+ getTargetService(), getTargetComponent(), getDescription(), getTargetType().name(),
+ getDefaultTimeout().toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionManager.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionManager.java b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionManager.java
new file mode 100644
index 0000000..e058ce7
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionManager.java
@@ -0,0 +1,202 @@
+/**
+ * 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.ambari.server.customactions;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.actionmanager.ActionType;
+import org.apache.ambari.server.actionmanager.TargetHostType;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.UnmarshalException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Manages Action definitions read from XML files
+ */
+public class ActionDefinitionManager {
+ public static final Short MIN_TIMEOUT = 60;
+ private final static Logger LOG = LoggerFactory
+ .getLogger(ActionDefinitionManager.class);
+ private static final Map<Class<?>, JAXBContext> _jaxbContexts =
+ new HashMap<Class<?>, JAXBContext>();
+ private static final Short MAX_TIMEOUT = 600;
+
+ static {
+ try {
+ JAXBContext ctx = JAXBContext.newInstance(ActionDefinitionXml.class);
+ _jaxbContexts.put(ActionDefinitionXml.class, ctx);
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private final Map<String, ActionDefinition> actionDefinitionMap = new HashMap<String, ActionDefinition>();
+
+ public ActionDefinitionManager() {
+ }
+
+ public static <T> T unmarshal(Class<T> clz, File file) throws JAXBException {
+ Unmarshaller u = _jaxbContexts.get(clz).createUnmarshaller();
+
+ return clz.cast(u.unmarshal(file));
+ }
+
+ private <E extends Enum<E>> E safeValueOf(Class<E> enumm, String s, StringBuilder reason) {
+ if (s == null || s.length() == 0) {
+ return null;
+ }
+
+ try {
+ return Enum.valueOf(enumm, s);
+ } catch (IllegalArgumentException iaex) {
+ reason.append("Invalid value provided for " + enumm.getName());
+ return null;
+ }
+ }
+
+ public void readCustomActionDefinitions(File customActionDefinitionRoot) throws JAXBException, AmbariException {
+ if (customActionDefinitionRoot == null
+ || !customActionDefinitionRoot.exists()
+ || !customActionDefinitionRoot.canRead()) {
+ LOG.warn("Cannot read custom action definitions. " +
+ customActionDefinitionRoot == null ? "" : "Check path " + customActionDefinitionRoot.getAbsolutePath());
+ }
+
+ File[] customActionDefinitionFiles
+ = customActionDefinitionRoot.listFiles(AmbariMetaInfo.FILENAME_FILTER);
+
+ if (customActionDefinitionFiles != null) {
+ for (File definitionFile : customActionDefinitionFiles) {
+ ActionDefinitionXml adx = null;
+ try {
+ adx = unmarshal(ActionDefinitionXml.class, definitionFile);
+ } catch (UnmarshalException uex) {
+ LOG.warn("Encountered badly formed action definition file - " + definitionFile.getAbsolutePath());
+ continue;
+ }
+ for (ActionDefinitionSpec ad : adx.actionDefinitions()) {
+ LOG.debug("Read action definition = " + ad.toString());
+ StringBuilder errorReason =
+ new StringBuilder("Error while parsing action definition. ").append(ad.toString()).append(" --- ");
+
+ TargetHostType targetType = safeValueOf(TargetHostType.class, ad.getTargetType(), errorReason);
+ ActionType actionType = safeValueOf(ActionType.class, ad.getActionType(), errorReason);
+
+ Short defaultTimeout = MIN_TIMEOUT;
+ if (ad.getDefaultTimeout() != null && !ad.getDefaultTimeout().isEmpty()) {
+ defaultTimeout = Short.parseShort(ad.getDefaultTimeout());
+ }
+
+ if (isValidActionDefinition(ad, actionType, defaultTimeout, errorReason)) {
+ String actionName = ad.getActionName();
+ if (actionDefinitionMap.containsKey(actionName)) {
+ LOG.warn("Ignoring action definition as a different definition by that name already exists. "
+ + ad.toString());
+ continue;
+ }
+
+ actionDefinitionMap.put(ad.getActionName(), new ActionDefinition(ad.getActionName(), actionType,
+ ad.getInputs(), ad.getTargetService(), ad.getTargetComponent(), ad.getDescription(), targetType, defaultTimeout));
+ LOG.info("Added custom action definition for " + ad.getActionName());
+ } else {
+ LOG.warn(errorReason.toString());
+ }
+ }
+ }
+ }
+ }
+
+ private boolean isValidActionDefinition(ActionDefinitionSpec ad, ActionType actionType,
+ Short defaultTimeout, StringBuilder reason) {
+ if (isValidActionName(ad.getActionName(), reason)) {
+
+ if (defaultTimeout < MIN_TIMEOUT || defaultTimeout > MAX_TIMEOUT) {
+ reason.append("Default timeout should be between " + MIN_TIMEOUT + " and " + MAX_TIMEOUT);
+ return false;
+ }
+
+ if (actionType == null || actionType == ActionType.SYSTEM_DISABLED) {
+ reason.append("Action type cannot be " + actionType);
+ return false;
+ }
+
+ if (ad.getDescription() == null || ad.getDescription().isEmpty()) {
+ reason.append("Action description cannot be empty");
+ return false;
+ }
+
+ if (ad.getTargetService() == null || ad.getTargetService().isEmpty()) {
+ if (ad.getTargetComponent() != null && !ad.getTargetComponent().isEmpty()) {
+ reason.append("Target component cannot be specified unless target service is specified");
+ return false;
+ }
+ }
+
+ if (ad.getInputs() != null && !ad.getInputs().isEmpty()) {
+ String[] parameters = ad.getInputs().split(",");
+ for (String parameter : parameters) {
+ if (parameter.trim().isEmpty()) {
+ reason.append("Empty parameter cannot be specified as an input parameter");
+ }
+ }
+ }
+ } else {
+ return false;
+ }
+
+ return true;
+ }
+
+ public List<ActionDefinition> getAllActionDefinition() {
+ return new ArrayList<ActionDefinition>(actionDefinitionMap.values());
+ }
+
+ public ActionDefinition getActionDefinition(String name) {
+ return actionDefinitionMap.get(name);
+ }
+
+ public void addActionDefinition(ActionDefinition ad) throws AmbariException {
+ if (!actionDefinitionMap.containsKey(ad.getActionName())) {
+ actionDefinitionMap.put(ad.getActionName(), ad);
+ } else {
+ throw new AmbariException("Action definition by name " + ad.getActionName() + " already exists.");
+ }
+ }
+
+ private boolean isValidActionName(String actionName, StringBuilder reason) {
+ if (actionName == null || actionName.isEmpty()) {
+ reason.append("Action name cannot be empty");
+ return false;
+ }
+ String trimmedName = actionName.replaceAll("\\s+", "");
+ if (actionName.length() > trimmedName.length()) {
+ reason.append("Action name cannot contain white spaces");
+ return false;
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8e8a9a47/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionSpec.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionSpec.java b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionSpec.java
new file mode 100644
index 0000000..2dfa1f2
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/customactions/ActionDefinitionSpec.java
@@ -0,0 +1,139 @@
+/**
+ * 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.ambari.server.customactions;
+
+public class ActionDefinitionSpec {
+ private String actionName;
+ private String actionType;
+ private String inputs;
+ private String targetService;
+ private String targetComponent;
+ private String description;
+ private String targetType;
+ private String defaultTimeout;
+
+ public String getTargetComponent() {
+ return targetComponent;
+ }
+
+ public void setTargetComponent(String targetComponent) {
+ this.targetComponent = targetComponent;
+ }
+
+ public String getTargetType() {
+ return targetType;
+ }
+
+ public void setTargetType(String targetType) {
+ this.targetType = targetType;
+ }
+
+ public String getDefaultTimeout() {
+ return defaultTimeout;
+ }
+
+ public void setDefaultTimeout(String defaultTimeout) {
+ this.defaultTimeout = defaultTimeout;
+ }
+
+ public String getActionName() {
+ return actionName;
+ }
+
+ public void setActionName(String actionName) {
+ this.actionName = actionName;
+ }
+
+ public String getActionType() {
+ return actionType;
+ }
+
+ public void setActionType(String actionType) {
+ this.actionType = actionType;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getInputs() {
+ return inputs;
+ }
+
+ public void setInputs(String inputs) {
+ this.inputs = inputs;
+ }
+
+ public String getTargetService() {
+ return targetService;
+ }
+
+ public void setTargetService(String targetService) {
+ this.targetService = targetService;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((actionName == null) ? 0 : actionName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ActionDefinitionSpec other = (ActionDefinitionSpec) obj;
+ if (description == null) {
+ if (other.description != null) {
+ return false;
+ }
+ } else if (!description.equals(other.description)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder().append("ActionDefinition:")
+ .append(" actionName: ").append(actionName)
+ .append(" actionType: ").append(actionType)
+ .append(" inputs: ").append(inputs)
+ .append(" description: ").append(description)
+ .append(" targetService: ").append(targetService)
+ .append(" targetComponent: ").append(targetComponent)
+ .append(" defaultTimeout: ").append(defaultTimeout)
+ .append(" targetType: ").append(targetType)
+ .toString();
+ }
+}