Author: tbeerbower
Date: Wed Jan 30 12:26:19 2013
New Revision: 1440370

URL: http://svn.apache.org/viewvc?rev=1440370&view=rev
Log:
AMBARI-1286 - Set version number property in gsInstaller cluster resource 
provider.

Modified:
    incubator/ambari/trunk/CHANGES.txt
    
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java
    
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java
    
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProviderTest.java
    
incubator/ambari/trunk/ambari-server/src/test/resources/gsInstaller-hosts.txt

Modified: incubator/ambari/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1440370&r1=1440369&r2=1440370&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Jan 30 12:26:19 2013
@@ -186,6 +186,8 @@ Trunk (unreleased changes):
  AMBARI-1270. Add predicate objects for checking empty resource category.
  (tbeerbower)
 
+ AMBARI - 1286. Set version number property in gsInstaller cluster resource 
provider. (tbeerbower)
+
  BUG FIXES
 
  AMBARI-1297. Edit User: if "old password" is not specified and "new

Modified: 
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java
URL: 
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java?rev=1440370&r1=1440369&r2=1440370&view=diff
==============================================================================
--- 
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java
 (original)
+++ 
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/ClusterDefinition.java
 Wed Jan 30 12:26:19 2013
@@ -36,13 +36,17 @@ public class ClusterDefinition {
   private static final String CLUSTER_DEFINITION_FILE = 
"gsInstaller-hosts.txt";
   private static final String DEFAULT_CLUSTER_NAME    = "ambari";
   private static final String CLUSTER_NAME_TAG        = "CLUSTER=";
+  private static final String DEFAULT_VERSION_ID      = "HDP-1.2.0";
+  private static final String VERSION_ID_TAG          = "VERSION=";
 
-  private final String clusterName;
   private final Set<String> services = new HashSet<String>();
   private final Set<String> hosts = new HashSet<String>();
   private final Map<String, Set<String>> components = new HashMap<String, 
Set<String>>();
   private final Map<String, Map<String, Set<String>>> hostComponents = new 
HashMap<String, Map<String, Set<String>>>();
 
+  private String clusterName;
+  private String versionId;
+
 
   // ----- Constructors ------------------------------------------------------
 
@@ -50,7 +54,9 @@ public class ClusterDefinition {
    * Create a cluster definition.
    */
   public ClusterDefinition() {
-    this.clusterName = readClusterDefinition();
+    clusterName = DEFAULT_CLUSTER_NAME;
+    versionId   = DEFAULT_VERSION_ID;
+    readClusterDefinition();
   }
 
 
@@ -66,6 +72,15 @@ public class ClusterDefinition {
   }
 
   /**
+   * Get the name of the cluster.
+   *
+   * @return the cluster name
+   */
+  public String getVersionId() {
+    return versionId;
+  }
+
+  /**
    * Get the services for the cluster.
    *
    * @return the set of service names
@@ -116,12 +131,8 @@ public class ClusterDefinition {
 
   /**
    * Read the gsInstaller cluster definition file.
-   *
-   * @return the cluster name
    */
-  private String readClusterDefinition() {
-    String clusterName = DEFAULT_CLUSTER_NAME;
-
+  private void readClusterDefinition() {
     try {
       InputStream    is = 
this.getClass().getClassLoader().getResourceAsStream(CLUSTER_DEFINITION_FILE);
       BufferedReader br = new BufferedReader(new InputStreamReader(is));
@@ -132,6 +143,9 @@ public class ClusterDefinition {
         if (line.startsWith(CLUSTER_NAME_TAG)) {
           clusterName = line.substring(CLUSTER_NAME_TAG.length());
         }
+        else if (line.startsWith(VERSION_ID_TAG)) {
+          versionId = line.substring(VERSION_ID_TAG.length());
+        }
         else {
           String[] parts = line.split("\\s+");
           assert(parts.length == 3);
@@ -167,6 +181,5 @@ public class ClusterDefinition {
       String msg = "Caught exception reading " + CLUSTER_DEFINITION_FILE + ".";
       throw new IllegalStateException(msg, e);
     }
-    return clusterName;
   }
 }

Modified: 
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java
URL: 
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java?rev=1440370&r1=1440369&r2=1440370&view=diff
==============================================================================
--- 
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java
 (original)
+++ 
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProvider.java
 Wed Jan 30 12:26:19 2013
@@ -28,7 +28,8 @@ import org.apache.ambari.server.controll
 public class GSInstallerClusterProvider extends GSInstallerResourceProvider{
 
   // Clusters
-  protected static final String CLUSTER_NAME_PROPERTY_ID = 
PropertyHelper.getPropertyId("Clusters", "cluster_name");
+  protected static final String CLUSTER_NAME_PROPERTY_ID    = 
PropertyHelper.getPropertyId("Clusters", "cluster_name");
+  protected static final String CLUSTER_VERSION_PROPERTY_ID = 
PropertyHelper.getPropertyId("Clusters", "version");
 
 
   // ----- Constructors ------------------------------------------------------
@@ -51,7 +52,9 @@ public class GSInstallerClusterProvider 
    */
   private void initClusterResources() {
     Resource cluster = new ResourceImpl(Resource.Type.Cluster);
-    cluster.setProperty(CLUSTER_NAME_PROPERTY_ID, 
getClusterDefinition().getClusterName());
+    ClusterDefinition clusterDefinition = getClusterDefinition();
+    cluster.setProperty(CLUSTER_NAME_PROPERTY_ID, 
clusterDefinition.getClusterName());
+    cluster.setProperty(CLUSTER_VERSION_PROPERTY_ID, 
clusterDefinition.getVersionId());
     addResource(cluster);
   }
 }

Modified: 
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProviderTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProviderTest.java?rev=1440370&r1=1440369&r2=1440370&view=diff
==============================================================================
--- 
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProviderTest.java
 (original)
+++ 
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/gsinstaller/GSInstallerClusterProviderTest.java
 Wed Jan 30 12:26:19 2013
@@ -52,7 +52,9 @@ public class GSInstallerClusterProviderT
     Predicate predicate = new 
PredicateBuilder().property(GSInstallerClusterProvider.CLUSTER_NAME_PROPERTY_ID).equals("ambari").toPredicate();
     Set<Resource> resources = 
provider.getResources(PropertyHelper.getReadRequest(), predicate);
     Assert.assertEquals(1, resources.size());
-    Assert.assertEquals("ambari", 
resources.iterator().next().getPropertyValue(GSInstallerClusterProvider.CLUSTER_NAME_PROPERTY_ID));
+    Resource next = resources.iterator().next();
+    Assert.assertEquals("ambari",    
next.getPropertyValue(GSInstallerClusterProvider.CLUSTER_NAME_PROPERTY_ID));
+    Assert.assertEquals("HDP-1.2.0", 
next.getPropertyValue(GSInstallerClusterProvider.CLUSTER_VERSION_PROPERTY_ID));
 
     predicate = new 
PredicateBuilder().property(GSInstallerClusterProvider.CLUSTER_NAME_PROPERTY_ID).equals("non-existent
 Cluster").toPredicate();
     resources = provider.getResources(PropertyHelper.getReadRequest(), 
predicate);

Modified: 
incubator/ambari/trunk/ambari-server/src/test/resources/gsInstaller-hosts.txt
URL: 
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/resources/gsInstaller-hosts.txt?rev=1440370&r1=1440369&r2=1440370&view=diff
==============================================================================
--- 
incubator/ambari/trunk/ambari-server/src/test/resources/gsInstaller-hosts.txt 
(original)
+++ 
incubator/ambari/trunk/ambari-server/src/test/resources/gsInstaller-hosts.txt 
Wed Jan 30 12:26:19 2013
@@ -1,4 +1,5 @@
 CLUSTER=ambari
+VERSION=HDP-1.2.0
 HDFS HDFS_CLIENT ip-10-190-97-104.ec2.internal
 HDFS NAMENODE ip-10-8-113-183.ec2.internal
 HDFS SECONDARY_NAMENODE ip-10-8-113-183.ec2.internal


Reply via email to