Parcourir la source

AMBARI-5621. Usability: Different umask can cause a lot of issue when installing - alert when first veriying berforei nstall.(vbrodetskyi)

Vitaly Brodetskyi il y a 11 ans
Parent
commit
b4d35ac315

+ 2 - 0
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.")

+ 10 - 5
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

+ 10 - 0
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>

+ 38 - 0
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()

+ 64 - 0
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);
+
+
+  }
+
 }