Java Code Examples for org.apache.atlas.ApplicationProperties#forceReload()

The following examples show how to use org.apache.atlas.ApplicationProperties#forceReload() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseSecurityTest.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static String writeConfiguration(final PropertiesConfiguration configuration) throws Exception {
    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
        url = BaseSecurityTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
        url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    PropertiesConfiguration configuredProperties = new PropertiesConfiguration();
    configuredProperties.load(url);

    configuredProperties.copy(configuration);

    String persistDir = TestUtils.getTempDirectory();
    configuredProperties.setProperty("atlas.authentication.method.file", "true");
    configuredProperties.setProperty("atlas.authentication.method.file.filename", persistDir
            + "/users-credentials");
    configuredProperties.setProperty("atlas.auth.policy.file",persistDir
            + "/policy-store.txt" );
    TestUtils.writeConfiguration(configuredProperties, persistDir + File.separator +
            ApplicationProperties.APPLICATION_PROPERTIES);
    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);
    ApplicationProperties.forceReload();
    return persistDir;
}
 
Example 2
Source File: BaseSecurityTest.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
public static String writeConfiguration(final PropertiesConfiguration configuration) throws Exception {
    String confLocation = System.getProperty("atlas.conf");
    URL url;
    if (confLocation == null) {
        url = BaseSecurityTest.class.getResource("/" + ApplicationProperties.APPLICATION_PROPERTIES);
    } else {
        url = new File(confLocation, ApplicationProperties.APPLICATION_PROPERTIES).toURI().toURL();
    }
    PropertiesConfiguration configuredProperties = new PropertiesConfiguration();
    configuredProperties.load(url);

    configuredProperties.copy(configuration);

    String persistDir = TestUtils.getTempDirectory();
    configuredProperties.setProperty("atlas.authentication.method.file", "true");
    configuredProperties.setProperty("atlas.authentication.method.file.filename", persistDir
            + "/users-credentials");
    configuredProperties.setProperty("atlas.auth.policy.file",persistDir
            + "/policy-store.txt" );
    TestUtils.writeConfiguration(configuredProperties, persistDir + File.separator +
            ApplicationProperties.APPLICATION_PROPERTIES);
    setupUserCredential(persistDir);
    setUpPolicyStore(persistDir);
    ApplicationProperties.forceReload();
    return persistDir;
}
 
Example 3
Source File: SecureEmbeddedServerTestBase.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoConfiguredCredentialProvider() throws Exception {
    String originalConf = null;
    try {
        originalConf = System.getProperty("atlas.conf");
        System.clearProperty("atlas.conf");
        ApplicationProperties.forceReload();
        secureEmbeddedServer = new SecureEmbeddedServer(securePort, TestUtils.getWarPath());
        secureEmbeddedServer.server.start();

        Assert.fail("Should have thrown an exception");
    } catch (IOException e) {
        Assert.assertEquals(e.getMessage(),
                "No credential provider path configured for storage of certificate store passwords");
    } finally {
        if (secureEmbeddedServer != null) {
            secureEmbeddedServer.server.stop();
        }

        if (originalConf == null) {
            System.clearProperty("atlas.conf");
        } else {
            System.setProperty("atlas.conf", originalConf);
        }
    }
}
 
Example 4
Source File: SecureEmbeddedServerTestBase.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoConfiguredCredentialProvider() throws Exception {
    String originalConf = null;
    try {
        originalConf = System.getProperty("atlas.conf");
        System.clearProperty("atlas.conf");
        ApplicationProperties.forceReload();
        secureEmbeddedServer = new SecureEmbeddedServer(
            EmbeddedServer.ATLAS_DEFAULT_BIND_ADDRESS, securePort, TestUtils.getWarPath());
        secureEmbeddedServer.server.start();

        Assert.fail("Should have thrown an exception");
    } catch (IOException e) {
        Assert.assertEquals(e.getMessage(),
                "No credential provider path configured for storage of certificate store passwords");
    } finally {
        if (secureEmbeddedServer != null) {
            secureEmbeddedServer.server.stop();
        }

        if (originalConf == null) {
            System.clearProperty("atlas.conf");
        } else {
            System.setProperty("atlas.conf", originalConf);
        }
    }
}
 
