Example usage for org.apache.commons.configuration MapConfiguration getString

List of usage examples for org.apache.commons.configuration MapConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration MapConfiguration getString.

Prototype

public String getString(String key) 

Source Link

Usage

From source file:com.cloudera.nav.plugin.model.PigIdGenerator.java

/**
 * Create a valid PigOperationExecution identity from the pig job
 * configurations// www .  ja v a 2s  .c  o m
 *
 * @param jobConf
 * @return
 */
public static String generateExecutionId(MapConfiguration jobConf) {
    Preconditions.checkArgument(jobConf.containsKey(PIG_SCRIPT_ID_PROP),
            "Could not find " + PIG_SCRIPT_ID_PROP + " in job configurations");
    return MD5IdGenerator.generateIdentity(jobConf.getString(PIG_SCRIPT_ID_PROP));
}

From source file:com.cloudera.nav.plugin.model.PigIdGenerator.java

/**
 * Generate the correct operation id based on the job name and the
 * job configurations//from   ww w .  jav  a  2 s . c o m
 *
 * @param jobName Yarn application name or MR job name
 * @param jobConf
 * @return
 */
public static String generateNewOperationId(String jobName, MapConfiguration jobConf) {
    Preconditions.checkArgument(jobConf.containsKey(PIG_LOGICAL_PLAN_HASH_PROP),
            "Could not find " + PIG_LOGICAL_PLAN_HASH_PROP + " in job configurations");
    String logicalPlanHash = jobConf.getString(PIG_LOGICAL_PLAN_HASH_PROP);
    return MD5IdGenerator.generateIdentity(jobName, logicalPlanHash);
}

From source file:com.cloudera.csd.tools.MetricDescriptorGeneratorTool.java

@Override
public void run(CommandLine cmdLine, OutputStream out, OutputStream err) throws Exception {
    Preconditions.checkNotNull(cmdLine);
    Preconditions.checkNotNull(out);/*from ww w  .  j ava 2s  .c  om*/
    Preconditions.checkNotNull(err);

    FileInputStream mdlInputStream = null;
    MapConfiguration config = generateAndValidateConfig(cmdLine);
    try {
        mdlInputStream = new FileInputStream(config.getString(OPT_INPUT_MDL.getLongOpt()));
        JsonMdlParser mdlParser = new JsonMdlParser();
        ServiceMonitoringDefinitionsDescriptor mdl = mdlParser.parse(IOUtils.toByteArray(mdlInputStream));
        ServiceMonitoringDefinitionsDescriptorImpl.Builder mdlBuilder = new ServiceMonitoringDefinitionsDescriptorImpl.Builder(
                mdl);

        MetricFixtureAdapter adapter = newMetricFixtureAdapter(config, out, err);
        adapter.init(config.getString(OPT_INPUT_FIXTURE.getLongOpt()),
                config.getString(OPT_INPUT_CONVENTIONS.getLongOpt()));

        mdlBuilder.addMetricDefinitions(adapter.getServiceMetrics());

        if (null != mdl.getRoles()) {
            List<RoleMonitoringDefinitionsDescriptor> roles = Lists.newArrayList();
            for (RoleMonitoringDefinitionsDescriptor role : mdl.getRoles()) {
                RoleMonitoringDefinitionsDescriptorImpl.Builder roleBuilder = new RoleMonitoringDefinitionsDescriptorImpl.Builder(
                        role);
                roleBuilder.addMetricDefinitions(adapter.getRoleMetrics(role.getName()));
                roles.add(roleBuilder.build());
            }
            mdlBuilder.setRoles(roles);
        }

        if (null != mdl.getMetricEntityTypeDefinitions()) {
            List<MetricEntityTypeDescriptor> entities = Lists.newArrayList();
            for (MetricEntityTypeDescriptor entity : mdl.getMetricEntityTypeDefinitions()) {
                MetricEntityTypeDescriptorImpl.Builder entityBuilder = new MetricEntityTypeDescriptorImpl.Builder(
                        entity);
                entityBuilder.addMetricDefinitions(adapter.getEntityMetrics(entity.getName()));
                entities.add(entityBuilder.build());
            }
            mdlBuilder.setMetricEntityTypeDescriptor(entities);
        }
        FileUtils.write(new File(config.getString(OPT_GENERATE_OUPTUT.getLongOpt(), DEFAULT_OUTPUT_FILE)),
                mdlParser.valueAsString(mdlBuilder.build(), true));
    } catch (Exception ex) {
        LOG.error("Could not run MetricGenerator tool.", ex);
        IOUtils.write(ex.getMessage() + "\n", err);
        throw ex;
    } finally {
        IOUtils.closeQuietly(mdlInputStream);
    }
}

