Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

In this page you can find the example usage for java.util Properties get.

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:edu.ku.brc.af.core.UsageTracker.java

/**
 * Transfers and removes any old statistics from the user prefs to the new location.
 * @param newProps the new statistics//  w  ww  .  ja  v  a 2 s.c om
 */
private static void transferOldStats(final Properties newProps) {
    Properties lpProps = AppPreferences.getLocalPrefs().getProperties(); // not a copy
    for (Object keyObj : new Vector<Object>(lpProps.keySet())) {
        String pName = keyObj.toString();
        if (pName.startsWith(USAGE_PREFIX)) {
            newProps.put(pName.substring(6), lpProps.get(keyObj));
            lpProps.remove(keyObj);
        }
    }
    save();
}

From source file:io.amient.yarn1.YarnClient.java

/**
 * This method should be called by the implementing application static main
 * method. It does all the work around creating a yarn application and
 * submitting the request to the yarn resource manager. The class given in
 * the appClass argument will be run inside the yarn-allocated master
 * container./*from   w  ww.  j  av a  2  s.  c o m*/
 */
public static void submitApplicationMaster(Properties appConfig, Class<? extends YarnMaster> masterClass,
        String[] args, Boolean awaitCompletion) throws Exception {
    log.info("Yarn1 App Configuration:");
    for (Object param : appConfig.keySet()) {
        log.info(param.toString() + " = " + appConfig.get(param).toString());
    }
    String yarnConfigPath = appConfig.getProperty("yarn1.site", "/etc/hadoop");
    String masterClassName = masterClass.getName();
    appConfig.setProperty("yarn1.master.class", masterClassName);
    String applicationName = appConfig.getProperty("yarn1.application.name", masterClassName);
    log.info("--------------------------------------------------------------");

    if (Boolean.valueOf(appConfig.getProperty("yarn1.local.mode", "false"))) {
        YarnMaster.run(appConfig, args);
        return;
    }

    int masterPriority = Integer.valueOf(
            appConfig.getProperty("yarn1.master.priority", String.valueOf(YarnMaster.DEFAULT_MASTER_PRIORITY)));
    int masterMemoryMb = Integer.valueOf(appConfig.getProperty("yarn1.master.memory.mb",
            String.valueOf(YarnMaster.DEFAULT_MASTER_MEMORY_MB)));
    int masterNumCores = Integer.valueOf(
            appConfig.getProperty("yarn1.master.num.cores", String.valueOf(YarnMaster.DEFAULT_MASTER_CORES)));
    String queue = appConfig.getProperty("yarn1.queue");

    Configuration yarnConfig = new YarnConfiguration();
    yarnConfig.addResource(new FileInputStream(yarnConfigPath + "/core-site.xml"));
    yarnConfig.addResource(new FileInputStream(yarnConfigPath + "/hdfs-site.xml"));
    yarnConfig.addResource(new FileInputStream(yarnConfigPath + "/yarn-site.xml"));
    for (Map.Entry<Object, Object> entry : appConfig.entrySet()) {
        yarnConfig.set(entry.getKey().toString(), entry.getValue().toString());
    }

    final org.apache.hadoop.yarn.client.api.YarnClient yarnClient = org.apache.hadoop.yarn.client.api.YarnClient
            .createYarnClient();
    yarnClient.init(yarnConfig);
    yarnClient.start();

    for (NodeReport report : yarnClient.getNodeReports(NodeState.RUNNING)) {
        log.debug("Node report:" + report.getNodeId() + " @ " + report.getHttpAddress() + " | "
                + report.getCapability());
    }

    log.info("Submitting application master class " + masterClassName);

    YarnClientApplication app = yarnClient.createApplication();
    GetNewApplicationResponse appResponse = app.getNewApplicationResponse();
    final ApplicationId appId = appResponse.getApplicationId();
    if (appId == null) {
        System.exit(111);
    } else {
        appConfig.setProperty("am.timestamp", String.valueOf(appId.getClusterTimestamp()));
        appConfig.setProperty("am.id", String.valueOf(appId.getId()));
    }

    YarnClient.distributeResources(yarnConfig, appConfig, applicationName);

    String masterJvmArgs = appConfig.getProperty("yarn1.master.jvm.args", "");
    YarnContainerContext masterContainer = new YarnContainerContext(yarnConfig, appConfig, masterJvmArgs,
            masterPriority, masterMemoryMb, masterNumCores, applicationName, YarnMaster.class, args);

    ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
    appContext.setApplicationName(masterClassName);
    appContext.setResource(masterContainer.capability);
    appContext.setPriority(masterContainer.priority);
    appContext.setQueue(queue);
    appContext.setApplicationType(appConfig.getProperty("yarn1.application.type", "YARN"));
    appContext.setAMContainerSpec(masterContainer.createContainerLaunchContext());

    log.info("Master container spec: " + masterContainer.capability);

    yarnClient.submitApplication(appContext);

    ApplicationReport report = yarnClient.getApplicationReport(appId);
    log.info("Tracking URL: " + report.getTrackingUrl());

    if (awaitCompletion) {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                if (!yarnClient.isInState(Service.STATE.STOPPED)) {
                    log.info("Killing yarn application in shutdown hook");
                    try {
                        yarnClient.killApplication(appId);
                    } catch (Throwable e) {
                        log.error("Failed to kill yarn application - please check YARN Resource Manager", e);
                    }
                }
            }
        });

        float lastProgress = -0.0f;
        while (true) {
            try {
                Thread.sleep(10000);
                report = yarnClient.getApplicationReport(appId);
                if (lastProgress != report.getProgress()) {
                    lastProgress = report.getProgress();
                    log.info(report.getApplicationId() + " " + (report.getProgress() * 100.00) + "% "
                            + (System.currentTimeMillis() - report.getStartTime()) + "(ms) "
                            + report.getDiagnostics());
                }
                if (!report.getFinalApplicationStatus().equals(FinalApplicationStatus.UNDEFINED)) {
                    log.info(report.getApplicationId() + " " + report.getFinalApplicationStatus());
                    log.info("Tracking url: " + report.getTrackingUrl());
                    log.info("Finish time: " + ((System.currentTimeMillis() - report.getStartTime()) / 1000)
                            + "(s)");
                    break;
                }
            } catch (Throwable e) {
                log.error("Master Heart Beat Error - terminating", e);
                yarnClient.killApplication(appId);
                Thread.sleep(2000);
            }
        }
        yarnClient.stop();

        if (!report.getFinalApplicationStatus().equals(FinalApplicationStatus.SUCCEEDED)) {
            System.exit(112);
        }
    }
    yarnClient.stop();
}

