Ver Fonte

AMBARI-5988 Stack extension does not work for monitoringService service property (dsen)

Dmitry Sen há 11 anos atrás
pai
commit
13797a0007

+ 2 - 1
ambari-server/src/main/java/org/apache/ambari/server/api/services/AmbariMetaInfo.java

@@ -561,7 +561,8 @@ public class AmbariMetaInfo {
 
     List<String> monitoringServices = new ArrayList<String>();
     for (ServiceInfo service : getSupportedServices(stackName, version)) {
-      if (service.isMonitoringService()) {
+      if ((service.isMonitoringService() != null) &&
+        service.isMonitoringService()) {
         monitoringServices.add(service.getName());
       }
     }

+ 4 - 0
ambari-server/src/main/java/org/apache/ambari/server/api/util/StackExtensionHelper.java

@@ -140,6 +140,10 @@ public class StackExtensionHelper {
             (childService.isRestartRequiredAfterChange() != null) 
                     ? childService.isRestartRequiredAfterChange()
                     : parentService.isRestartRequiredAfterChange());
+    mergedServiceInfo.setMonitoringService(
+            (childService.isMonitoringService() != null)
+                    ? childService.isMonitoringService()
+                    : parentService.isMonitoringService());
 
     Map<String, ServiceOsSpecific> osSpecific = childService.getOsSpecifics();
     if (! osSpecific.isEmpty()) {

+ 9 - 4
ambari-server/src/main/java/org/apache/ambari/server/state/ServiceInfo.java

@@ -59,8 +59,7 @@ public class ServiceInfo {
   private List<String> configDependencies;
 
   @JsonIgnore
-  @XmlElement(defaultValue = "false")
-  private boolean monitoringService;
+  private Boolean monitoringService;
   
   @JsonIgnore
   @XmlElement(name = "restartRequiredAfterChange")
@@ -395,11 +394,17 @@ public class ServiceInfo {
     return configDir;
   }
 
-  public boolean isMonitoringService() {
+  /**
+   * @return whether the service is a monitoring service
+   */
+  public Boolean isMonitoringService() {
     return monitoringService;
   }
 
-  public void setMonitoringService(boolean monitoringService) {
+  /**
+   * @param monitoringService whether the service is a monitoring service
+   */
+  public void setMonitoringService(Boolean monitoringService) {
     this.monitoringService = monitoringService;
   }
 }

+ 43 - 8
ambari-server/src/test/java/org/apache/ambari/server/api/util/StackExtensionHelperTest.java

@@ -19,7 +19,6 @@
 package org.apache.ambari.server.api.util;
 
 import org.apache.ambari.server.api.services.AmbariMetaInfo;
-import org.apache.ambari.server.api.services.AmbariMetaInfoTest.MockModule;
 import org.apache.ambari.server.metadata.ActionMetadata;
 import org.apache.ambari.server.state.*;
 
@@ -30,7 +29,6 @@ import java.util.Map;
 
 import static org.junit.Assert.*;
 
-import org.junit.Before;
 import org.junit.Test;
 
 import com.google.inject.AbstractModule;
@@ -41,11 +39,7 @@ public class StackExtensionHelperTest {
 
   private final String stackRootStr = "./src/test/resources/stacks/".
           replaceAll("/", File.separator);
-  private final String hBaseDirStr = stackRootStr + "services/HBASE/".
-          replaceAll("/", File.separator);
-  private final String yarnDirStr = stackRootStr + "services/YARN/".
-          replaceAll("/", File.separator);
-  
+
   private Injector injector = Guice.createInjector(new MockModule());
   
   
@@ -69,7 +63,7 @@ public class StackExtensionHelperTest {
     StackExtensionHelper helper = new StackExtensionHelper(injector, stackRoot);
     helper.populateServicesForStack(stackInfo);
     List<ServiceInfo> services =  stackInfo.getServices();
-    assertEquals(7, services.size());
+    assertEquals(8, services.size());
     for (ServiceInfo serviceInfo : services) {
       if (serviceInfo.getName().equals("HIVE")) {
         // Check old-style service
@@ -203,6 +197,7 @@ public class StackExtensionHelperTest {
         if (!serviceInfo.getName().equals("YARN") &&
             !serviceInfo.getName().equals("HDFS") &&
             !serviceInfo.getName().equals("MAPREDUCE2") &&
+            !serviceInfo.getName().equals("NAGIOS") &&
             !serviceInfo.getName().equals("SQOOP")) {
           fail("Unknown service");
         }
@@ -210,6 +205,46 @@ public class StackExtensionHelperTest {
     }
   }
 
+  @Test
+  public void testPropertyInheritance() throws Exception{
+    File stackRoot = new File(stackRootStr);
+    StackInfo stackInfo = new StackInfo();
+    stackInfo.setName("HDP");
+    stackInfo.setVersion("2.0.7");
+    StackExtensionHelper helper = new StackExtensionHelper(injector, stackRoot);
+    helper.populateServicesForStack(stackInfo);
+    helper.fillInfo();
+    List<ServiceInfo> allServices = helper.getAllApplicableServices(stackInfo);
+    assertEquals(13, allServices.size());
+    for (ServiceInfo serviceInfo : allServices) {
+      if (serviceInfo.getName().equals("NAGIOS")) {
+        assertTrue(serviceInfo.isMonitoringService());
+      } else {
+        assertNull(serviceInfo.isMonitoringService());
+      }
+    }
+  }
+
+  @Test
+  public void testPropertyInheritance() throws Exception{
+    File stackRoot = new File(stackRootStr);
+    StackInfo stackInfo = new StackInfo();
+    stackInfo.setName("HDP");
+    stackInfo.setVersion("2.0.7");
+    StackExtensionHelper helper = new StackExtensionHelper(injector, stackRoot);
+    helper.populateServicesForStack(stackInfo);
+    helper.fillInfo();
+    List<ServiceInfo> allServices = helper.getAllApplicableServices(stackInfo);
+    assertEquals(13, allServices.size());
+    for (ServiceInfo serviceInfo : allServices) {
+      if (serviceInfo.getName().equals("NAGIOS")) {
+        assertTrue(serviceInfo.isMonitoringService());
+      } else {
+        assertNull(serviceInfo.isMonitoringService());
+      }
+    }
+  }
+
   @Test
   public void getSchemaVersion() throws Exception {
     File stackRoot = new File(stackRootStr);

+ 137 - 0
ambari-server/src/test/resources/stacks/HDP/2.0.6/services/NAGIOS/metainfo.xml

@@ -0,0 +1,137 @@
+<?xml version="1.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.
+-->
+<metainfo>
+  <schemaVersion>2.0</schemaVersion>
+  <services>
+    <service>
+      <name>NAGIOS</name>
+      <comment>Nagios Monitoring and Alerting system</comment>
+      <version>3.5.0</version>
+      <components>
+        <component>
+           <name>NAGIOS_SERVER</name>
+           <category>MASTER</category>
+           <cardinality>1</cardinality>
+          <dependencies>
+            <dependency>
+              <name>HDFS/HDFS_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>MAPREDUCE2/MAPREDUCE2_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>OOZIE/OOZIE_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>YARN/YARN_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>TEZ/TEZ_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>HCATALOG/HCAT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+          </dependencies>
+           <commandScript>
+             <script>scripts/nagios_server.py</script>
+             <scriptType>PYTHON</scriptType>
+             <timeout>600</timeout>
+           </commandScript>
+        </component>
+      </components>
+      <osSpecifics>
+        <osSpecific>
+          <osFamily>any</osFamily>
+          <packages>
+            <package>
+              <name>perl</name>
+            </package>
+            <package>
+              <name>nagios-plugins-1.4.9</name>
+            </package>
+            <package>
+              <name>nagios-3.5.0-99</name>
+            </package>
+            <package>
+              <name>nagios-www-3.5.0-99</name>
+            </package>
+            <package>
+              <name>nagios-devel-3.5.0-99</name>
+            </package>
+            <package>
+              <name>fping</name>
+            </package>
+            <package>
+              <name>hdp_mon_nagios_addons</name>
+            </package>
+          </packages>
+        </osSpecific>
+        <osSpecific>
+          <osFamily>suse11</osFamily>
+          <packages>
+            <package>
+              <name>php5-json</name>
+            </package>
+            <package>
+              <name>apache2?mod_php*</name>
+            </package>
+            <package>
+              <name>php-curl</name>
+            </package>
+          </packages>
+        </osSpecific>
+        <osSpecific>
+          <osFamily>redhat5</osFamily>
+          <packages>
+            <package>
+              <name>php-pecl-json.x86_64</name>
+            </package>
+          </packages>
+        </osSpecific>
+      </osSpecifics>
+      <configuration-dependencies>
+        <config-type>global</config-type>
+      </configuration-dependencies>
+      <monitoringService>true</monitoringService>
+    </service>
+  </services>
+</metainfo>

+ 136 - 0
ambari-server/src/test/resources/stacks/HDP/2.0.7/services/NAGIOS/metainfo.xml

@@ -0,0 +1,136 @@
+<?xml version="1.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.
+-->
+<metainfo>
+  <schemaVersion>2.0</schemaVersion>
+  <services>
+    <service>
+      <name>NAGIOS</name>
+      <comment>Nagios Monitoring and Alerting system</comment>
+      <version>3.5.0</version>
+      <components>
+        <component>
+           <name>NAGIOS_SERVER</name>
+           <category>MASTER</category>
+           <cardinality>1</cardinality>
+          <dependencies>
+            <dependency>
+              <name>HDFS/HDFS_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>MAPREDUCE2/MAPREDUCE2_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>OOZIE/OOZIE_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>YARN/YARN_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>TEZ/TEZ_CLIENT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+            <dependency>
+              <name>HCATALOG/HCAT</name>
+              <scope>host</scope>
+              <auto-deploy>
+                <enabled>true</enabled>
+              </auto-deploy>
+            </dependency>
+          </dependencies>
+           <commandScript>
+             <script>scripts/nagios_server.py</script>
+             <scriptType>PYTHON</scriptType>
+             <timeout>600</timeout>
+           </commandScript>
+        </component>
+      </components>
+      <osSpecifics>
+        <osSpecific>
+          <osFamily>any</osFamily>
+          <packages>
+            <package>
+              <name>perl</name>
+            </package>
+            <package>
+              <name>nagios-plugins-1.4.9</name>
+            </package>
+            <package>
+              <name>nagios-3.5.0-99</name>
+            </package>
+            <package>
+              <name>nagios-www-3.5.0-99</name>
+            </package>
+            <package>
+              <name>nagios-devel-3.5.0-99</name>
+            </package>
+            <package>
+              <name>fping</name>
+            </package>
+            <package>
+              <name>hdp_mon_nagios_addons</name>
+            </package>
+          </packages>
+        </osSpecific>
+        <osSpecific>
+          <osFamily>suse11</osFamily>
+          <packages>
+            <package>
+              <name>php5-json</name>
+            </package>
+            <package>
+              <name>apache2?mod_php*</name>
+            </package>
+            <package>
+              <name>php-curl</name>
+            </package>
+          </packages>
+        </osSpecific>
+        <osSpecific>
+          <osFamily>redhat5</osFamily>
+          <packages>
+            <package>
+              <name>php-pecl-json.x86_64</name>
+            </package>
+          </packages>
+        </osSpecific>
+      </osSpecifics>
+      <configuration-dependencies>
+        <config-type>global</config-type>
+      </configuration-dependencies>
+    </service>
+  </services>
+</metainfo>