List of usage examples for com.google.common.io Resources getResource
public static URL getResource(String resourceName)
From source file:com.cloudera.cdk.tools.CombinedLogFormatConverter.java
@Override public int run(String... args) throws Exception { if (args.length != 3) { System.err.println("Usage: " + CombinedLogFormatConverter.class.getSimpleName() + " <input> <dataset_root> <dataset name>"); return 1; }/* ww w . j a v a 2s . co m*/ String input = args[0]; String datasetRoot = args[1]; String datasetName = args[2]; Schema schema = new Schema.Parser().parse(Resources.getResource("combined_log_format.avsc").openStream()); // Create the dataset Path root = new Path(datasetRoot); Configuration conf = new Configuration(); FileSystem fs = root.getFileSystem(conf); DatasetRepository repo = new FileSystemDatasetRepository.Builder().fileSystem(fs).rootDirectory(root) .build(); DatasetDescriptor datasetDescriptor = new DatasetDescriptor.Builder().schema(schema).build(); repo.create(datasetName, datasetDescriptor); // Run the job final String schemaString = schema.toString(); AvroType<GenericData.Record> outputType = Avros.generics(schema); PCollection<String> lines = readTextFile(input); PCollection<GenericData.Record> records = lines.parallelDo(new ConvertFn(schemaString), outputType); getPipeline().write(records, new AvroFileTarget(new Path(root, datasetName)), Target.WriteMode.APPEND); run(); return 0; }
From source file:com.arpnetworking.metrics.mad.performance.FilePerfTestBase.java
/** * Runs a filter.// www . ja va2 s. c om * * @param pipelineConfigurationFile Pipeline configuration file. * @param duration Timeout period. * @param variables Substitution key-value pairs into pipeline configuration file. * @throws IOException if configuration cannot be loaded. */ protected void benchmark(final String pipelineConfigurationFile, final Duration duration, final ImmutableMap<String, String> variables) throws IOException { // Replace any variables in the configuration file String configuration = Resources.toString(Resources.getResource(pipelineConfigurationFile), Charsets.UTF_8); for (final Map.Entry<String, String> entry : variables.entrySet()) { configuration = configuration.replace(entry.getKey(), entry.getValue()); } // Load the specified stock configuration final PipelineConfiguration stockPipelineConfiguration = new StaticConfiguration.Builder() .addSource(new JsonNodeLiteralSource.Builder().setSource(configuration).build()) .setObjectMapper(PipelineConfiguration.createObjectMapper(_injector)).build() .getRequiredAs(PipelineConfiguration.class); // Canary tracking LOGGER.info(String.format("Expected canaries; periods=%s", stockPipelineConfiguration.getPeriods())); final CountDownLatch latch = new CountDownLatch(stockPipelineConfiguration.getPeriods().size()); final Set<Period> periods = Sets.newConcurrentHashSet(); // Create custom "canary" sink final ListeningSink sink = new ListeningSink((periodicData) -> { if (periodicData != null) { for (final String metricName : periodicData.getData().keys()) { if (TestFileGenerator.CANARY.equals(metricName)) { if (periods.add(periodicData.getPeriod())) { LOGGER.info(String.format("Canary flew; filter=%s, period=%s", this.getClass(), periodicData.getPeriod())); latch.countDown(); } } } } return null; }); // Add the custom "canary" sink final List<Sink> benchmarkSinks = Lists.newArrayList(stockPipelineConfiguration.getSinks()); benchmarkSinks.add(sink); // Create the custom configuration final PipelineConfiguration benchmarkPipelineConfiguration = OvalBuilder.<PipelineConfiguration, PipelineConfiguration.Builder>clone( stockPipelineConfiguration).setSinks(benchmarkSinks).build(); // Instantiate the pipeline final Pipeline pipeline = new Pipeline(benchmarkPipelineConfiguration); // Execute the pipeline until the canary flies the coop try { LOGGER.debug(String.format("Launching pipeline; configuration=%s", pipelineConfigurationFile)); final Stopwatch timer = Stopwatch.createUnstarted(); timer.start(); pipeline.launch(); if (!latch.await(duration.getMillis(), TimeUnit.MILLISECONDS)) { LOGGER.error("Test timed out"); throw new RuntimeException("Test timed out"); } timer.stop(); LOGGER.info(String.format("Performance filter result; filter=%s, seconds=%s", this.getClass(), timer.elapsed(TimeUnit.SECONDS))); } catch (final InterruptedException e) { Thread.interrupted(); throw new RuntimeException("Test interrupted"); } finally { pipeline.shutdown(); } }
From source file:com.cloudera.cdk.maven.plugins.CreateDatasetMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { DatasetRepository repo = getDatasetRepository(); DatasetDescriptor.Builder descriptorBuilder = new DatasetDescriptor.Builder(); File avroSchema = new File(avroSchemaFile); try {//from ww w. j a v a 2s . c om if (avroSchema.exists()) { descriptorBuilder.schema(avroSchema); } else { descriptorBuilder.schema(Resources.getResource(avroSchemaFile).openStream()); } } catch (IOException e) { throw new MojoExecutionException("Problem while reading file " + avroSchemaFile, e); } if (format.equals(Formats.AVRO.getName())) { descriptorBuilder.format(Formats.AVRO); } else if (format.equals(Formats.PARQUET.getName())) { descriptorBuilder.format(Formats.PARQUET); } else { throw new MojoExecutionException("Unrecognized format: " + format); } if (partitionExpression != null) { descriptorBuilder.partitionStrategy(Accessor.getDefault().fromExpression(partitionExpression)); } repo.create(datasetName, descriptorBuilder.get()); }
From source file:org.killbill.billing.server.modules.EmbeddedDBProvider.java
protected void initializeEmbeddedDB(final EmbeddedDB embeddedDB) throws IOException { embeddedDB.initialize();/*www. jav a 2 s.c o m*/ embeddedDB.start(); // If the tables have not been created yet, do it, otherwise don't clobber them if (!embeddedDB.getAllTables().isEmpty()) { return; } for (final String ddlFile : getDDLFiles()) { final URL resource = Resources.getResource(ddlFile); final InputStream inputStream = resource.openStream(); try { final String ddl = streamToString(inputStream); embeddedDB.executeScript(ddl); } finally { inputStream.close(); } } embeddedDB.refreshTableNames(); }
From source file:com.ning.jetty.core.server.HttpServer.java
public void configure(final String jettyXml) throws Exception { final XmlConfiguration configuration = new XmlConfiguration(Resources.getResource(jettyXml)); configuration.configure(server);//w w w . ja v a 2 s . c o m }
From source file:com.arcbees.beestore.server.servlets.RootServlet.java
private Properties loadVelocityProperties() { Properties properties = new Properties(); try {//from w ww . j av a 2 s.c om URL url = Resources.getResource(VELOCITY_PROPERTIES); ByteSource byteSource = Resources.asByteSource(url); properties.load(byteSource.openStream()); } catch (IOException e) { throw new RuntimeException("Unable to load velocity properties from '" + VELOCITY_PROPERTIES + "'.", e); } return properties; }
From source file:com.zxy.commons.hystrix.web.HystrixInitializer.java
/** * webspringproperties??/* ww w.j a v a 2 s .c o m*/ * * @return Properties */ private Properties load() { Properties properties = new Properties(); InputStream inputStream = null; try { final URL url = Resources.getResource("hystrix.properties"); final ByteSource byteSource = Resources.asByteSource(url); inputStream = byteSource.openBufferedStream(); properties.load(inputStream); // properties.list(System.out); } catch (Exception e) { // do nothing } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException ioException) { // do nothing } } } return properties; }
From source file:com.mgmtp.perfload.perfalyzer.reporting.email.EmailSkeleton.java
@Override protected void build() { String css = null;// www.j a v a 2 s . c om try { css = Resources.toString(Resources.getResource("email/email.css"), Charsets.UTF_8); } catch (IOException ex) { log.error("Could not read CSS for e-mail", ex); } raw("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"); //@formatter:off html(); head(); title().text("perfAlyzer Report").end(); meta().httpEquiv("Content-Type").content("text/html; charset=UTF-8").end(); if (css != null) { style().type("text/css").text(SystemUtils.LINE_SEPARATOR + css).end(); } end(); body(); div().id("content"); h1().text("perfAlyzer E-mail Report").end(); div(); table(); tbody(); tr(); th().text(resourceBundle.getString("overview.testplan")).end(); td().text(testMetadata.getTestPlanFile()).end(); end(); tr(); th().text(resourceBundle.getString("overview.start")).end(); td().text(dateTimeFormatter.format(testMetadata.getTestStart())).end(); end(); tr(); th().text(resourceBundle.getString("overview.end")).end(); td().text(dateTimeFormatter.format(testMetadata.getTestEnd())).end(); end(); tr(); th().text(resourceBundle.getString("overview.duration")).end(); td().text(testMetadata.getTestDuration()).end(); end(); tr(); th().text(resourceBundle.getString("overview.operations")).end(); td().text(on(", ").join(testMetadata.getOperations())).end(); end(); tr(); th().text(resourceBundle.getString("overview.comment")).end(); td().text(testMetadata.getTestComment()).end(); end(); tr(); th().text(resourceBundle.getString("overview.rawResultsDir")).end(); td().text(testMetadata.getRawResultsDir()).end(); end(); tr(); th().text(resourceBundle.getString("overview.perfloadVersion")).end(); td().text(testMetadata.getPerfLoadVersion()).end(); end(); if (linkToReport != null) { tr(); th().text(resourceBundle.getString("report.link")).end(); td().a().href(linkToReport).text(linkToReport).alt("Link to perfAlyzer Report").end().end(); end(); } end(); end(); end(); br(); addDataTable(data, true); for (Entry<String, List<? extends List<String>>> entry : comparisonData.entrySet()) { br(); h2().text("Comparison - " + entry.getKey()).end(); addDataTable(entry.getValue(), false); } end(); end(); end(); //@formatter:on }
From source file:com.facebook.buck.lua.AbstractLuaScriptStarter.java
private String getPureStarterTemplate() { try {/*from ww w .j a va 2s. com*/ return Resources.toString(Resources.getResource(STARTER), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:w3bigdata.downloader.DriveSample.java
/** * Authorizes the installed application to access user's protected data. *//* w ww.j ava2 s .com*/ private static Credential authorize() throws Exception { // load client secrets URL resource = Resources.getResource("client_secrets.json"); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(Resources.asByteSource(resource).getInput())); // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(DriveScopes.DRIVE)).setDataStoreFactory(dataStoreFactory) .build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }