ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject git commit: AMBARI-5970 - Views: Add <label> to <instance>
Date Fri, 30 May 2014 17:16:31 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk a6b34b893 -> c8de2f181


AMBARI-5970 - Views: Add <label> to <instance>


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

Branch: refs/heads/trunk
Commit: c8de2f181532309361ed10c8bc901d9c95d828d8
Parents: a6b34b8
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Fri May 30 12:45:52 2014 -0400
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Fri May 30 13:16:14 2014 -0400

----------------------------------------------------------------------
 .../internal/ViewInstanceResourceProvider.java  | 35 ++++++++++++------
 .../server/orm/entities/ViewInstanceEntity.java | 29 ++++++++++++++-
 .../server/upgrade/UpgradeCatalog161.java       |  3 ++
 .../apache/ambari/server/view/ViewRegistry.java |  3 +-
 .../view/configuration/InstanceConfig.java      | 14 ++++++++
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  2 +-
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  2 +-
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  2 +-
 .../Ambari-DDL-Postgres-EMBEDDED-CREATE.sql     |  2 +-
 .../orm/entities/ViewInstanceEntityTest.java    | 37 ++++++++++++++++++++
 .../server/upgrade/UpgradeCatalog161Test.java   | 34 +++++++++++++-----
 .../view/configuration/InstanceConfigTest.java  |  9 +++++
 .../view/configuration/ViewConfigTest.java      |  2 ++
 .../ambari/view/ViewInstanceDefinition.java     |  7 ++++
 14 files changed, 157 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