Example 5
Source File: SecureEmbeddedServerTest.java    From atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testServerConfiguredUsingCredentialProvider() throws Exception {
    // setup the configuration
    final PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
    configuration.setProperty("atlas.services.enabled", false);
    configuration.setProperty("atlas.notification.embedded", "false");
    // setup the credential provider
    setupCredentials();

    String persistDir = BaseSecurityTest.writeConfiguration(configuration);
    String originalConf = System.getProperty("atlas.conf");
    System.setProperty("atlas.conf", persistDir);

    ApplicationProperties.forceReload();
    SecureEmbeddedServer secureEmbeddedServer = null;
    try {
        secureEmbeddedServer = new SecureEmbeddedServer(EmbeddedServer.ATLAS_DEFAULT_BIND_ADDRESS,
            21443, TestUtils.getWarPath()) {
            @Override
            protected PropertiesConfiguration getConfiguration() {
                return configuration;
            }

            @Override
            protected WebAppContext getWebAppContext(String path) {
                WebAppContext application = new WebAppContext(path, "/");
                application.setDescriptor(
                        System.getProperty("projectBaseDir") + "/webapp/src/test/webapp/WEB-INF/web.xml");
                application.setClassLoader(Thread.currentThread().getContextClassLoader());
                return application;
            }

        };
        secureEmbeddedServer.server.start();

        URL url = new URL("https://localhost:21443/api/atlas/admin/status");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();

        // test to see whether server is up and root page can be served
        Assert.assertEquals(connection.getResponseCode(), 200);
    } catch(Throwable e) {
        Assert.fail("War deploy failed", e);
    } finally {
        secureEmbeddedServer.server.stop();

        if (originalConf == null) {
            System.clearProperty("atlas.conf");
        } else {
            System.setProperty("atlas.conf", originalConf);
        }
    }
}
 
Example 6
Source File: SecureEmbeddedServerTest.java    From incubator-atlas with Apache License 2.0 4 votes vote down vote up
@Test
public void testServerConfiguredUsingCredentialProvider() throws Exception {
    // setup the configuration
    final PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.setProperty(CERT_STORES_CREDENTIAL_PROVIDER_PATH, providerUrl);
    configuration.setProperty("atlas.services.enabled", false);
    configuration.setProperty("atlas.notification.embedded", "false");
    // setup the credential provider
    setupCredentials();

    String persistDir = BaseSecurityTest.writeConfiguration(configuration);
    String originalConf = System.getProperty("atlas.conf");
    System.setProperty("atlas.conf", persistDir);

    ApplicationProperties.forceReload();
    SecureEmbeddedServer secureEmbeddedServer = null;
    try {
        secureEmbeddedServer = new SecureEmbeddedServer(21443, TestUtils.getWarPath()) {
            @Override
            protected PropertiesConfiguration getConfiguration() {
                return configuration;
            }

            @Override
            protected WebAppContext getWebAppContext(String path) {
                WebAppContext application = new WebAppContext(path, "/");
                application.setDescriptor(
                        System.getProperty("projectBaseDir") + "/webapp/src/test/webapp/WEB-INF/web.xml");
                application.setClassLoader(Thread.currentThread().getContextClassLoader());
                return application;
            }

        };
        secureEmbeddedServer.server.start();

        URL url = new URL("https://localhost:21443/api/atlas/admin/status");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.connect();

        // test to see whether server is up and root page can be served
        Assert.assertEquals(connection.getResponseCode(), 200);
    } catch(Throwable e) {
        Assert.fail("War deploy failed", e);
    } finally {
        secureEmbeddedServer.server.stop();

        if (originalConf == null) {
            System.clearProperty("atlas.conf");
        } else {
            System.setProperty("atlas.conf", originalConf);
        }
    }
}
 
