List of usage examples for java.io StringWriter toString
public String toString()
From source file:org.apache.flink.benchmark.Runner.java
public static void main(String[] args) throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); env.getConfig().enableObjectReuse(); env.getConfig().disableSysoutLogging(); ParameterTool parameters = ParameterTool.fromArgs(args); if (!(parameters.has("p") && parameters.has("types") && parameters.has("algorithms"))) { printUsage();//from ww w .j a va 2s.co m System.exit(-1); } int parallelism = parameters.getInt("p"); env.setParallelism(parallelism); Set<IdType> types = new HashSet<>(); if (parameters.get("types").equals("all")) { types.add(IdType.INT); types.add(IdType.LONG); types.add(IdType.STRING); } else { for (String type : parameters.get("types").split(",")) { if (type.toLowerCase().equals("int")) { types.add(IdType.INT); } else if (type.toLowerCase().equals("long")) { types.add(IdType.LONG); } else if (type.toLowerCase().equals("string")) { types.add(IdType.STRING); } else { printUsage(); throw new RuntimeException("Unknown type: " + type); } } } Queue<RunnerWithScore> queue = new PriorityQueue<>(); if (parameters.get("algorithms").equals("all")) { for (Map.Entry<String, Class> entry : AVAILABLE_ALGORITHMS.entrySet()) { for (IdType type : types) { AlgorithmRunner runner = (AlgorithmRunner) entry.getValue().newInstance(); runner.initialize(type, SAMPLES, parallelism); runner.warmup(env); queue.add(new RunnerWithScore(runner, 1.0)); } } } else { for (String algorithm : parameters.get("algorithms").split(",")) { double ratio = 1.0; if (algorithm.contains("=")) { String[] split = algorithm.split("="); algorithm = split[0]; ratio = Double.parseDouble(split[1]); } if (AVAILABLE_ALGORITHMS.containsKey(algorithm.toLowerCase())) { Class clazz = AVAILABLE_ALGORITHMS.get(algorithm.toLowerCase()); for (IdType type : types) { AlgorithmRunner runner = (AlgorithmRunner) clazz.newInstance(); runner.initialize(type, SAMPLES, parallelism); runner.warmup(env); queue.add(new RunnerWithScore(runner, ratio)); } } else { printUsage(); throw new RuntimeException("Unknown algorithm: " + algorithm); } } } JsonFactory factory = new JsonFactory(); while (queue.size() > 0) { RunnerWithScore current = queue.poll(); AlgorithmRunner runner = current.getRunner(); StringWriter writer = new StringWriter(); JsonGenerator gen = factory.createGenerator(writer); gen.writeStartObject(); gen.writeStringField("algorithm", runner.getClass().getSimpleName()); boolean running = true; while (running) { try { runner.run(env, gen); running = false; } catch (ProgramInvocationException e) { // only suppress job cancellations if (!(e.getCause() instanceof JobCancellationException)) { throw e; } } } JobExecutionResult result = env.getLastJobExecutionResult(); long runtime_ms = result.getNetRuntime(); gen.writeNumberField("runtime_ms", runtime_ms); current.credit(runtime_ms); if (!runner.finished()) { queue.add(current); } gen.writeObjectFieldStart("accumulators"); for (Map.Entry<String, Object> accumulatorResult : result.getAllAccumulatorResults().entrySet()) { gen.writeStringField(accumulatorResult.getKey(), accumulatorResult.getValue().toString()); } gen.writeEndObject(); gen.writeEndObject(); gen.close(); System.out.println(writer.toString()); } }
From source file:edu.ucsd.crbs.cws.App.java
License:asdf
public static void main(String[] args) { Job.REFS_ENABLED = false;//w w w . ja v a 2 s . c o m Workflow.REFS_ENABLED = false; try { OptionParser parser = new OptionParser() { { accepts(UPLOAD_WF_ARG, "Add/Update Workflow").withRequiredArg().ofType(File.class) .describedAs("Kepler .kar file"); //accepts(LOAD_TEST,"creates lots of workflows and jobs"); accepts(SYNC_WITH_CLUSTER_ARG, "Submits & Synchronizes Workflow Jobs on local cluster with CRBS Workflow Webservice. Requires --" + PROJECT_ARG + " --" + PORTALNAME_ARG + " --" + PORTAL_URL_ARG + " --" + HELP_EMAIL_ARG).withRequiredArg().ofType(String.class).describedAs("URL"); accepts(GEN_OLD_KEPLER_XML_ARG, "Generates version 1.x kepler xml for given workflow") .withRequiredArg().ofType(String.class).describedAs("wfid or .kar file"); accepts(UPLOAD_FILE_ARG, "Registers and uploads Workspace file to REST service") .withRequiredArg().ofType(File.class); accepts(REGISTER_FILE_ARG, "Registers Workspace file to REST service (DOES NOT UPLOAD FILE TO REST SERVICE)") .withRequiredArg().ofType(File.class); accepts(GET_WORKSPACE_FILE_INFO_ARG, "Outputs JSON of specified workspace file(s)") .withRequiredArg().ofType(String.class).describedAs("workspace file id"); accepts(GET_WORKFLOW_ARG, "Outputs JSON of specified Workflow").withRequiredArg() .ofType(Long.class).describedAs("Workflow Id"); accepts(DOWNLOAD_FILE_ARG, "Downloads Workspace file").withRequiredArg().ofType(String.class) .describedAs("workspace file id"); accepts(UPDATE_PATH_ARG, "Updates Workspace file path").withRequiredArg().ofType(String.class) .describedAs("workspace file id"); accepts(PATH_ARG, "Sets WorkspaceFile file path. Used in coordination with --" + UPDATE_PATH_ARG) .withRequiredArg().ofType(String.class).describedAs("file path"); accepts(URL_ARG, "URL to use with --" + UPLOAD_WF_ARG + ", --" + UPLOAD_FILE_ARG + ", --" + GET_WORKSPACE_FILE_INFO_ARG + " flags").withRequiredArg().ofType(String.class) .describedAs("URL"); accepts(EXAMPLE_JSON_ARG, "Outputs example JSON of Job, User, Workflow, and WorkspaceFile objects"); accepts(WF_EXEC_DIR_ARG, "Workflow Execution Directory").withRequiredArg().ofType(File.class) .describedAs("Directory"); accepts(WF_DIR_ARG, "Workflows Directory").withRequiredArg().ofType(File.class) .describedAs("Directory"); accepts(KEPLER_SCRIPT_ARG, "Kepler").withRequiredArg().ofType(File.class).describedAs("Script"); accepts(QUEUE_ARG, "SGE Queue").withRequiredArg().ofType(String.class).describedAs("Queue"); accepts(CAST_ARG, "Panfishcast binary").withRequiredArg().ofType(File.class) .describedAs("panfishcast"); accepts(STAT_ARG, "Panfishstat binary").withRequiredArg().ofType(File.class) .describedAs("panfishstat"); accepts(LOGIN_ARG, "User Login").withRequiredArg().ofType(String.class).describedAs("username"); accepts(TOKEN_ARG, "User Token").withRequiredArg().ofType(String.class).describedAs("token"); accepts(RUN_AS_ARG, "User to run as (for power accounts that can run as other users)") .withRequiredArg().ofType(String.class).describedAs("runas"); accepts(OWNER_ARG, "Sets owner when creating Workspace file and Workflow").withRequiredArg() .ofType(String.class).describedAs("username"); accepts(JOB_ID_ARG, "Sets source job id for Workspace file when used with --" + UPLOAD_FILE_ARG + " and --" + REGISTER_FILE_ARG).withRequiredArg().ofType(Long.class) .describedAs("Job Id"); accepts(MD5_ARG, "Sets md5 for Workspace file when used with --" + UPLOAD_FILE_ARG + " and --" + REGISTER_FILE_ARG).withRequiredArg().ofType(String.class) .describedAs("MD5 message digest"); accepts(SIZE_ARG, "Sets size in bytes for Workspace file when used with --" + UPLOAD_FILE_ARG + " and --" + REGISTER_FILE_ARG).withRequiredArg().ofType(Long.class) .describedAs("Size of file/dir in bytes"); accepts(RESAVE_WORKSPACEFILE_ARG, "Resaves Workspace file").withRequiredArg().ofType(Long.class) .describedAs("WorkspaceFile Id or -1 to resave all"); accepts(RESAVE_JOB_ARG, "Resaves Job").withRequiredArg().ofType(Long.class) .describedAs("Job Id or -1 to resave all"); accepts(RESAVE_WORKFLOW_ARG, "Resaves Workflow").withRequiredArg().ofType(Long.class) .describedAs("Workflow Id or -1 to resave all"); accepts(PREVIEW_WORKFLOW_ARG, "Preview Workflow on Web, requires --" + URL_ARG + " currently it should be: http://imafish.dynamic.ucsd.edu/cws/makepreview") .withRequiredArg().ofType(File.class).describedAs("Kepler .kar file"); accepts(DESCRIPTION_ARG, "Description for WorkspaceFile").withRequiredArg() .ofType(String.class); accepts(TYPE_ARG, "Type of WorkspaceFile").withRequiredArg().ofType(String.class); accepts(NAME_ARG, "Sets name for Workspace file when used with --" + UPLOAD_FILE_ARG + " and --" + REGISTER_FILE_ARG).withRequiredArg().ofType(String.class) .describedAs("WorkspaceFile name"); accepts(REGISTER_JAR_ARG, "Path to Jar to register WorkspaceFiles").withRequiredArg() .ofType(File.class).describedAs("Path to this jar"); accepts(GET_JOB_ARG, "Gets job from service in JSON format, requires --" + URL_ARG) .withRequiredArg().ofType(Long.class).describedAs("Job Id"); accepts(GET_WORKSPACE_FILE_ARG, "Gets WorkspaceFile from service in JSON format, requires --" + URL_ARG) .withRequiredArg().ofType(Long.class) .describedAs("WorkspaceFile Id or -1 for all"); accepts(PROJECT_ARG, "Project name ie CRBS. Used with --" + SYNC_WITH_CLUSTER_ARG) .withRequiredArg().ofType(String.class); accepts(PORTALNAME_ARG, "Portal name ie SLASH portal Used with --" + SYNC_WITH_CLUSTER_ARG) .withRequiredArg().ofType(String.class); accepts(PORTAL_URL_ARG, "Portal url ie http://slashsegmentation.com Used with --" + SYNC_WITH_CLUSTER_ARG) .withRequiredArg().ofType(String.class); accepts(HELP_EMAIL_ARG, "Help and reply to email address Used with --" + SYNC_WITH_CLUSTER_ARG) .withRequiredArg().ofType(String.class); accepts(BCC_EMAIL_ARG, "Blind Carbon copy email address Used with --" + SYNC_WITH_CLUSTER_ARG) .withRequiredArg().ofType(String.class); accepts(WORKSPACE_FILE_FAILED_ARG, "Denotes whether workspacefile failed (true) or not (false). Used with --" + UPDATE_PATH_ARG).withRequiredArg().ofType(Boolean.class) .describedAs("false = success and true = failed"); accepts(ERROR_EMAIL_ARG, "Email to receive notifications if errors are encountered. Used with --" + SYNC_WITH_CLUSTER_ARG).withRequiredArg().ofType(String.class); accepts(HELP_ARG).forHelp(); } }; OptionSet optionSet = null; try { optionSet = parser.parse(args); } catch (OptionException oe) { System.err.println("\nThere was an error parsing arguments: " + oe.getMessage() + "\n\n"); parser.printHelpOn(System.err); System.exit(1); } if (optionSet.has(HELP_ARG) || (!optionSet.has(SYNC_WITH_CLUSTER_ARG) && !optionSet.has(UPLOAD_WF_ARG)) && !optionSet.has(EXAMPLE_JSON_ARG) && !optionSet.has(UPLOAD_FILE_ARG) && !optionSet.has(GET_WORKSPACE_FILE_INFO_ARG) && !optionSet.has(UPDATE_PATH_ARG) && !optionSet.has(REGISTER_FILE_ARG) && !optionSet.has(RESAVE_WORKSPACEFILE_ARG) && !optionSet.has(RESAVE_JOB_ARG) && !optionSet.has(RESAVE_WORKFLOW_ARG) && !optionSet.has(PREVIEW_WORKFLOW_ARG) && !optionSet.has(GEN_OLD_KEPLER_XML_ARG) && !optionSet.has(GET_JOB_ARG) && !optionSet.has(GET_WORKSPACE_FILE_ARG) && !optionSet.has(GET_WORKFLOW_ARG)) { System.out.println(PROGRAM_HELP + "\n"); parser.printHelpOn(System.out); System.exit(0); } if (optionSet.has(EXAMPLE_JSON_ARG)) { renderExampleWorkflowsAndTasksAsJson(); System.exit(0); } if (optionSet.has(GET_JOB_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + GET_JOB_ARG + " flag"); getJobAsJson(optionSet); System.exit(0); } if (optionSet.has(GET_WORKSPACE_FILE_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + GET_WORKSPACE_FILE_ARG + " flag"); getWorkspaceFileAsJson(optionSet); System.exit(0); } if (optionSet.has(GET_WORKFLOW_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + GET_WORKFLOW_ARG + " flag"); getWorkflowAsJson(optionSet); System.exit(0); } MultivaluedMapFactory multivaluedMapFactory = new MultivaluedMapFactoryImpl(); if (optionSet.has(GEN_OLD_KEPLER_XML_ARG)) { String workflowFileOrId = (String) optionSet.valueOf(GEN_OLD_KEPLER_XML_ARG); File workflowFile = new File(workflowFileOrId); Workflow w = null; //if value is a file attempt to load it as a workflow file if (workflowFile.exists() && workflowFile.isFile()) { w = getWorkflowFromFile(workflowFile); if (w == null) { throw new Exception("Unable to extract workflow from file: " + workflowFile); } } else { //assume the value is a workflow id and get it from the service //but fail if url is missing failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + GEN_OLD_KEPLER_XML_ARG + " flag"); User u = getUserFromOptionSet(optionSet); WorkflowRestDAOImpl workflowDAO = new WorkflowRestDAOImpl(); workflowDAO.setRestURL((String) optionSet.valueOf(URL_ARG)); workflowDAO.setUser(u); w = workflowDAO.getWorkflowById(workflowFileOrId, u); if (w == null) { throw new Exception("Unable to extract workflow from id: " + workflowFileOrId); } } VersionOneWorkflowXmlWriter xmlWriter = new VersionOneWorkflowXmlWriter(); StringWriter sw = new StringWriter(); xmlWriter.write(sw, w); System.out.println(sw.toString()); System.exit(0); } if (optionSet.has(PREVIEW_WORKFLOW_ARG)) { failIfOptionSetMissingURL(optionSet, "--" + PREVIEW_WORKFLOW_ARG + " flag"); File workflowFile = (File) optionSet.valueOf(PREVIEW_WORKFLOW_ARG); Workflow w = getWorkflowFromFile(workflowFile); if (w == null) { throw new Exception("Unable to extract workflow from file"); } uploadPreviewWorkflowFile((String) optionSet.valueOf(URL_ARG), w); System.exit(0); } if (optionSet.has(REGISTER_FILE_ARG)) { addNewWorkspaceFile(optionSet, false, REGISTER_FILE_ARG); System.exit(0); } if (optionSet.has(RESAVE_WORKSPACEFILE_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + RESAVE_WORKSPACEFILE_ARG + " flag"); WorkspaceFileRestDAOImpl workspaceFileDAO = new WorkspaceFileRestDAOImpl(); User u = getUserFromOptionSet(optionSet); workspaceFileDAO.setUser(u); workspaceFileDAO.setRestURL((String) optionSet.valueOf(URL_ARG)); Long workspaceId = (Long) optionSet.valueOf(RESAVE_WORKSPACEFILE_ARG); if (workspaceId == -1) { System.out.println("Resaving all workspace files"); List<WorkspaceFile> wsfList = workspaceFileDAO.getWorkspaceFiles(null, null, null, null, null); if (wsfList != null) { System.out.println("Found " + wsfList.size() + " workspace files to resave"); for (WorkspaceFile wsf : wsfList) { System.out.println("WorkspaceFile Id: " + wsf.getId()); workspaceFileDAO.resave(wsf.getId()); } } } else { workspaceFileDAO.resave(workspaceId); } System.exit(0); } if (optionSet.has(RESAVE_JOB_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + RESAVE_JOB_ARG + " flag"); JobRestDAOImpl jobDAO = new JobRestDAOImpl(); User u = getUserFromOptionSet(optionSet); jobDAO.setUser(u); jobDAO.setRestURL((String) optionSet.valueOf(URL_ARG)); Long jobId = (Long) optionSet.valueOf(RESAVE_JOB_ARG); if (jobId == -1) { System.out.println("Resaving all jobs"); List<Job> jobList = jobDAO.getJobs(null, null, null, true, true, Boolean.TRUE); if (jobList != null) { System.out.println("Found " + jobList.size() + " jobs to resave"); for (Job j : jobList) { System.out.println("job id: " + j.getId()); jobDAO.resave(j.getId()); } } } else { jobDAO.resave(jobId); } System.exit(0); } if (optionSet.has(RESAVE_WORKFLOW_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + RESAVE_WORKFLOW_ARG + " flag"); WorkflowRestDAOImpl workflowDAO = new WorkflowRestDAOImpl(); User u = getUserFromOptionSet(optionSet); workflowDAO.setUser(u); workflowDAO.setRestURL((String) optionSet.valueOf(URL_ARG)); Long workflowId = (Long) optionSet.valueOf(RESAVE_WORKFLOW_ARG); if (workflowId == -1) { System.out.println("Resaving all workflows"); List<Workflow> workflowList = workflowDAO.getAllWorkflows(true, Boolean.TRUE); if (workflowList != null) { System.out.println("Found " + workflowList.size() + " workflow(s) to resave"); for (Workflow w : workflowList) { System.out.println("workflow id: " + w.getId()); workflowDAO.resave(w.getId()); } } } else { workflowDAO.resave(workflowId); } System.exit(0); } if (optionSet.has(UPDATE_PATH_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + UPDATE_PATH_ARG + " flag"); User u = getUserFromOptionSet(optionSet); String workspaceId = (String) optionSet.valueOf(UPDATE_PATH_ARG); String path = null; if (optionSet.has(PATH_ARG)) { path = (String) optionSet.valueOf(PATH_ARG); } String size = null; if (optionSet.has(SIZE_ARG)) { size = ((Long) optionSet.valueOf(SIZE_ARG)).toString(); } if (optionSet.has(MD5_ARG)) { //wsp.setMd5((String)optionSet.valueOf(MD5_ARG)); } Boolean isFailed = null; if (optionSet.has(WORKSPACE_FILE_FAILED_ARG)) { isFailed = (Boolean) optionSet.valueOf(WORKSPACE_FILE_FAILED_ARG); } WorkspaceFileRestDAOImpl workspaceFileDAO = new WorkspaceFileRestDAOImpl(); workspaceFileDAO.setUser(u); workspaceFileDAO.setRestURL((String) optionSet.valueOf(URL_ARG)); workspaceFileDAO.updatePathSizeAndFailStatus(Long.parseLong(workspaceId), path, size, isFailed); System.exit(0); } if (optionSet.has(SYNC_WITH_CLUSTER_ARG)) { // @TODO NEED TO MAKE JOPT DO THIS REQUIRED FLAG CHECKING STUFF if (!optionSet.has(WF_EXEC_DIR_ARG)) { System.err.println( "-" + WF_EXEC_DIR_ARG + " is required with -" + SYNC_WITH_CLUSTER_ARG + " flag"); System.exit(2); } if (!optionSet.has(WF_DIR_ARG)) { System.err.println("-" + WF_DIR_ARG + " is required with -" + SYNC_WITH_CLUSTER_ARG + " flag"); System.exit(3); } if (!optionSet.has(KEPLER_SCRIPT_ARG)) { System.err.println( "-" + KEPLER_SCRIPT_ARG + " is required with -" + SYNC_WITH_CLUSTER_ARG + " flag"); System.exit(4); } if (!optionSet.has(CAST_ARG)) { System.err.println("-" + CAST_ARG + " is required with -" + SYNC_WITH_CLUSTER_ARG + " flag"); System.exit(5); } if (!optionSet.has(STAT_ARG)) { System.err.println("-" + STAT_ARG + " is required with -" + SYNC_WITH_CLUSTER_ARG + " flag"); System.exit(6); } if (!optionSet.has(QUEUE_ARG)) { System.err.println("-" + QUEUE_ARG + " is required with -" + SYNC_WITH_CLUSTER_ARG + " flag"); System.exit(7); } if (!optionSet.has(REGISTER_JAR_ARG)) { System.err.println( "-" + REGISTER_JAR_ARG + " is required with -" + SYNC_WITH_CLUSTER_ARG + " flag"); System.exit(8); } failIfOptionSetMissingLoginOrToken(optionSet, "--" + SYNC_WITH_CLUSTER_ARG + " flag"); File castFile = (File) optionSet.valueOf(CAST_ARG); String castPath = castFile.getAbsolutePath(); File statFile = (File) optionSet.valueOf(STAT_ARG); String statPath = statFile.getAbsolutePath(); String queue = (String) optionSet.valueOf(QUEUE_ARG); File wfExecDir = (File) optionSet.valueOf(WF_EXEC_DIR_ARG); File wfDir = (File) optionSet.valueOf(WF_DIR_ARG); File keplerScript = (File) optionSet.valueOf(KEPLER_SCRIPT_ARG); String registerJar = null; if (optionSet.has(REGISTER_JAR_ARG)) { File registerJarFile = (File) optionSet.valueOf(REGISTER_JAR_ARG); registerJar = registerJarFile.getAbsolutePath(); } JobEmailNotificationData emailNotifyData = getJobEmailNotificationData(optionSet); User u = getUserFromOptionSet(optionSet); ObjectifyService.ofy(); String url = (String) optionSet.valueOf(SYNC_WITH_CLUSTER_ARG); JobRestDAOImpl jobDAO = new JobRestDAOImpl(); jobDAO.setRestURL(url); jobDAO.setUser(u); System.out.println("Running sync with cluster"); WorkspaceFileRestDAOImpl workspaceFileDAO = new WorkspaceFileRestDAOImpl(); workspaceFileDAO.setRestURL(url); workspaceFileDAO.setUser(u); JobPath jobPath = new JobPathImpl(wfExecDir.getAbsolutePath()); WorkspaceFilePathSetterImpl pathSetter = new WorkspaceFilePathSetterImpl(workspaceFileDAO); // Submit jobs to scheduler JobSubmissionManager submitter = new JobSubmissionManager(jobDAO, workspaceFileDAO, pathSetter, jobPath, wfDir.getAbsolutePath(), keplerScript.getAbsolutePath(), castPath, queue, u, url, registerJar, emailNotifyData); submitter.submitJobs(); // Update job status for all jobs in system MapOfJobStatusFactoryImpl jobStatusFactory = new MapOfJobStatusFactoryImpl(statPath); WorkflowFailedParser workflowFailedParser = new WorkflowFailedParserImpl(); JobStatusUpdater updater = new JobStatusUpdater(jobDAO, jobStatusFactory, workflowFailedParser, jobPath); updater.updateJobs(); System.exit(0); } if (optionSet.has(App.GET_WORKSPACE_FILE_INFO_ARG)) { failIfOptionSetMissingURLOrLoginOrToken(optionSet, "--" + GET_WORKSPACE_FILE_INFO_ARG + " flag"); WorkspaceFileRestDAOImpl workspaceFileDAO = new WorkspaceFileRestDAOImpl(); workspaceFileDAO.setRestURL((String) optionSet.valueOf(URL_ARG)); List<WorkspaceFile> wsFiles = workspaceFileDAO .getWorkspaceFilesById((String) optionSet.valueOf(GET_WORKSPACE_FILE_INFO_ARG), null); if (wsFiles != null) { ObjectMapper om = new ObjectMapper(); ObjectWriter ow = om.writerWithDefaultPrettyPrinter(); System.out.print("["); boolean first = true; for (WorkspaceFile wsf : wsFiles) { if (first == false) { System.out.println(","); } else { first = false; } System.out.print(ow.writeValueAsString(wsf)); } System.out.println("]"); } else { System.err.println("[]"); } System.exit(0); } if (optionSet.has(UPLOAD_FILE_ARG)) { addNewWorkspaceFile(optionSet, true, UPLOAD_FILE_ARG); System.exit(0); } if (optionSet.has(UPLOAD_WF_ARG)) { Long parentWfId = null; String postURL = null; if (optionSet.has(URL_ARG)) { postURL = (String) optionSet.valueOf(URL_ARG); failIfOptionSetMissingLoginOrToken(optionSet, "--" + UPLOAD_WF_ARG + " and --" + URL_ARG + " flag"); } File workflowFile = (File) optionSet.valueOf(UPLOAD_WF_ARG); Workflow w = getWorkflowFromFile(workflowFile); if (w != null) { if (optionSet.has(OWNER_ARG)) { w.setOwner((String) optionSet.valueOf(OWNER_ARG)); } ObjectMapper om = new ObjectMapper(); if (parentWfId != null) { w.setId(parentWfId); } if (postURL == null) { System.out.println("\n--- JSON Representation of Workflow ---"); ObjectWriter ow = om.writerWithDefaultPrettyPrinter(); System.out.println(ow.writeValueAsString(w)); System.out.flush(); System.out.println("---------------------------------------"); } else { postURL = new StringBuilder().append(postURL).append(Constants.SLASH) .append(Constants.REST_PATH).append(Constants.SLASH) .append(Constants.WORKFLOWS_PATH).toString(); ClientConfig cc = new DefaultClientConfig(); cc.getClasses().add(StringProvider.class); cc.getClasses().add(MultiPartWriter.class); Client client = Client.create(cc); client.setFollowRedirects(true); WebResource resource = client.resource(postURL); String workflowAsJson = om.writeValueAsString(w); User u = getUserFromOptionSet(optionSet); client.addFilter(new HTTPBasicAuthFilter(u.getLogin(), u.getToken())); MultivaluedMap queryParams = multivaluedMapFactory.getMultivaluedMap(u); String response = resource.queryParams(queryParams).type(MediaType.APPLICATION_JSON_TYPE) .entity(workflowAsJson).post(String.class); Workflow workflowRes = om.readValue(response, Workflow.class); ObjectWriter ow = om.writerWithDefaultPrettyPrinter(); if (workflowRes.getWorkflowFileUploadURL() == null) { throw new Exception( "No upload url found for workflow!!!" + ow.writeValueAsString(workflowRes)); } uploadWorkflowFile(workflowRes, workflowFile); } } } } catch (Exception ex) { ex.printStackTrace(); System.err.println("Caught Exception: " + ex.getMessage()); System.exit(2); } System.exit(0); }
From source file:com.jayway.restassured.itest.java.support.RequestPathFromLogExtractor.java
public static String loggedRequestPathIn(StringWriter writer) { return StringUtils.substringBetween(writer.toString(), "Request path:", "\n").trim(); }
From source file:io.restassured.itest.java.support.RequestPathFromLogExtractor.java
public static String loggedRequestPathIn(StringWriter writer) { return StringUtils.substringBetween(writer.toString(), "Request URI:", "\n").trim(); }
From source file:Main.java
public static String bean2XML(Object obj) throws Exception { JAXBContext context = JAXBContext.newInstance(obj.getClass()); Marshaller m = context.createMarshaller(); StringWriter sw = new StringWriter(); m.marshal(obj, sw);// ww w. j ava 2 s .c om return sw.toString(); }
From source file:Main.java
public static String getExceptionStackTrace(Exception e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); return sw.toString(); }
From source file:Main.java
public static String saveObjectToXmlString(Object obj) throws JAXBException { final Marshaller m = JAXBContext.newInstance(obj.getClass()).createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); final StringWriter writer = new StringWriter(); m.marshal(obj, writer);//from ww w . ja v a 2 s . c om return writer.toString(); }
From source file:org.pathirage.freshet.utils.ExpressionSerde.java
public static String serialize(Expression expression) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); StringWriter sw = new StringWriter(); objectMapper.writeValue(sw, expression); return sw.toString(); }
From source file:Main.java
public static <T> String toXml(T object) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter writer = new StringWriter(); marshaller.marshal(object, writer);/*from ww w. j a v a 2 s. c o m*/ return writer.toString(); }
From source file:Main.java
/** * Get the Stack trace from throwable instance. * * @param t Exception to be print.//from w w w. java 2s . c om * @return String formed stack Trace. */ public static String getStack(Throwable t) { if (t == null) return null; StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); return sw.toString(); }