ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmitriu...@apache.org
Subject ambari git commit: AMBARI-15830. Atlas Upgrade Check (dgrinenko via dlysnichenko)
Date Tue, 10 May 2016 17:20:56 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk f83e258da -> 6c36aa437


AMBARI-15830. Atlas Upgrade Check (dgrinenko via dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 6c36aa437d0e86ac9b82cab52b221af837c47519
Parents: f83e258
Author: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Authored: Tue May 10 20:21:56 2016 +0300
Committer: Lisnichenko Dmitro <dlysnichenko@hortonworks.com>
Committed: Tue May 10 20:22:28 2016 +0300

----------------------------------------------------------------------
 .../server/checks/AbstractCheckDescriptor.java  | 12 ++-
 .../server/checks/AtlasPresenceCheck.java       | 57 ++++++++++++
 .../ambari/server/checks/CheckDescription.java  |  9 ++
 .../HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml |  2 +
 .../stacks/HDP/2.3/upgrades/upgrade-2.5.xml     |  1 +
 .../HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml |  2 +
 .../stacks/HDP/2.4/upgrades/upgrade-2.5.xml     |  1 +
 .../checks/AbstractCheckDescriptorTest.java     | 91 +++++++++++++++++++-
 .../server/checks/AtlasPresenceCheckTest.java   | 40 +++++++++
 9 files changed, 210 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
index 597c121..4bc64d4 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/AbstractCheckDescriptor.java
@@ -123,17 +123,21 @@ public abstract class AbstractCheckDescriptor {
   public boolean isApplicable(PrereqCheckRequest request, List<String> requiredServices,
boolean requiredAll) throws AmbariException {
     final Cluster cluster = clustersProvider.get().getCluster(request.getClusterName());
     Set<String> services = cluster.getServices().keySet();
-    boolean serviceFound = false;
+
+    // default return value depends on assign inside check block
+    boolean serviceFound = requiredAll && !requiredServices.isEmpty();
 
     for (String service : requiredServices) {
-      if (services.contains(service) && !requiredAll) {
+      if ( services.contains(service) && !requiredAll) {
         serviceFound = true;
+        break;
       } else if (!services.contains(service) && requiredAll) {
-        return false;
+        serviceFound = false;
+        break;
       }
     }
 
-    return !(!serviceFound && !requiredAll);
+    return serviceFound;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
new file mode 100644
index 0000000..8556436
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/AtlasPresenceCheck.java
@@ -0,0 +1,57 @@
+/**
+ * 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.checks;
+
+import java.util.Arrays;
+
+import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Singleton;
+
+/**
+ * Checks if Atlas service is present. Upgrade to stack HDP 2.5 can't pursuit
+ * with existed on the cluster Atlas service.
+ */
+@Singleton
+@UpgradeCheck(group = UpgradeCheckGroup.DEFAULT)
+public class AtlasPresenceCheck extends AbstractCheckDescriptor{
+
+  private static final Logger LOG = LoggerFactory.getLogger(AtlasPresenceCheck.class);
+  private static final String serviceName = "ATLAS";
+
+  public AtlasPresenceCheck(){
+    super(CheckDescription.ATLAS_SERVICE_PRESENCE_CHECK);
+  }
+
+  @Override
+  public boolean isApplicable(PrereqCheckRequest request) throws AmbariException {
+    return super.isApplicable(request, Arrays.asList(serviceName), true);
+  }
+
+  @Override
+  public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws
AmbariException {
+    prerequisiteCheck.getFailedOn().add(serviceName);
+    prerequisiteCheck.setStatus(PrereqCheckStatus.FAIL);
+    prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request));
+  }
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/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 6b39082..5899370 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
@@ -266,6 +266,15 @@ public enum CheckDescription {
             "Could not check credentials.  Missing property %s/%s");
       }}),
 
