List of usage examples for org.apache.commons.configuration Configuration getBoolean
Boolean getBoolean(String key, Boolean defaultValue);
From source file:org.apache.atlas.Atlas.java
private static void runSetupIfRequired(Configuration configuration) throws SetupException { boolean shouldRunSetup = configuration.getBoolean(ATLAS_SERVER_RUN_SETUP_KEY, false); if (shouldRunSetup) { LOG.warn("Running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY); AtlasSetup atlasSetup = new AtlasSetup(); try {/* w w w. j a v a 2s . c o m*/ atlasSetup.run(); } catch (SetupException se) { LOG.error("Failed running setup. Will not start the server."); throw se; } LOG.warn("Finished running setup."); } else { LOG.info("Not running setup per configuration {}.", ATLAS_SERVER_RUN_SETUP_KEY); } }
From source file:org.apache.atlas.AtlasBaseClient.java
@VisibleForTesting protected Client getClient(Configuration configuration, UserGroupInformation ugi, String doAsUser) { DefaultClientConfig config = new DefaultClientConfig(); // Enable POJO mapping feature config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); int readTimeout = configuration.getInt("atlas.client.readTimeoutMSecs", 60000); int connectTimeout = configuration.getInt("atlas.client.connectTimeoutMSecs", 60000); if (configuration.getBoolean(TLS_ENABLED, false)) { // create an SSL properties configuration if one doesn't exist. SSLFactory expects a file, so forced // to create a // configuration object, persist it, then subsequently pass in an empty configuration to SSLFactory try {/* ww w .j a v a 2s .co m*/ SecureClientUtils.persistSSLClientConfiguration(configuration); } catch (Exception e) { LOG.info("Error processing client configuration.", e); } } final URLConnectionClientHandler handler; if ((!AuthenticationUtil.isKerberosAuthenticationEnabled()) && basicAuthUser != null && basicAuthPassword != null) { if (configuration.getBoolean(TLS_ENABLED, false)) { handler = SecureClientUtils.getUrlConnectionClientHandler(); } else { handler = new URLConnectionClientHandler(); } } else { handler = SecureClientUtils.getClientConnectionHandler(config, configuration, doAsUser, ugi); } Client client = new Client(handler, config); client.setReadTimeout(readTimeout); client.setConnectTimeout(connectTimeout); return client; }
From source file:org.apache.atlas.hook.AtlasTopicCreator.java
/** * Create an Atlas topic./*from w ww .j a va 2s. com*/ * * The topic will get created based on following conditions: * {@link #ATLAS_NOTIFICATION_CREATE_TOPICS_KEY} is set to true. * The topic does not already exist. * Note that despite this, there could be multiple topic creation calls that happen in parallel because hooks * run in a distributed fashion. Exceptions are caught and logged by this method to prevent the startup of * the hooks from failing. * @param atlasProperties {@link Configuration} containing properties to be used for creating topics. * @param topicNames list of topics to create */ public void createAtlasTopic(Configuration atlasProperties, String... topicNames) { if (atlasProperties.getBoolean(ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) { if (!handleSecurity(atlasProperties)) { return; } ZkUtils zkUtils = createZkUtils(atlasProperties); for (String topicName : topicNames) { try { LOG.warn("Attempting to create topic {}", topicName); if (!ifTopicExists(topicName, zkUtils)) { createTopic(atlasProperties, topicName, zkUtils); } else { LOG.warn("Ignoring call to create topic {}, as it already exists.", topicName); } } catch (Throwable t) { LOG.error("Failed while creating topic {}", topicName, t); } } zkUtils.close(); } else { LOG.info("Not creating topics {} as {} is false", StringUtils.join(topicNames, ","), ATLAS_NOTIFICATION_CREATE_TOPICS_KEY); } }
From source file:org.apache.atlas.hook.AtlasTopicCreatorTest.java
@Test public void shouldNotCreateAtlasTopicIfNotConfiguredToDoSo() { Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) .thenReturn(false);/*from www . j av a2s . c om*/ when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false"); final boolean[] topicExistsCalled = new boolean[] { false }; AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() { @Override protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { topicExistsCalled[0] = true; return false; } }; atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK"); assertFalse(topicExistsCalled[0]); }
From source file:org.apache.atlas.hook.AtlasTopicCreatorTest.java
@Test public void shouldNotCreateTopicIfItAlreadyExists() { Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) .thenReturn(true);/*from w w w .j av a 2 s . co m*/ when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false"); final ZkUtils zookeeperUtils = mock(ZkUtils.class); final boolean[] topicExistsCalled = new boolean[] { false }; final boolean[] createTopicCalled = new boolean[] { false }; AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() { @Override protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { topicExistsCalled[0] = true; return true; } @Override protected ZkUtils createZkUtils(Configuration atlasProperties) { return zookeeperUtils; } @Override protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) { createTopicCalled[0] = true; } }; atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK"); assertTrue(topicExistsCalled[0]); assertFalse(createTopicCalled[0]); }
From source file:org.apache.atlas.hook.AtlasTopicCreatorTest.java
@Test public void shouldCreateTopicIfItDoesNotExist() { Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) .thenReturn(true);/*from w ww .j a v a 2s . c o m*/ when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false"); final ZkUtils zookeeperUtils = mock(ZkUtils.class); final boolean[] createdTopic = new boolean[] { false }; AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() { @Override protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { return false; } @Override protected ZkUtils createZkUtils(Configuration atlasProperties) { return zookeeperUtils; } @Override protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) { createdTopic[0] = true; } }; atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK"); assertTrue(createdTopic[0]); }
From source file:org.apache.atlas.hook.AtlasTopicCreatorTest.java
@Test public void shouldNotFailIfExceptionOccursDuringCreatingTopic() { Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) .thenReturn(true);//w w w. ja va 2s .com when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false"); final ZkUtils zookeeperUtils = mock(ZkUtils.class); final boolean[] createTopicCalled = new boolean[] { false }; AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() { @Override protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { return false; } @Override protected ZkUtils createZkUtils(Configuration atlasProperties) { return zookeeperUtils; } @Override protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) { createTopicCalled[0] = true; throw new RuntimeException("Simulating failure during creating topic"); } }; atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK"); assertTrue(createTopicCalled[0]); }
From source file:org.apache.atlas.hook.AtlasTopicCreatorTest.java
@Test public void shouldCreateMultipleTopics() { Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) .thenReturn(true);/*from www .jav a 2 s. c o m*/ when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false"); final ZkUtils zookeeperUtils = mock(ZkUtils.class); final Map<String, Boolean> createdTopics = new HashMap<>(); createdTopics.put("ATLAS_HOOK", false); createdTopics.put("ATLAS_ENTITIES", false); AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() { @Override protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { return false; } @Override protected ZkUtils createZkUtils(Configuration atlasProperties) { return zookeeperUtils; } @Override protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) { createdTopics.put(topicName, true); } }; atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK", "ATLAS_ENTITIES"); assertTrue(createdTopics.get("ATLAS_HOOK")); assertTrue(createdTopics.get("ATLAS_ENTITIES")); }
From source file:org.apache.atlas.hook.AtlasTopicCreatorTest.java
@Test public void shouldCreateTopicEvenIfEarlierOneFails() { Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) .thenReturn(true);//from w ww.j a v a2 s . c o m when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false"); final ZkUtils zookeeperUtils = mock(ZkUtils.class); final Map<String, Boolean> createdTopics = new HashMap<>(); createdTopics.put("ATLAS_ENTITIES", false); AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() { @Override protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { return false; } @Override protected ZkUtils createZkUtils(Configuration atlasProperties) { return zookeeperUtils; } @Override protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) { if (topicName.equals("ATLAS_HOOK")) { throw new RuntimeException("Simulating failure when creating ATLAS_HOOK topic"); } else { createdTopics.put(topicName, true); } } }; atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK", "ATLAS_ENTITIES"); assertTrue(createdTopics.get("ATLAS_ENTITIES")); }
From source file:org.apache.atlas.hook.AtlasTopicCreatorTest.java
@Test public void shouldCloseResources() { Configuration configuration = mock(Configuration.class); when(configuration.getBoolean(AtlasTopicCreator.ATLAS_NOTIFICATION_CREATE_TOPICS_KEY, true)) .thenReturn(true);//from w ww .j a v a2s . c o m when(configuration.getString("atlas.authentication.method.kerberos")).thenReturn("false"); final ZkUtils zookeeperUtils = mock(ZkUtils.class); AtlasTopicCreator atlasTopicCreator = new AtlasTopicCreator() { @Override protected boolean ifTopicExists(String topicName, ZkUtils zkUtils) { return false; } @Override protected ZkUtils createZkUtils(Configuration atlasProperties) { return zookeeperUtils; } @Override protected void createTopic(Configuration atlasProperties, String topicName, ZkUtils zkUtils) { } }; atlasTopicCreator.createAtlasTopic(configuration, "ATLAS_HOOK", "ATLAS_ENTITIES"); verify(zookeeperUtils, times(1)).close(); }