@Test public void testUpdateFalconConfigs() throws Exception{ 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 mockFalconEnv = easyMockSupport.createNiceMock(Config.class); final Map<String, String> propertiesExpectedFalconEnv = new HashMap<String, String>(); propertiesExpectedFalconEnv.put("falcon_store_uri", "file: propertiesExpectedFalconEnv.put("content", "# content"); propertiesExpectedFalconEnv.put("property", "value"); final String applicationServicesOldPropertyValue = "org.apache.falcon.security.AuthenticationInitializationService,\\\n" + " org.apache.falcon.workflow.WorkflowJobEndNotificationService, \\\n" + " org.apache.falcon.service.ProcessSubscriberService,\\\n" + " org.apache.falcon.entity.store.ConfigurationStore,\\\n" + " org.apache.falcon.rerun.service.RetryService,\\\n" + " org.apache.falcon.rerun.service.LateRunService,\\\n" + " org.apache.falcon.service.LogCleanupService,\\\n" + " org.apache.falcon.metadata.MetadataMappingService"; final String applicationServicesExpectedPropertyValue = "org.apache.falcon.security.AuthenticationInitializationService,\\\n" + " org.apache.falcon.workflow.WorkflowJobEndNotificationService, \\\n" + " org.apache.falcon.service.ProcessSubscriberService,\\\n" + " org.apache.falcon.entity.store.ConfigurationStore,\\\n" + " org.apache.falcon.rerun.service.RetryService,\\\n" + " org.apache.falcon.rerun.service.LateRunService,\\\n" + " org.apache.falcon.service.LogCleanupService,\\\n" + " org.apache.falcon.metadata.MetadataMappingService{{atlas_application_class_addition}}"; final Config falconStartupConfig = easyMockSupport.createNiceMock(Config.class); final Map<String, String> falconStartupConfigProperties= new HashMap<String, String>(); falconStartupConfigProperties.put("*.application.services", applicationServicesOldPropertyValue); falconStartupConfigProperties.put("property", "value"); final Injector mockInjector = Guice.createInjector(new Module() { @Override public void configure(Binder binder) { binder.bind(AmbariManagementController.class).toInstance(mockAmbariManagementController); binder.bind(ConfigHelper.class).toInstance(mockConfigHelper); binder.bind(Clusters.class).toInstance(mockClusters); binder.bind(EntityManager.class).toInstance(entityManager); binder.bind(DBAccessor.class).toInstance(createNiceMock(DBAccessor.class)); binder.bind(OsFamily.class).toInstance(createNiceMock(OsFamily.class)); binder.bind(PasswordEncoder.class).toInstance(createNiceMock(PasswordEncoder.class)); binder.bind(HookContextFactory.class).toInstance(createMock(HookContextFactory.class)); binder.bind(HookService.class).toInstance(createMock(HookService.class)); } }); expect(mockAmbariManagementController.getClusters()).andReturn(mockClusters).once(); expect(mockClusters.getClusters()).andReturn(new HashMap<String, Cluster>() {{ put("normal", mockClusterExpected); }}).once(); expect(mockClusterExpected.getDesiredConfigByType("falcon-env")).andReturn(mockFalconEnv).atLeastOnce(); expect(mockFalconEnv.getProperties()).andReturn(propertiesExpectedFalconEnv).anyTimes(); expect(mockClusterExpected.getDesiredConfigByType("falcon-startup.properties")).andReturn(falconStartupConfig).atLeastOnce(); expect(falconStartupConfig.getProperties()).andReturn(falconStartupConfigProperties).anyTimes(); Capture<Map<String, String>> falconCapture = newCapture(); expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-env"), capture(falconCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once(); Capture<Map<String, String>> falconCapture2 = newCapture(); expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-env"), capture(falconCapture2), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once(); Capture<Map<String, String>> falconStartupCapture = newCapture(); expect(mockAmbariManagementController.createConfig(eq(mockClusterExpected), eq("falcon-startup.properties"), capture(falconStartupCapture), anyString(), EasyMock.<Map<String, Map<String, String>>>anyObject())).andReturn(null).once(); easyMockSupport.replayAll(); mockInjector.getInstance(UpgradeCatalog240.class).updateFalconConfigs(); easyMockSupport.verifyAll(); final String expectredEnvContent = "# content\n" + "\n" + "{% if falcon_atlas_support %}\n" + "# Add the Atlas Falcon hook to the Falcon classpath\n" + "export FALCON_EXTRA_CLASS_PATH={{atlas_hook_cp}}${FALCON_EXTRA_CLASS_PATH}\n" + "{% endif %}"; assertEquals("value", falconCapture.getValue().get("property")); assertEquals("# content", falconCapture.getValue().get("content")); assertNull(falconCapture.getValue().get("falcon_store_uri")); assertEquals(expectredEnvContent, falconCapture2.getValue().get("content")); assertEquals("value", falconStartupCapture.getValue().get("property")); assertEquals(applicationServicesExpectedPropertyValue, falconStartupCapture.getValue().get("*.application.services")); }
protected void updateFalconConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { Config falconEnvConfig = cluster.getDesiredConfigByType("falcon-env"); if (falconEnvConfig != null) { Map<String, String> falconEnvEnvProperties = falconEnvConfig.getProperties(); if (falconEnvEnvProperties.containsKey("falcon_store_uri")) { LOG.info("Removing property falcon_store_uri from falcon-env"); removeConfigurationPropertiesFromCluster(cluster, "falcon-env", Collections.singleton("falcon_store_uri")); } final String envContentPropertyName = "content"; String contentValue = falconEnvConfig.getProperties().get(envContentPropertyName); if (contentValue != null) { final String atlasHookCPAddition = "{{atlas_hook_cp}}"; if (!contentValue.contains(atlasHookCPAddition)) { LOG.info("Appending '{}' to FALCON_EXTRA_CLASS_PATH from falcon-env since it doesn't contain it", atlasHookCPAddition); String newValue = contentValue + "\n\n{% if falcon_atlas_support %}\n" + "# Add the Atlas Falcon hook to the Falcon classpath\n" + "export FALCON_EXTRA_CLASS_PATH={{atlas_hook_cp}}${FALCON_EXTRA_CLASS_PATH}\n" + "{% endif %}"; updateConfigurationPropertiesForCluster(cluster, "falcon-env", Collections.singletonMap(envContentPropertyName, newValue), null, true, false); } } } Config falconStartupConfig = cluster.getDesiredConfigByType("falcon-startup.properties"); if (falconStartupConfig != null) { final String applicationServicesPropertyName = "*.application.services"; String value = falconStartupConfig.getProperties().get(applicationServicesPropertyName); if (value != null) { final String atlasApplicationClassAddition = "{{atlas_application_class_addition}}"; if (!(value.contains(atlasApplicationClassAddition) || value.contains("org.apache.falcon.atlas.service.AtlasService") || value.contains("org.apache.atlas.falcon.service.AtlasService"))) { LOG.info("Appending '{}' to *.application.services from falcon-startup.properties since it doesn't contain it", atlasApplicationClassAddition); String newValue = value.trim().concat(atlasApplicationClassAddition); updateConfigurationPropertiesForCluster(cluster, "falcon-startup.properties", Collections.singletonMap(applicationServicesPropertyName, newValue), null, true, false); } } } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateFalconConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { Config falconEnvConfig = cluster.getDesiredConfigByType("falcon-env"); if (falconEnvConfig != null) { Map<String, String> falconEnvEnvProperties = falconEnvConfig.getProperties(); if (falconEnvEnvProperties.containsKey("falcon_store_uri")) { LOG.info("Removing property falcon_store_uri from falcon-env"); removeConfigurationPropertiesFromCluster(cluster, "falcon-env", Collections.singleton("falcon_store_uri")); } final String envContentPropertyName = "content"; String contentValue = falconEnvConfig.getProperties().get(envContentPropertyName); if (contentValue != null) { final String atlasHookCPAddition = "{{atlas_hook_cp}}"; if (!contentValue.contains(atlasHookCPAddition)) { LOG.info("Appending '{}' to FALCON_EXTRA_CLASS_PATH from falcon-env since it doesn't contain it", atlasHookCPAddition); String newValue = contentValue + "\n\n{% if falcon_atlas_support %}\n" + "# Add the Atlas Falcon hook to the Falcon classpath\n" + "export FALCON_EXTRA_CLASS_PATH={{atlas_hook_cp}}${FALCON_EXTRA_CLASS_PATH}\n" + "{% endif %}"; updateConfigurationPropertiesForCluster(cluster, "falcon-env", Collections.singletonMap(envContentPropertyName, newValue), null, true, false); } } } Config falconStartupConfig = cluster.getDesiredConfigByType("falcon-startup.properties"); if (falconStartupConfig != null) { final String applicationServicesPropertyName = "*.application.services"; String value = falconStartupConfig.getProperties().get(applicationServicesPropertyName); if (value != null) { final String atlasApplicationClassAddition = "{{atlas_application_class_addition}}"; if (!(value.contains(atlasApplicationClassAddition) || value.contains("org.apache.falcon.atlas.service.AtlasService") || value.contains("org.apache.atlas.falcon.service.AtlasService"))) { LOG.info("Appending '{}' to *.application.services from falcon-startup.properties since it doesn't contain it", atlasApplicationClassAddition); String newValue = value.trim().concat(atlasApplicationClassAddition); updateConfigurationPropertiesForCluster(cluster, "falcon-startup.properties", Collections.singletonMap(applicationServicesPropertyName, newValue), null, true, false); } } } } } }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateFalconConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { Config falconEnvConfig = cluster.getDesiredConfigByType("falcon-env"); if (falconEnvConfig != null) { Map<String, String> falconEnvEnvProperties = falconEnvConfig.getProperties(); if (falconEnvEnvProperties.containsKey("falcon_store_uri")) { LOG.info("Removing property falcon_store_uri from falcon-env"); removeConfigurationPropertiesFromCluster(cluster, "falcon-env", Collections.singleton("falcon_store_uri")); } final String envContentPropertyName = "content"; String contentValue = falconEnvConfig.getProperties().get(envContentPropertyName); if (contentValue != null) { final String atlasHookCPAddition = "{{atlas_hook_cp}}"; if (!contentValue.contains(atlasHookCPAddition)) { LOG.info("Appending '{}' to FALCON_EXTRA_CLASS_PATH from falcon-env since it doesn't contain it", atlasHookCPAddition); String newValue = contentValue + "\n\n{% if falcon_atlas_support %}\n" + "# Add the Atlas Falcon hook to the Falcon classpath\n" + "export FALCON_EXTRA_CLASS_PATH={{atlas_hook_cp}}${FALCON_EXTRA_CLASS_PATH}\n" + "{% endif %}"; updateConfigurationPropertiesForCluster(cluster, "falcon-env", Collections.singletonMap(envContentPropertyName, newValue), null, true, false); } } } Config falconStartupConfig = cluster.getDesiredConfigByType("falcon-startup.properties"); if (falconStartupConfig != null) { final String applicationServicesPropertyName = "*.application.services"; String value = falconStartupConfig.getProperties().get(applicationServicesPropertyName); if (value != null) { final String atlasApplicationClassAddition = "{{atlas_application_class_addition}}"; if (!(value.contains(atlasApplicationClassAddition) || value.contains("org.apache.falcon.atlas.service.AtlasService") || value.contains("org.apache.atlas.falcon.service.AtlasService"))) { LOG.info("Appending '{}' to *.application.services from falcon-startup.properties since it doesn't contain it", atlasApplicationClassAddition); String newValue = value.trim().concat(atlasApplicationClassAddition); updateConfigurationPropertiesForCluster(cluster, "falcon-startup.properties", Collections.singletonMap(applicationServicesPropertyName, newValue), null, true, false); } } } } } @Inject  UpgradeCatalog240(Injector injector); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateFalconConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { Config falconEnvConfig = cluster.getDesiredConfigByType("falcon-env"); if (falconEnvConfig != null) { Map<String, String> falconEnvEnvProperties = falconEnvConfig.getProperties(); if (falconEnvEnvProperties.containsKey("falcon_store_uri")) { LOG.info("Removing property falcon_store_uri from falcon-env"); removeConfigurationPropertiesFromCluster(cluster, "falcon-env", Collections.singleton("falcon_store_uri")); } final String envContentPropertyName = "content"; String contentValue = falconEnvConfig.getProperties().get(envContentPropertyName); if (contentValue != null) { final String atlasHookCPAddition = "{{atlas_hook_cp}}"; if (!contentValue.contains(atlasHookCPAddition)) { LOG.info("Appending '{}' to FALCON_EXTRA_CLASS_PATH from falcon-env since it doesn't contain it", atlasHookCPAddition); String newValue = contentValue + "\n\n{% if falcon_atlas_support %}\n" + "# Add the Atlas Falcon hook to the Falcon classpath\n" + "export FALCON_EXTRA_CLASS_PATH={{atlas_hook_cp}}${FALCON_EXTRA_CLASS_PATH}\n" + "{% endif %}"; updateConfigurationPropertiesForCluster(cluster, "falcon-env", Collections.singletonMap(envContentPropertyName, newValue), null, true, false); } } } Config falconStartupConfig = cluster.getDesiredConfigByType("falcon-startup.properties"); if (falconStartupConfig != null) { final String applicationServicesPropertyName = "*.application.services"; String value = falconStartupConfig.getProperties().get(applicationServicesPropertyName); if (value != null) { final String atlasApplicationClassAddition = "{{atlas_application_class_addition}}"; if (!(value.contains(atlasApplicationClassAddition) || value.contains("org.apache.falcon.atlas.service.AtlasService") || value.contains("org.apache.atlas.falcon.service.AtlasService"))) { LOG.info("Appending '{}' to *.application.services from falcon-startup.properties since it doesn't contain it", atlasApplicationClassAddition); String newValue = value.trim().concat(atlasApplicationClassAddition); updateConfigurationPropertiesForCluster(cluster, "falcon-startup.properties", Collections.singletonMap(applicationServicesPropertyName, newValue), null, true, false); } } } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); }
UpgradeCatalog240 extends AbstractUpgradeCatalog { protected void updateFalconConfigs() throws AmbariException { AmbariManagementController ambariManagementController = injector.getInstance(AmbariManagementController.class); Clusters clusters = ambariManagementController.getClusters(); Map<String, Cluster> clusterMap = getCheckedClusterMap(clusters); for (final Cluster cluster : clusterMap.values()) { Config falconEnvConfig = cluster.getDesiredConfigByType("falcon-env"); if (falconEnvConfig != null) { Map<String, String> falconEnvEnvProperties = falconEnvConfig.getProperties(); if (falconEnvEnvProperties.containsKey("falcon_store_uri")) { LOG.info("Removing property falcon_store_uri from falcon-env"); removeConfigurationPropertiesFromCluster(cluster, "falcon-env", Collections.singleton("falcon_store_uri")); } final String envContentPropertyName = "content"; String contentValue = falconEnvConfig.getProperties().get(envContentPropertyName); if (contentValue != null) { final String atlasHookCPAddition = "{{atlas_hook_cp}}"; if (!contentValue.contains(atlasHookCPAddition)) { LOG.info("Appending '{}' to FALCON_EXTRA_CLASS_PATH from falcon-env since it doesn't contain it", atlasHookCPAddition); String newValue = contentValue + "\n\n{% if falcon_atlas_support %}\n" + "# Add the Atlas Falcon hook to the Falcon classpath\n" + "export FALCON_EXTRA_CLASS_PATH={{atlas_hook_cp}}${FALCON_EXTRA_CLASS_PATH}\n" + "{% endif %}"; updateConfigurationPropertiesForCluster(cluster, "falcon-env", Collections.singletonMap(envContentPropertyName, newValue), null, true, false); } } } Config falconStartupConfig = cluster.getDesiredConfigByType("falcon-startup.properties"); if (falconStartupConfig != null) { final String applicationServicesPropertyName = "*.application.services"; String value = falconStartupConfig.getProperties().get(applicationServicesPropertyName); if (value != null) { final String atlasApplicationClassAddition = "{{atlas_application_class_addition}}"; if (!(value.contains(atlasApplicationClassAddition) || value.contains("org.apache.falcon.atlas.service.AtlasService") || value.contains("org.apache.atlas.falcon.service.AtlasService"))) { LOG.info("Appending '{}' to *.application.services from falcon-startup.properties since it doesn't contain it", atlasApplicationClassAddition); String newValue = value.trim().concat(atlasApplicationClassAddition); updateConfigurationPropertiesForCluster(cluster, "falcon-startup.properties", Collections.singletonMap(applicationServicesPropertyName, newValue), null, true, false); } } } } } @Inject  UpgradeCatalog240(Injector injector); @Override String getTargetVersion(); @Override String getSourceVersion(); static final String DESIRED_VERSION_COLUMN_NAME; static final String BLUEPRINT_SETTING_TABLE; static final String BLUEPRINT_NAME_COL; static final String SETTING_NAME_COL; static final String SETTING_DATA_COL; static final String ID; static final String BLUEPRINT_TABLE; static final String VIEWINSTANCE_TABLE; static final String SHORT_URL_COLUMN; static final String CLUSTER_HANDLE_COLUMN; static final String REQUESTSCHEDULE_TABLE; static final String AUTHENTICATED_USER_ID_COLUMN; static final String TIMELINE_METRICS_SINK_COLLECTION_PERIOD; static final String ONE_DIR_PER_PARITION_PROPERTY; static final String VIEWURL_TABLE; static final String URL_ID_COLUMN; static final String PRECISION_TABLE_TTL_PROPERTY; static final String CLUSTER_SECOND_TABLE_TTL_PROPERTY; static final String CLUSTER_TYPE_COLUMN; static final String REMOTE_AMBARI_CLUSTER_TABLE; static final String REMOTE_AMBARI_CLUSTER_SERVICE_TABLE; static final String CLUSTER_ID; static final String SERVICE_NAME; static final String CLUSTER_NAME; }