@Test public void testUpdateOozieConfigs() throws Exception { setupIoCContext(); EasyMockSupport easyMockSupport = new EasyMockSupport(); final AmbariManagementController mockAmbariManagementController = easyMockSupport.createNiceMock(AmbariManagementController.class); final ConfigHelper mockConfigHelper = easyMockSupport.createMock(ConfigHelper.class); final Clusters mockClusters = easyMockSupport.createStrictMock(Clusters.class); final Cluster mockClusterExpected = easyMockSupport.createNiceMock(Cluster.class); final Config mockOozieEnv = easyMockSupport.createNiceMock(Config.class); final Map<String, String> propertiesExpectedOozieEnv = new HashMap<String, String>() {{ put("oozie_hostname", ""); put("oozie_database", "123"); }}; final Injector mockInjector = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); bind(ConfigHelper.class).toInstance(mockConfigHelper); bind(Clusters.class).toInstance(mockClusters); bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).once(); expect(mockClusterExpected.getDesiredConfigByType("oozie-env")).andReturn(mockOozieEnv).atLeastOnce(); expect(mockOozieEnv.getProperties()).andReturn(propertiesExpectedOozieEnv).atLeastOnce(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog212.class).updateOozieConfigs(); easyMockSupport.verifyAll(); }
protected void updateOozieConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config oozieEnv = cluster.getDesiredConfigByType(OOZIE_ENV); if (oozieEnv != null) { Map<String, String> oozieEnvProperties = oozieEnv.getProperties(); String hostname = oozieEnvProperties.get("oozie_hostname"); String db_type = oozieEnvProperties.get("oozie_database"); String final_db_host = null; if (hostname != null && db_type != null && hostname.equals("")) { switch (db_type.toUpperCase()) { case "EXISTING MYSQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_mysql_host"); break; case "EXISTING POSTGRESQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_postgresql_host"); break; case "EXISTING ORACLE DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_oracle_host"); break; default: final_db_host = null; break; } if (final_db_host != null) { Map<String, String> newProperties = new HashMap<>(); newProperties.put("oozie_hostname", final_db_host); updateConfigurationPropertiesForCluster(cluster, OOZIE_ENV, newProperties, true, true); } } } } } } }
UpgradeCatalog212 extends AbstractUpgradeCatalog { protected void updateOozieConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config oozieEnv = cluster.getDesiredConfigByType(OOZIE_ENV); if (oozieEnv != null) { Map<String, String> oozieEnvProperties = oozieEnv.getProperties(); String hostname = oozieEnvProperties.get("oozie_hostname"); String db_type = oozieEnvProperties.get("oozie_database"); String final_db_host = null; if (hostname != null && db_type != null && hostname.equals("")) { switch (db_type.toUpperCase()) { case "EXISTING MYSQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_mysql_host"); break; case "EXISTING POSTGRESQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_postgresql_host"); break; case "EXISTING ORACLE DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_oracle_host"); break; default: final_db_host = null; break; } if (final_db_host != null) { Map<String, String> newProperties = new HashMap<>(); newProperties.put("oozie_hostname", final_db_host); updateConfigurationPropertiesForCluster(cluster, OOZIE_ENV, newProperties, true, true); } } } } } } } }
UpgradeCatalog212 extends AbstractUpgradeCatalog { protected void updateOozieConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config oozieEnv = cluster.getDesiredConfigByType(OOZIE_ENV); if (oozieEnv != null) { Map<String, String> oozieEnvProperties = oozieEnv.getProperties(); String hostname = oozieEnvProperties.get("oozie_hostname"); String db_type = oozieEnvProperties.get("oozie_database"); String final_db_host = null; if (hostname != null && db_type != null && hostname.equals("")) { switch (db_type.toUpperCase()) { case "EXISTING MYSQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_mysql_host"); break; case "EXISTING POSTGRESQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_postgresql_host"); break; case "EXISTING ORACLE DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_oracle_host"); break; default: final_db_host = null; break; } if (final_db_host != null) { Map<String, String> newProperties = new HashMap<>(); newProperties.put("oozie_hostname", final_db_host); updateConfigurationPropertiesForCluster(cluster, OOZIE_ENV, newProperties, true, true); } } } } } } } @Inject  UpgradeCatalog212(Injector injector); protected  UpgradeCatalog212(); }
UpgradeCatalog212 extends AbstractUpgradeCatalog { protected void updateOozieConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config oozieEnv = cluster.getDesiredConfigByType(OOZIE_ENV); if (oozieEnv != null) { Map<String, String> oozieEnvProperties = oozieEnv.getProperties(); String hostname = oozieEnvProperties.get("oozie_hostname"); String db_type = oozieEnvProperties.get("oozie_database"); String final_db_host = null; if (hostname != null && db_type != null && hostname.equals("")) { switch (db_type.toUpperCase()) { case "EXISTING MYSQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_mysql_host"); break; case "EXISTING POSTGRESQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_postgresql_host"); break; case "EXISTING ORACLE DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_oracle_host"); break; default: final_db_host = null; break; } if (final_db_host != null) { Map<String, String> newProperties = new HashMap<>(); newProperties.put("oozie_hostname", final_db_host); updateConfigurationPropertiesForCluster(cluster, OOZIE_ENV, newProperties, true, true); } } } } } } } @Inject  UpgradeCatalog212(Injector injector); protected  UpgradeCatalog212(); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog212 extends AbstractUpgradeCatalog { protected void updateOozieConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); if (clusters != null) { Map<String, Cluster> clusterMap = clusters.getClusters(); if (clusterMap != null && !clusterMap.isEmpty()) { for (final Cluster cluster : clusterMap.values()) { Config oozieEnv = cluster.getDesiredConfigByType(OOZIE_ENV); if (oozieEnv != null) { Map<String, String> oozieEnvProperties = oozieEnv.getProperties(); String hostname = oozieEnvProperties.get("oozie_hostname"); String db_type = oozieEnvProperties.get("oozie_database"); String final_db_host = null; if (hostname != null && db_type != null && hostname.equals("")) { switch (db_type.toUpperCase()) { case "EXISTING MYSQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_mysql_host"); break; case "EXISTING POSTGRESQL DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_postgresql_host"); break; case "EXISTING ORACLE DATABASE": final_db_host = oozieEnvProperties.get("oozie_existing_oracle_host"); break; default: final_db_host = null; break; } if (final_db_host != null) { Map<String, String> newProperties = new HashMap<>(); newProperties.put("oozie_hostname", final_db_host); updateConfigurationPropertiesForCluster(cluster, OOZIE_ENV, newProperties, true, true); } } } } } } } @Inject  UpgradeCatalog212(Injector injector); protected  UpgradeCatalog212(); @Override String getTargetVersion(); @Override String getSourceVersion();  }