This is an automated email from the ASF dual-hosted git repository.

jonathanhurley pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new ec097f6  [AMBARI-24685] - Create a Maven Consumable Ambari SPI Client 
Library
ec097f6 is described below

commit ec097f6563b85b49e06c4d41053e101d2c6c8656
Author: Jonathan Hurley <jonathanhur...@apache.org>
AuthorDate: Wed Sep 26 08:16:42 2018 -0400

    [AMBARI-24685] - Create a Maven Consumable Ambari SPI Client Library
---
 ambari-server-spi/pom.xml                          | 177 +++++++++++++++++++++
 .../apache/ambari/annotations/UpgradeCheck.java    |  84 ++++++++++
 .../org/apache/ambari/server/AmbariException.java  |   0
 .../java/org/apache/ambari/spi/RepositoryType.java |  93 +++++++++++
 .../java/org/apache/ambari/spi/package-info.java   |  22 +++
 .../ambari/spi/upgrade/CheckDescription.java       | 144 +++++++++++++++++
 .../ambari/spi/upgrade/CheckQualification.java     |  31 ++--
 .../apache/ambari/spi/upgrade/UpgradeCheck.java    |  92 +++++++++++
 .../ambari/spi/upgrade/UpgradeCheckGroup.java      | 114 +++++++++++++
 .../ambari/spi/upgrade/UpgradeCheckRequest.java    | 111 +++++++++++++
 .../ambari/spi/upgrade/UpgradeCheckResult.java     |  84 ++++++++++
 .../ambari/spi/upgrade/UpgradeCheckStatus.java     |  37 +++--
 .../ambari/spi/upgrade/UpgradeCheckType.java       |  22 +--
 .../org/apache/ambari/spi/upgrade/UpgradeType.java |  35 ++--
 .../ambari/spi/upgrade/RepositoryTypeTest.java     |  31 ++--
 ambari-server/pom.xml                              |   5 +
 pom.xml                                            |   5 +
 17 files changed, 1024 insertions(+), 63 deletions(-)