+  ATLAS_SERVICE_PRESENCE_CHECK(PrereqCheckType.SERVICE,
+    "Atlas Is Not Supported For Upgrades",
+    new HashMap<String, String>() {{
+      put(AbstractCheckDescriptor.DEFAULT,
+        "The Atlas service is currently installed on the cluster. " +
+        "This service does not support upgrades and must be removed before the upgrade can
continue. " +
+        "After upgrading, Atlas can be reinstalled");
+    }}),
+
   KAFKA_KERBEROS_CHECK(PrereqCheckType.SERVICE,
     "Kafka upgrade on Kerberized cluster",
     new HashMap<String, String>() {{

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
index 017980d..7873853 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/nonrolling-upgrade-2.5.xml
@@ -28,6 +28,8 @@
         <property name="min-failure-stack-version">HDP-2.3.0.0</property>
       </check-properties>
     </configuration>
+
+    <check>org.apache.ambari.server.checks.AtlasPresenceCheck</check>
   </prerequisite-checks>
 
   <!-- Instructs the upgrade pack how to build the configuration pack -->

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.5.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.5.xml b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.5.xml
index a3b1494..1cd2ffa 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.5.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.3/upgrades/upgrade-2.5.xml
@@ -35,6 +35,7 @@
     <check>org.apache.ambari.server.checks.ServicesYarnWorkPreservingCheck</check>
     <check>org.apache.ambari.server.checks.YarnRMHighAvailabilityCheck</check>
     <check>org.apache.ambari.server.checks.YarnTimelineServerStatePreservingCheck</check>
+    <check>org.apache.ambari.server.checks.AtlasPresenceCheck</check>
 
     <configuration>
       <!-- Configuration properties for all pre-reqs including required pre-reqs -->

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
index 1569c79..7d67f8e 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/nonrolling-upgrade-2.5.xml
@@ -28,6 +28,8 @@
         <property name="min-failure-stack-version">HDP-2.3.0.0</property>
       </check-properties>
     </configuration>
+
+    <check>org.apache.ambari.server.checks.AtlasPresenceCheck</check>
   </prerequisite-checks>
   <order>
     <group xsi:type="cluster" name="PRE_CLUSTER" title="Prepare Upgrade">

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.5.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.5.xml b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.5.xml
index ac53f3b..9c6a02d 100644
--- a/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.5.xml
+++ b/ambari-server/src/main/resources/stacks/HDP/2.4/upgrades/upgrade-2.5.xml
@@ -35,6 +35,7 @@
     <check>org.apache.ambari.server.checks.ServicesYarnWorkPreservingCheck</check>
     <check>org.apache.ambari.server.checks.YarnRMHighAvailabilityCheck</check>
     <check>org.apache.ambari.server.checks.YarnTimelineServerStatePreservingCheck</check>
+    <check>org.apache.ambari.server.checks.AtlasPresenceCheck</check>
 
     <configuration>
       <!-- Configuration properties for all pre-reqs including required pre-reqs -->

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
index 5281a1b..55c8815 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/AbstractCheckDescriptorTest.java
@@ -17,26 +17,63 @@
  */
 package org.apache.ambari.server.checks;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
 import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
 
 import junit.framework.Assert;
+import static org.easymock.EasyMock.anyString;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
 
 import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.api.services.AmbariMetaInfo;
+import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.orm.dao.ClusterVersionDAO;
+import org.apache.ambari.server.orm.dao.HostVersionDAO;
+import org.apache.ambari.server.orm.dao.RepositoryVersionDAO;
+import org.apache.ambari.server.orm.dao.UpgradeDAO;
+import org.apache.ambari.server.state.Cluster;
+import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Service;
+import org.apache.ambari.server.state.ServiceImpl;
 import org.apache.ambari.server.state.stack.PrereqCheckType;
 import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.apache.ambari.server.state.stack.upgrade.RepositoryVersionHelper;
+import org.apache.ambari.server.state.stack.upgrade.UpgradeType;
+import org.apache.commons.collections.map.HashedMap;
+import org.easymock.EasyMock;
 import org.junit.Test;
 
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Provider;
+
 /**
  * Unit tests for AbstractCheckDescriptor
  */
 public class AbstractCheckDescriptorTest {
+  final private Clusters clusters = EasyMock.createNiceMock(Clusters.class);
 
   private class TestCheckImpl extends AbstractCheckDescriptor {
     private PrereqCheckType m_type;
-    public TestCheckImpl(PrereqCheckType type) {
+
+    TestCheckImpl(PrereqCheckType type) {
       super(null);
       m_type = type;
+
+      clustersProvider = new Provider<Clusters>() {
+        @Override
+        public Clusters get() {
+          return clusters;
+        }
+      };
     }
 
     @Override
@@ -78,4 +115,56 @@ public class AbstractCheckDescriptorTest {
     Assert.assertEquals("host1, host2 and host3", check.formatEntityList(failedOn));
   }
 
+  @Test
+  public void testIsApplicable() throws Exception{
+    final String clusterName = "c1";
+    final Cluster cluster = EasyMock.createMock(Cluster.class);
+
+
+    Map<String, Service> services = new HashMap<String, Service>(){{
+      put("SERVICE1", null);
+      put("SERVICE2", null);
+      put("SERVICE3", null);
+    }};
+
+    expect(clusters.getCluster(anyString())).andReturn(cluster).atLeastOnce();
+    expect(cluster.getServices()).andReturn(services).atLeastOnce();
+
+    replay(clusters, cluster);
+
+    AbstractCheckDescriptor check = new TestCheckImpl(PrereqCheckType.SERVICE);
+    PrereqCheckRequest request = new PrereqCheckRequest(clusterName, UpgradeType.ROLLING);
+
+    List<String> oneServiceList = new ArrayList<String>() {{
+      add("SERVICE1");
+    }};
+    List<String> atLeastOneServiceList = new ArrayList<String>() {{
+      add("SERVICE1");
+      add("NON_EXISTED_SERVICE");
+    }};
+    List<String> allServicesList = new ArrayList<String>(){{
+      add("SERVICE1");
+      add("SERVICE2");
+    }};
+    List<String> nonExistedList = new ArrayList<String>(){{
+      add("NON_EXISTED_SERVICE");
+    }};
+
+    // case, where we need at least one service to be present
+    Assert.assertEquals(true, check.isApplicable(request, oneServiceList, false));
+    Assert.assertEquals(true, check.isApplicable(request, atLeastOneServiceList, false));
+
+    // case, where all services need to be present
+    Assert.assertEquals(false, check.isApplicable(request,atLeastOneServiceList, true));
+    Assert.assertEquals(true, check.isApplicable(request, allServicesList, true));
+
+    // Case with empty list of the required services
+    Assert.assertEquals(false, check.isApplicable(request, new ArrayList<String>(),
true));
+    Assert.assertEquals(false, check.isApplicable(request, new ArrayList<String>(),
false));
+
+    // Case with non existed services
+    Assert.assertEquals(false, check.isApplicable(request, nonExistedList, false));
+    Assert.assertEquals(false, check.isApplicable(request, nonExistedList, true));
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/6c36aa43/ambari-server/src/test/java/org/apache/ambari/server/checks/AtlasPresenceCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/AtlasPresenceCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/AtlasPresenceCheckTest.java
new file mode 100644
index 0000000..c833026
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/AtlasPresenceCheckTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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.checks;
+
+import org.apache.ambari.server.controller.PrereqCheckRequest;
+import org.apache.ambari.server.state.stack.PrereqCheckStatus;
+import org.apache.ambari.server.state.stack.PrerequisiteCheck;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class AtlasPresenceCheckTest {
+  private final AtlasPresenceCheck m_check = new AtlasPresenceCheck();
+
+  @Test
+  public void perform() throws Exception {
+    PrerequisiteCheck check = new PrerequisiteCheck(null, null);
+    PrereqCheckRequest request = new PrereqCheckRequest("cluster");
+    request.setRepositoryVersion("2.5.0.0");
+    m_check.perform(check, request);
+
+    assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
+  }
+}
\ No newline at end of file


Mime
View raw message