Repository: ambari Updated Branches: refs/heads/trunk 9d9ec5e21 -> 87d95d299
AMBARI-11818 - Views : By default do not delete view data when View archive is removed (tbeerbower) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/87d95d29 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/87d95d29 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/87d95d29 Branch: refs/heads/trunk Commit: 87d95d299b19ed4f2bcb15e0e39e14b5661ce5b0 Parents: 9d9ec5e Author: tbeerbower <tbeerbo...@hortonworks.com> Authored: Wed Jun 10 08:34:05 2015 -0400 Committer: tbeerbower <tbeerbo...@hortonworks.com> Committed: Wed Jun 10 08:34:05 2015 -0400 ---------------------------------------------------------------------- .../server/configuration/Configuration.java | 12 +++++++++++- .../apache/ambari/server/view/ViewRegistry.java | 2 +- .../server/configuration/ConfigurationTest.java | 19 +++++++++++++++++++ .../ambari/server/view/ViewRegistryTest.java | 18 ++++++++++++------ 4 files changed, 43 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/87d95d29/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java index f62ab64..dc6089a 100644 --- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java +++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java @@ -69,6 +69,8 @@ public class Configuration { public static final String VIEWS_DIR_DEFAULT = "/var/lib/ambari-server/resources/views"; public static final String VIEWS_VALIDATE = "views.validate"; public static final String VIEWS_VALIDATE_DEFAULT = "false"; + public static final String VIEWS_REMOVE_UNDEPLOYED = "views.remove.undeployed"; + public static final String VIEWS_REMOVE_UNDEPLOYED_DEFAULT = "false"; public static final String WEBAPP_DIR = "webapp.dir"; public static final String BOOTSTRAP_SCRIPT = "bootstrap.script"; public static final String BOOTSTRAP_SCRIPT_DEFAULT = "/usr/bin/ambari_bootstrap"; @@ -730,9 +732,17 @@ public class Configuration { * @return true if view validation is enabled */ public boolean isViewValidationEnabled() { - return "true".equalsIgnoreCase(properties.getProperty(VIEWS_VALIDATE, VIEWS_VALIDATE_DEFAULT)); + return Boolean.parseBoolean(properties.getProperty(VIEWS_VALIDATE, VIEWS_VALIDATE_DEFAULT)); } + /** + * Determine whether or not a view that has been undeployed (archive deleted) should be removed from the database. + * + * @return true if undeployed views should be removed + */ + public boolean isViewRemoveUndeployedEnabled() { + return Boolean.parseBoolean(properties.getProperty(VIEWS_REMOVE_UNDEPLOYED, VIEWS_REMOVE_UNDEPLOYED_DEFAULT)); + } /** * @return conventional Java version number, e.g. 7. http://git-wip-us.apache.org/repos/asf/ambari/blob/87d95d29/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 3ee2c5a..61b9327 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 @@ -1510,7 +1510,7 @@ public class ViewRegistry { } } - if (removeUndeployed) { + if (configuration.isViewRemoveUndeployedEnabled()) { removeUndeployedViews(); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/87d95d29/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java index 0823f99..70ab3b6 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java @@ -341,6 +341,25 @@ public class ConfigurationTest { } @Test + public void testIsViewRemoveUndeployedEnabled() throws Exception { + final Properties ambariProperties = new Properties(); + Configuration configuration = new Configuration(ambariProperties); + Assert.assertFalse(configuration.isViewRemoveUndeployedEnabled()); + + ambariProperties.setProperty(Configuration.VIEWS_REMOVE_UNDEPLOYED, "false"); + configuration = new Configuration(ambariProperties); + Assert.assertFalse(configuration.isViewRemoveUndeployedEnabled()); + + ambariProperties.setProperty(Configuration.VIEWS_REMOVE_UNDEPLOYED, "true"); + configuration = new Configuration(ambariProperties); + Assert.assertTrue(configuration.isViewRemoveUndeployedEnabled()); + + ambariProperties.setProperty(Configuration.VIEWS_REMOVE_UNDEPLOYED, Configuration.VIEWS_REMOVE_UNDEPLOYED_DEFAULT); + configuration = new Configuration(ambariProperties); + Assert.assertFalse(configuration.isViewRemoveUndeployedEnabled()); + } + + @Test public void testGetLdapServerProperties() throws Exception { final Properties ambariProperties = new Properties(); final Configuration configuration = new Configuration(ambariProperties); http://git-wip-us.apache.org/repos/asf/ambari/blob/87d95d29/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java index a8c938f..ebe607b 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/view/ViewRegistryTest.java @@ -227,18 +227,22 @@ public class ViewRegistryTest { clusters); } - @Test public void testReadViewArchives() throws Exception { - testReadViewArchives(false); + testReadViewArchives(false, false); + } + + @Test + public void testReadViewArchives_removeUndeployed() throws Exception { + testReadViewArchives(false, true); } @Test public void testReadViewArchives_badArchive() throws Exception { - testReadViewArchives(true); + testReadViewArchives(true, false); } - private void testReadViewArchives(boolean badArchive) throws Exception { + private void testReadViewArchives(boolean badArchive, boolean removeUndeployed) throws Exception { File viewDir = createNiceMock(File.class); File extractedArchiveDir = createNiceMock(File.class); @@ -380,7 +384,10 @@ public class ViewRegistryTest { expect(libDir.listFiles()).andReturn(new File[]{fileEntry}).anyTimes(); expect(fileEntry.toURI()).andReturn(new URI("file:./")).anyTimes(); - expect(viewDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList()); + expect(configuration.isViewRemoveUndeployedEnabled()).andReturn(removeUndeployed).anyTimes(); + if (removeUndeployed) { + expect(viewDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList()); + } // replay mocks replay(configuration, viewDir, extractedArchiveDir, viewArchive, archiveDir, entryFile, classesDir, @@ -553,7 +560,6 @@ public class ViewRegistryTest { expect(libDir.listFiles()).andReturn(new File[]{fileEntry}); expect(fileEntry.toURI()).andReturn(new URI("file:./")); - expect(viewDAO.findAll()).andReturn(Collections.<ViewEntity>emptyList()); expect(viewDAO.findByName("MY_VIEW{1.0.0}")).andThrow(new IllegalArgumentException("Expected exception.")); // replay mocks