List of usage examples for org.apache.hadoop.conf Configuration setLong
public void setLong(String name, long value)
name
property to a long
. From source file:com.ning.metrics.action.binder.modules.FileSystemAccessProvider.java
License:Apache License
@Inject public FileSystemAccessProvider(final ActionCoreConfig actionCoreConfig) throws IOException { final Configuration hadoopConfig = new Configuration(); final String hfsHost = actionCoreConfig.getNamenodeUrl(); if (hfsHost.isEmpty()) { // Local filesystem, for testing hadoopConfig.set("fs.default.name", "file:///"); } else {//from w ww . j av a 2 s .c o m hadoopConfig.set("fs.default.name", hfsHost); } // Bump the default timeout hadoopConfig.setInt("dfs.socket.timeout", actionCoreConfig.getHadoopSocketTimeOut()); hadoopConfig.setBoolean("fs.automatic.close", false); hadoopConfig.setLong("dfs.block.size", actionCoreConfig.getHadoopBlockSize()); hadoopConfig.set("hadoop.job.ugi", actionCoreConfig.getHadoopUgi()); hadoopConfig.setStrings("io.serializations", HadoopThriftWritableSerialization.class.getName(), HadoopThriftEnvelopeSerialization.class.getName(), HadoopSmileOutputStreamSerialization.class.getName(), "org.apache.hadoop.io.serializer.WritableSerialization", actionCoreConfig.getSerializations()); fileSystemAccess = new FileSystemAccess(hadoopConfig); }
From source file:com.ning.metrics.collector.binder.FileSystemProvider.java
License:Apache License
@Inject public FileSystemProvider(CollectorConfig collectorConfig) throws IOException { String hfsHost = collectorConfig.getHfsHost(); Configuration hadoopConfig = new Configuration(); if (hfsHost.isEmpty()) { // Local filesystem, for testing hadoopConfig.set("fs.default.name", "file:///"); } else {//from www . j a va2 s . c om hadoopConfig.set("fs.default.name", hfsHost); } hadoopConfig.setLong("dfs.block.size", collectorConfig.getHadoopBlockSize()); hadoopConfig.set("hadoop.job.ugi", collectorConfig.getHadoopUgi()); hadoopConfig.setStrings("io.serializations", HadoopThriftWritableSerialization.class.getName(), HadoopThriftEnvelopeSerialization.class.getName(), HadoopSmileOutputStreamSerialization.class.getName(), "org.apache.hadoop.io.serializer.WritableSerialization"); fileSystem = FileSystem.get(hadoopConfig); }
From source file:com.ning.metrics.collector.events.hadoop.writer.FileSystemAccessProvider.java
License:Apache License
@Inject public FileSystemAccessProvider(final CollectorConfig collectorConfig) throws IOException { final String hfsHost = collectorConfig.getHfsHost(); final Configuration hadoopConfig = new Configuration(); if (hfsHost.isEmpty()) { // Local filesystem, for testing hadoopConfig.set("fs.default.name", "file:///"); } else {//from w ww .j a v a 2 s . co m hadoopConfig.set("fs.default.name", hfsHost); } hadoopConfig.setLong("dfs.block.size", collectorConfig.getHadoopBlockSize()); hadoopConfig.set("hadoop.job.ugi", collectorConfig.getHadoopUgi()); hadoopConfig.setStrings("io.serializations", HadoopThriftWritableSerialization.class.getName(), HadoopThriftEnvelopeSerialization.class.getName(), HadoopSmileOutputStreamSerialization.class.getName(), "org.apache.hadoop.io.serializer.WritableSerialization"); fileSystemAccess = new FileSystemAccess(hadoopConfig); }
From source file:com.ning.metrics.collector.guice.providers.FileSystemAccessProvider.java
License:Apache License
@Inject public FileSystemAccessProvider(final CollectorConfig collectorConfig) throws IOException { final String hfsHost = collectorConfig.getHfsHost(); final Configuration hadoopConfig = new Configuration(); if (hfsHost.isEmpty()) { // Local filesystem, for testing hadoopConfig.set("fs.default.name", "file:///"); } else {// w w w .ja va 2s .c o m hadoopConfig.set("fs.default.name", hfsHost); } hadoopConfig.setBoolean("fs.automatic.close", false); hadoopConfig.setLong("dfs.block.size", collectorConfig.getHadoopBlockSize()); hadoopConfig.set("hadoop.job.ugi", collectorConfig.getHadoopUgi()); hadoopConfig.setStrings("io.serializations", HadoopThriftWritableSerialization.class.getName(), HadoopThriftEnvelopeSerialization.class.getName(), HadoopSmileOutputStreamSerialization.class.getName(), "org.apache.hadoop.io.serializer.WritableSerialization"); fileSystemAccess = new FileSystemAccess(hadoopConfig); }
From source file:com.phantom.hadoop.examples.BaileyBorweinPlouffe.java
License:Apache License
/** Create and setup a job */ private static Job createJob(String name, Configuration conf) throws IOException { final Job job = new Job(conf, NAME + "_" + name); final Configuration jobconf = job.getConfiguration(); job.setJarByClass(BaileyBorweinPlouffe.class); // setup mapper job.setMapperClass(BbpMapper.class); job.setMapOutputKeyClass(LongWritable.class); job.setMapOutputValueClass(BytesWritable.class); // setup reducer job.setReducerClass(BbpReducer.class); job.setOutputKeyClass(LongWritable.class); job.setOutputValueClass(BytesWritable.class); job.setNumReduceTasks(1);// ww w.j a v a 2s. c o m // setup input job.setInputFormatClass(BbpInputFormat.class); // disable task timeout jobconf.setLong(MRJobConfig.TASK_TIMEOUT, 0); // do not use speculative execution jobconf.setBoolean(MRJobConfig.MAP_SPECULATIVE, false); jobconf.setBoolean(MRJobConfig.REDUCE_SPECULATIVE, false); return job; }
From source file:com.phantom.hadoop.examples.pi.DistSum.java
License:Apache License
/** Create a job */ private Job createJob(String name, Summation sigma) throws IOException { final Job job = new Job(getConf(), parameters.remoteDir + "/" + name); final Configuration jobconf = job.getConfiguration(); job.setJarByClass(DistSum.class); jobconf.setInt(N_PARTS, parameters.nParts); SummationWritable.write(sigma, DistSum.class, jobconf); // disable task timeout jobconf.setLong(MRJobConfig.TASK_TIMEOUT, 0); // do not use speculative execution jobconf.setBoolean(MRJobConfig.MAP_SPECULATIVE, false); jobconf.setBoolean(MRJobConfig.REDUCE_SPECULATIVE, false); return job;// www . j av a2s . c o m }
From source file:com.phantom.hadoop.examples.RandomTextWriter.java
License:Apache License
/** * This is the main routine for launching a distributed random write job. It * runs 10 maps/node and each node writes 1 gig of data to a DFS file. The * reduce doesn't do anything.//from ww w . ja v a 2s. co m * * @throws IOException */ public int run(String[] args) throws Exception { if (args.length == 0) { return printUsage(); } Configuration conf = getConf(); JobClient client = new JobClient(conf); ClusterStatus cluster = client.getClusterStatus(); int numMapsPerHost = conf.getInt(MAPS_PER_HOST, 10); long numBytesToWritePerMap = conf.getLong(BYTES_PER_MAP, 1 * 1024 * 1024 * 1024); if (numBytesToWritePerMap == 0) { System.err.println("Cannot have " + BYTES_PER_MAP + " set to 0"); return -2; } long totalBytesToWrite = conf.getLong(TOTAL_BYTES, numMapsPerHost * numBytesToWritePerMap * cluster.getTaskTrackers()); int numMaps = (int) (totalBytesToWrite / numBytesToWritePerMap); if (numMaps == 0 && totalBytesToWrite > 0) { numMaps = 1; conf.setLong(BYTES_PER_MAP, totalBytesToWrite); } conf.setInt(MRJobConfig.NUM_MAPS, numMaps); Job job = new Job(conf); job.setJarByClass(RandomTextWriter.class); job.setJobName("random-text-writer"); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setInputFormatClass(RandomWriter.RandomInputFormat.class); job.setMapperClass(RandomTextMapper.class); Class<? extends OutputFormat> outputFormatClass = SequenceFileOutputFormat.class; List<String> otherArgs = new ArrayList<String>(); for (int i = 0; i < args.length; ++i) { try { if ("-outFormat".equals(args[i])) { outputFormatClass = Class.forName(args[++i]).asSubclass(OutputFormat.class); } else { otherArgs.add(args[i]); } } catch (ArrayIndexOutOfBoundsException except) { System.out.println("ERROR: Required parameter missing from " + args[i - 1]); return printUsage(); // exits } } job.setOutputFormatClass(outputFormatClass); FileOutputFormat.setOutputPath(job, new Path(otherArgs.get(0))); System.out.println("Running " + numMaps + " maps."); // reducer NONE job.setNumReduceTasks(0); Date startTime = new Date(); System.out.println("Job started: " + startTime); int ret = job.waitForCompletion(true) ? 0 : 1; Date endTime = new Date(); System.out.println("Job ended: " + endTime); System.out.println("The job took " + (endTime.getTime() - startTime.getTime()) / 1000 + " seconds."); return ret; }
From source file:com.phantom.hadoop.examples.RandomWriter.java
License:Apache License
/** * This is the main routine for launching a distributed random write job. It * runs 10 maps/node and each node writes 1 gig of data to a DFS file. The * reduce doesn't do anything.// w ww .ja v a 2 s . c o m * * @throws IOException */ public int run(String[] args) throws Exception { if (args.length == 0) { System.out.println("Usage: writer <out-dir>"); ToolRunner.printGenericCommandUsage(System.out); return 2; } Path outDir = new Path(args[0]); Configuration conf = getConf(); JobClient client = new JobClient(conf); ClusterStatus cluster = client.getClusterStatus(); int numMapsPerHost = conf.getInt(MAPS_PER_HOST, 10); long numBytesToWritePerMap = conf.getLong(BYTES_PER_MAP, 1 * 1024 * 1024 * 1024); if (numBytesToWritePerMap == 0) { System.err.println("Cannot have" + BYTES_PER_MAP + " set to 0"); return -2; } long totalBytesToWrite = conf.getLong(TOTAL_BYTES, numMapsPerHost * numBytesToWritePerMap * cluster.getTaskTrackers()); int numMaps = (int) (totalBytesToWrite / numBytesToWritePerMap); if (numMaps == 0 && totalBytesToWrite > 0) { numMaps = 1; conf.setLong(BYTES_PER_MAP, totalBytesToWrite); } conf.setInt(MRJobConfig.NUM_MAPS, numMaps); Job job = new Job(conf); job.setJarByClass(RandomWriter.class); job.setJobName("random-writer"); FileOutputFormat.setOutputPath(job, outDir); job.setOutputKeyClass(BytesWritable.class); job.setOutputValueClass(BytesWritable.class); job.setInputFormatClass(RandomInputFormat.class); job.setMapperClass(RandomMapper.class); job.setReducerClass(Reducer.class); job.setOutputFormatClass(SequenceFileOutputFormat.class); System.out.println("Running " + numMaps + " maps."); // reducer NONE job.setNumReduceTasks(0); Date startTime = new Date(); System.out.println("Job started: " + startTime); int ret = job.waitForCompletion(true) ? 0 : 1; Date endTime = new Date(); System.out.println("Job ended: " + endTime); System.out.println("The job took " + (endTime.getTime() - startTime.getTime()) / 1000 + " seconds."); return ret; }
From source file:com.pinterest.terrapin.TerrapinUtil.java
License:Apache License
public static void setupConfiguration(Configuration conf, long dfsBlockSize, int dfsReplication) { conf.setInt("mapred.map.max.attempts", Constants.MAPRED_MAP_MAX_ATTEMPTS); conf.setInt("io.bytes.per.checksum", Constants.CHECKSUM_BYTES); long dfsBlockSizeAdjusted = dfsBlockSize; if (dfsBlockSize % Constants.CHECKSUM_BYTES != 0) { dfsBlockSizeAdjusted = (dfsBlockSize / Constants.CHECKSUM_BYTES + 1) * Constants.CHECKSUM_BYTES; }/*from w w w . jav a 2 s . c o m*/ conf.setLong("dfs.block.size", dfsBlockSizeAdjusted); conf.setInt("dfs.replication", dfsReplication); conf.set(Constants.HFILE_COMPRESSION, System.getProperty(Constants.HFILE_COMPRESSION, Constants.HFILE_COMPRESSION_DEFAULT)); conf.setInt(Constants.HFILE_BLOCKSIZE, Integer.parseInt( System.getProperty(Constants.HFILE_BLOCKSIZE, String.valueOf(Constants.HFILE_BLOCKSIZE_DEFAULT)))); }
From source file:com.pivotal.gfxd.demo.mapreduce.LoadAverage.java
License:Open Source License
/** * This method is assuming fs.default.name as args[0] * * @param args//from w ww. j a va2 s . c o m * @return * @throws Exception */ @Override public int run(String[] args) throws Exception { System.out.println("Starting MapReduce Job"); GfxdDataSerializable.initTypes(); Configuration conf = new Configuration(); //Configuration conf = getConf(); Path outputPath = new Path("/output"); String hdfsHomeDir = "/sensorStore"; //args[1]; String tableName = "RAW_SENSOR"; String outTableName = "LOAD_AVERAGES_SHADOW"; String gfxdURL = conf.get("gemfirexd.url", "jdbc:gemfirexd://localhost:1527"); // conf.set("fs.default.name", args[0]); String hdfsUrl = conf.get("fs.defaultFS"); FileSystem hdfs = FileSystem.get(new URI(hdfsUrl), conf); // Retrieve last run timestamp long now = System.currentTimeMillis(); long lastStart = getLastStart(hdfs); outputPath.getFileSystem(conf).delete(outputPath, true); conf.set(RowInputFormat.HOME_DIR, hdfsHomeDir); conf.set(RowInputFormat.INPUT_TABLE, tableName); conf.setBoolean(RowInputFormat.CHECKPOINT_MODE, false); conf.setLong(RowInputFormat.START_TIME_MILLIS, lastStart); conf.setLong(RowInputFormat.END_TIME_MILLIS, now); conf.set(RowOutputFormat.OUTPUT_URL, gfxdURL); conf.set(RowOutputFormat.OUTPUT_TABLE, outTableName); // print config to troubleshoot possible issues // Configuration.dumpConfiguration(conf, new PrintWriter(System.out)); Job job = Job.getInstance(conf, "LoadAverage"); job.setNumReduceTasks(1); job.setInputFormatClass(RowInputFormat.class); // configure mapper and reducer job.setJarByClass(LoadAverage.class); job.setMapperClass(LoadAverageMapper.class); job.setReducerClass(LoadAverageReducer.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(LoadKey.class); TextOutputFormat.setOutputPath(job, outputPath); job.setOutputFormatClass(RowOutputFormat.class); job.setOutputKeyClass(Key.class); job.setOutputValueClass(LoadAverageModel.class); boolean jobSuccess = job.waitForCompletion(true); if (jobSuccess) { writeLastStart(hdfs, now); } return jobSuccess ? 0 : 1; }