diff --git a/ambari-server-spi/pom.xml b/ambari-server-spi/pom.xml
new file mode 100644
index 0000000..cad3270
--- /dev/null
+++ b/ambari-server-spi/pom.xml
@@ -0,0 +1,177 @@
+<?xml version="1.0"?>
+<!--
+  Licensed 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. See accompanying LICENSE file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.ambari</groupId>
+    <artifactId>ambari-project</artifactId>
+    <version>2.0.0.0-SNAPSHOT</version>
+    <relativePath>../ambari-project</relativePath>
+  </parent>
+  <artifactId>ambari-server-spi</artifactId>
+  <url>http://ambari.apache.org</url>
+  <name>Ambari Server SPI</name>
+  <description>A client library which is used for providing plugins for the 
Ambari Server framework.</description>  
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <xlint>none</xlint>
+    <jdk.version>1.8</jdk.version>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.2</version>
+        <configuration>
+          <source>${jdk.version}</source>
+          <target>${jdk.version}</target>
+          <useIncrementalCompilation>false</useIncrementalCompilation>
+          <compilerArgs>
+            <arg>-Xlint:${xlint}</arg>
+            <arg>-Xmaxwarns</arg>
+            <arg>50000</arg>
+          </compilerArgs>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <configuration>
+          <tarLongFileMode>gnu</tarLongFileMode>
+          <descriptors>
+            
<descriptor>../ambari-project/src/main/assemblies/empty.xml</descriptor>
+          </descriptors>
+        </configuration>
+        <executions>
+          <execution>
+            <id>build-tarball</id>
+            <phase>prepare-package</phase>
+            <goals>
+              <goal>single</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.rat</groupId>
+        <artifactId>apache-rat-plugin</artifactId>
+        <configuration>
+          <excludes>
+            <exclude>**/*.json</exclude>
+            <exclude>**/*.iml</exclude>
+            <exclude>**/*.lst</exclude>
+            <exclude>**/rat.txt</exclude>
+          </excludes>
+        </configuration>
+        <executions>
+          <execution>
+            <phase>test</phase>
+            <goals>
+              <goal>check</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+     
+     <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <skip>${skipSurefireTests}</skip>
+          <argLine>${surefire.argLine}</argLine>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <version>1.8</version>
+        <executions>
+          <execution>
+            <id>parse-version</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>parse-version</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>regex-property</id>
+            <goals>
+              <goal>regex-property</goal>
+            </goals>
+            <configuration>
+              <name>ambariVersion</name>
+              <value>${project.version}</value>
+              <regex>^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(\.|-).*</regex>
+              <replacement>$1.$2.$3.$4</replacement>
+              <failIfNoMatch>false</failIfNoMatch>
+            </configuration>
+          </execution>
+          <execution>
+            <id>parse-package-version</id>
+            <goals>
+              <goal>regex-property</goal>
+            </goals>
+            <configuration>
+              <name>package-version</name>
+              <value>${project.version}</value>
+              <regex>^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(\.|-).*</regex>
+              <replacement>$1.$2.$3.$4</replacement>
+              <failIfNoMatch>true</failIfNoMatch>
+            </configuration>
+          </execution>
+          <execution>
+            <id>parse-package-release</id>
+            <goals>
+              <goal>regex-property</goal>
+            </goals>
+            <configuration>
+              <name>package-release</name>
+              <value>${project.version}</value>
+              <regex>
+                
^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(\.|-)((([a-zA-Z]+)?([0-9]+))|(SNAPSHOT)).*
+              </regex>
+              <replacement>$7</replacement>
+              <failIfNoMatch>true</failIfNoMatch>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>      
+    </plugins>
+  </build>  
+  
+  <dependencies>
+    <dependency>
+      <groupId>com.google.code.gson</groupId>
+      <artifactId>gson</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.guava</groupId>
+      <artifactId>guava</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>com.google.inject</groupId>
+      <artifactId>guice</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/annotations/UpgradeCheck.java
 
