ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-20592 ServicePresences check should also check for services dropped from a release (dili)
Date Tue, 04 Apr 2017 17:59:15 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 6ee881bcf -> 3ca41f262


AMBARI-20592 ServicePresences check should also check for services dropped from a release
(dili)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3ca41f26
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3ca41f26
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3ca41f26

Branch: refs/heads/trunk
Commit: 3ca41f26205de3ac6c316dde749abcedf4082509
Parents: 6ee881b
Author: Di Li <dili@apache.org>
Authored: Tue Apr 4 13:58:58 2017 -0400
Committer: Di Li <dili@apache.org>
Committed: Tue Apr 4 13:58:58 2017 -0400

----------------------------------------------------------------------
 .../ambari/server/checks/CheckDescription.java  |  5 +-
 .../server/checks/ServicePresenceCheck.java     | 52 +++++++++++++++++---
 .../server/checks/ServicePresenceCheckTest.java | 41 ++++++++++++---
 3 files changed, 83 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3ca41f26/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
index 71c5857..e17185f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/CheckDescription.java
@@ -280,9 +280,12 @@ public class CheckDescription {
             "This service does not support upgrades and must be removed before the upgrade
can continue. " +
             "After upgrading, %s can be reinstalled")
         .put(ServicePresenceCheck.KEY_SERVICE_REMOVED,
+             "The %s service is currently installed on the cluster. " +
+             "This service is removed from the new release and must be removed before the
upgrade can continue.")
+        .put(ServicePresenceCheck.KEY_SERVICE_REPLACED,
             "The %s service is currently installed on the cluster. " +
             "This service is removed from the new release and must be removed before the
upgrade can continue. " +
-            "After upgrading, %s can be installed").build());
+            "After upgrading, %s can be installed as the replacement.").build());
 
   public static CheckDescription RANGER_SERVICE_AUDIT_DB_CHECK = new CheckDescription("RANGER_SERVICE_AUDIT_DB_CHECK",
     PrereqCheckType.SERVICE,

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ca41f26/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
index ed38882..5ff1f0b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/ServicePresenceCheck.java
@@ -46,7 +46,9 @@ public class ServicePresenceCheck extends AbstractCheckDescriptor{
 
   private static final Logger LOG = LoggerFactory.getLogger(ServicePresenceCheck.class);
 
+  static final String KEY_SERVICE_REPLACED = "service_replaced";
   static final String KEY_SERVICE_REMOVED = "service_removed";
+
   /*
    * List of services that do not support upgrade
    * services must be removed before the stack upgrade
@@ -59,6 +61,11 @@ public class ServicePresenceCheck extends AbstractCheckDescriptor{
   static final String REMOVED_SERVICES_PROPERTY_NAME = "removed-service-names";
 
   /*
+   * List of services replaced by other services in the new release
+   * */
+  static final String REPLACED_SERVICES_PROPERTY_NAME = "replaced-service-names";
+
+  /*
    * Such as Spark to Spark2
    */
   static final String NEW_SERVICES_PROPERTY_NAME = "new-service-names";
@@ -73,7 +80,9 @@ public class ServicePresenceCheck extends AbstractCheckDescriptor{
     Set<String> installedServices = cluster.getServices().keySet();
 
     List<String> noUpgradeSupportServices = getNoUpgradeSupportServices(request);
-    Map<String, String> removedServices = getRemovedServices(request);
+    Map<String, String> replacedServices = getReplacedServices(request);
+    List<String> removedServices = getRemovedServices(request);
+
     List<String> failReasons = new ArrayList<>();
 
     String reason = getFailReason(prerequisiteCheck, request);
@@ -85,8 +94,8 @@ public class ServicePresenceCheck extends AbstractCheckDescriptor{
       }
     }
 
-    reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
-    for (Map.Entry<String, String> entry : removedServices.entrySet()) {
+    reason = getFailReason(KEY_SERVICE_REPLACED, prerequisiteCheck, request);
+    for (Map.Entry<String, String> entry : replacedServices.entrySet()) {
       String removedService = entry.getKey();
       if(installedServices.contains(removedService.toUpperCase())){
         prerequisiteCheck.getFailedOn().add(removedService);
@@ -96,6 +105,15 @@ public class ServicePresenceCheck extends AbstractCheckDescriptor{
       }
     }
 
+    reason = getFailReason(KEY_SERVICE_REMOVED, prerequisiteCheck, request);
+    for(String service: removedServices){
+      if (installedServices.contains(service.toUpperCase())){
+        prerequisiteCheck.getFailedOn().add(service);
+        String msg = String.format(reason, service);
+        failReasons.add(msg);
+      }
+    }
+
     if(!failReasons.isEmpty()){
       prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
       prerequisiteCheck.setFailReason(StringUtils.join(failReasons, '\n'));
@@ -138,28 +156,46 @@ public class ServicePresenceCheck extends AbstractCheckDescriptor{
   }
 
   /**
+  +   * @return service names
+  +   * */
+  private List<String> getRemovedServices(PrereqCheckRequest request){
+    List<String> result = new ArrayList<String>();
+    String value = getPropertyValue(request, REMOVED_SERVICES_PROPERTY_NAME);
+    if (null != value){
+      String[] services = value.split(",");
+      for(String service: services){
+        service = service.trim();
+        if (!service.isEmpty()){
+          result.add(service);
+        }
+      }
+    }
+    return result;
+  }
+
+  /**
    * @return service names and new service names map
    * */
-  private Map<String, String> getRemovedServices(PrereqCheckRequest request) throws
AmbariException{
+  private Map<String, String> getReplacedServices(PrereqCheckRequest request) throws
AmbariException{
     Map<String, String> result = new LinkedHashMap<>();
-    String value = getPropertyValue(request, REMOVED_SERVICES_PROPERTY_NAME);
+    String value = getPropertyValue(request, REPLACED_SERVICES_PROPERTY_NAME);
     String newValue = getPropertyValue(request, NEW_SERVICES_PROPERTY_NAME);
     if(value == null && newValue == null){
       return result; //no need to check removed services as they are not specified in the
upgrade xml file.
     } else {
       if (value == null || newValue == null){
-        throw new AmbariException(String.format("Both %s and %s list must be specified in
the upgrade XML file.", REMOVED_SERVICES_PROPERTY_NAME, NEW_SERVICES_PROPERTY_NAME));
+        throw new AmbariException(String.format("Both %s and %s list must be specified in
the upgrade XML file.", REPLACED_SERVICES_PROPERTY_NAME, NEW_SERVICES_PROPERTY_NAME));
       } else {
         List<String> oldServices = Arrays.asList(value.split(","));
         List<String> newServices = Arrays.asList(newValue.split(","));
         if (oldServices.size() != newServices.size()){
-          throw new AmbariException(String.format("%s must have the same number of services
as the %s list.", NEW_SERVICES_PROPERTY_NAME, REMOVED_SERVICES_PROPERTY_NAME));
+          throw new AmbariException(String.format("%s must have the same number of services
as the %s list.", NEW_SERVICES_PROPERTY_NAME, REPLACED_SERVICES_PROPERTY_NAME));
         } else {
           for (int i = 0; i < oldServices.size(); i++){
             String oldService = oldServices.get(i).trim();
             String newService = newServices.get(i).trim();
             if (oldService.isEmpty() || newService.isEmpty()) {
-              throw new AmbariException(String.format("Make sure both %s and %s list only
contain comma separated list of services.", NEW_SERVICES_PROPERTY_NAME, REMOVED_SERVICES_PROPERTY_NAME));
+              throw new AmbariException(String.format("Make sure both %s and %s list only
contain comma separated list of services.", NEW_SERVICES_PROPERTY_NAME, REPLACED_SERVICES_PROPERTY_NAME));
             } else {
               result.put(oldService, newService);
             }

http://git-wip-us.apache.org/repos/asf/ambari/blob/3ca41f26/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
index d89f0e5..ed2fcb9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/ServicePresenceCheckTest.java
@@ -64,7 +64,8 @@ public class ServicePresenceCheckTest {
 
     Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"MyServiceOne,
MyServiceTwo");
-    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"OldServiceOne,
OldServiceTwo");
+    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"RemovedServiceOne,
RemovedServiceTwo");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"OldServiceOne,
OldServiceTwo");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"NewServiceOne, NewServiceTwo");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
@@ -105,7 +106,7 @@ public class ServicePresenceCheckTest {
   }
 
   @Test
-  public void testPerformHasRemovedServices() throws Exception {
+  public void testPerformHasReplacedServices() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
     Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
@@ -116,7 +117,7 @@ public class ServicePresenceCheckTest {
     Mockito.when(cluster.getServices()).thenReturn(services);
 
     Map<String, String> checkProperties = new HashMap<>();
-    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"Atlas, OldService");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"Atlas, OldService");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"Atlas2, NewService");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
@@ -132,6 +133,32 @@ public class ServicePresenceCheckTest {
   }
 
   @Test
+  public void testPerformHasRemovedServices() throws Exception {
+    final Cluster cluster = Mockito.mock(Cluster.class);
+    Mockito.when(cluster.getClusterId()).thenReturn(1L);
+    Mockito.when(m_clusters.getCluster("cluster")).thenReturn(cluster);
+
+    Map<String, Service> services = new HashMap<String, Service>();
+    services.put("ATLAS", Mockito.mock(Service.class));
+    services.put("OLDSERVICE", Mockito.mock(Service.class));
+    Mockito.when(cluster.getServices()).thenReturn(services);
+
+    Map<String, String> checkProperties = new HashMap<String, String>();
+    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"OldService");
+
+    PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
+    Mockito.when(prerequisiteCheckConfig.getCheckProperties(
+        m_check.getClass().getName())).thenReturn(checkProperties);
+
+    PrerequisiteCheck check = new PrerequisiteCheck(null, null);
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setPrerequisiteCheckConfig(prerequisiteCheckConfig);
+
+    m_check.perform(check, request);
+    Assert.assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+  }
+
+  @Test
   public void testPerformMixOne() throws Exception {
     final Cluster cluster = Mockito.mock(Cluster.class);
     Mockito.when(cluster.getClusterId()).thenReturn(1L);
@@ -139,12 +166,14 @@ public class ServicePresenceCheckTest {
 
     Map<String, Service> services = new HashMap<>();
     services.put("ATLAS", Mockito.mock(Service.class));
+    services.put("REMOVEDSERVICE", Mockito.mock(Service.class));
     Mockito.when(cluster.getServices()).thenReturn(services);
 
     Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"MyServiceOne,
MyServiceTwo");
-    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"Atlas, OldService");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"Atlas, OldService");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"Atlas2, NewService");
+    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"RemovedService");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
     Mockito.when(prerequisiteCheckConfig.getCheckProperties(
@@ -170,7 +199,7 @@ public class ServicePresenceCheckTest {
 
     Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"Atlas,
MyService");
-    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"OldService");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"OldService");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"NewService");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);
@@ -200,7 +229,7 @@ public class ServicePresenceCheckTest {
 
     Map<String, String> checkProperties = new HashMap<>();
     checkProperties.put(ServicePresenceCheck.NO_UPGRADE_SUPPORT_SERVICES_PROPERTY_NAME,"Atlas,
HDFS");
-    checkProperties.put(ServicePresenceCheck.REMOVED_SERVICES_PROPERTY_NAME,"Storm, Ranger");
+    checkProperties.put(ServicePresenceCheck.REPLACED_SERVICES_PROPERTY_NAME,"Storm, Ranger");
     checkProperties.put(ServicePresenceCheck.NEW_SERVICES_PROPERTY_NAME,"Storm2, Ranger2");
 
     PrerequisiteCheckConfig prerequisiteCheckConfig = Mockito.mock(PrerequisiteCheckConfig.class);


Mime
View raw message