ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-21806 - Repository Entities Which Can't Be Removed Should Be Hide-able (jonathanhurley)
Date Fri, 25 Aug 2017 12:55:01 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 f9f6de142 -> 952b8cad8


AMBARI-21806 - Repository Entities Which Can't Be Removed Should Be Hide-able (jonathanhurley)


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

Branch: refs/heads/branch-2.6
Commit: 952b8cad8c6f20b3cc6547982e952e32fbceba52
Parents: f9f6de1
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Thu Aug 24 13:03:52 2017 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Fri Aug 25 08:54:45 2017 -0400

----------------------------------------------------------------------
 .../RepositoryVersionResourceProvider.java      | 12 ++++++---
 .../orm/entities/RepositoryVersionEntity.java   | 27 +++++++++++++++++++-
 .../server/upgrade/UpgradeCatalog260.java       | 15 ++++++++++-
 .../main/resources/Ambari-DDL-Derby-CREATE.sql  |  1 +
 .../main/resources/Ambari-DDL-MySQL-CREATE.sql  |  1 +
 .../main/resources/Ambari-DDL-Oracle-CREATE.sql |  1 +
 .../resources/Ambari-DDL-Postgres-CREATE.sql    |  1 +
 .../resources/Ambari-DDL-SQLAnywhere-CREATE.sql |  1 +
 .../resources/Ambari-DDL-SQLServer-CREATE.sql   |  1 +
 .../server/upgrade/UpgradeCatalog260Test.java   | 24 +++++++++++++++--
 10 files changed, 77 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
index 34b7b92..e1da813 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RepositoryVersionResourceProvider.java
@@ -86,6 +86,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
   public static final String REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID      = PropertyHelper.getPropertyId("RepositoryVersions",
"stack_version");
   public static final String REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID = PropertyHelper.getPropertyId("RepositoryVersions",
"repository_version");
   public static final String REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID       = PropertyHelper.getPropertyId("RepositoryVersions",
"display_name");
+  public static final String REPOSITORY_VERSION_HIDDEN_PROPERTY_ID             = PropertyHelper.getPropertyId("RepositoryVersions",
"hidden");
   public static final String SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID         = new OperatingSystemResourceDefinition().getPluralName();
   public static final String SUBRESOURCE_REPOSITORIES_PROPERTY_ID              = new RepositoryResourceDefinition().getPluralName();
 
@@ -108,6 +109,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
       REPOSITORY_VERSION_ID_PROPERTY_ID,
       REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID,
       REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID,
+      REPOSITORY_VERSION_HIDDEN_PROPERTY_ID,
       REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID,
       REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID,
       SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID,
@@ -252,6 +254,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
       setResourceProperty(resource, REPOSITORY_VERSION_STACK_NAME_PROPERTY_ID, entity.getStackName(),
requestedIds);
       setResourceProperty(resource, REPOSITORY_VERSION_STACK_VERSION_PROPERTY_ID, entity.getStackVersion(),
requestedIds);
       setResourceProperty(resource, REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID, entity.getDisplayName(),
requestedIds);
+      setResourceProperty(resource, REPOSITORY_VERSION_HIDDEN_PROPERTY_ID, entity.isHidden(),
requestedIds);
       setResourceProperty(resource, REPOSITORY_VERSION_REPOSITORY_VERSION_PROPERTY_ID, entity.getVersion(),
requestedIds);
       setResourceProperty(resource, REPOSITORY_VERSION_TYPE_PROPERTY_ID, entity.getType(),
requestedIds);
 
@@ -324,8 +327,6 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
             throw new ObjectNotFoundException("There is no repository version with id " +
id);
           }
 
