AMBARI-7211 - Views : support for a <system> property

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

Branch: refs/heads/branch-alerts-dev
Commit: dc15b7706294371444c455f40f2792d8fea4c0bc
Parents: 1ef2af3
Author: tbeerbower <tbeerbo...@hortonworks.com>
Authored: Tue Sep 9 13:55:18 2014 -0400
Committer: tbeerbower <tbeerbo...@hortonworks.com>
Committed: Wed Sep 10 11:02:03 2014 -0400

----------------------------------------------------------------------
 .../AmbariPrivilegeResourceProvider.java        |  8 ++++--
 .../internal/ViewVersionResourceProvider.java   |  3 ++
 .../ambari/server/orm/entities/ViewEntity.java  | 29 +++++++++++++++++++-
 .../server/upgrade/UpgradeCatalog170.java       |  2 ++
 .../server/view/configuration/ViewConfig.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 +-
 .../AmbariPrivilegeResourceProviderTest.java    |  1 +
 .../server/orm/entities/ViewEntityTest.java     | 11 ++++++++
 .../server/upgrade/UpgradeCatalog170Test.java   | 20 +++++++++++---
 .../view/configuration/ViewConfigTest.java      | 23 ++++++++++++++++
 13 files changed, 107 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
index d7c6a8f..85e5906 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProvider.java
@@ -122,11 +122,13 @@ public class AmbariPrivilegeResourceProvider extends 
PrivilegeResourceProvider<O
         resourceEntities.put(clusterEntity.getResource().getId(), 
clusterEntity);
       }
     }