From source file:com.cloudera.csd.tools.MetricDescriptorGeneratorTool.java

private MetricFixtureAdapter newMetricFixtureAdapter(MapConfiguration config, OutputStream out,
        OutputStream err) throws IllegalAccessException, InstantiationException {
    Preconditions.checkNotNull(config);/*  ww w. j a  v  a 2s. c  o  m*/
    Preconditions.checkNotNull(out);
    Preconditions.checkNotNull(err);
    // All implementations of the MetricFixtureAdapter must have a no-argument
    // c'tor.
    LOG.info("Instantiating new metric fixture of class " + config.getString(OPT_ADAPTER_CLASS.getLongOpt()));
    Class<?> adapterClass = (Class<?>) config.getProperty(ADAPTER_CLASS_CONFIG);
    Preconditions.checkNotNull(adapterClass);
    return (MetricFixtureAdapter) adapterClass.newInstance();
}

From source file:com.cloudera.csd.tools.MetricDescriptorGeneratorTool.java

private MapConfiguration generateAndValidateConfig(CommandLine cmdLine) throws ParseException {
    Preconditions.checkNotNull(cmdLine);
    MapConfiguration ret = new MapConfiguration(Maps.<String, Object>newHashMap());

    for (Option option : cmdLine.getOptions()) {
        ret.addProperty(option.getLongOpt(), option.getValue());
    }/* ww  w . j a  v a2  s  .  c o  m*/

    if (null == ret.getProperty(OPT_INPUT_MDL.getLongOpt())) {
        throw new ParseException("MetricGeneratorTool missing mdl file " + "location");
    } else {
        String fileName = ret.getString(OPT_INPUT_MDL.getLongOpt());
        File file = new File(fileName);
        if (!file.exists()) {
            throw new ParseException("MDL file '" + fileName + "' does not " + "exist");
        } else if (!file.isFile()) {
            throw new ParseException("MDL file '" + fileName + "' is not a " + "file");
        }
    }

    if (null == ret.getProperty(OPT_INPUT_FIXTURE.getLongOpt())) {
        throw new ParseException("MetricGeneratorTool missing fixture file " + "location");
    } else {
        String fileName = ret.getString(OPT_INPUT_FIXTURE.getLongOpt());
        File file = new File(fileName);
        if (!file.exists()) {
            throw new ParseException("Fixture file '" + fileName + "' does not " + "exist");
        } else if (!file.isFile()) {
            throw new ParseException("Fixture file '" + fileName + "' is not a " + "file");
        }
    }

    if (null != ret.getProperty(OPT_INPUT_CONVENTIONS.getLongOpt())) {
        String fileName = ret.getString(OPT_INPUT_CONVENTIONS.getLongOpt());
        File file = new File(fileName);
        if (!file.exists()) {
            throw new ParseException("Conventions file '" + fileName + "' does " + "not exist");
        } else if (!file.isFile()) {
            throw new ParseException("Conventions file '" + fileName + "' is " + "not a file");
        }
    }

    if (null == ret.getProperty(OPT_ADAPTER_CLASS.getLongOpt())) {
        throw new ParseException("MetricGeneratorTool missing adapter class");
    } else {
        String className = ret.getString(OPT_ADAPTER_CLASS.getLongOpt());
        try {
            Class<?> adapterClass = this.getClass().getClassLoader().loadClass(className);
            if (!MetricFixtureAdapter.class.isAssignableFrom(adapterClass)) {
                throw new ParseException("Adapter class " + className + "is of the " + "wrong type");
            }
            ret.addProperty(ADAPTER_CLASS_CONFIG, adapterClass);
        } catch (ClassNotFoundException e) {
            throw new ParseException("Unknown metric adapter " + className);
        }
    }
    return ret;
}