List of usage examples for java.util List isEmpty
boolean isEmpty();
From source file:mvm.rya.indexing.external.ExternalIndexMain.java
public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length == 6, "java " + ExternalIndexMain.class.getCanonicalName() + " sparqlFile cbinstance cbzk cbuser cbpassword rdfTablePrefix."); final String sparqlFile = args[0]; instStr = args[1];//from w ww . jav a 2s .co m zooStr = args[2]; userStr = args[3]; passStr = args[4]; tablePrefix = args[5]; String queryString = FileUtils.readFileToString(new File(sparqlFile)); // Look for Extra Indexes Instance inst = new ZooKeeperInstance(instStr, zooStr); Connector c = inst.getConnector(userStr, passStr.getBytes()); System.out.println("Searching for Indexes"); Map<String, String> indexTables = Maps.newLinkedHashMap(); for (String table : c.tableOperations().list()) { if (table.startsWith(tablePrefix + "INDEX_")) { Scanner s = c.createScanner(table, new Authorizations()); s.setRange(Range.exact(new Text("~SPARQL"))); for (Entry<Key, Value> e : s) { indexTables.put(table, e.getValue().toString()); } } } List<ExternalTupleSet> index = Lists.newArrayList(); if (indexTables.isEmpty()) { System.out.println("No Index found"); } else { for (String table : indexTables.keySet()) { String indexSparqlString = indexTables.get(table); System.out.println("====================== INDEX FOUND ======================"); System.out.println(" table : " + table); System.out.println(" sparql : "); System.out.println(indexSparqlString); index.add(new AccumuloIndexSet(indexSparqlString, c, table)); } } // Connect to Rya Sail s = getRyaSail(); SailRepository repo = new SailRepository(s); repo.initialize(); // Perform Query CountingTupleQueryResultHandler count = new CountingTupleQueryResultHandler(); SailRepositoryConnection conn; if (index.isEmpty()) { conn = repo.getConnection(); } else { ExternalProcessor processor = new ExternalProcessor(index); Sail processingSail = new ExternalSail(s, processor); SailRepository smartSailRepo = new SailRepository(processingSail); smartSailRepo.initialize(); conn = smartSailRepo.getConnection(); } startTime = System.currentTimeMillis(); lastTime = startTime; System.out.println("Query Started"); conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(count); System.out.println("Count of Results found : " + count.i); System.out.println("Total query time (s) : " + (System.currentTimeMillis() - startTime) / 1000.); }
From source file:com.gemini.geminimain.GeminiMain.java
public static void main(String[] args) throws IOException { //setup the mongodb access mongoClient = new MongoClient(DB_SERVER); //create table for the application, networks and servers ds = morphia.createDatastore(mongoClient, "Gemini"); //create the mapper Injector injector = Guice.createInjector(new GeminiMapperModule()); GeminiMapper mapper = injector.getInstance(GeminiMapper.class); //set the current logging level to debug Configurator.currentConfig().level(Level.INFO).activate(); //create some data to transfer to the front end createSampleData();/*from w w w . j ava 2 s . c o m*/ //close the db client mongoClient.close(); //check if authenticated, create the call context and user context here //for now it is empty!!!! before((request, response) -> { boolean authenticated = true; // ... check if authenticated if (!authenticated) { halt(401, "Nice try, you are not welcome here"); } }); after((request, response) -> { response.header("Access-Control-Allow-Origin", "*"); //response.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); //response.header("Access-Control-Max-Age", "3600"); //response.header("Access-Control-Allow-Headers", "x-requested-with"); }); //get all environments of the tenant get("/environments/:tenantid", "application/json", (request, response) -> { String tenantID = request.params("tenantid"); try { List<GeminiEnvironment> lEnvs = getEnvironments(tenantID); if (lEnvs != null) { response.status(200); Logger.info("Found environments for tenant {}", tenantID); List<GeminiEnvironmentDTO> dtoEnvs = new ArrayList(); lEnvs.stream().forEach(e -> dtoEnvs.add(mapper.getDTOFromEnv(e))); return lEnvs; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {}", DB_SERVER); response.status(500); return "Severe Error: Unknown database host " + DB_SERVER; } return "not implemented yet"; }, new JsonTransformer()); //return all applications for a given tenant and environment get("/applications/:tenantid/:envname", "application/json", (request, response) -> { String tenantID, envName; try { tenantID = URLDecoder.decode(request.params(":tenantid"), "UTF-8"); envName = URLDecoder.decode(request.params(":envname"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - server Name: {} Exception: {}", request.params(":name"), ex); return "Severe Error: Unsupported encoding in URL"; } try { List<GeminiApplication> apps = getEnvApplications(tenantID, envName); if (apps == null || apps.isEmpty()) { response.status(404); Logger.info("Could not find any applications."); return "No Applications found."; } else { response.status(200); Logger.debug("Found applications"); List<GeminiApplicationDTO> dtoApps = new ArrayList(); apps.stream().forEach((a) -> { dtoApps.add(mapper.getDTOFromApp(a)); }); return dtoApps; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {}", DB_SERVER); response.status(500); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); //return application given a name get("/applications/:name", "application/json", (request, response) -> { String appName = ""; //decode the URL as it may contain escape characters, etc. try { appName = URLDecoder.decode(request.params(":name"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - application Name: {} Exception: {}", request.params(":name"), ex); return "Severe Error: Unsupported encoding in URL - server name " + appName; } try { GeminiApplication a = getAppByName(appName); if (a != null) { Logger.debug("Found application {}", appName); return mapper.getDTOFromApp(a); } else { Logger.info("Could not find application {}", appName); return "Could not find application " + appName; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); response.status(500); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); post("/applications", (request, response) -> { String body = request.body(); return "Hello World: " + request.body(); }); //return all networks related to application with ID = ':id' get("/applications/:name/networks", "application/json", (Request request, Response response) -> { String appName; //decode the URL as it may contain escape characters, etc. try { appName = URLDecoder.decode(request.params(":name"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - server Name: {} Exception: {}", request.params(":name"), ex); return "Severe Error: Unsupported encoding in URL"; } try { List<GeminiNetwork> lNet = getAppNetworks(appName); if (lNet != null) { Logger.debug("Found networks for application {}", appName); List<GeminiNetworkDTO> dtoNets = new ArrayList(); lNet.stream().forEach(aNet -> dtoNets.add(mapper.getDTOFromNetwork(aNet))); return dtoNets; } else { response.status(404); Logger.info("Could not find any networks for application {}", appName); return "Could not find any networks for application: " + appName; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); response.status(500); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); //return all servers related to application with ID = ':id' get("/applications/:id/servers", "application/json", (Request request, Response response) -> { String appName = ""; //decode the URL as it may contain escape characters, etc. try { appName = URLDecoder.decode(request.params(":name"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - server Name: {} Exception: {}", request.params(":name"), ex); return "Severe Error: Unsupported encoding in URL"; } try { List<GeminiServer> lSrv = getAppServers(appName); if (lSrv != null) { Logger.debug("Found servers for application {}", appName); List<GeminiServerDTO> dtoSrvs = new ArrayList(); for (GeminiServer s : lSrv) { dtoSrvs.add(mapper.getDTOFromServer(s)); } return dtoSrvs; } else { Logger.info("Could not find servers for application {}", appName); response.status(404); return "Could not find servers for application: " + appName; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); //return all servers related to application with ID = ':appID' AND network with ID = ':nID' get("/applications/:appname/networks/:netstart/:netend/servers", "application/json", (request, response) -> { String appName = "", netStart = "", netEnd = ""; //decode the URL as it may contain escape characters, etc. try { appName = URLDecoder.decode(request.params(":appname"), "UTF-8"); netStart = URLDecoder.decode(request.params(":netstart"), "UTF-8"); netEnd = URLDecoder.decode(request.params(":netend"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error( "Severe Error: Unsupported encoding in URL - application {} with network start: {} and end: {} Exception {}", request.params(":appname"), request.params(":netstart"), request.params(":netend"), ex); return "Severe Error: Unsupported encoding in URL"; } //get the servers for app network try { List<GeminiServer> lSrv = getAppNetworkServers(appName, netStart, netEnd); if (lSrv == null || lSrv.isEmpty()) { Logger.info("No servers for application {} with network start: {} and end: {}", appName, netStart, netEnd); response.status(404); return "No servers for application " + appName + " with network start: " + netStart + " and end: " + netEnd; } else { Logger.debug("Found servers for application {} with network start: {} and end: ", appName, netStart, netEnd); List<GeminiServerDTO> dtoSrvs = new ArrayList(); for (GeminiServer s : lSrv) { dtoSrvs.add(mapper.getDTOFromServer(s)); } return dtoSrvs; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); //get the networks for a tenant and environment, get("/networks/:tenantid/:envname", "application/json", (request, response) -> { String tenantID, envName; try { tenantID = URLDecoder.decode(request.params(":tenantid"), "UTF-8"); envName = URLDecoder.decode(request.params(":envname"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - server Name: {} Exception: {}", request.params(":name"), ex); return "Severe Error: Unsupported encoding in URL"; } try { List<GeminiNetwork> nets = getEnvNetworks(tenantID, envName); if (nets == null) { Logger.info("No networks discovered for tenant {} in environment {}", tenantID, envName); return "No networks discovered for tenant" + tenantID + "in environment" + envName; } else { response.status(200); List<GeminiNetworkDTO> dtoNets = new ArrayList(); nets.stream().forEach(n -> dtoNets.add(mapper.getDTOFromNetwork(n))); Logger.debug("Found {} networks for tenant {} env {}", nets.size(), tenantID, envName); return dtoNets; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown datbase host - {}", DB_SERVER); return "Severe Error: Unknown data host " + DB_SERVER; } }, new JsonTransformer()); get("/networks/:netstart/:netend", "application/json", (request, response) -> { String netStart = "", netEnd = ""; //decode the URL as it may contain escape characters, etc. try { netStart = URLDecoder.decode(request.params(":netstart"), "UTF-8"); netEnd = URLDecoder.decode(request.params(":netend"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - netStart: {} netEnd: {} Exception: {}", request.params(":netstart"), request.params(":netend"), ex); return "Severe Error: Unsupported encoding in URL"; } try { GeminiNetwork n = getNetworkFromDB(netStart, netEnd); if (n == null) { Logger.info("No network with start {} and end {} found", netStart, netEnd); return "No network with start " + netStart + " and end " + netEnd + " found"; } else { Logger.debug("Found network with start {} and end {} ", netStart, netEnd); return mapper.getDTOFromNetwork(n); } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); get("/networks/:netstart/:netend/servers", "application/json", (request, response) -> { String netStart = "", netEnd = ""; //decode the URL as it may contain escape characters, etc. try { netStart = URLDecoder.decode(request.params(":netstart"), "UTF-8"); netEnd = URLDecoder.decode(request.params(":netend"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - netStart: {} netEnd: {} Exception: {}", request.params(":netstart"), request.params(":netend"), ex); return "Severe Error: Unsupported encoding in URL"; } try { List<GeminiServer> lSrv = getNetworkServersFromDB(netStart, netEnd); if (lSrv == null) { Logger.info("No servers in network with start {} and end {} found", netStart, netEnd); return "No servers in network with start " + netStart + " and end " + netEnd + " found"; } else { Logger.debug("Found servers in network with start {} and end {} ", netStart, netEnd); List<GeminiServerDTO> dtoSrvs = new ArrayList(); for (GeminiServer s : lSrv) { dtoSrvs.add(mapper.getDTOFromServer(s)); } return dtoSrvs; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); post("/networks/:netstart/:netend", "application/json", (request, response) -> { String netStart = "", netEnd = ""; //decode the URL as it may contain escape characters, etc. try { netStart = URLDecoder.decode(request.params(":netstart"), "UTF-8"); netEnd = URLDecoder.decode(request.params(":netend"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - netStart: {} netEnd: {} Exception: {}", request.params(":netstart"), request.params(":netend"), ex); return "Severe Error: Unsupported encoding in URL"; } //return the discovered networks // DiscoverNetworkRange newNet = new DiscoverNetworkRange(netStart, netEnd); // List<GeminiNetwork> lNet; // if (autoDiscover) { // try { // //start discovering... // lNet = discoverNetworks(netStart, netEnd); // } catch (IOException ex) { // java.util.logging.Logger.getLogger(GeminiMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); // } // } //since all the services are running on the same computer response.header("Access-Control-Allow-Origin", "*"); //return the networks... return "no networks"; }, new JsonTransformer()); //get all servers for tenant within an environment get("/servers", "application/json", (request, response) -> { try { List<GeminiServer> srvs = getServersFromDB(); if (srvs == null) { Logger.info("Found no servers in database"); return "No Networks"; } else { Logger.debug("Found servers in database"); List<GeminiServerDTO> dtoSrvs = new ArrayList(); for (GeminiServer s : srvs) { dtoSrvs.add(mapper.getDTOFromServer(s)); } response.status(200); return dtoSrvs; } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); get("/servers/:name", "application/json", (request, response) -> { String srvName; try { srvName = URLDecoder.decode(request.params(":name"), "UTF-8"); } catch (UnsupportedEncodingException ex) { Logger.error("Severe Error: Unsupported encoding in URL - {} Exception {}", request.params(":name"), ex); return "Severe Error: Unsupported encoding in URL"; } try { GeminiServer s = getServerFromDB(srvName); if (s == null) { Logger.info("No server with name {} found", srvName); return "No server with name " + srvName; } else { Logger.debug("Found server with name {}", srvName); return mapper.getDTOFromServer(s); } } catch (UnknownHostException ex) { Logger.error("Severe Error: Unknown host - {} Exception: {}", DB_SERVER, ex); return "Severe Error: Unknown database host " + DB_SERVER; } }, new JsonTransformer()); }
From source file:com.bazaarvoice.jsonpps.PrettyPrintJson.java
public static void main(String[] args) throws Exception { try {/*from w w w. j av a2 s . c om*/ ArgumentParser parser = ArgumentParsers.newArgumentParser("jsonpps") .description("A streaming JSON pretty printer that can format multi-GB input files.") .defaultHelp(true); parser.addArgument("-o", "--out").type(Arguments.fileType()).setDefault(STDINOUT).help("output file"); parser.addArgument("--flatten").metavar("N").type(Integer.class).setDefault(0) .help("flatten the top-N levels of object/array structure"); parser.addArgument("-i", "--in-place").action(Arguments.storeTrue()) .help("modify the original file(s)"); parser.addArgument("-S", "--sort-keys").action(Arguments.storeTrue()).help( "emit objects with keys in sorted order. this increases memory requirements since objects must be buffered in memory."); parser.addArgument("--strict").action(Arguments.storeTrue()).help("reject non-conforming json"); parser.addArgument("--wrap").action(Arguments.storeTrue()).help("wrap all output in a json array"); parser.addArgument("--unwrap").action(Arguments.storeTrue()) .help("flatten the top level of object/array structure"); parser.addArgument("in").nargs("*") .type(Arguments.fileType().acceptSystemIn().verifyExists().verifyIsFile().verifyCanRead()) .setDefault(new File[] { STDINOUT }).help("input file(s)"); Namespace ns; try { ns = parser.parseArgs(args); } catch (ArgumentParserException e) { parser.handleError(e); System.exit(2); return; } PrettyPrintJson jsonpp = new PrettyPrintJson(); File outputFile = ns.get("out"); List<File> inputFiles = ns.getList("in"); boolean inPlace = ns.getBoolean("in_place"); jsonpp.setFlatten(ns.getInt("flatten")); jsonpp.setSortKeys(ns.getBoolean("sort_keys")); jsonpp.setStrict(ns.getBoolean("strict")); jsonpp.setWrap(ns.getBoolean("wrap")); if (ns.getBoolean("unwrap")) { jsonpp.setFlatten(1); } if (!inPlace) { // Pretty print all input files to a single output jsonpp.prettyPrint(inputFiles, outputFile); } else { // Pretty print all input files back to themselves. if (outputFile != STDINOUT) { // use "!=" not "!.equals()" since default is ok but "-o -" is not. System.err.println("error: -o and --in-place are mutually exclusive"); System.exit(2); } if (inputFiles.isEmpty()) { System.err.println("error: --in-place requires at least one input file"); System.exit(2); } if (inputFiles.contains(STDINOUT)) { System.err.println("error: --in-place cannot operate on stdin"); System.exit(2); } for (File inputFile : inputFiles) { jsonpp.prettyPrint(inputFile, inputFile); } } } catch (Throwable t) { t.printStackTrace(); System.err.println(t.toString()); System.exit(1); } }
From source file:com.jgaap.backend.CLI.java
/** * Parses the arguments passed to jgaap from the command line. Will either * display the help or run jgaap on an experiment. * //from w w w. j a va 2s .co m * @param args * command line arguments * @throws Exception */ public static void main(String[] args) throws Exception { CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption('h')) { String command = cmd.getOptionValue('h'); if (command == null) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setLeftPadding(5); helpFormatter.setWidth(100); helpFormatter.printHelp( "jgaap -c [canon canon ...] -es [event] -ec [culler culler ...] -a [analysis] <-d [distance]> -l [file] <-s [file]>", "Welcome to JGAAP the Java Graphical Authorship Attribution Program.\nMore information can be found at http://jgaap.com", options, "Copyright 2013 Evaluating Variation in Language Lab, Duquesne University"); } else { List<Displayable> list = new ArrayList<Displayable>(); if (command.equalsIgnoreCase("c")) { list.addAll(Canonicizers.getCanonicizers()); } else if (command.equalsIgnoreCase("es")) { list.addAll(EventDrivers.getEventDrivers()); } else if (command.equalsIgnoreCase("ec")) { list.addAll(EventCullers.getEventCullers()); } else if (command.equalsIgnoreCase("a")) { list.addAll(AnalysisDrivers.getAnalysisDrivers()); } else if (command.equalsIgnoreCase("d")) { list.addAll(DistanceFunctions.getDistanceFunctions()); } else if (command.equalsIgnoreCase("lang")) { list.addAll(Languages.getLanguages()); } for (Displayable display : list) { if (display.showInGUI()) System.out.println(display.displayName() + " - " + display.tooltipText()); } if (list.isEmpty()) { System.out.println("Option " + command + " was not found."); System.out.println("Please use c, es, d, a, or lang"); } } } else if (cmd.hasOption('v')) { System.out.println("Java Graphical Authorship Attribution Program version 5.2.0"); } else if (cmd.hasOption("ee")) { String eeFile = cmd.getOptionValue("ee"); String lang = cmd.getOptionValue("lang"); ExperimentEngine.runExperiment(eeFile, lang); System.exit(0); } else { JGAAP.commandline = true; API api = API.getPrivateInstance(); String documentsFilePath = cmd.getOptionValue('l'); if (documentsFilePath == null) { throw new Exception("No Documents CSV specified"); } List<Document> documents; if (documentsFilePath.startsWith(JGAAPConstants.JGAAP_RESOURCE_PACKAGE)) { documents = Utils.getDocumentsFromCSV( CSVIO.readCSV(com.jgaap.JGAAP.class.getResourceAsStream(documentsFilePath))); } else { documents = Utils.getDocumentsFromCSV(CSVIO.readCSV(documentsFilePath)); } for (Document document : documents) { api.addDocument(document); } String language = cmd.getOptionValue("lang", "english"); api.setLanguage(language); String[] canonicizers = cmd.getOptionValues('c'); if (canonicizers != null) { for (String canonicizer : canonicizers) { api.addCanonicizer(canonicizer); } } String[] events = cmd.getOptionValues("es"); if (events == null) { throw new Exception("No EventDriver specified"); } for (String event : events) { api.addEventDriver(event); } String[] eventCullers = cmd.getOptionValues("ec"); if (eventCullers != null) { for (String eventCuller : eventCullers) { api.addEventCuller(eventCuller); } } String analysis = cmd.getOptionValue('a'); if (analysis == null) { throw new Exception("No AnalysisDriver specified"); } AnalysisDriver analysisDriver = api.addAnalysisDriver(analysis); String distanceFunction = cmd.getOptionValue('d'); if (distanceFunction != null) { api.addDistanceFunction(distanceFunction, analysisDriver); } api.execute(); List<Document> unknowns = api.getUnknownDocuments(); OutputStreamWriter outputStreamWriter; String saveFile = cmd.getOptionValue('s'); if (saveFile == null) { outputStreamWriter = new OutputStreamWriter(System.out); } else { outputStreamWriter = new OutputStreamWriter(new FileOutputStream(saveFile)); } Writer writer = new BufferedWriter(outputStreamWriter); for (Document unknown : unknowns) { writer.append(unknown.getFormattedResult(analysisDriver)); } writer.append('\n'); } }
From source file:com.github.checkstyle.Main.java
/** * Entry point./*from w w w . j a va 2 s. co m*/ * @param args command line arguments. */ public static void main(String... args) { int errorCounter; List<String> publicationErrors = null; try { final CliProcessor cliProcessor = new CliProcessor(args); cliProcessor.process(); if (cliProcessor.hasErrors()) { printListOf(cliProcessor.getErrorMessages()); errorCounter = cliProcessor.getErrorMessages().size(); } else { final CliOptions cliOptions = cliProcessor.getCliOptions(); final Result notesBuilderResult = runNotesBuilder(cliOptions); errorCounter = notesBuilderResult.getErrorMessages().size(); if (errorCounter == 0) { runPostGeneration(notesBuilderResult.getReleaseNotes(), cliOptions); publicationErrors = runPostPublication(cliOptions); } } } catch (ParseException | GitAPIException | IOException | TemplateException ex) { errorCounter = 1; System.out.println(ex.getMessage()); CliProcessor.printUsage(); } if (errorCounter == 0) { if (publicationErrors != null && !publicationErrors.isEmpty()) { System.out.println(String.format("%nPublication ends with %d errors:", publicationErrors.size())); printListOf(publicationErrors); } else { System.out.println(String.format("%nExecution succeeded!")); } } else { System.out.println(String.format("%nGeneration ends with %d errors.", errorCounter)); System.exit(ERROR_EXIT_CODE); } }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step5LinguisticPreprocessing.java
public static void main(String[] args) throws Exception { // input dir - list of xml query containers // step4-boiler-plate/ File inputDir = new File(args[0]); // output dir File outputDir = new File(args[1]); if (!outputDir.exists()) { outputDir.mkdirs();// ww w . j a va2 s.c o m } // iterate over query containers for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) { // System.out.println(rankedResults.plainText); if (rankedResults.plainText != null) { String[] lines = StringUtils.split(rankedResults.plainText, "\n"); // collecting all cleaned lines List<String> cleanLines = new ArrayList<>(lines.length); // collecting line tags List<String> lineTags = new ArrayList<>(lines.length); for (String line : lines) { // get the tag String tag = null; Matcher m = OPENING_TAG_PATTERN.matcher(line); if (m.find()) { tag = m.group(1); } if (tag == null) { throw new IllegalArgumentException("No html tag found for line:\n" + line); } // replace the tag at the beginning and the end String noTagText = line.replaceAll("^<\\S+>", "").replaceAll("</\\S+>$", ""); // do some html cleaning noTagText = noTagText.replaceAll(" ", " "); noTagText = noTagText.trim(); // add to the output if (!noTagText.isEmpty()) { cleanLines.add(noTagText); lineTags.add(tag); } } if (cleanLines.isEmpty()) { // the document is empty System.err.println("Document " + rankedResults.clueWebID + " in query " + queryResultContainer.qID + " is empty"); } else { // now join them back to paragraphs String text = StringUtils.join(cleanLines, "\n"); // create JCas JCas jCas = JCasFactory.createJCas(); jCas.setDocumentText(text); jCas.setDocumentLanguage("en"); // annotate WebParagraph SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngineDescription(WebParagraphAnnotator.class)); // fill the original tag information List<WebParagraph> webParagraphs = new ArrayList<>( JCasUtil.select(jCas, WebParagraph.class)); // they must be the same size as original ones if (webParagraphs.size() != lineTags.size()) { throw new IllegalStateException( "Different size of annotated paragraphs and original lines"); } for (int i = 0; i < webParagraphs.size(); i++) { WebParagraph p = webParagraphs.get(i); // get tag String tag = lineTags.get(i); p.setOriginalHtmlTag(tag); } SimplePipeline.runPipeline(jCas, AnalysisEngineFactory.createEngineDescription(StanfordSegmenter.class, // only on existing WebParagraph annotations StanfordSegmenter.PARAM_ZONE_TYPES, WebParagraph.class.getCanonicalName())); // now convert to XMI ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); XmiCasSerializer.serialize(jCas.getCas(), byteOutputStream); // encode to base64 String encoded = new BASE64Encoder().encode(byteOutputStream.toByteArray()); rankedResults.originalXmi = encoded; } } } // and save the query to output dir File outputFile = new File(outputDir, queryResultContainer.qID + ".xml"); FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8"); System.out.println("Finished " + outputFile); } }
From source file:org.apache.cxf.cwiki.SiteExporter.java
public static void main(String[] args) throws Exception { Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password.toCharArray()); }//from w w w .j av a 2 s .com }); ListIterator<String> it = Arrays.asList(args).listIterator(); List<String> files = new ArrayList<String>(); boolean forceAll = false; int maxThreads = -1; while (it.hasNext()) { String s = it.next(); if ("-debug".equals(s)) { debug = true; } else if ("-user".equals(s)) { userName = it.next(); } else if ("-password".equals(s)) { password = it.next(); } else if ("-d".equals(s)) { rootOutputDir = new File(it.next()); } else if ("-force".equals(s)) { forceAll = true; } else if ("-svn".equals(s)) { svn = true; } else if ("-commit".equals(s)) { commit = true; } else if ("-maxThreads".equals(s)) { maxThreads = Integer.parseInt(it.next()); } else if (s != null && s.length() > 0) { files.add(s); } } List<SiteExporter> exporters = new ArrayList<SiteExporter>(); for (String file : files) { exporters.add(new SiteExporter(file, forceAll)); } List<SiteExporter> modified = new ArrayList<SiteExporter>(); for (SiteExporter exporter : exporters) { if (exporter.initialize()) { modified.add(exporter); } } // render stuff only if needed if (!modified.isEmpty()) { setSiteExporters(exporters); if (maxThreads <= 0) { maxThreads = modified.size(); } ExecutorService executor = Executors.newFixedThreadPool(maxThreads, new ThreadFactory() { public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setDaemon(true); return t; } }); List<Future<?>> futures = new ArrayList<Future<?>>(modified.size()); for (SiteExporter exporter : modified) { futures.add(executor.submit(exporter)); } for (Future<?> t : futures) { t.get(); } } if (commit) { File file = FileUtils.createTempFile("svncommit", "txt"); FileWriter writer = new FileWriter(file); writer.write(svnCommitMessage.toString()); writer.close(); callSvn(rootOutputDir, "commit", "-F", file.getAbsolutePath(), rootOutputDir.getAbsolutePath()); svnCommitMessage.setLength(0); } }
From source file:com.healthmarketscience.rmiio.RemoteStreamServerTest.java
public static void main(String[] args) throws Exception { int argc = 0; String appType = null;/*from w ww . j av a 2s. c om*/ if (args.length > argc) { appType = args[argc++]; } // create sub-argument list int subArgsLength = ((args.length > argc) ? (args.length - argc) : 0); String[] subArgs = new String[subArgsLength]; if (subArgsLength > 0) { System.arraycopy(args, argc, subArgs, 0, subArgsLength); } List<AccumulateRemoteStreamMonitor<?>> monitors = new ArrayList<AccumulateRemoteStreamMonitor<?>>(); List<Throwable> clientExceptions = new ArrayList<Throwable>(); if (appType.equals("-server")) { FileServer.main(subArgs); } else if (appType.equals("-client")) { FileClient.main(subArgs); } else if (appType.equals("-test")) { mainTest(subArgs, clientExceptions, null); } else { LOG.debug("First argument must be '-server' or 'client'"); System.exit(1); } if (!clientExceptions.isEmpty()) { LOG.debug("Client exceptions: " + clientExceptions); } }
From source file:azkaban.webapp.AzkabanWebServer.java
/** * Azkaban using Jetty/*ww w . j a va 2 s .c om*/ * * @param args */ public static void main(String[] args) throws Exception { logger.info("Starting Jetty Azkaban Web Server..."); Props azkabanSettings = AzkabanServer.loadProps(args); if (azkabanSettings == null) { logger.error("Azkaban Properties not loaded."); logger.error("Exiting Azkaban..."); return; } int maxThreads = azkabanSettings.getInt("jetty.maxThreads", DEFAULT_THREAD_NUMBER); boolean isStatsOn = azkabanSettings.getBoolean("jetty.connector.stats", true); logger.info("Setting up connector with stats on: " + isStatsOn); boolean ssl; int port; final Server server = new Server(); if (azkabanSettings.getBoolean("jetty.use.ssl", true)) { int sslPortNumber = azkabanSettings.getInt("jetty.ssl.port", DEFAULT_SSL_PORT_NUMBER); port = sslPortNumber; ssl = true; logger.info( "Setting up Jetty Https Server with port:" + sslPortNumber + " and numThreads:" + maxThreads); SslSocketConnector secureConnector = new SslSocketConnector(); secureConnector.setPort(sslPortNumber); secureConnector.setKeystore(azkabanSettings.getString("jetty.keystore")); secureConnector.setPassword(azkabanSettings.getString("jetty.password")); secureConnector.setKeyPassword(azkabanSettings.getString("jetty.keypassword")); secureConnector.setTruststore(azkabanSettings.getString("jetty.truststore")); secureConnector.setTrustPassword(azkabanSettings.getString("jetty.trustpassword")); secureConnector.setHeaderBufferSize(MAX_HEADER_BUFFER_SIZE); // set up vulnerable cipher suites to exclude List<String> cipherSuitesToExclude = azkabanSettings.getStringList("jetty.excludeCipherSuites"); logger.info("Excluded Cipher Suites: " + String.valueOf(cipherSuitesToExclude)); if (cipherSuitesToExclude != null && !cipherSuitesToExclude.isEmpty()) { secureConnector.setExcludeCipherSuites(cipherSuitesToExclude.toArray(new String[0])); } server.addConnector(secureConnector); } else { ssl = false; port = azkabanSettings.getInt("jetty.port", DEFAULT_PORT_NUMBER); SocketConnector connector = new SocketConnector(); connector.setPort(port); connector.setHeaderBufferSize(MAX_HEADER_BUFFER_SIZE); server.addConnector(connector); } // setting stats configuration for connectors for (Connector connector : server.getConnectors()) { connector.setStatsOn(isStatsOn); } String hostname = azkabanSettings.getString("jetty.hostname", "localhost"); azkabanSettings.put("server.hostname", hostname); azkabanSettings.put("server.port", port); azkabanSettings.put("server.useSSL", String.valueOf(ssl)); app = new AzkabanWebServer(server, azkabanSettings); boolean checkDB = azkabanSettings.getBoolean(AzkabanDatabaseSetup.DATABASE_CHECK_VERSION, false); if (checkDB) { AzkabanDatabaseSetup setup = new AzkabanDatabaseSetup(azkabanSettings); setup.loadTableInfo(); if (setup.needsUpdating()) { logger.error("Database is out of date."); setup.printUpgradePlan(); logger.error("Exiting with error."); System.exit(-1); } } try { JdbcExecutorLoader jdbcExecutorLoader = new JdbcExecutorLoader(azkabanSettings); jdbcExecutorLoader.updateExecutableJobsOnStartUp(); } catch (Exception e) { logger.warn("There could be some jobs KILLED by this server restart event," + "but their status still erroneously being shown as RUNNING." + "Please run the SQL " + "[update execution_jobs join execution_flows" + " on execution_jobs.exec_id = execution_flows.exec_id" + " set execution_jobs.status = 70 where" + " execution_jobs.status = 30 and execution_flows.status = 70]" + "on the database to rectify their status", e); } QueuedThreadPool httpThreadPool = new QueuedThreadPool(maxThreads); server.setThreadPool(httpThreadPool); String staticDir = azkabanSettings.getString("web.resource.dir", DEFAULT_STATIC_DIR); logger.info("Setting up web resource dir " + staticDir); Context root = new Context(server, "/", Context.SESSIONS); root.setMaxFormContentSize(MAX_FORM_CONTENT_SIZE); String defaultServletPath = azkabanSettings.getString("azkaban.default.servlet.path", "/index"); root.setResourceBase(staticDir); ServletHolder indexRedirect = new ServletHolder(new IndexRedirectServlet(defaultServletPath)); root.addServlet(indexRedirect, "/"); ServletHolder index = new ServletHolder(new ProjectServlet()); root.addServlet(index, "/index"); ServletHolder staticServlet = new ServletHolder(new DefaultServlet()); root.addServlet(staticServlet, "/css/*"); root.addServlet(staticServlet, "/js/*"); root.addServlet(staticServlet, "/images/*"); root.addServlet(staticServlet, "/fonts/*"); root.addServlet(staticServlet, "/favicon.ico"); root.addServlet(new ServletHolder(new ProjectManagerServlet()), "/manager"); root.addServlet(new ServletHolder(new ExecutorServlet()), "/executor"); root.addServlet(new ServletHolder(new HistoryServlet()), "/history"); root.addServlet(new ServletHolder(new ScheduleServlet()), "/schedule"); root.addServlet(new ServletHolder(new JMXHttpServlet()), "/jmx"); root.addServlet(new ServletHolder(new TriggerManagerServlet()), "/triggers"); root.addServlet(new ServletHolder(new StatsServlet()), "/stats"); root.addServlet(new ServletHolder(new AboutServlet()), "/about"); root.addServlet(new ServletHolder(new FileEditorServlet()), "/fileeditor"); ServletHolder restliHolder = new ServletHolder(new RestliServlet()); restliHolder.setInitParameter("resourcePackages", "azkaban.restli"); root.addServlet(restliHolder, "/restli/*"); String viewerPluginDir = azkabanSettings.getString("viewer.plugin.dir", "plugins/viewer"); loadViewerPlugins(root, viewerPluginDir, app.getVelocityEngine()); // triggerplugin String triggerPluginDir = azkabanSettings.getString("trigger.plugin.dir", "plugins/triggers"); Map<String, TriggerPlugin> triggerPlugins = loadTriggerPlugins(root, triggerPluginDir, app); app.setTriggerPlugins(triggerPlugins); // always have basic time trigger // TODO: find something else to do the job app.getTriggerManager().start(); root.setAttribute(ServerConstants.AZKABAN_SERVLET_CONTEXT_KEY, app); try { server.start(); } catch (Exception e) { logger.warn(e); Utils.croak(e.getMessage(), 1); } Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { try { logTopMemoryConsumers(); } catch (Exception e) { logger.info(("Exception when logging top memory consumers"), e); } logger.info("Shutting down http server..."); try { app.close(); server.stop(); server.destroy(); } catch (Exception e) { logger.error("Error while shutting down http server.", e); } logger.info("kk thx bye."); } public void logTopMemoryConsumers() throws Exception, IOException { if (new File("/bin/bash").exists() && new File("/bin/ps").exists() && new File("/usr/bin/head").exists()) { logger.info("logging top memeory consumer"); java.lang.ProcessBuilder processBuilder = new java.lang.ProcessBuilder("/bin/bash", "-c", "/bin/ps aux --sort -rss | /usr/bin/head"); Process p = processBuilder.start(); p.waitFor(); InputStream is = p.getInputStream(); java.io.BufferedReader reader = new java.io.BufferedReader(new InputStreamReader(is)); String line = null; while ((line = reader.readLine()) != null) { logger.info(line); } is.close(); } } }); logger.info("Server running on " + (ssl ? "ssl" : "") + " port " + port + "."); }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.documents.Step7CollectMTurkResults.java
public static void main(String[] args) throws Exception { // input dir - list of xml query containers // /home/user-ukp/research/data/dip/wp1-documents/step4-boiler-plate/ File inputDir = new File(args[0] + "/"); // MTurk result file // output dir File outputDir = new File(args[2]); if (!outputDir.exists()) { outputDir.mkdirs();//w w w.j av a2 s .com } // Folder with success files File mturkSuccessDir = new File(args[1]); Collection<File> files = FileUtils.listFiles(mturkSuccessDir, new String[] { "result" }, false); if (files.isEmpty()) { throw new IllegalArgumentException("Input folder is empty. " + mturkSuccessDir); } HashMap<String, List<MTurkAnnotation>> mturkAnnotations = new HashMap<>(); // parsing all CSV files for (File mturkCSVResultFile : files) { System.out.println("Parsing " + mturkCSVResultFile.getName()); MTurkOutputReader outputReader = new MTurkOutputReader( new HashSet<>(Arrays.asList("annotation", "workerid")), mturkCSVResultFile); // for fixing broken data input: for each hit, collect all sentence IDs Map<String, SortedSet<String>> hitSentences = new HashMap<>(); // first iteration: collect the sentences for (Map<String, String> record : outputReader) { String hitID = record.get("hitid"); if (!hitSentences.containsKey(hitID)) { hitSentences.put(hitID, new TreeSet<>()); } String relevantSentences = record.get("Answer.relevant_sentences"); String irrelevantSentences = record.get("Answer.irrelevant_sentences"); if (relevantSentences != null) { hitSentences.get(hitID).addAll(Arrays.asList(relevantSentences.split(","))); } if (irrelevantSentences != null) { hitSentences.get(hitID).addAll(Arrays.asList(irrelevantSentences.split(","))); } } // and now second iteration for (Map<String, String> record : outputReader) { String hitID = record.get("hitid"); String annotatorID = record.get("workerid"); String acceptTime = record.get("assignmentaccepttime"); String submitTime = record.get("assignmentsubmittime"); String relevantSentences = record.get("Answer.relevant_sentences"); String irrelevantSentences = record.get("Answer.irrelevant_sentences"); String reject = record.get("reject"); String filename[]; String comment; String clueWeb; String[] relevant = {}; String[] irrelevant = {}; filename = record.get("annotation").split("_"); String fileXml = filename[0]; clueWeb = filename[1].trim(); comment = record.get("Answer.comment"); if (relevantSentences != null) { relevant = relevantSentences.split(","); } if (irrelevantSentences != null) { irrelevant = irrelevantSentences.split(","); } // sanitizing data: if both relevant and irrelevant are empty, that's a bug // we're gonna look up all sentences from this HIT and treat this assignment // as if there were only irrelevant ones if (relevant.length == 0 && irrelevant.length == 0) { SortedSet<String> strings = hitSentences.get(hitID); irrelevant = new String[strings.size()]; strings.toArray(irrelevant); } if (reject != null) { System.out.println(" HIT " + hitID + " annotated by " + annotatorID + " was rejected "); } else { /* // relevant sentences is a comma-delimited string, // this regular expression is rather strange // it must contain digits, it might be that there is only one space or a comma or some other char // digits are the sentence ids. if relevant sentences do not contain digits then it is wrong if (relevantSentences.matches("^\\D*$") && irrelevantSentences.matches("^\\D*$")) { try { throw new IllegalStateException( "No annotations found for HIT " + hitID + " in " + fileXml + " for document " + clueWeb); } catch (IllegalStateException ex) { ex.printStackTrace(); } } */ MTurkAnnotation mturkAnnotation; try { mturkAnnotation = new MTurkAnnotation(hitID, annotatorID, acceptTime, submitTime, comment, clueWeb, relevant, irrelevant); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException("Record: " + record, ex); } List<MTurkAnnotation> listOfAnnotations = mturkAnnotations.get(fileXml); if (listOfAnnotations == null) { listOfAnnotations = new ArrayList<>(); } listOfAnnotations.add(mturkAnnotation); mturkAnnotations.put(fileXml, listOfAnnotations); } } // parser.close(); } // Debugging: output number of HITs of a query System.out.println("Accepted HITs for a query:"); for (Map.Entry e : mturkAnnotations.entrySet()) { ArrayList<MTurkAnnotation> a = (ArrayList<MTurkAnnotation>) e.getValue(); System.out.println(e.getKey() + " " + a.size()); } for (File f : FileUtils.listFiles(inputDir, new String[] { "xml" }, false)) { QueryResultContainer queryResultContainer = QueryResultContainer .fromXML(FileUtils.readFileToString(f, "utf-8")); String fileName = f.getName(); List<MTurkAnnotation> listOfAnnotations = mturkAnnotations.get(fileName); if (listOfAnnotations == null || listOfAnnotations.isEmpty()) { throw new IllegalStateException("No annotations for " + f.getName()); } for (QueryResultContainer.SingleRankedResult rankedResults : queryResultContainer.rankedResults) { for (MTurkAnnotation mtAnnotation : listOfAnnotations) { String clueWeb = mtAnnotation.clueWeb; if (rankedResults.clueWebID.equals(clueWeb)) { List<QueryResultContainer.MTurkRelevanceVote> mTurkRelevanceVotes = rankedResults.mTurkRelevanceVotes; QueryResultContainer.MTurkRelevanceVote relevanceVote = new QueryResultContainer.MTurkRelevanceVote(); String annotatorID = mtAnnotation.annotatorID; String hitID = mtAnnotation.hitID; String acceptTime = mtAnnotation.acceptTime; String submitTime = mtAnnotation.submitTime; String comment = mtAnnotation.comment; String[] relevant = mtAnnotation.relevant; String[] irrelevant = mtAnnotation.irrelevant; relevanceVote.turkID = annotatorID.trim(); relevanceVote.hitID = hitID.trim(); relevanceVote.acceptTime = acceptTime.trim(); relevanceVote.submitTime = submitTime.trim(); relevanceVote.comment = comment != null ? comment.trim() : null; if (relevant.length == 0 && irrelevant.length == 0) { try { throw new IllegalStateException("the length of the annotations is 0" + rankedResults.clueWebID + " for HIT " + relevanceVote.hitID); } catch (IllegalStateException e) { e.printStackTrace(); } } for (String r : relevant) { String sentenceId = r.trim(); if (!sentenceId.isEmpty() && sentenceId.matches("\\d+")) { QueryResultContainer.SingleSentenceRelevanceVote singleSentenceVote = new QueryResultContainer.SingleSentenceRelevanceVote(); singleSentenceVote.sentenceID = sentenceId; singleSentenceVote.relevant = "true"; relevanceVote.singleSentenceRelevanceVotes.add(singleSentenceVote); } } for (String r : irrelevant) { String sentenceId = r.trim(); if (!sentenceId.isEmpty() && sentenceId.matches("\\d+")) { QueryResultContainer.SingleSentenceRelevanceVote singleSentenceVote = new QueryResultContainer.SingleSentenceRelevanceVote(); singleSentenceVote.sentenceID = sentenceId; singleSentenceVote.relevant = "false"; relevanceVote.singleSentenceRelevanceVotes.add(singleSentenceVote); } } mTurkRelevanceVotes.add(relevanceVote); } } } File outputFile = new File(outputDir, f.getName()); FileUtils.writeStringToFile(outputFile, queryResultContainer.toXML(), "utf-8"); System.out.println("Finished " + outputFile); } }