Repository: ambari Updated Branches: refs/heads/trunk fa787e559 -> b4d35ac31
AMBARI-5621. Usability: Different umask can cause a lot of issue when installing - alert when first veriying berforei nstall.(vbrodetskyi) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b4d35ac3 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b4d35ac3 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b4d35ac3 Branch: refs/heads/trunk Commit: b4d35ac315fc70da74b6299f6dd854f461b0dcaf Parents: fa787e5 Author: Vitaly Brodetskyi <[email protected]> Authored: Wed Apr 30 12:16:26 2014 +0300 Committer: Vitaly Brodetskyi <[email protected]> Committed: Wed Apr 30 12:16:26 2014 +0300 ---------------------------------------------------------------------- .../src/main/python/ambari_agent/ActionQueue.py | 2 + .../server/actionmanager/ActionScheduler.java | 15 +++-- .../system_action_definitions.xml | 10 +++ .../resources/custom_actions/check_umask.py | 38 ++++++++++++ .../actionmanager/TestActionScheduler.java | 64 ++++++++++++++++++++ 5 files changed, 124 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b4d35ac3/ambari-agent/src/main/python/ambari_agent/ActionQueue.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py index 221bf27..bc675dc 100644 --- a/ambari-agent/src/main/python/ambari_agent/ActionQueue.py +++ b/ambari-agent/src/main/python/ambari_agent/ActionQueue.py @@ -100,6 +100,8 @@ class ActionQueue(threading.Thread): def put(self, commands): for command in commands: + if not command.has_key('serviceName'): + command['serviceName'] = "null" logger.info("Adding " + command['commandType'] + " for service " + \ command['serviceName'] + " of cluster " + \ command['clusterName'] + " to the queue.") http://git-wip-us.apache.org/repos/asf/ambari/blob/b4d35ac3/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java index 84e9fbf..eaac6b9 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionScheduler.java @@ -383,12 +383,17 @@ class ActionScheduler implements Runnable { ExecutionCommand c = wrapper.getExecutionCommand(); String roleStr = c.getRole(); HostRoleStatus status = s.getHostRoleStatus(host, roleStr); - Service svc = cluster.getService(c.getServiceName()); + Service svc = null; + if (c.getServiceName() != null && !c.getServiceName().isEmpty()) { + svc = cluster.getService(c.getServiceName()); + } ServiceComponent svcComp = null; Map<String, ServiceComponentHost> scHosts = null; try { - svcComp = svc.getServiceComponent(roleStr); - scHosts = svcComp.getServiceComponentHosts(); + if (svc != null) { + svcComp = svc.getServiceComponent(roleStr); + scHosts = svcComp.getServiceComponentHosts(); + } } catch (ServiceComponentNotFoundException scnex) { String msg = String.format( "%s is not not a service component, assuming its an action", @@ -407,8 +412,8 @@ class ActionScheduler implements Runnable { "Execution command details: " + "cluster=%s; host=%s; service=%s; component=%s; " + "cmdId: %s; taskId: %s; roleCommand: %s", - c.getClusterName(), host, svcComp.getServiceName(), - svcComp.getName(), + c.getClusterName(), host, svcComp == null ? "null" : svcComp.getServiceName(), + svcComp == null ? "null" : svcComp.getName(), c.getCommandId(), c.getTaskId(), c.getRoleCommand()); LOG.warn(message); // Abort the command itself http://git-wip-us.apache.org/repos/asf/ambari/blob/b4d35ac3/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 index db03a8b..7ac344a 100644 --- 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 @@ -39,4 +39,14 @@ <description>Used to create an alert blackout</description> <targetType>ANY</targetType> </actionDefinition> + <actionDefinition> + <actionName>check_umask</actionName> + <actionType>SYSTEM</actionType> + <inputs>threshold</inputs> + <targetService></targetService> + <targetComponent></targetComponent> + <defaultTimeout>60</defaultTimeout> + <description>Check umask</description> + <targetType>ANY</targetType> + </actionDefinition> </actionDefinitions> http://git-wip-us.apache.org/repos/asf/ambari/blob/b4d35ac3/ambari-server/src/main/resources/custom_actions/check_umask.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/custom_actions/check_umask.py b/ambari-server/src/main/resources/custom_actions/check_umask.py new file mode 100644 index 0000000..fe1c1c6 --- /dev/null +++ b/ambari-server/src/main/resources/custom_actions/check_umask.py @@ -0,0 +1,38 @@ +#!/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 CheckUmask(Script): + def actionexecute(self, env): + Execute("umask | grep 0022") + + structured_output_example = { + 'result': 'UMASK validation completed.' + } + + self.put_structured_out(structured_output_example) + + +if __name__ == "__main__": + CheckUmask().execute() http://git-wip-us.apache.org/repos/asf/ambari/blob/b4d35ac3/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 97ee040..3e1d286 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 @@ -1451,4 +1451,68 @@ public class TestActionScheduler { scheduler.stop(); } + + @Test + public void testServerActionWOService() throws Exception { + ActionQueue aq = new ActionQueue(); + Properties properties = new Properties(); + Configuration conf = new Configuration(properties); + Clusters fsm = mock(Clusters.class); + Cluster oneClusterMock = mock(Cluster.class); + Service serviceObj = mock(Service.class); + ServiceComponent scomp = mock(ServiceComponent.class); + ServiceComponentHost sch = mock(ServiceComponentHost.class); + UnitOfWork unitOfWork = mock(UnitOfWork.class); + when(fsm.getCluster(anyString())).thenReturn(oneClusterMock); + when(oneClusterMock.getService(anyString())).thenReturn(serviceObj); + when(serviceObj.getServiceComponent(anyString())).thenReturn(scomp); + when(scomp.getServiceComponentHost(anyString())).thenReturn(sch); + when(serviceObj.getCluster()).thenReturn(oneClusterMock); + + String hostname = "ahost.ambari.apache.org"; + HashMap<String, ServiceComponentHost> hosts = + new HashMap<String, ServiceComponentHost>(); + hosts.put(hostname, sch); + when(scomp.getServiceComponentHosts()).thenReturn(hosts); + + List<Stage> stages = new ArrayList<Stage>(); + Map<String, String> payload = new HashMap<String, String>(); + payload.put(ServerAction.PayloadName.CLUSTER_NAME, "cluster1"); + payload.put(ServerAction.PayloadName.CURRENT_STACK_VERSION, "HDP-0.2"); + final Stage s = getStageWithServerAction(1, 977, hostname, payload, "test"); + s.getExecutionCommands().get("ahost.ambari.apache.org").get(0).getExecutionCommand().setServiceName(null); + stages.add(s); + + ActionDBAccessor db = mock(ActionDBAccessor.class); + when(db.getStagesInProgress()).thenReturn(stages); + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocation) throws Throwable { + String host = (String) invocation.getArguments()[0]; + String role = (String) invocation.getArguments()[3]; + CommandReport commandReport = (CommandReport) invocation.getArguments()[4]; + HostRoleCommand command = s.getHostRoleCommand(host, role); + command.setStatus(HostRoleStatus.valueOf(commandReport.getStatus())); + return null; + } + }).when(db).updateHostRoleState(anyString(), anyLong(), anyLong(), anyString(), any(CommandReport.class)); + + + ActionScheduler scheduler = new ActionScheduler(100, 50, db, aq, fsm, 3, + new HostsMap((String) null), new ServerActionManagerImpl(fsm), + unitOfWork, conf); + scheduler.start(); + + while (!stages.get(0).getHostRoleStatus(hostname, "AMBARI_SERVER_ACTION") + .equals(HostRoleStatus.COMPLETED)) { + Thread.sleep(100); + } + + scheduler.stop(); + assertEquals(stages.get(0).getHostRoleStatus(hostname, "AMBARI_SERVER_ACTION"), + HostRoleStatus.COMPLETED); + + + } + }
