Example usage for org.apache.commons.configuration Configuration getStringArray

List of usage examples for org.apache.commons.configuration Configuration getStringArray

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getStringArray.

Prototype

String[] getStringArray(String key);

Source Link

Document

Get an array of strings associated with the given configuration key.

Usage

From source file:org.apache.atlas.examples.QuickStartV2.java

static String[] getServerUrl(String[] args) throws AtlasException {
    if (args.length > 0) {
        return args[0].split(",");
    }//from w  w w .j a v  a  2s .c o m

    Configuration configuration = ApplicationProperties.get();
    String[] urls = configuration.getStringArray(ATLAS_REST_ADDRESS);

    if (ArrayUtils.isEmpty(urls)) {
        System.out.println(
                "org.apache.atlas.examples.QuickStartV2 <Atlas REST address <http/https>://<atlas-fqdn>:<atlas-port> like http://localhost:21000>");
        System.exit(-1);
    }

    return urls;
}

From source file:org.apache.atlas.falcon.hook.FalconHookIT.java

@BeforeClass
public void setUp() throws Exception {
    Configuration atlasProperties = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(atlasProperties.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT),
                new String[] { "admin", "admin" });
    } else {/*from   w w  w.  j a  v  a  2 s.co m*/
        atlasClient = new AtlasClient(atlasProperties.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }

    AtlasService service = new AtlasService();
    service.init();
    STORE.registerListener(service);
    CurrentUser.authenticate(System.getProperty("user.name"));
}

From source file:org.apache.atlas.ha.AtlasServerIdSelector.java

/**
 * Return the ID corresponding to this Atlas instance.
 *
 * The match is done by looking for an ID configured in {@link HAConfiguration#ATLAS_SERVER_IDS} key
 * that has a host:port entry for the key {@link HAConfiguration#ATLAS_SERVER_ADDRESS_PREFIX}+ID where
 * the host is a local IP address and port is set in the system property
 * {@link AtlasConstants#SYSTEM_PROPERTY_APP_PORT}.
 *
 * @param configuration/* w  w w .  j a  va  2s. c  om*/
 * @return
 * @throws AtlasException if no ID is found that maps to a local IP Address or port
 */
public static String selectServerId(Configuration configuration) throws AtlasException {
    // ids are already trimmed by this method
    String[] ids = configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS);
    String matchingServerId = null;
    int appPort = Integer.parseInt(System.getProperty(AtlasConstants.SYSTEM_PROPERTY_APP_PORT));
    for (String id : ids) {
        String hostPort = configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + id);
        if (!StringUtils.isEmpty(hostPort)) {
            InetSocketAddress socketAddress;
            try {
                socketAddress = NetUtils.createSocketAddr(hostPort);
            } catch (Exception e) {
                LOG.warn("Exception while trying to get socket address for {}", hostPort, e);
                continue;
            }
            if (!socketAddress.isUnresolved() && NetUtils.isLocalAddress(socketAddress.getAddress())
                    && appPort == socketAddress.getPort()) {
                LOG.info("Found matched server id {} with host port: {}", id, hostPort);
                matchingServerId = id;
                break;
            }
        } else {
            LOG.info("Could not find matching address entry for id: {}", id);
        }
    }
    if (matchingServerId == null) {
        String msg = String.format(
                "Could not find server id for this instance. "
                        + "Unable to find IDs matching any local host and port binding among %s",
                StringUtils.join(ids, ","));
        throw new AtlasException(msg);
    }
    return matchingServerId;
}

From source file:org.apache.atlas.ha.HAConfiguration.java

/**
 * Return whether HA is enabled or not.//from  w  ww  .j a  va 2 s .c o  m
 * @param configuration underlying configuration instance
 * @return
 */
public static boolean isHAEnabled(Configuration configuration) {
    boolean ret = false;

    if (configuration.containsKey(HAConfiguration.ATLAS_SERVER_HA_ENABLED_KEY)) {
        ret = configuration.getBoolean(ATLAS_SERVER_HA_ENABLED_KEY);
    } else {
        String[] ids = configuration.getStringArray(HAConfiguration.ATLAS_SERVER_IDS);

        ret = ids != null && ids.length > 1;
    }

    return ret;
}

From source file:org.apache.atlas.ha.HAConfiguration.java

public static List<String> getServerInstances(Configuration configuration) {
    String[] serverIds = configuration.getStringArray(ATLAS_SERVER_IDS);
    List<String> serverInstances = new ArrayList<>(serverIds.length);
    for (String serverId : serverIds) {
        serverInstances.add(getBoundAddressForId(configuration, serverId));
    }/*w  ww  .  j  a  v  a2s.  co  m*/
    return serverInstances;
}

From source file:org.apache.atlas.hive.bridge.HiveMetaStoreBridge.java