Example 7
Source File: ReportLineageToAtlas.java    From nifi with Apache License 2.0 4 votes vote down vote up
private void initAtlasProperties(ConfigurationContext context) throws Exception {
    final String atlasAuthNMethod = context.getProperty(ATLAS_AUTHN_METHOD).getValue();

    final String confDirStr = context.getProperty(ATLAS_CONF_DIR).evaluateAttributeExpressions().getValue();
    final File confDir = confDirStr != null && !confDirStr.isEmpty() ? new File(confDirStr) : null;

    atlasProperties = new Properties();
    final File atlasPropertiesFile = new File(confDir, ATLAS_PROPERTIES_FILENAME);

    final Boolean createAtlasConf = context.getProperty(ATLAS_CONF_CREATE).asBoolean();
    if (!createAtlasConf) {
        // Load existing properties file.
        if (atlasPropertiesFile.isFile()) {
            getLogger().info("Loading {}", new Object[]{atlasPropertiesFile});
            try (InputStream in = new FileInputStream(atlasPropertiesFile)) {
                atlasProperties.load(in);
            }
        } else {
            final String fileInClasspath = "/" + ATLAS_PROPERTIES_FILENAME;
            try (InputStream in = ReportLineageToAtlas.class.getResourceAsStream(fileInClasspath)) {
                getLogger().info("Loading {} from classpath", new Object[]{fileInClasspath});
                if (in == null) {
                    throw new ProcessException(String.format("Could not find %s in classpath." +
                            " Please add it to classpath," +
                            " or specify %s a directory containing Atlas properties file," +
                            " or enable %s to generate it.",
                            fileInClasspath, ATLAS_CONF_DIR.getDisplayName(), ATLAS_CONF_CREATE.getDisplayName()));
                }
                atlasProperties.load(in);
            }
        }
    }

    List<String> urls = parseAtlasUrls(context.getProperty(ATLAS_URLS));

    setValue(
        value -> defaultMetadataNamespace = value,
        () -> {
            throw new ProcessException("Default metadata namespace (or cluster name) is not defined.");
        },
        context.getProperty(ATLAS_DEFAULT_CLUSTER_NAME),
        atlasProperties.getProperty(ATLAS_PROPERTY_METADATA_NAMESPACE),
        atlasProperties.getProperty(ATLAS_PROPERTY_CLUSTER_NAME)
    );

    String atlasConnectTimeoutMs = context.getProperty(ATLAS_CONNECT_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue() + "";
    String atlasReadTimeoutMs = context.getProperty(ATLAS_READ_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue() + "";

    atlasAuthN = getAtlasAuthN(atlasAuthNMethod);
    atlasAuthN.configure(context);

    // Create Atlas configuration file if necessary.
    if (createAtlasConf) {
        // enforce synchronous notification sending (needed for the checkpointing in ProvenanceEventConsumer)
        atlasProperties.setProperty(AtlasHook.ATLAS_NOTIFICATION_ASYNCHRONOUS, "false");

        atlasProperties.put(ATLAS_PROPERTY_REST_ADDRESS, urls.stream().collect(Collectors.joining(ATLAS_URL_DELIMITER)));
        atlasProperties.put(ATLAS_PROPERTY_CLIENT_CONNECT_TIMEOUT_MS, atlasConnectTimeoutMs);
        atlasProperties.put(ATLAS_PROPERTY_CLIENT_READ_TIMEOUT_MS, atlasReadTimeoutMs);
        atlasProperties.put(ATLAS_PROPERTY_METADATA_NAMESPACE, defaultMetadataNamespace);
        atlasProperties.put(ATLAS_PROPERTY_CLUSTER_NAME, defaultMetadataNamespace);

        setAtlasSSLConfig(atlasProperties, context, urls, confDir);

        setKafkaConfig(atlasProperties, context);

        atlasAuthN.populateProperties(atlasProperties);

        try (FileOutputStream fos = new FileOutputStream(atlasPropertiesFile)) {
            String ts = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX")
                    .withZone(ZoneOffset.UTC)
                    .format(Instant.now());
            atlasProperties.store(fos, "Generated by Apache NiFi ReportLineageToAtlas ReportingTask at " + ts);
        }
    } else {
        // check if synchronous notification sending has been set (needed for the checkpointing in ProvenanceEventConsumer)
        String isAsync = atlasProperties.getProperty(AtlasHook.ATLAS_NOTIFICATION_ASYNCHRONOUS);
        if (isAsync == null || !isAsync.equalsIgnoreCase("false")) {
            throw new ProcessException("Atlas property '" + AtlasHook.ATLAS_NOTIFICATION_ASYNCHRONOUS + "' must be set to 'false' in " + ATLAS_PROPERTIES_FILENAME + "." +
                    " Sending notifications asynchronously is not supported by the reporting task.");
        }
    }

    getLogger().debug("Force reloading Atlas application properties.");
    ApplicationProperties.forceReload();

    if (confDir != null) {
        // If atlasConfDir is not set, atlas-application.properties will be searched under classpath.
        Properties props = System.getProperties();
        final String atlasConfProp = ApplicationProperties.ATLAS_CONFIGURATION_DIRECTORY_PROPERTY;
        props.setProperty(atlasConfProp, confDir.getAbsolutePath());
        getLogger().debug("{} has been set to: {}", new Object[]{atlasConfProp, props.getProperty(atlasConfProp)});
    }
}