-    //add view entites
+    //add view entities
     ViewRegistry viewRegistry = ViewRegistry.getInstance();
     for (ViewEntity viewEntity : viewRegistry.getDefinitions()) {
-      for (ViewInstanceEntity viewInstanceEntity : viewEntity.getInstances()) {
-        resourceEntities.put(viewInstanceEntity.getResource().getId(), 
viewInstanceEntity);
+      if (viewEntity.isLoaded()) {
+        for (ViewInstanceEntity viewInstanceEntity : 
viewEntity.getInstances()) {
+          resourceEntities.put(viewInstanceEntity.getResource().getId(), 
viewInstanceEntity);
+        }
       }
     }
     return resourceEntities;

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewVersionResourceProvider.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewVersionResourceProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewVersionResourceProvider.java
index ed9f06a..58cf774 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewVersionResourceProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ViewVersionResourceProvider.java
@@ -54,6 +54,7 @@ public class ViewVersionResourceProvider extends 
AbstractResourceProvider {
   public static final String MASKER_CLASS_PROPERTY_ID       = 
"ViewVersionInfo/masker_class";
   public static final String VIEW_STATUS_PROPERTY_ID        = 
"ViewVersionInfo/status";
   public static final String VIEW_STATUS_DETAIL_PROPERTY_ID = 
"ViewVersionInfo/status_detail";
+  public static final String SYSTEM_PROPERTY_ID             = 
"ViewVersionInfo/system";
 
   /**
    * The key property ids for a view resource.
@@ -79,6 +80,7 @@ public class ViewVersionResourceProvider extends 
AbstractResourceProvider {
     propertyIds.add(MASKER_CLASS_PROPERTY_ID);
     propertyIds.add(VIEW_STATUS_PROPERTY_ID);
     propertyIds.add(VIEW_STATUS_DETAIL_PROPERTY_ID);
+    propertyIds.add(SYSTEM_PROPERTY_ID);
   }
 
 
@@ -135,6 +137,7 @@ public class ViewVersionResourceProvider extends 
AbstractResourceProvider {
             setResourceProperty(resource, MASKER_CLASS_PROPERTY_ID, 
viewDefinition.getMask(), requestedIds);
             setResourceProperty(resource, VIEW_STATUS_PROPERTY_ID, 
viewDefinition.getStatus().toString(), requestedIds);
             setResourceProperty(resource, VIEW_STATUS_DETAIL_PROPERTY_ID, 
viewDefinition.getStatusDetail(), requestedIds);
+            setResourceProperty(resource, SYSTEM_PROPERTY_ID, 
viewDefinition.isSystem(), requestedIds);
 
             resources.add(resource);
           }

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewEntity.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewEntity.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewEntity.java
index 073451d..b6ec922 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewEntity.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/ViewEntity.java
@@ -112,8 +112,15 @@ public class ViewEntity implements ViewDefinition {
   private String mask;
 
   /**
-   * The list of view parameters.
+   * Indicates whether or not this is a system view.
    */
+  @Column(name = "system_view")
+  @Basic
+  private Integer system;
+
+  /**
+  * The list of view parameters.
+  */
   @OneToMany(cascade = CascadeType.ALL, mappedBy = "view")
   private Collection<ViewParameterEntity> parameters = new 
HashSet<ViewParameterEntity>();
 
@@ -226,6 +233,7 @@ public class ViewEntity implements ViewDefinition {
     this.ambariConfiguration  = null;
     this.archive              = null;
     this.externalResourceType = null;
+    this.system               = 0;
   }
 
   /**
@@ -251,6 +259,7 @@ public class ViewEntity implements ViewDefinition {
     this.mask        = configuration.getMasker();
     this.icon        = configuration.getIcon();
     this.icon64      = configuration.getIcon64();
+    this.system      = configuration.isSystem() ? 1 : 0;
 
     this.externalResourceType =
         new 
Resource.Type(getQualifiedResourceTypeName(ResourceConfig.EXTERNAL_RESOURCE_PLURAL_NAME));
@@ -714,6 +723,24 @@ public class ViewEntity implements ViewDefinition {
   }
 
   /**
+   * Determine whether or not the view is a system view.
+   *
+   * @return true if the view is a system view
+   */
+  public boolean isSystem() {
+    return system == 1;
+  }
+
+  /**
+   * Set the flag which indicates whether or not the view is a system view.
+   *
+   * @param required  the system flag; true if the view is a system view
+   */
+  public void setSystem(boolean required) {
+    this.system = required ? 1 : 0;
+  }
+
+  /**
    * Get the admin resource type entity.
    *
    * @return the resource type entity

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
index 801249f..ee67330 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog170.java
@@ -231,6 +231,8 @@ public class UpgradeCatalog170 extends 
AbstractUpgradeCatalog {
     // Add columns
     dbAccessor.addColumn("viewmain", new DBColumnInfo("mask",
       String.class, 255, null, true));
+    dbAccessor.addColumn("viewmain", new DBColumnInfo("system_view",
+        Character.class, 1, null, true));
     dbAccessor.addColumn("viewparameter", new DBColumnInfo("masked",
       Character.class, 1, null, true));
     dbAccessor.addColumn("users", new DBColumnInfo("active",

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
index 816c178..3a23ea7 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/view/configuration/ViewConfig.java
@@ -68,6 +68,11 @@ public class ViewConfig {
   private String icon64;
 
   /**
+   * Indicates whether or not this is a system view.
+   */
+  private boolean system;
+
+  /**
    * The main view class name.
    */
   @XmlElement(name="view-class")
@@ -174,6 +179,15 @@ public class ViewConfig {
   }
 
   /**
+   * Determine whether or not this is a system view.
+   *
+   * @return true if this is a system view
+   */
+  public boolean isSystem() {
+    return system;
+  }
+
+  /**
    * Get the view class name.
    *
    * @return the view class name

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/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 59d972e..356ef0c 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -65,7 +65,7 @@ CREATE TABLE hostgroup (blueprint_name VARCHAR(255) NOT NULL, 
name VARCHAR(255)
 CREATE TABLE hostgroup_component (blueprint_name VARCHAR(255) NOT NULL, 
hostgroup_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY 
KEY(blueprint_name, hostgroup_name, name));
 CREATE TABLE blueprint_configuration (blueprint_name VARCHAR(255) NOT NULL, 
type_name VARCHAR(255) NOT NULL, config_data VARCHAR(32000) NOT NULL, 
config_attributes VARCHAR(32000), PRIMARY KEY(blueprint_name, type_name));
 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, config_attributes TEXT, PRIMARY KEY(blueprint_name, 
hostgroup_name, type_name));
-CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), 
description VARCHAR(255), version VARCHAR(255), resource_type_id INTEGER NOT 
NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask 
VARCHAR(255), PRIMARY KEY(view_name));
+CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), 
description VARCHAR(255), version VARCHAR(255), resource_type_id INTEGER NOT 
NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask 
VARCHAR(255), system_view TINYINT(1) NOT NULL DEFAULT 0, PRIMARY 
KEY(view_name));
 CREATE TABLE viewinstancedata (view_instance_id BIGINT, 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_INSTANCE_ID, NAME, USER_NAME));
 CREATE TABLE viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT 
NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label 
VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), 
icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id));
 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));

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/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 52ca857..ecaf220 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -56,7 +56,7 @@ CREATE TABLE hostgroup (blueprint_name VARCHAR2(255) NOT 
NULL, name VARCHAR2(255
 CREATE TABLE hostgroup_component (blueprint_name VARCHAR2(255) NOT NULL, 
hostgroup_name VARCHAR2(255) NOT NULL, name VARCHAR2(255) NOT NULL, PRIMARY 
KEY(blueprint_name, hostgroup_name, name));
 CREATE TABLE blueprint_configuration (blueprint_name VARCHAR2(255) NOT NULL, 
type_name VARCHAR2(255) NOT NULL, config_data CLOB NOT NULL, config_attributes 
CLOB, PRIMARY KEY(blueprint_name, type_name));
 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, config_attributes CLOB, PRIMARY KEY(blueprint_name, 
hostgroup_name, type_name));
-CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), 
description VARCHAR(255), version VARCHAR(255), resource_type_id NUMBER(10) NOT 
NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask 
VARCHAR(255), PRIMARY KEY(view_name));
+CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), 
description VARCHAR(255), version VARCHAR(255), resource_type_id NUMBER(10) NOT 
NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask 
VARCHAR(255), system_view NUMBER(1) DEFAULT 0 NOT NULL, PRIMARY KEY(view_name));
 CREATE TABLE viewinstancedata (view_instance_id NUMBER(19), 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_instance_id, name, user_name));
 CREATE TABLE viewinstance (view_instance_id NUMBER(19), resource_id NUMBER(19) 
NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label 
VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), 
icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id));
 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));

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/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 39d3ecf..f0ac53a 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -91,7 +91,7 @@ CREATE TABLE hostgroup_component (blueprint_name VARCHAR(255) 
NOT NULL, hostgrou
 CREATE TABLE blueprint_configuration (blueprint_name varchar(255) NOT NULL, 
type_name varchar(255) NOT NULL, config_data varchar(32000) NOT NULL , 
config_attributes varchar(32000), PRIMARY KEY(blueprint_name, type_name));
 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, config_attributes varchar(32000), PRIMARY 
KEY(blueprint_name, hostgroup_name, type_name));
 
-CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), 
description VARCHAR(255), version VARCHAR(255), resource_type_id INTEGER NOT 
NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask 
VARCHAR(255), PRIMARY KEY(view_name));
+CREATE TABLE viewmain (view_name VARCHAR(255) NOT NULL, label VARCHAR(255), 
description VARCHAR(255), version VARCHAR(255), resource_type_id INTEGER NOT 
NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), mask 
VARCHAR(255), system_view SMALLINT NOT NULL DEFAULT 0, PRIMARY KEY(view_name));
 CREATE TABLE viewinstancedata (view_instance_id BIGINT, 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_instance_id, name, user_name));
 CREATE TABLE viewinstance (view_instance_id BIGINT, resource_id BIGINT NOT 
NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label 
VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), 
icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id));
 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));

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/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 196d298..6e82ae1 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
@@ -141,7 +141,7 @@ GRANT ALL PRIVILEGES ON TABLE ambari.hostgroup_component TO 
:username;
 GRANT ALL PRIVILEGES ON TABLE ambari.blueprint_configuration TO :username;
 GRANT ALL PRIVILEGES ON TABLE ambari.hostgroup_configuration TO :username;
 
-CREATE TABLE ambari.viewmain (view_name VARCHAR(255) NOT NULL, label 
VARCHAR(255), description VARCHAR(255), version VARCHAR(255), resource_type_id 
INTEGER NOT NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), 
mask VARCHAR(255), PRIMARY KEY(view_name));
+CREATE TABLE ambari.viewmain (view_name VARCHAR(255) NOT NULL, label 
VARCHAR(255), description VARCHAR(255), version VARCHAR(255), resource_type_id 
INTEGER NOT NULL, icon VARCHAR(255), icon64 VARCHAR(255), archive VARCHAR(255), 
mask VARCHAR(255), system_view SMALLINT NOT NULL DEFAULT 0, PRIMARY 
KEY(view_name));
 CREATE TABLE ambari.viewinstancedata (view_instance_id BIGINT, 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_instance_id, name, user_name));
 CREATE TABLE ambari.viewinstance (view_instance_id BIGINT, resource_id BIGINT 
NOT NULL, view_name VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL, label 
VARCHAR(255), description VARCHAR(255), visible CHAR(1), icon VARCHAR(255), 
icon64 VARCHAR(255), xml_driven CHAR(1), PRIMARY KEY(view_instance_id));
 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));

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProviderTest.java
index fbeb0cc..f6a49cf 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AmbariPrivilegeResourceProviderTest.java
@@ -203,6 +203,7 @@ public class AmbariPrivilegeResourceProviderTest {
     
expect(viewInstanceEntity.getViewEntity()).andReturn(viewEntity).anyTimes();
     expect(viewEntity.getCommonName()).andReturn("view").anyTimes();
     expect(viewEntity.getVersion()).andReturn("1.0.1").anyTimes();
+    expect(viewEntity.isLoaded()).andReturn(true).anyTimes();
     expect(viewInstanceEntity.getName()).andReturn("inst1").anyTimes();
     
expect(viewInstanceEntity.getResource()).andReturn(viewResourceEntity).anyTimes();
     
expect(viewUserEntity.getPrincipal()).andReturn(viewPrincipalEntity).anyTimes();

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewEntityTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewEntityTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewEntityTest.java
index 977e01d..be0d3a6 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewEntityTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/orm/entities/ViewEntityTest.java
@@ -283,4 +283,15 @@ public class ViewEntityTest {
     viewDefinition.setStatus(ViewDefinition.ViewStatus.ERROR);
     Assert.assertFalse(viewDefinition.isLoaded());
   }
+
+  @Test
+  public void testSetIsSystem() throws Exception {
+    ViewEntity viewDefinition = getViewEntity();
+
+    viewDefinition.setSystem(false);
+    Assert.assertFalse(viewDefinition.isSystem());
+
+    viewDefinition.setSystem(true);
+    Assert.assertTrue(viewDefinition.isSystem());
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
index 9668ed5..abd97d6 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog170Test.java
@@ -133,6 +133,7 @@ public class UpgradeCatalog170Test {
 
     Capture<DBAccessor.DBColumnInfo> clusterConfigAttributesColumnCapture = 
new Capture<DBAccessor.DBColumnInfo>();
     Capture<DBAccessor.DBColumnInfo> maskColumnCapture = new 
Capture<DBAccessor.DBColumnInfo>();
+    Capture<DBAccessor.DBColumnInfo> systemColumnCapture = new 
Capture<DBAccessor.DBColumnInfo>();
     Capture<DBAccessor.DBColumnInfo> maskedColumnCapture = new 
Capture<DBAccessor.DBColumnInfo>();
     Capture<DBAccessor.DBColumnInfo> stageCommandParamsColumnCapture = new 
Capture<DBAccessor.DBColumnInfo>();
     Capture<DBAccessor.DBColumnInfo> stageHostParamsColumnCapture = new 
Capture<DBAccessor.DBColumnInfo>();
@@ -147,7 +148,7 @@ public class UpgradeCatalog170Test {
     Capture<List<DBAccessor.DBColumnInfo>> serviceConfigCapture = new 
Capture<List<DBAccessor.DBColumnInfo>>();
     Capture<List<DBAccessor.DBColumnInfo>> serviceConfigMappingCapture = new 
Capture<List<DBAccessor.DBColumnInfo>>();
 
-    setViewExpectations(dbAccessor, maskColumnCapture);
+    setViewExpectations(dbAccessor, maskColumnCapture, systemColumnCapture);
     setViewParameterExpectations(dbAccessor, maskedColumnCapture);
     setClusterConfigExpectations(dbAccessor, 
clusterConfigAttributesColumnCapture);
     setStageExpectations(dbAccessor, stageCommandParamsColumnCapture, 
stageHostParamsColumnCapture);
@@ -201,7 +202,7 @@ public class UpgradeCatalog170Test {
     verify(dbAccessor, configuration, resultSet, connection, stmt);
 
     assertClusterConfigColumns(clusterConfigAttributesColumnCapture);
-    assertViewColumns(maskColumnCapture);
+    assertViewColumns(maskColumnCapture, systemColumnCapture);
     assertViewParameterColumns(maskedColumnCapture);
     assertStageColumns(stageCommandParamsColumnCapture, 
stageHostParamsColumnCapture);
 
@@ -456,10 +457,12 @@ public class UpgradeCatalog170Test {
   }
 
   private void setViewExpectations(DBAccessor dbAccessor,
-                                   Capture<DBAccessor.DBColumnInfo> 
maskColumnCapture)
+                                   Capture<DBAccessor.DBColumnInfo> 
maskColumnCapture,
+                                   Capture<DBAccessor.DBColumnInfo> 
systemColumnCapture)
     throws SQLException {
 
     dbAccessor.addColumn(eq("viewmain"), capture(maskColumnCapture));
+    dbAccessor.addColumn(eq("viewmain"), capture(systemColumnCapture));
   }
 
   private void setViewParameterExpectations(DBAccessor dbAccessor,
@@ -470,13 +473,22 @@ public class UpgradeCatalog170Test {
   }
 
   private void assertViewColumns(
-    Capture<DBAccessor.DBColumnInfo> maskColumnCapture) {
+    Capture<DBAccessor.DBColumnInfo> maskColumnCapture,
+    Capture<DBAccessor.DBColumnInfo> systemColumnCapture) {
+
     DBAccessor.DBColumnInfo column = maskColumnCapture.getValue();
     assertEquals("mask", column.getName());
     assertEquals(255, (int) column.getLength());
     assertEquals(String.class, column.getType());
     assertNull(column.getDefaultValue());
     assertTrue(column.isNullable());
+
+    column = systemColumnCapture.getValue();
+    assertEquals("system_view", column.getName());
+    assertEquals(1, (int) column.getLength());
+    assertEquals(Character.class, column.getType());
+    assertNull(column.getDefaultValue());
+    assertTrue(column.isNullable());
   }
 
   private void assertViewParameterColumns(

http://git-wip-us.apache.org/repos/asf/ambari/blob/dc15b770/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 2ed365e..0e0ace8 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
@@ -117,6 +117,20 @@ public class ViewConfigTest {
       "    <view-class>ViewImpl</view-class>\n" +
       "</view>";
 
+  private static String system_xml = "<view>\n" +
+      "    <name>MY_VIEW</name>\n" +
+      "    <label>My View!</label>\n" +
+      "    <version>1.0.0</version>\n" +
+      "    <system>true</system>\n" +
+      "</view>";
+
+  private static String non_system_xml = "<view>\n" +
+      "    <name>MY_VIEW</name>\n" +
+      "    <label>My View!</label>\n" +
+      "    <version>1.0.0</version>\n" +
+      "    <system>false</system>\n" +
+      "</view>";
+
   @Test
   public void testGetName() throws Exception {
     ViewConfig config = getConfig();
@@ -210,6 +224,15 @@ public class ViewConfigTest {
     Assert.assertEquals(0, instances.size());
   }
 
+  @Test
+  public void testIsSystem() throws Exception {
+    ViewConfig config = getConfig(system_xml);
+    Assert.assertTrue(config.isSystem());
+
+    config = getConfig(non_system_xml);
+    Assert.assertFalse(config.isSystem());
+  }
+
   public static  ViewConfig getConfig() throws JAXBException {
       return getConfig(xml);
   }

Reply via email to