public static void main(String[] args) throws AtlasHookException {
    try {//from  ww  w  .j  av a 2  s  . c om
        Configuration atlasConf = ApplicationProperties.get();
        String[] atlasEndpoint = atlasConf.getStringArray(ATLAS_ENDPOINT);
        if (atlasEndpoint == null || atlasEndpoint.length == 0) {
            atlasEndpoint = new String[] { DEFAULT_DGI_URL };
        }
        AtlasClient atlasClient;

        if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
            String[] basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput();
            atlasClient = new AtlasClient(atlasEndpoint, basicAuthUsernamePassword);
        } else {
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            atlasClient = new AtlasClient(ugi, ugi.getShortUserName(), atlasEndpoint);
        }

        Options options = new Options();
        CommandLineParser parser = new BasicParser();
        CommandLine cmd = parser.parse(options, args);

        boolean failOnError = false;
        if (cmd.hasOption("failOnError")) {
            failOnError = true;
        }

        HiveMetaStoreBridge hiveMetaStoreBridge = new HiveMetaStoreBridge(atlasConf, new HiveConf(),
                atlasClient);
        hiveMetaStoreBridge.importHiveMetadata(failOnError);
    } catch (Exception e) {
        throw new AtlasHookException("HiveMetaStoreBridge.main() failed.", e);
    }
}

From source file:org.apache.atlas.hive.HiveITBase.java

@BeforeClass
public void setUp() throws Exception {
    //Set-up hive session
    conf = new HiveConf();
    conf.setClassLoader(Thread.currentThread().getContextClassLoader());
    driver = new Driver(conf);
    ss = new SessionState(conf);
    ss = SessionState.start(ss);//www  .ja  v a 2 s. c o  m

    SessionState.setCurrentSessionState(ss);

    Configuration configuration = ApplicationProperties.get();

    String[] atlasEndPoint = configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT);
    if (atlasEndPoint == null || atlasEndPoint.length == 0) {
        atlasEndPoint = new String[] { DGI_URL };
    }

    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(atlasEndPoint, new String[] { "admin", "admin" });
    } else {
        atlasClient = new AtlasClient(atlasEndPoint);
    }

    hiveMetaStoreBridge = new HiveMetaStoreBridge(configuration, conf, atlasClient);

    HiveConf conf = new HiveConf();
    conf.set("hive.exec.post.hooks", "");
    SessionState ss = new SessionState(conf);
    ss = SessionState.start(ss);
    SessionState.setCurrentSessionState(ss);
    driverWithoutContext = new Driver(conf);
}

From source file:org.apache.atlas.sqoop.hook.SqoopHookIT.java

@BeforeClass
public void setUp() throws Exception {
    //Set-up sqoop session
    Configuration configuration = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT),
                new String[] { "admin", "admin" });
    } else {//  www .ja  va2  s.c o m
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }
}

From source file:org.apache.atlas.storm.hook.StormAtlasHookIT.java

@BeforeClass
public void setUp() throws Exception {
    // start a local storm cluster
    stormCluster = StormTestUtil.createLocalStormCluster();
    LOG.info("Created a storm local cluster");

    Configuration configuration = ApplicationProperties.get();
    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT),
                new String[] { "admin", "admin" });
    } else {//from   w  w w.j a  va 2  s .com
        atlasClient = new AtlasClient(configuration.getStringArray(HiveMetaStoreBridge.ATLAS_ENDPOINT));
    }
}

From source file:org.apache.atlas.util.AtlasRepositoryConfiguration.java

/**
 * Get the list of operations which are configured to be skipped from auditing
 * Valid format is HttpMethod:URL eg: GET:Version
 * @return list of string//from  w  w w. j a v a  2  s.  c o  m
 * @throws AtlasException
 */
public static List<String> getAuditExcludedOperations(Configuration config) throws AtlasException {
    if (config == null) {
        try {
            config = ApplicationProperties.get();
        } catch (AtlasException e) {
            LOG.error(" Error reading operations for auditing ", e);
            throw e;
        }
    }
    if (skippedOperations == null) {
        skippedOperations = new ArrayList<String>();
        String[] skipAuditForOperations = config.getStringArray(AUDIT_EXCLUDED_OPERATIONS);
        if (skipAuditForOperations != null && skipAuditForOperations.length > 0) {
            for (String skippedOperation : skipAuditForOperations) {
                String[] excludedOperations = skippedOperation.trim().toLowerCase().split(SEPARATOR);
                if (excludedOperations != null && excludedOperations.length == 2) {
                    skippedOperations.add(skippedOperation.toLowerCase());
                } else {
                    LOG.error(
                            "Invalid format for skipped operation {}. Valid format is HttpMethod:URL eg: GET:Version",
                            skippedOperation);
                }
            }
        }
    }
    return skippedOperations;
}