index 49298b0..af3a549 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewInstanceResourceProvider.java
@@ -54,6 +54,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider
{
   public static final String VIEW_NAME_PROPERTY_ID     = "ViewInstanceInfo/view_name";
   public static final String VIEW_VERSION_PROPERTY_ID  = "ViewInstanceInfo/version";
   public static final String INSTANCE_NAME_PROPERTY_ID = "ViewInstanceInfo/instance_name";
+  public static final String LABEL_PROPERTY_ID         = "ViewInstanceInfo/label";
   public static final String PROPERTIES_PROPERTY_ID    = "ViewInstanceInfo/properties";
   public static final String DATA_PROPERTY_ID          = "ViewInstanceInfo/instance_data";
   public static final String CONTEXT_PATH_PROPERTY_ID  = "ViewInstanceInfo/context_path";
@@ -82,6 +83,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider
{
     propertyIds.add(VIEW_NAME_PROPERTY_ID);
     propertyIds.add(VIEW_VERSION_PROPERTY_ID);
     propertyIds.add(INSTANCE_NAME_PROPERTY_ID);
+    propertyIds.add(LABEL_PROPERTY_ID);
     propertyIds.add(PROPERTIES_PROPERTY_ID);
     propertyIds.add(DATA_PROPERTY_ID);
     propertyIds.add(CONTEXT_PATH_PROPERTY_ID);
@@ -198,6 +200,7 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider
{
     setResourceProperty(resource, VIEW_NAME_PROPERTY_ID, viewName, requestedIds);
     setResourceProperty(resource, VIEW_VERSION_PROPERTY_ID, version, requestedIds);
     setResourceProperty(resource, INSTANCE_NAME_PROPERTY_ID, name, requestedIds);
+    setResourceProperty(resource, LABEL_PROPERTY_ID, viewInstanceEntity.getLabel(), requestedIds);
     Map<String, String> properties = new HashMap<String, String>();
 
     for (ViewInstancePropertyEntity viewInstancePropertyEntity : viewInstanceEntity.getProperties())
{
@@ -234,17 +237,25 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider
{
     if (viewName == null || viewName.isEmpty()) {
       throw new IllegalArgumentException("View name must be provided");
     }
-    viewName = ViewEntity.getViewName(viewName, version);
 
-    ViewInstanceEntity viewInstanceEntity = new ViewInstanceEntity();
-    viewInstanceEntity.setName(name);
-    viewInstanceEntity.setViewName(viewName);
+    ViewRegistry       viewRegistry       = ViewRegistry.getInstance();
+    ViewInstanceEntity viewInstanceEntity = viewRegistry.getInstanceDefinition(viewName,
version, name);
 
-    ViewEntity viewEntity = new ViewEntity();
-    viewEntity.setName(viewName);
-    viewEntity.setVersion(version);
+    viewName = ViewEntity.getViewName(viewName, version);
 
-    viewInstanceEntity.setViewEntity(viewEntity);
+    if (viewInstanceEntity == null) {
+      viewInstanceEntity = new ViewInstanceEntity();
+      viewInstanceEntity.setName(name);
+      viewInstanceEntity.setViewName(viewName);
+      ViewEntity viewEntity = new ViewEntity();
+      viewEntity.setName(viewName);
+      viewEntity.setVersion(version);
+      viewInstanceEntity.setViewEntity(viewEntity);
+    }
+    String label = (String) properties.get(LABEL_PROPERTY_ID);
+    if (label != null) {
+      viewInstanceEntity.setLabel(label);
+    }
 
     Collection<ViewInstancePropertyEntity> instanceProperties = new HashSet<ViewInstancePropertyEntity>();
     Collection<ViewInstanceDataEntity>     instanceData       = new HashSet<ViewInstanceDataEntity>();
@@ -275,8 +286,12 @@ public class ViewInstanceResourceProvider extends AbstractResourceProvider
{
         instanceData.add(viewInstanceDataEntity);
       }
     }
-    viewInstanceEntity.setProperties(instanceProperties);
-    viewInstanceEntity.setData(instanceData);
+    if (!instanceProperties.isEmpty()) {
+      viewInstanceEntity.setProperties(instanceProperties);
+    }
+    if (!instanceData.isEmpty()) {
+      viewInstanceEntity.setData(instanceData);
+    }
 
     return viewInstanceEntity;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
index 0faf411..6456492 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewInstanceEntity.java
@@ -28,6 +28,7 @@ import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.userdetails.UserDetails;
 
+import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
@@ -69,6 +70,13 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
   private String name;
 
   /**
+   * The public view instance name.
+   */
+  @Column
+  @Basic
+  private String label;
+
+  /**
    * The instance properties.
    */
   @OneToMany(cascade = CascadeType.ALL, mappedBy = "viewInstance")
@@ -138,6 +146,9 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
     this.instanceConfig = instanceConfig;
     this.view           = view;
     this.viewName       = view.getName();
+
+    String label = instanceConfig.getLabel();
+    this.label = (label == null || label.length()== 0) ? view.getLabel() : label;
   }
 
   /**
@@ -151,6 +162,7 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
     this.instanceConfig = null;
     this.view           = view;
     this.viewName       = view.getName();
+    this.label          = view.getLabel();
   }
 
 
@@ -195,7 +207,13 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
     return view;
   }
 
-// ----- ViewInstanceEntity ------------------------------------------------
+  @Override
+  public String getLabel() {
+    return label;
+  }
+
+
+  // ----- ViewInstanceEntity ------------------------------------------------
 
   /**
    * Set the view name.
@@ -225,6 +243,15 @@ public class ViewInstanceEntity implements ViewInstanceDefinition {
   }
 
   /**
+   * Set the label.
+   *
+   * @param label  the label
+   */
+  public void setLabel(String label) {
+    this.label = label;
+  }
+
+  /**
    * Get the instance properties.
    *
    * @return the instance properties

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
index 2155ce6..fa1861a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog161.java
@@ -79,6 +79,9 @@ public class UpgradeCatalog161 extends AbstractUpgradeCatalog {
     dbAccessor.addColumn("viewinstancedata",
         new DBAccessor.DBColumnInfo("user_name", String.class, 255, " ", false));
 
+    dbAccessor.addColumn("viewinstance",
+        new DBAccessor.DBColumnInfo("label", String.class, 255, null, true));
+
     // ========================================================================
     // Add constraints
     dbAccessor.addFKConstraint("requestoperationlevel", "FK_req_op_level_req_id",

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
index bc193a4..2a7f334 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/ViewRegistry.java
@@ -422,7 +422,7 @@ public class ViewRegistry {
           LOG.debug("Updating view instance " + viewName + "/" +
               version + "/" + instanceName);
         }
-
+        entity.setLabel(instanceEntity.getLabel());
         entity.setProperties(instanceEntity.getProperties());
         entity.setData(instanceEntity.getData());
 
@@ -796,6 +796,7 @@ public class ViewRegistry {
           instanceDefinitions.add(viewInstanceEntity);
         } else {
           // apply overrides to the in-memory view instance entities
+          instanceDefinition.setLabel(viewInstanceEntity.getLabel());
           instanceDefinition.setData(viewInstanceEntity.getData());
           instanceDefinition.setProperties(viewInstanceEntity.getProperties());
           instanceDefinition.setEntities(viewInstanceEntity.getEntities());

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
index 4b0c085..95441c6 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/InstanceConfig.java
@@ -35,6 +35,11 @@ public class InstanceConfig {
   private String name;
 
   /**
+   * The public view name.
+   */
+  private String label;
+
+  /**
    * The instance properties.
    */
   @XmlElement(name="property")
@@ -50,6 +55,15 @@ public class InstanceConfig {
   }
 
   /**
+   * Get the public view name.
+   *
+   * @return the view label
+   */
+  public String getLabel() {
+    return label;
+  }
+
+  /**
    * Get the instance properties.
    *
    * @return the instance properties

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
index de5a8ed..67fb846 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -64,7 +64,7 @@ CREATE TABLE blueprint_configuration (blueprint_name VARCHAR(255) NOT NULL,
type
 CREATE TABLE hostgroup_configuration (blueprint_name VARCHAR(255) NOT NULL, hostgroup_name
VARCHAR(255) NOT NULL, type_name VARCHAR(255) NOT NULL, config_data TEXT NOT NULL, PRIMARY
KEY(blueprint_name, hostgroup_name, type_name));
 CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version VARCHAR(255),
archive VARCHAR(255), PRIMARY KEY(view_name));
 CREATE TABLE viewinstancedata (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255)
NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value VARCHAR(2000)
NOT NULL, PRIMARY KEY(view_name, view_instance_name, name, user_name));
-CREATE TABLE viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY
KEY(view_name, name));
+CREATE TABLE viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label
VARCHAR(255), PRIMARY KEY(view_name, name));
 CREATE TABLE viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255)
NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name,
view_instance_name, name));
 CREATE TABLE viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
description VARCHAR(255), required CHAR(1), PRIMARY KEY(view_name, name));
 CREATE TABLE viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, plural_name
VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255), provider VARCHAR(255),
service VARCHAR(255), resource VARCHAR(255), PRIMARY KEY(view_name, name));

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
index eec4a3a..5ec05fd 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -54,7 +54,7 @@ CREATE TABLE blueprint_configuration (blueprint_name VARCHAR2(255) NOT NULL,
typ
 CREATE TABLE hostgroup_configuration (blueprint_name VARCHAR2(255) NOT NULL, hostgroup_name
VARCHAR2(255) NOT NULL, type_name VARCHAR2(255) NOT NULL, config_data CLOB NOT NULL, PRIMARY
KEY(blueprint_name, hostgroup_name, type_name));
 CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version VARCHAR(255),
archive VARCHAR(255), PRIMARY KEY(view_name));
 CREATE TABLE viewinstancedata (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255)
NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value VARCHAR(2000)
NOT NULL, PRIMARY KEY(view_name, view_instance_name, name, user_name));
-CREATE TABLE viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY
KEY(view_name, name));
+CREATE TABLE viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label
VARCHAR(255), PRIMARY KEY(view_name, name));
 CREATE TABLE viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255)
NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name,
view_instance_name, name));
 CREATE TABLE viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
description VARCHAR(255), required CHAR(1), PRIMARY KEY(view_name, name));
 CREATE TABLE viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, plural_name
VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255), provider VARCHAR(255),
service VARCHAR(255), "resource" VARCHAR(255), PRIMARY KEY(view_name, name));

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
index 330c1fb..72ed1eb 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -87,7 +87,7 @@ CREATE TABLE hostgroup_configuration (blueprint_name VARCHAR(255) NOT NULL,
host
 
 CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version VARCHAR(255),
archive VARCHAR(255), PRIMARY KEY(view_name));
 CREATE TABLE viewinstancedata (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255)
NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value VARCHAR(2000)
NOT NULL, PRIMARY KEY(view_name, view_instance_name, name, user_name));
-CREATE TABLE viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY
KEY(view_name, name));
+CREATE TABLE viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label
VARCHAR(255), PRIMARY KEY(view_name, name));
 CREATE TABLE viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name VARCHAR(255)
NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name,
view_instance_name, name));
 CREATE TABLE viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL,
description VARCHAR(255), required CHAR(1), PRIMARY KEY(view_name, name));
 CREATE TABLE viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, plural_name
VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255), provider VARCHAR(255),
service VARCHAR(255), resource VARCHAR(255), PRIMARY KEY(view_name, name));

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
index 2418332..c2440ce 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-EMBEDDED-CREATE.sql
@@ -134,7 +134,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.hostgroup_configuration TO :username;
 
 CREATE TABLE ambari.viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), version
VARCHAR(255), archive VARCHAR(255), PRIMARY KEY(view_name));
 CREATE TABLE ambari.viewinstancedata (view_name VARCHAR(255) NOT NULL, view_instance_name
VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, user_name VARCHAR(255) NOT NULL, value
VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name, view_instance_name, name, user_name));
-CREATE TABLE ambari.viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT
NULL, PRIMARY KEY(view_name, name));
+CREATE TABLE ambari.viewinstance (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT
NULL, label VARCHAR(255), PRIMARY KEY(view_name, name));
 CREATE TABLE ambari.viewinstanceproperty (view_name VARCHAR(255) NOT NULL, view_instance_name
VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, value VARCHAR(2000) NOT NULL, PRIMARY KEY(view_name,
view_instance_name, name));
 CREATE TABLE ambari.viewparameter (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT
NULL, description VARCHAR(255), required CHAR(1), PRIMARY KEY(view_name, name));
 CREATE TABLE ambari.viewresource (view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT
NULL, plural_name VARCHAR(255), id_property VARCHAR(255), subResource_names VARCHAR(255),
provider VARCHAR(255), service VARCHAR(255), resource VARCHAR(255), PRIMARY KEY(view_name,
name));

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewInstanceEntityTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewInstanceEntityTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewInstanceEntityTest.java
index b8cb7f4..7b4fcff 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewInstanceEntityTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewInstanceEntityTest.java
@@ -34,6 +34,25 @@ import static org.easymock.EasyMock.createNiceMock;
  */
 public class ViewInstanceEntityTest {
 
+  private static String xml_with_instance_label = "<view>\n" +
+      "    <name>MY_VIEW</name>\n" +
+      "    <label>My View!</label>\n" +
+      "    <version>1.0.0</version>\n" +
+      "    <instance>\n" +
+      "        <name>INSTANCE1</name>\n" +
+      "        <label>My Instance 1!</label>\n" +
+      "    </instance>\n" +
+      "</view>";
+
+  private static String xml_without_instance_label = "<view>\n" +
+      "    <name>MY_VIEW</name>\n" +
+      "    <label>My View!</label>\n" +
+      "    <version>1.0.0</version>\n" +
+      "    <instance>\n" +
+      "        <name>INSTANCE1</name>\n" +
+      "    </instance>\n" +
+      "</view>";
+
   @Test
   public void testGetViewEntity() throws Exception {
     InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs().get(0);
@@ -60,6 +79,24 @@ public class ViewInstanceEntityTest {
   }
 
   @Test
+  public void testGetLabel() throws Exception {
+    // with an instance label
+    InstanceConfig instanceConfig = InstanceConfigTest.getInstanceConfigs(xml_with_instance_label).get(0);
+    ViewEntity viewDefinition = ViewEntityTest.getViewEntity();
+    ViewInstanceEntity viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
+
+    Assert.assertEquals("My Instance 1!", viewInstanceDefinition.getLabel());
+
+    // without an instance label
+    instanceConfig = InstanceConfigTest.getInstanceConfigs(xml_without_instance_label).get(0);
+    viewDefinition = ViewEntityTest.getViewEntity();
+    viewInstanceDefinition = new ViewInstanceEntity(viewDefinition, instanceConfig);
+
+    // should default to view label
+    Assert.assertEquals("My View!", viewInstanceDefinition.getLabel());
+  }
+
+  @Test
   public void testAddGetProperty() throws Exception {
     ViewInstanceEntity viewInstanceDefinition = getViewInstanceEntity();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
index b45e266..9904c0c 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog161Test.java
@@ -22,7 +22,6 @@ import com.google.inject.Binder;
 import com.google.inject.Guice;
 import com.google.inject.Injector;
 import com.google.inject.Module;
-
 import com.google.inject.Provider;
 import org.apache.ambari.server.configuration.Configuration;
 import org.apache.ambari.server.orm.DBAccessor;
@@ -36,12 +35,8 @@ import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
 import javax.persistence.TypedQuery;
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
 import java.sql.SQLException;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import static junit.framework.Assert.assertEquals;
 import static junit.framework.Assert.assertFalse;
@@ -54,7 +49,6 @@ import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.createStrictMock;
 import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 
@@ -72,9 +66,11 @@ public class UpgradeCatalog161Test {
 
     Capture<DBAccessor.DBColumnInfo> provisioningStateColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
     Capture<List<DBAccessor.DBColumnInfo>> operationLevelEntityColumnCapture
= new Capture<List<DBAccessor.DBColumnInfo>>();
-    
+    Capture<DBAccessor.DBColumnInfo> labelColumnCapture = new Capture<DBAccessor.DBColumnInfo>();
+
     setClustersConfigExpectations(dbAccessor, provisioningStateColumnCapture);    
     setOperationLevelEntityConfigExpectations(dbAccessor, operationLevelEntityColumnCapture);
+    setViewInstanceExpectations(dbAccessor, labelColumnCapture);
 
     replay(dbAccessor, configuration);
     AbstractUpgradeCatalog upgradeCatalog = getUpgradeCatalog(dbAccessor);
@@ -88,6 +84,7 @@ public class UpgradeCatalog161Test {
 
     assertClusterColumns(provisioningStateColumnCapture);
     assertOperationLevelEntityColumns(operationLevelEntityColumnCapture);
+    assertViewInstanceColumns(labelColumnCapture);
   }
 
   @SuppressWarnings("unchecked")
@@ -237,5 +234,26 @@ public class UpgradeCatalog161Test {
       assertEquals(String.class, column.getType());
       assertEquals(State.INIT.name(), column.getDefaultValue());
       assertFalse(column.isNullable());
-    }  
+    }
+
+
+  private void setViewInstanceExpectations(DBAccessor dbAccessor,
+                                             Capture<DBAccessor.DBColumnInfo> labelColumnCapture)
throws SQLException {
+
+    dbAccessor.addColumn(eq("viewinstance"),
+        capture(labelColumnCapture));
+  }
+
+  private void assertViewInstanceColumns(
+      Capture<DBAccessor.DBColumnInfo> labelColumnCapture) {
+    DBAccessor.DBColumnInfo column = labelColumnCapture.getValue();
+    assertEquals("label", column.getName());
+    assertEquals(255, (int) column.getLength());
+    assertEquals(String.class, column.getType());
+    assertNull(column.getDefaultValue());
+    assertTrue(column.isNullable());
+  }
+
+
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
index 4f49425..a10f321 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/InstanceConfigTest.java
@@ -57,6 +57,15 @@ public class InstanceConfigTest {
   }
 
   @Test
+  public void testGetLabel() throws Exception {
+    List<InstanceConfig> instances = getInstanceConfigs();
+
+    Assert.assertEquals(2, instances.size());
+    Assert.assertEquals("My Instance 1!", instances.get(0).getLabel());
+    Assert.assertEquals("My Instance 2!", instances.get(1).getLabel());
+  }
+
+  @Test
   public void testGetProperties() throws Exception {
     List<InstanceConfig> instances = getInstanceConfigs();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
index c44e40b..74f48a8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/view/configuration/ViewConfigTest.java
@@ -75,6 +75,7 @@ public class ViewConfigTest {
       "    </resource>\n" +
       "    <instance>\n" +
       "        <name>INSTANCE1</name>\n" +
+      "        <label>My Instance 1!</label>\n" +
       "        <property>\n" +
       "            <key>p1</key>\n" +
       "            <value>v1-1</value>\n" +
@@ -86,6 +87,7 @@ public class ViewConfigTest {
       "    </instance>\n" +
       "    <instance>\n" +
       "        <name>INSTANCE2</name>\n" +
+      "        <label>My Instance 2!</label>\n" +
       "        <property>\n" +
       "            <key>p1</key>\n" +
       "            <value>v1-2</value>\n" +

http://git-wip-us.apache.org/repos/asf/ambari/blob/c8de2f18/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
b/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
index 58f40b0..5b9b92d 100644
--- a/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
+++ b/ambari-views/src/main/java/org/apache/ambari/view/ViewInstanceDefinition.java
@@ -40,6 +40,13 @@ public interface ViewInstanceDefinition {
   public String getViewName();
 
   /**
+   * Get the view instance label (display name).
+   *
+   * @return the view instance label
+   */
+  public String getLabel();
+
+  /**
    * Get the instance property map.
    *
    * @return the map of instance properties


Mime
View raw message