-          List<OperatingSystemEntity> operatingSystemEntities = null;
-
           if (StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID))))
{
             if (!AuthorizationHelper.isAuthorized(ResourceType.AMBARI, null, RoleAuthorization.AMBARI_EDIT_STACK_REPOS))
{
               throw new AuthorizationException("The authenticated user does not have authorization
to modify stack repositories");
@@ -334,7 +335,7 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
             final Object operatingSystems = propertyMap.get(SUBRESOURCE_OPERATING_SYSTEMS_PROPERTY_ID);
             final String operatingSystemsJson = gson.toJson(operatingSystems);
             try {
-              operatingSystemEntities = repositoryVersionHelper.parseOperatingSystems(operatingSystemsJson);
+              repositoryVersionHelper.parseOperatingSystems(operatingSystemsJson);
             } catch (Exception ex) {
               throw new AmbariException("Json structure for operating systems is incorrect",
ex);
             }
@@ -345,6 +346,11 @@ public class RepositoryVersionResourceProvider extends AbstractAuthorizedResourc
             entity.setDisplayName(propertyMap.get(REPOSITORY_VERSION_DISPLAY_NAME_PROPERTY_ID).toString());
           }
 
+          if(StringUtils.isNotBlank(ObjectUtils.toString(propertyMap.get(REPOSITORY_VERSION_HIDDEN_PROPERTY_ID)))){
+            boolean isHidden = Boolean.valueOf(ObjectUtils.toString(propertyMap.get(REPOSITORY_VERSION_HIDDEN_PROPERTY_ID)));
+            entity.setHidden(isHidden);
+          }
+
           validateRepositoryVersion(repositoryVersionDAO, ambariMetaInfo, entity);
 
           repositoryVersionDAO.merge(entity);

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
index f84f3a4..72269f0 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/RepositoryVersionEntity.java
@@ -143,6 +143,9 @@ public class RepositoryVersionEntity {
   @Column(name="version_xsd", insertable = true, updatable = true)
   private String versionXsd;
 
+  @Column(name = "hidden", nullable = false, insertable = true, updatable = true)
+  private short isHidden = 0;
+
   @ManyToOne
   @JoinColumn(name = "parent_id")
   private RepositoryVersionEntity parent;
@@ -150,6 +153,7 @@ public class RepositoryVersionEntity {
   @OneToMany(mappedBy = "parent")
   private List<RepositoryVersionEntity> children;
 
+
   // ----- RepositoryVersionEntity -------------------------------------------------------
 
   public RepositoryVersionEntity() {
@@ -399,7 +403,7 @@ public class RepositoryVersionEntity {
   @Override
   public String toString() {
     return Objects.toStringHelper(this).add("id", id).add("stack", stack).add("version",
-        version).add("type", type).toString();
+        version).add("type", type).add("hidden", isHidden == 1).toString();
   }
 
   /**
@@ -448,4 +452,25 @@ public class RepositoryVersionEntity {
     return null == parent ? null : parent.getId();
   }
 
+  /**
+   * Gets whether this repository is hidden.
+   *
+   * @return
+   */
+  public boolean isHidden() {
+    return isHidden != 0;
+  }
+
+  /**
+   * Sets whether this repository is hidden. A repository can be hidden for
+   * several reasons, including if it has been removed (but needs to be kept
+   * around for foreign key relationships) or if it just is not longer desired
+   * to see it.
+   *
+   * @param isHidden
+   */
+  public void setHidden(boolean isHidden) {
+    this.isHidden = (short) (isHidden ? 1 : 0);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
index c8d33d2..cee05ef 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog260.java
@@ -57,6 +57,7 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
 
   public static final String REPO_VERSION_TABLE = "repo_version";
   public static final String REPO_VERSION_ID_COLUMN = "repo_version_id";
+  public static final String REPO_VERSION_HIDDEN_COLUMN = "hidden";
 
   public static final String HOST_COMPONENT_DESIRED_STATE_TABLE = "hostcomponentdesiredstate";
   public static final String FK_HCDS_DESIRED_STACK_ID = "FK_hcds_desired_stack_id";
@@ -148,10 +149,11 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
     updateUpgradeTable();
     createUpgradeHistoryTable();
     dropStaleTables();
+    updateRepositoryVersionTable();
   }
 
   private void createUpgradeHistoryTable() throws SQLException {
-    List<DBAccessor.DBColumnInfo> columns = new ArrayList<DBAccessor.DBColumnInfo>();
+    List<DBAccessor.DBColumnInfo> columns = new ArrayList<>();
 
     columns.add(new DBAccessor.DBColumnInfo(ID_COLUMN, Long.class, null, null, false));
     columns.add(new DBAccessor.DBColumnInfo(UPGRADE_ID_COLUMN, Long.class, null, null, false));
@@ -304,6 +306,17 @@ public class UpgradeCatalog260 extends AbstractUpgradeCatalog {
   }
 
   /**
+   * Updates {@value #REPO_VERSION_TABLE} table. Adds
+   * {@value #REPO_VERSION_HIDDEN_COLUMN} column.
+   *
+   * @throws java.sql.SQLException
+   */
+  private void updateRepositoryVersionTable() throws SQLException {
+    dbAccessor.addColumn(REPO_VERSION_TABLE,
+        new DBAccessor.DBColumnInfo(REPO_VERSION_HIDDEN_COLUMN, Short.class, null, 0, false));
+  }
+
+  /**
    * {@inheritDoc}
    */
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
index 9cdf8e8..7348d4f 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Derby-CREATE.sql
@@ -154,6 +154,7 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   repositories VARCHAR(3000) NOT NULL,
   repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
+  hidden SMALLINT NOT NULL DEFAULT 0,
   version_url VARCHAR(1024),
   version_xml CLOB,
   version_xsd VARCHAR(512),

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/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 d616e77..28ac59e 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-MySQL-CREATE.sql
@@ -174,6 +174,7 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   repositories MEDIUMTEXT NOT NULL,
   repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
+  hidden SMALLINT NOT NULL DEFAULT 0,
   version_url VARCHAR(1024),
   version_xml MEDIUMTEXT,
   version_xsd VARCHAR(512),

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/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 0530651..f31b308 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Oracle-CREATE.sql
@@ -155,6 +155,7 @@ CREATE TABLE repo_version (
   display_name VARCHAR2(128) NOT NULL,
   repositories CLOB NOT NULL,
   repo_type VARCHAR2(255) DEFAULT 'STANDARD' NOT NULL,
+  hidden NUMBER(1) DEFAULT 0 NOT NULL,
   version_url VARCHAR(1024),
   version_xml CLOB,
   version_xsd VARCHAR(512),

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/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 1d16eb6..8ed9da5 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-Postgres-CREATE.sql
@@ -154,6 +154,7 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   repositories TEXT NOT NULL,
   repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
+  hidden SMALLINT NOT NULL DEFAULT 0,
   version_url VARCHAR(1024),
   version_xml TEXT,
   version_xsd VARCHAR(512),

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
index da23e95..2a45476 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLAnywhere-CREATE.sql
@@ -153,6 +153,7 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   repositories TEXT NOT NULL,
   repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
+  hidden SMALLINT NOT NULL DEFAULT 0,
   version_url VARCHAR(1024),
   version_xml TEXT,
   version_xsd VARCHAR(512),

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
index e410555..c5d2e90 100644
--- a/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
+++ b/ambari-server/src/main/resources/Ambari-DDL-SQLServer-CREATE.sql
@@ -167,6 +167,7 @@ CREATE TABLE repo_version (
   display_name VARCHAR(128) NOT NULL,
   repositories VARCHAR(MAX) NOT NULL,
   repo_type VARCHAR(255) DEFAULT 'STANDARD' NOT NULL,
+  hidden SMALLINT NOT NULL DEFAULT 0,
   version_url VARCHAR(1024),
   version_xml VARCHAR(MAX),
   version_xsd VARCHAR(512),

http://git-wip-us.apache.org/repos/asf/ambari/blob/952b8cad/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
index df15657..2e38686 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/upgrade/UpgradeCatalog260Test.java
@@ -138,7 +138,7 @@ public class UpgradeCatalog260Test {
   @Test
   public void testExecuteDDLUpdates() throws Exception {
 
-    List<Integer> current = new ArrayList<Integer>();
+    List<Integer> current = new ArrayList<>();
     current.add(1);
 
     expect(dbAccessor.getConnection()).andReturn(connection).anyTimes();
@@ -179,6 +179,9 @@ public class UpgradeCatalog260Test {
 
     expectDropStaleTables();
 
+    Capture<DBColumnInfo> repoVersionHiddenColumnCapture = newCapture();
+    expectUpdateRepositoryVersionTableTable(repoVersionHiddenColumnCapture);
+
     replay(dbAccessor, configuration, connection, statement, resultSet);
 
     Module module = new Module() {
@@ -203,7 +206,7 @@ public class UpgradeCatalog260Test {
     verifyAddSelectedCollumsToClusterconfigTable(selectedColumnInfo, selectedmappingColumnInfo,
selectedTimestampColumnInfo, createTimestampColumnInfo);
     verifyUpdateUpgradeTable(rvid, orchestration);
     verifyCreateUpgradeHistoryTable(columns);
-
+    verifyUpdateRepositoryVersionTableTable(repoVersionHiddenColumnCapture);
   }
 
   public void expectDropStaleTables() throws SQLException {
@@ -507,5 +510,22 @@ public class UpgradeCatalog260Test {
 
   }
 
+  /**
+   * Sets expectations for DDL work on the
+   * {@link UpgradeCatalog260#REPO_VERSION_TABLE}.
+   *
+   * @param hiddenColumnCapture
+   * @throws SQLException
+   */
+  public void expectUpdateRepositoryVersionTableTable(Capture<DBColumnInfo> hiddenColumnCapture)
throws SQLException {
+    dbAccessor.addColumn(eq(UpgradeCatalog260.REPO_VERSION_TABLE), capture(hiddenColumnCapture));
+    expectLastCall().once();
+  }
 
+  public void verifyUpdateRepositoryVersionTableTable(Capture<DBColumnInfo> hiddenColumnCapture)
{
+    DBColumnInfo hiddenColumn = hiddenColumnCapture.getValue();
+    Assert.assertEquals(0, hiddenColumn.getDefaultValue());
+    Assert.assertEquals(UpgradeCatalog260.REPO_VERSION_HIDDEN_COLUMN, hiddenColumn.getName());
+    Assert.assertEquals(false, hiddenColumn.isNullable());
+  }
 }


Mime
View raw message