b/ambari-server-spi/src/main/java/org/apache/ambari/annotations/UpgradeCheck.java
new file mode 100644
index 0000000..ba22c51
--- /dev/null
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/annotations/UpgradeCheck.java
@@ -0,0 +1,84 @@
+/*
+ * 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.annotations;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.apache.ambari.spi.RepositoryType;
+import org.apache.ambari.spi.upgrade.UpgradeCheckGroup;
+import org.apache.ambari.spi.upgrade.UpgradeType;
+
+import com.google.inject.ScopeAnnotation;
+import com.google.inject.Singleton;
+
+/**
+ * The {@link UpgradeCheck} annotation is used to provide ordering and grouping
+ * to any {@link ClusterCheck} instance.
+ * <p/>
+ * Classes marked with this annotation should also be {@link Singleton}. They
+ * will be discovered on the classpath and then registered with the
+ * {@link UpgradeCheckRegistry}.
+ */
+@Target({ ElementType.TYPE })
+@Retention(RUNTIME)
+@ScopeAnnotation
+public @interface UpgradeCheck {
+
+  /**
+   * The group that the pre-upgrade check belongs to.
+   *
+   * @return the group, or {@link UpgradeCheckGroup#DEFAULT} if not specified.
+   */
+  UpgradeCheckGroup group() default UpgradeCheckGroup.DEFAULT;
+
+  /**
+   * The order of the pre-upgrade check within its group.
+   * <p/>
+   * The order is determined by a {@code float} so that new checks can be added
+   * in between others without the need to reorder all of the existing checks.
+   *
+   * @return the order, or {@code 1.0f} if not specified.
+   */
+  float order() default 1.0f;
+
+  /**
+   * Gets the upgrade types for which an upgrade check is required. By default,
+   * a pre-upgrade check needs to be declared in the upgrade pack. This flag
+   * will override that setting.
+   * <p/>
+   * Leaving this blank assumes that the check is not required.
+   *
+   * @return the upgrade types which do not need the check to be explicitely
+   *         defined in the upgrade pack or an empty array for none.
+   */
+  UpgradeType[] required() default {};
+
+
+  /**
+   * The valid orchestration repository type that this check if valid for. By
+   * default, a check is valid for all orchestration types.
+   *
+   * @return the repository types that the check is valid for.
+   */
+  RepositoryType[] orchestration() default { RepositoryType.STANDARD, 
RepositoryType.PATCH,
+      RepositoryType.MAINT, RepositoryType.SERVICE };
+}
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java 
b/ambari-server-spi/src/main/java/org/apache/ambari/server/AmbariException.java
similarity index 100%
copy from 
ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
copy to 
ambari-server-spi/src/main/java/org/apache/ambari/server/AmbariException.java
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/spi/RepositoryType.java 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/RepositoryType.java
new file mode 100644
index 0000000..c0192ce
--- /dev/null
+++ b/ambari-server-spi/src/main/java/org/apache/ambari/spi/RepositoryType.java
@@ -0,0 +1,93 @@
+/*
+ * 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.spi;
+
+import java.util.EnumSet;
+
+/**
+ * Identifies the type of repository
+ */
+public enum RepositoryType {
+
+  /**
+   * Repository should be considered to have all components for a cluster
+   * deployment.
+   */
+  STANDARD,
+
+  /**
+   * Repository may have only minimum components and is used for patching
+   * purposes.
+   */
+  PATCH,
+
+  /**
+   * Repository is used as Maintenance release, which could be several patches 
rolled up in one.
+   * Orchestration should treat Maintenance just as it does for Patch..
+   */
+  MAINT,
+
+  /**
+   * Repository is used to update services.
+   */
+  SERVICE;
+
+  /**
+   * The types of repositories which are revertable.
+   */
+  public static final EnumSet<RepositoryType> REVERTABLE = 
EnumSet.of(RepositoryType.MAINT,
+      RepositoryType.PATCH);
+
+  /**
+   * The types of repositories which can participate in an upgrade where only
+   * some services are orchestrated.
+   */
+  public static final EnumSet<RepositoryType> PARTIAL = 
EnumSet.of(RepositoryType.MAINT,
+      RepositoryType.PATCH, RepositoryType.SERVICE);
+
+  /**
+   * Gets whether applications of this repository are revertable after they 
have
+   * been finalized.
+   *
+   * @return {@code true} if the repository can be revert, {@code false}
+   *         otherwise.
+   */
+  public boolean isRevertable() {
+    switch (this) {
+      case MAINT:
+      case PATCH:
+        return true;
+      case SERVICE:
+      case STANDARD:
+        return false;
+      default:
+        return false;
+    }
+  }
+
+  /**
+   * Gets whether this repository type can be used to upgrade only a subset of
+   * services.
+   *
+   * @return {@code true} if the repository can be be applied to a subset of
+   *         isntalled services, {@code false} otherwise.
+   */
+  public boolean isPartial() {
+    return PARTIAL.contains(this);
+  }
+}
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/spi/package-info.java 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/package-info.java
new file mode 100644
index 0000000..188240d
--- /dev/null
+++ b/ambari-server-spi/src/main/java/org/apache/ambari/spi/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+
+/**
+ * Provides classes for extending Ambari Server functionality, such as adding
+ * upgrade checks and server-side custom actions.
+ */
+package org.apache.ambari.spi;
\ No newline at end of file
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/CheckDescription.java
 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/CheckDescription.java