From source file:com.kixeye.chassis.bootstrap.configuration.ConfigurationBuilder.java

private static void join(Map<String, Object> base, Properties properties, String propertyFile,
        String[] propertyFiles) {
    for (Object key : properties.keySet()) {
        if (base.get(key) != null) {
            BootstrapException.moduleKeysConflictFound(propertyFile, propertyFiles);
        }/*from  ww w .  j  a  v  a 2 s . c  o m*/
        base.put((String) key, properties.get(key));
    }
}

From source file:com.jiangyifen.ec2.globaldata.license.LicenseManagerMain.java

/**
 * ?License????/*from  ww  w  . j  av a 2  s .  c om*/
 * 
 * @return
 */
public static void loadLicenseFile(String licenseFilename) {
    try {
        // ???
        Properties props = new Properties();
        InputStream inputStream = LicenseManagerMain.class.getClassLoader()
                .getResourceAsStream(licenseFilename);
        props.load(inputStream);
        inputStream.close();

        // ??
        String license_count = (String) props.get(LicenseManagerMain.LICENSE_COUNT);
        license_count = license_count == null ? "" : license_count;
        licenseMap.put(LicenseManagerMain.LICENSE_COUNT, license_count);

        // ?
        String license_date = (String) props.get(LicenseManagerMain.LICENSE_DATE);
        license_date = license_date == null ? "" : license_date;
        licenseMap.put(LicenseManagerMain.LICENSE_DATE, license_date);

        // ???
        String license_localmd5 = (String) props.get(LicenseManagerMain.LICENSE_LOCALMD5);
        license_localmd5 = license_localmd5 == null ? "" : license_localmd5;
        licenseMap.put(LicenseManagerMain.LICENSE_LOCALMD5, license_localmd5);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:info.bonjean.quinkana.Main.java

private static void run(String[] args) throws QuinkanaException {
    Properties properties = new Properties();
    InputStream inputstream = Main.class.getResourceAsStream("/config.properties");

    try {/*from   w  ww. j  a  v a2s . co  m*/
        properties.load(inputstream);
        inputstream.close();
    } catch (IOException e) {
        throw new QuinkanaException("cannot load internal properties", e);
    }

    String name = (String) properties.get("name");
    String description = (String) properties.get("description");
    String url = (String) properties.get("url");
    String version = (String) properties.get("version");
    String usage = (String) properties.get("help.usage");
    String defaultHost = (String) properties.get("default.host");
    int defaultPort = Integer.valueOf(properties.getProperty("default.port"));

    ArgumentParser parser = ArgumentParsers.newArgumentParser(name).description(description)
            .epilog("For more information, go to " + url).version("${prog} " + version).usage(usage);
    parser.addArgument("ACTION").type(Action.class).choices(Action.tail, Action.list).dest("action");
    parser.addArgument("-H", "--host").setDefault(defaultHost)
            .help(String.format("logstash host (default: %s)", defaultHost));
    parser.addArgument("-P", "--port").type(Integer.class).setDefault(defaultPort)
            .help(String.format("logstash TCP port (default: %d)", defaultPort));
    parser.addArgument("-f", "--fields").nargs("+").help("fields to display");
    parser.addArgument("-i", "--include").nargs("+").help("include filter (OR), example host=example.com")
            .metavar("FILTER").type(Filter.class);
    parser.addArgument("-x", "--exclude").nargs("+")
            .help("exclude filter (OR, applied after include), example: severity=debug").metavar("FILTER")
            .type(Filter.class);
    parser.addArgument("-s", "--single").action(Arguments.storeTrue()).help("display single result and exit");
    parser.addArgument("--version").action(Arguments.version()).help("output version information and exit");

    Namespace ns = parser.parseArgsOrFail(args);

    Action action = ns.get("action");
    List<String> fields = ns.getList("fields");
    List<Filter> includes = ns.getList("include");
    List<Filter> excludes = ns.getList("exclude");
    boolean single = ns.getBoolean("single");
    String host = ns.getString("host");
    int port = ns.getInt("port");

    final Socket clientSocket;
    final InputStream is;
    try {
        clientSocket = new Socket(host, port);
        is = clientSocket.getInputStream();
    } catch (IOException e) {
        throw new QuinkanaException("cannot connect to the server " + host + ":" + port, e);
    }

    // add a hook to ensure we clean the resources when leaving
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                clientSocket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    // prepare JSON parser
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory jsonFactory = mapper.getFactory();
    JsonParser jp;
    try {
        jp = jsonFactory.createParser(is);
    } catch (IOException e) {
        throw new QuinkanaException("error during JSON parser creation", e);
    }

    JsonToken token;

    // action=list
    if (action.equals(Action.list)) {
        try {
            // do this in a separate loop to not pollute the main loop
            while ((token = jp.nextToken()) != null) {
                if (token != JsonToken.START_OBJECT)
                    continue;

                // parse object
                JsonNode node = jp.readValueAsTree();

                // print fields
                Iterator<String> fieldNames = node.fieldNames();
                while (fieldNames.hasNext())
                    System.out.println(fieldNames.next());

                System.exit(0);
            }
        } catch (IOException e) {
            throw new QuinkanaException("error during JSON parsing", e);
        }
    }

    // action=tail
    try {
        while ((token = jp.nextToken()) != null) {
            if (token != JsonToken.START_OBJECT)
                continue;

            // parse object
            JsonNode node = jp.readValueAsTree();

            // filtering (includes)
            if (includes != null) {
                boolean skip = true;
                for (Filter include : includes) {
                    if (include.match(node)) {
                        skip = false;
                        break;
                    }
                }
                if (skip)
                    continue;
            }

            // filtering (excludes)
            if (excludes != null) {
                boolean skip = false;
                for (Filter exclude : excludes) {
                    if (exclude.match(node)) {
                        skip = true;
                        break;
                    }
                }
                if (skip)
                    continue;
            }

            // if no field specified, print raw output (JSON)
            if (fields == null) {
                System.out.println(node.toString());
                if (single)
                    break;
                continue;
            }

            // formatted output, build and print the string
            StringBuilder sb = new StringBuilder(128);
            for (String field : fields) {
                if (sb.length() > 0)
                    sb.append(" ");

                if (node.get(field) != null && node.get(field).textValue() != null)
                    sb.append(node.get(field).textValue());
            }
            System.out.println(sb.toString());

            if (single)
                break;
        }
    } catch (IOException e) {
        throw new QuinkanaException("error during JSON parsing", e);
    }
}

From source file:info.guardianproject.net.http.HttpManager.java

public static String doGet(String serviceEndpoint, Properties props) throws Exception {

    HttpClient httpClient = new SocksHttpClient();

    StringBuilder uriBuilder = new StringBuilder(serviceEndpoint);

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;//ww w.ja  v a2 s . c om

    uriBuilder.append('?');

    while (enumProps.hasMoreElements()) {
        key = (String) enumProps.nextElement();
        value = (String) props.get(key);
        uriBuilder.append(key);
        uriBuilder.append('=');
        uriBuilder.append(java.net.URLEncoder.encode(value));
        uriBuilder.append('&');

    }

    HttpGet request = new HttpGet(uriBuilder.toString());
    HttpResponse response = httpClient.execute(request);

    int status = response.getStatusLine().getStatusCode();

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        response.getEntity().writeTo(ostream);
        Log.e("HTTP CLIENT", ostream.toString());

        return null;

    } else {
        InputStream content = response.getEntity().getContent();
        // <consume response>

        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;

        while ((line = reader.readLine()) != null)
            sbResponse.append(line);

        content.close(); // this will also close the connection
    }

    return sbResponse.toString();

}

From source file:com.openideals.android.net.HttpManager.java

public static String doGet(String serviceEndpoint, Properties props) throws Exception {

    HttpClient httpClient = new DefaultHttpClient();

    StringBuilder uriBuilder = new StringBuilder(serviceEndpoint);

    StringBuffer sbResponse = new StringBuffer();

    Enumeration<Object> enumProps = props.keys();
    String key, value = null;/*w ww.j  a  v  a 2 s. co m*/

    uriBuilder.append('?');

    while (enumProps.hasMoreElements()) {
        key = (String) enumProps.nextElement();
        value = (String) props.get(key);
        uriBuilder.append(key);
        uriBuilder.append('=');
        uriBuilder.append(java.net.URLEncoder.encode(value));
        uriBuilder.append('&');

    }

    HttpGet request = new HttpGet(uriBuilder.toString());
    HttpResponse response = httpClient.execute(request);

    int status = response.getStatusLine().getStatusCode();

    // we assume that the response body contains the error message
    if (status != HttpStatus.SC_OK) {
        ByteArrayOutputStream ostream = new ByteArrayOutputStream();
        response.getEntity().writeTo(ostream);
        Log.e("HTTP CLIENT", ostream.toString());

        return null;

    } else {
        InputStream content = response.getEntity().getContent();
        // <consume response>

        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
        String line;

        while ((line = reader.readLine()) != null)
            sbResponse.append(line);

        content.close(); // this will also close the connection
    }

    return sbResponse.toString();

}

From source file:com.wandrell.example.swss.client.console.ConsoleClient.java

/**
 * Returns the URIs for an endpoint./* ww  w .j  a va2s. c  om*/
 * <p>
 * This is created by combining the common base path all the endpoints use
 * with the most concrete ending taken from a property in the specified
 * properties file.
 *
 * @param propertiesPath
 *            path to the properties file with the endpoint path
 * @return the fill URI for the endpoint
 * @throws IOException
 *             if any error occurs while loading the properties
 */
private static final String getEndpointUri(final String propertiesPath) throws IOException {
    final Properties properties; // Properties with the endpoint data

    properties = new Properties();
    properties.load(new ClassPathResource(propertiesPath).getInputStream());

    return String.format(ENDPOINT_URL_TEMPLATE, (String) properties.get(PROPERTY_ENDPOINT_URI));
}

From source file:org.ops4j.pax.web.itest.base.TestConfiguration.java

public static Option paxCdiWithWeldBundles() {

    Properties props = new Properties();
    try {/*from   ww  w .j  a  va  2  s  .c o  m*/
        props.load(TestConfiguration.class.getResourceAsStream("/systemPackages.properties"));
    } catch (IOException exc) {
        throw new Ops4jException(exc);
    }

    return composite(
            // do not treat javax.annotation as system package
            when(isEquinox()).useOptions(frameworkProperty("org.osgi.framework.system.packages")
                    .value(props.get("org.osgi.framework.system.packages"))),

            linkBundle("org.ops4j.pax.cdi.weld"),

            // there is a classloader conflict when adding this dep to the POM
            mavenBundle("org.ops4j.pax.cdi", "pax-cdi-undertow-weld", PAX_CDI_VERSION),

            mavenBundle("com.google.guava", "guava", "13.0.1"),
            mavenBundle("org.jboss.weld", "weld-osgi-bundle", "2.2.8.Final"));
}

From source file:com.aliyun.odps.ship.common.OptionsBuilder.java

private static void loadConfig() throws IOException, ODPSConsoleException {

    String cf = DshipContext.INSTANCE.getExecutionContext().getConfigFile();

    if (cf == null) {
        return;/* w  w  w.  ja  v a 2s  . com*/
    }

    File file = new File(cf);
    if (!file.exists()) {
        return;
    }

    FileInputStream cfIns = new FileInputStream(file);
    Properties properties = new Properties();
    properties.load(cfIns);
    for (Object key : properties.keySet()) {
        String k = key.toString();
        String v = (String) properties.get(key);
        setContextValue(k.toLowerCase(), v);
    }
    cfIns.close();
}