new file mode 100644
index 0000000..3c510fb
--- /dev/null
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/CheckDescription.java
@@ -0,0 +1,144 @@
+/**
+ * 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.spi.upgrade;
+
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * The {@link CheckDescription} is used to provide information about an upgrade
+ * check, such as its description, applicable upgrade types, and the various
+ * reasons which could cause it to fail.
+ */
+public class CheckDescription {
+
+  /**
+   * All of the instantiated {@link CheckDescription}s.
+   */
+  private static final Set<CheckDescription> s_values = new LinkedHashSet<>();
+
+  /**
+   * A unique identifier.
+   */
+  private final String m_name;
+  private final UpgradeCheckType m_type;
+  private final String m_description;
+  private Map<String, String> m_fails;
+
+  /**
+   * Constructor.
+   *
+   * @param name
+   * @param type
+   * @param description
+   * @param fails
+   */
+  public CheckDescription(String name, UpgradeCheckType type, String 
description, Map<String, String> fails) {
+    m_name = name;
+    m_type = type;
+    m_description = description;
+    m_fails = fails;
+
+    if (s_values.contains(this)) {
+      throw new RuntimeException("Unable to add the upgrade check description 
named " + m_name
+          + " because it already is registered");
+    }
+
+    s_values.add(this);
+  }
+
+  /**
+   * @return the name of check
+   */
+  public String name() {
+    return m_name;
+  }
+
+  /**
+   * Gets all of the registered check descriptions.
+   *
+   * @return
+   */
+  public Set<CheckDescription> values() {
+    return s_values;
+  }
+
+  /**
+   * @return the type of check
+   */
+  public UpgradeCheckType getType() {
+    return m_type;
+  }
+
+  /**
+   * @return the text associated with the description
+   */
+  public String getText() {
+    return m_description;
+  }
+
+  /**
+   * @param key the failure text key
+   * @return the fail text template.  Never {@code null}
+   */
+  public String getFail(String key) {
+    return m_fails.containsKey(key) ? m_fails.get(key) : "";
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public int hashCode() {
+    return Objects.hash(m_name);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public boolean equals(Object object) {
+    if (null == object) {
+      return false;
+    }
+
+    if (this == object) {
+      return true;
+    }
+
+    if (object.getClass() != getClass()) {
+      return false;
+    }
+
+    CheckDescription that = (CheckDescription) object;
+
+    return Objects.equals(m_name, that.m_name);
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  @Override
+  public String toString() {
+    return MoreObjects.toStringHelper(this).add("name", m_name).toString();
+  }
+}
\ No newline at end of file
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/CheckQualification.java
similarity index 58%
copy from 
ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
copy to 
ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/CheckQualification.java
index 812ea1e..83022eb 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/CheckQualification.java
@@ -15,19 +15,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.ambari.spi.upgrade;
 
-package org.apache.ambari.server;
+import org.apache.ambari.server.AmbariException;
 
-import java.io.IOException;
-
-@SuppressWarnings("serial")
-public class AmbariException extends IOException {
-
-  public AmbariException(String message) {
-    super(message);
-  }
+/**
+ * The {@link CheckQualification} interface is used to provide multiple
+ * different qualifications against which an upgrade check is determined to be
+ * applicable to the upgrade.
+ */
+interface CheckQualification {
 
-  public AmbariException(String message, Throwable cause) {
-    super(message, cause);
-  }
-}
+  /**
+   * Gets whether the upgrade check meets this qualification and should
+   * therefore be run before the upgrade.
+   *
+   * @param request
+   * @return
+   * @throws AmbariException
+   */
+  boolean isApplicable(UpgradeCheckRequest request) throws AmbariException;
+}
\ No newline at end of file
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheck.java
 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheck.java
new file mode 100644
index 0000000..a813c96
--- /dev/null
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheck.java
@@ -0,0 +1,92 @@
+/*
+ * 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.spi.upgrade;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.ambari.server.AmbariException;
+
+/**
+ * The {@link UpgradeCheck} is used before an upgrade in order to present the
+ * administrator with a warning or a failure about an upgrade.
+ */
+public interface UpgradeCheck {
+
+  /**
+   * Gets the set of services that this check is associated with. If the check
+   * is not associated with a particular service, then this should be an empty
+   * set.
+   *
+   * @return a set of services which will determine whether this check is
+   *         applicable, or an empty set.
+   */
+  Set<String> getApplicableServices();
+
+  /**
+   * Gets any additional qualifications which an upgrade check should run in
+   * order to determine if it's applicable to the upgrade.
+   *
+   * @return a list of qualifications, or an empty list.
+   */
+  List<CheckQualification> getQualifications();
+
+  /**
+   * Tests if the prerequisite check is applicable to given upgrade request.
+   *
+   * @param request
+   *          prerequisite check request
+   * @return true if check should be performed
+   * @throws AmbariException
+   */
+  boolean isApplicable(UpgradeCheckRequest request) throws AmbariException;
+
+  /**
+   * Executes check against given cluster.
+   * @param request pre upgrade check request
+   * @return TODO
+   *
+   * @throws AmbariException if server error happens
+   */
+  UpgradeCheckResult perform(UpgradeCheckRequest request)
+      throws AmbariException;
+
+  /**
+   * Gets the type of check.
+   *
+   * @return the type of check (not {@code null}).
+   */
+  UpgradeCheckType getType();
+
+  /**
+   * Gets whether this upgrade check is required for the specified
+   * {@link UpgradeType}. Checks which are marked as required do not need to be
+   * explicitely declared in the upgrade pack to be run.
+   *
+   * @return {@code true} if it is required, {@code false} otherwise.
+   */
+  boolean isRequired(UpgradeType upgradeType);
+
+  /**
+   * The {@link CheckDescription} which includes the name, description, and
+   * success/failure messages for a {@link UpgradeCheck}.
+   *
+   * @return the check description.
+   */
+  CheckDescription getCheckDescrption();
+}
\ No newline at end of file
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckGroup.java
 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckGroup.java
new file mode 100644
index 0000000..56ca7cd
--- /dev/null
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckGroup.java
@@ -0,0 +1,114 @@
+/*
+ * 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.spi.upgrade;
+
+/**
+ * The {@link UpgradeCheckGroup} enum is used to organize pre-upgrade checks
+ * into specific groups that have their own relational ordering.
+ * <p/>
+ * The order for each group is determined by a {@code float} so that new groups
+ * can be added in between others without the need to reorder all of the 
groups.
+ */
+public enum UpgradeCheckGroup {
+
+  /**
+   * Check for masters in maintenance mode and then services in maintenance
+   * mode.
+   */
+  MAINTENANCE_MODE(1.0f),
+
+  /**
+   * Checks the repository version on the hosts.
+   */
+  REPOSITORY_VERSION(2.0f),
+
+  /**
+   * Checks for NameNode HA and checks that depend on NameNode HA.
+   */
+  NAMENODE_HA(3.0f),
+
+  /**
+   * Checks for the topology of service and components.
+   */
+  TOPOLOGY(4.0f),
+
+  /**
+   * Checks for the state of a host or service being alive and responsive.
+   */
+  LIVELINESS(5.0f),
+
+  /**
+   * Checks for the client retry properties to be set in clients that support
+   * this.
+   */
+  CLIENT_RETRY_PROPERTY(6.0f),
+
+  /**
+   * Checks for various HA components, such as multiple metastores, are
+   * available.
+   */
+  MULTIPLE_COMPONENT_WARNING(7.0f),
+
+  /**
+   * A general group for warning about configuration properties.
+   */
+  CONFIGURATION_WARNING(8.0f),
+
+  /***
+   * Checks the component version on the hosts.
+   */
+  COMPONENT_VERSION(9.0f),
+
+  /**
+   * A general group for related to Kerberos checks.
+   */
+  KERBEROS(10.0f),
+
+  /**
+   * A general group for informational warning checks.
+   */
+  INFORMATIONAL_WARNING(100.0f),
+
+  /**
+   * All other checks.
+   */
+  DEFAULT(Float.MAX_VALUE);
+
+  /**
+   * The order of upgrade check groups.
+   */
+  private final Float m_order;
+
+  /**
+   * Constructor.
+   *
+   * @param order
+   */
+  UpgradeCheckGroup(Float order) {
+    m_order = order;
+  }
+
+  /**
+   * Gets the group's order.
+   *
+   * @return the order of the group.
+   */
+  public Float getOrder() {
+    return m_order;
+  }
+}
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckRequest.java
 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckRequest.java
new file mode 100644
index 0000000..2203fce
--- /dev/null
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckRequest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.spi.upgrade;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Represents a request to run the upgrade checks before an upgrade begins.
+ */
+public class UpgradeCheckRequest {
+  private String m_clusterName;
+  private Map<String, String> m_configurations;
+
+  private UpgradeType m_upgradeType;
+
+  private Map<CheckDescription, UpgradeCheckStatus> m_results = new 
HashMap<>();
+  private boolean m_revert = false;
+
+
+  /**
+   * Constructor.
+   *
+   * @param clusterName
+   *          the name of the cluster.
+   * @param upgradeType
+   *          the type of the upgrade.
+   * @param configurations
+   *          any configurations specified in the upgrade pack which can be 
used
+   *          to when
+   */
+  public UpgradeCheckRequest(String clusterName, UpgradeType upgradeType,
+      Map<String, String> configurations) {
+    m_clusterName = clusterName;
+    m_upgradeType = upgradeType;
+    m_configurations = configurations;
+  }
+
+  /**
+   * Construct a request to performs checks before an Upgrade.
+   * The default type is Rolling.
+   * @param clusterName
+   */
+  public UpgradeCheckRequest(String clusterName) {
+    this(clusterName, UpgradeType.ROLLING, new HashMap<String, String>());
+  }
+
+  public String getClusterName() {
+    return m_clusterName;
+  }
+
+  public UpgradeType getUpgradeType() {
+    return m_upgradeType;
+  }
+
+  /**
+   * Sets the result of a check.
+   * @param description the description
+   * @param status      the status result
+   */
+  public void addResult(CheckDescription description, UpgradeCheckStatus 
status) {
+    m_results.put(description, status);
+  }
+
+  /**
+   * Gets the result of a check of the supplied description
+   * @param description the description
+   * @return the return value, or {@code null} if it has not been run
+   */
+  public UpgradeCheckStatus getResult(CheckDescription description) {
+    return m_results.get(description);
+  }
+
+  /**
+   * Gets the prerequisite check config
+   * @return the prereqCheckConfig
+   */
+  public Map<String, String> getConfigurations() {
+    return m_configurations;
+  }
+
+  /**
+   * @param revert
+   *          {@code true} if the check is for a patch reversion
+   */
+  public void setRevert(boolean revert) {
+    m_revert = revert;
+  }
+
+  /**
+   * @return if the check is for a patch reversion
+   */
+  public boolean isRevert() {
+    return m_revert;
+  }
+}
diff --git 
a/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckResult.java
 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckResult.java
new file mode 100644
index 0000000..a15891b
--- /dev/null
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckResult.java
@@ -0,0 +1,84 @@
+/*
+ * 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.spi.upgrade;
+
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+/**
+ * Contains information about performed prerequisite check. Newly initialized
+ * {@link UpgradeCheckResult} instances are always set to
+ * {@link UpgradeCheckStatus#PASS}.
+ */
+public class UpgradeCheckResult {
+  private UpgradeCheck m_upgradeCheck;
+  private UpgradeCheckStatus m_status = UpgradeCheckStatus.PASS;
+  private String m_failReason = "";
+  private LinkedHashSet<String> m_failedOn = new LinkedHashSet<>();
+  private List<Object> m_failedDetail = new ArrayList<>();
+
+  public UpgradeCheckResult(UpgradeCheck check) {
+    m_upgradeCheck = check;
+  }
+
+  public UpgradeCheckResult(UpgradeCheck check, UpgradeCheckStatus status) {
+    m_upgradeCheck = check;
+    m_status = status;
+  }
+
+  public String getId() {
+    return m_upgradeCheck.getCheckDescrption().name();
+  }
+
+  public String getDescription() {
+    return m_upgradeCheck.getCheckDescrption().getText();
+  }
+
+  public UpgradeCheckStatus getStatus() {
+    return m_status;
+  }
+
+  public void setStatus(UpgradeCheckStatus status) {
+    m_status = status;
+  }
+
+  public String getFailReason() {
+    return m_failReason;
+  }
+
+  public void setFailReason(String failReason) {
+    m_failReason = failReason;
+  }
+
+  public LinkedHashSet<String> getFailedOn() {
+    return m_failedOn;
+  }
+
+  public List<Object> getFailedDetail() {
+    return m_failedDetail;
+  }
+
+  public void setFailedOn(LinkedHashSet<String> failedOn) {
+    m_failedOn = failedOn;
+  }
+
+  public UpgradeCheckType getType() {
+    return m_upgradeCheck.getType();
+  }
+}
\ No newline at end of file
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckStatus.java
similarity index 65%
copy from 
ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
copy to 
ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckStatus.java
index 812ea1e..bce5381 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckStatus.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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
@@ -15,19 +15,26 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.ambari.spi.upgrade;
 
-package org.apache.ambari.server;
-
-import java.io.IOException;
-
-@SuppressWarnings("serial")
-public class AmbariException extends IOException {
-
-  public AmbariException(String message) {
-    super(message);
-  }
-
-  public AmbariException(String message, Throwable cause) {
-    super(message, cause);
-  }
+/**
+ *
+ */
+public enum UpgradeCheckStatus {
+  /**
+   * The check passed with no warnings or errors.
+   */
+  PASS,
+  /**
+   * The check passed but reporting a warning that should be examined.
+   */
+  WARNING,
+  /**
+   * The check failed but a configuration allows bypassing failures.
+   */
+  BYPASS,
+  /**
+   * The check failed and is not allowed to bypass errors.
+   */
+  FAIL
 }
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckType.java
similarity index 72%
copy from 
ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
copy to 
ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckType.java
index 812ea1e..c52f329 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeCheckType.java
@@ -15,19 +15,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.ambari.spi.upgrade;
 
-package org.apache.ambari.server;
-
-import java.io.IOException;
-
-@SuppressWarnings("serial")
-public class AmbariException extends IOException {
-
-  public AmbariException(String message) {
-    super(message);
-  }
-
-  public AmbariException(String message, Throwable cause) {
-    super(message, cause);
-  }
+/**
+ * Type of prerequisite check.
+ */
+public enum UpgradeCheckType {
+  SERVICE,
+  HOST,
+  CLUSTER
 }
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeType.java
similarity index 57%
copy from 
ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
copy to 
ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeType.java
index 812ea1e..65d2a40 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
+++ 
b/ambari-server-spi/src/main/java/org/apache/ambari/spi/upgrade/UpgradeType.java
@@ -15,19 +15,34 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.ambari.spi.upgrade;
 
-package org.apache.ambari.server;
+import javax.xml.bind.annotation.XmlEnumValue;
 
-import java.io.IOException;
+import com.google.gson.annotations.SerializedName;
 
-@SuppressWarnings("serial")
-public class AmbariException extends IOException {
+/**
+ * Indicates the type of Upgrade performed.
+ */
+public enum UpgradeType {
+  /**
+   * Services are up the entire time
+   */
+  @XmlEnumValue("ROLLING")
+  @SerializedName("rolling_upgrade")
+  ROLLING,
 
-  public AmbariException(String message) {
-    super(message);
-  }
+  /**
+   * All services are stopped, then started
+   */
+  @XmlEnumValue("NON_ROLLING")
+  @SerializedName("nonrolling_upgrade")
+  NON_ROLLING,
 
-  public AmbariException(String message, Throwable cause) {
-    super(message, cause);
-  }
+  /**
+   * Host-ordered upgrade.
+   */
+  @XmlEnumValue("HOST_ORDERED")
+  @SerializedName("host_ordered_upgrade")
+  HOST_ORDERED;
 }
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java 
b/ambari-server-spi/src/test/java/org/apache/ambari/spi/upgrade/RepositoryTypeTest.java
similarity index 57%
rename from 
ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
rename to 
ambari-server-spi/src/test/java/org/apache/ambari/spi/upgrade/RepositoryTypeTest.java
index 812ea1e..83f8a01 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/AmbariException.java
+++ 
b/ambari-server-spi/src/test/java/org/apache/ambari/spi/upgrade/RepositoryTypeTest.java
@@ -1,4 +1,4 @@
-/*
+/**
  * 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
@@ -15,19 +15,28 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.ambari.spi.upgrade;
 
-package org.apache.ambari.server;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
-import java.io.IOException;
+import org.apache.ambari.spi.RepositoryType;
+import org.junit.Test;
 
-@SuppressWarnings("serial")
-public class AmbariException extends IOException {
-
-  public AmbariException(String message) {
-    super(message);
-  }
+/**
+ * Tests {@link RepositoryType}.
+ */
+public class RepositoryTypeTest {
 
-  public AmbariException(String message, Throwable cause) {
-    super(message, cause);
+  /**
+   * Tests that the repository types support the revertable flag.
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testIsRevertable() throws Exception {
+    assertTrue(RepositoryType.MAINT.isRevertable());
+    assertTrue(RepositoryType.PATCH.isRevertable());
+    assertFalse(RepositoryType.STANDARD.isRevertable());
   }
 }
diff --git a/ambari-server/pom.xml b/ambari-server/pom.xml
index ecbf9f7..9cb85de 100644
--- a/ambari-server/pom.xml
+++ b/ambari-server/pom.xml
@@ -1154,6 +1154,11 @@
       <version>${project.version}</version>
     </dependency>
     <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>ambari-server-spi</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
       <groupId>commons-collections</groupId>
       <artifactId>commons-collections</artifactId>
     </dependency>
diff --git a/pom.xml b/pom.xml
index 61300d6..42bc947 100644
--- a/pom.xml
+++ b/pom.xml
@@ -440,6 +440,7 @@
         <module>contrib/views</module>
         <module>ambari-metrics</module>
         <module>ambari-server</module>
+        <module>ambari-server-spi</module>
         <module>ambari-funtest</module>
         <module>ambari-agent</module>
         <module>ambari-logsearch</module>
@@ -462,6 +463,7 @@
         <module>ambari-views/examples</module>
         <module>ambari-metrics</module>
         <module>ambari-server</module>
+        <module>ambari-server-spi</module>
         <module>ambari-funtest</module>
         <module>ambari-agent</module>
       </modules>
@@ -474,6 +476,7 @@
         <module>ambari-admin</module>
         <module>ambari-metrics</module>
         <module>ambari-server</module>
+        <module>ambari-server-spi</module>
         <module>ambari-funtest</module>
         <module>ambari-agent</module>
         <module>ambari-logsearch</module>
@@ -495,6 +498,7 @@
         <module>ambari-admin</module>
         <module>ambari-metrics</module>
         <module>ambari-server</module>
+        <module>ambari-server-spi</module>
         <module>ambari-funtest</module>
         <module>ambari-agent</module>
         <module>ambari-logsearch</module>
@@ -529,6 +533,7 @@
         <module>ambari-admin</module>
         <module>ambari-metrics</module>
         <module>ambari-server</module>
+        <module>ambari-server-spi</module>
         <module>ambari-funtest</module>
         <module>ambari-agent</module>
       </modules>

Reply via email to