io.javalin.Context Java Examples
The following examples show how to use
io.javalin.Context.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllAggregatedReportsController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { List<Report> reports = reportDao.fetchAllAggregated(); context.json(reports); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #2
Source File: ReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("id")); Report report = reportDao.fetch(id); if (report != null) { context.json(report); } else { context.status(404); } } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #3
Source File: LatencyStatisticsReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("id")); Report report = reportDao.fetch(id); LatencyStatisticsResponse response = new LatencyStatisticsResponse(); processReports(report, response); context.json(response); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #4
Source File: AggregatedLatencyStatisticsReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int testId = Integer.parseInt(context.param("id")); int testNumber = Integer.parseInt(context.param("number")); Report report = reportDao.fetchAggregated(testId, testNumber); LatencyStatisticsResponse response = new LatencyStatisticsResponse(); processReports(report, response); context.json(response); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #5
Source File: RateReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("id")); Report report = reportDao.fetch(id); SingleData<Long> rateData = processReport(report, report.getTestHostRole()); RateResponse rateResponse = new RateResponse(); rateResponse.setPeriods(rateData.getPeriods()); rateResponse.setRate(rateData.getValues()); context.json(rateResponse); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #6
Source File: AggregatedLatencyReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int testId = Integer.parseInt( Objects.requireNonNull(context.param("id"), "The ID must be provided")); int testNumber = Integer.parseInt( Objects.requireNonNull(context.param("number"), "The test number must be provided")); Report report = reportDao.fetchAggregated(testId, testNumber); LatencyResponse response = new LatencyResponse(); processReports(report, response); context.json(response); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #7
Source File: RateStatisticsReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("id")); Report report = reportDao.fetch(id); SingleData<Long> rateData = processReport(report, report.getTestHostRole()); RateStatisticsResponse rateResponse = new RateStatisticsResponse(); rateResponse.addStatistics(rateData.getStatistics()); context.json(rateResponse); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #8
Source File: LatencyReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("id")); Report report = reportDao.fetch(id); LatencyResponse response = new LatencyResponse(); processReports(report, response); context.json(response); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #9
Source File: AggregatedRateStatisticsReportController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int testId = Integer.parseInt(context.param("id")); int testNumber = Integer.parseInt(context.param("number")); String hostRole = context.param("role"); Report report = reportDao.fetchAggregated(testId, testNumber); SingleData<Long> rateData = processReport(report, hostRole); RateStatisticsResponse rateResponse = new RateStatisticsResponse(); rateResponse.addStatistics(rateData.getStatistics()); context.json(rateResponse); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #10
Source File: SutNodeInfoController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int testId = Integer.parseInt(context.param("test")); List<SutNodeInfo> sutNodeInfo = dao.fetchByTest(testId); context.json(sutNodeInfo); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #11
Source File: RawFileController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("id")); String name = context.param("name"); Report report = reportDao.fetch(id); File file = getReportFile(report, name); context.result(new FileInputStream(file)) .header("Content-Length: ", String.valueOf(FileUtils.sizeOf(file))) .header("Content-Type", "application/octet-stream"); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #12
Source File: AllReportsController.java From maestro-java with Apache License 2.0 | 6 votes |
@Override public void handle(Context context) { try { List<Report> reports = reportDao.fetch(); context.json(reports); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #13
Source File: FileSystemViewHandler.java From hudi with Apache License 2.0 | 6 votes |
/** * Syncs data-set view if local view is behind. */ private boolean syncIfLocalViewBehind(Context ctx) { if (isLocalViewBehind(ctx)) { String basePath = ctx.queryParam(RemoteHoodieTableFileSystemView.BASEPATH_PARAM); String lastKnownInstantFromClient = ctx.queryParam(RemoteHoodieTableFileSystemView.LAST_INSTANT_TS, HoodieTimeline.INVALID_INSTANT_TS); SyncableFileSystemView view = viewManager.getFileSystemView(basePath); synchronized (view) { if (isLocalViewBehind(ctx)) { HoodieTimeline localTimeline = viewManager.getFileSystemView(basePath).getTimeline(); LOG.info("Syncing view as client passed last known instant " + lastKnownInstantFromClient + " as last known instant but server has the folling timeline :" + localTimeline.getInstants().collect(Collectors.toList())); view.sync(); return true; } } } return false; }
Example #14
Source File: FileSystemViewHandler.java From hudi with Apache License 2.0 | 6 votes |
/** * Determines if local view of table's timeline is behind that of client's view. */ private boolean isLocalViewBehind(Context ctx) { String basePath = ctx.queryParam(RemoteHoodieTableFileSystemView.BASEPATH_PARAM); String lastKnownInstantFromClient = ctx.queryParam(RemoteHoodieTableFileSystemView.LAST_INSTANT_TS, HoodieTimeline.INVALID_INSTANT_TS); String timelineHashFromClient = ctx.queryParam(RemoteHoodieTableFileSystemView.TIMELINE_HASH, ""); HoodieTimeline localTimeline = viewManager.getFileSystemView(basePath).getTimeline().filterCompletedAndCompactionInstants(); if (LOG.isDebugEnabled()) { LOG.debug("Client [ LastTs=" + lastKnownInstantFromClient + ", TimelineHash=" + timelineHashFromClient + "], localTimeline=" + localTimeline.getInstants().collect(Collectors.toList())); } if ((localTimeline.getInstants().count() == 0) && HoodieTimeline.INVALID_INSTANT_TS.equals(lastKnownInstantFromClient)) { return false; } String localTimelineHash = localTimeline.getTimelineHash(); if (!localTimelineHash.equals(timelineHashFromClient)) { return true; } // As a safety check, even if hash is same, ensure instant is present return !localTimeline.containsOrBeforeTimelineStarts(lastKnownInstantFromClient); }
Example #15
Source File: WorkerHandler.java From openmessaging-benchmark with Apache License 2.0 | 6 votes |
private void handleCumulativeLatencies(Context ctx) throws Exception { CumulativeLatencies stats = localWorker.getCumulativeLatencies(); // Serialize histograms synchronized (histogramSerializationBuffer) { histogramSerializationBuffer.clear(); stats.publishLatency.encodeIntoCompressedByteBuffer(histogramSerializationBuffer); stats.publishLatencyBytes = new byte[histogramSerializationBuffer.position()]; histogramSerializationBuffer.flip(); histogramSerializationBuffer.get(stats.publishLatencyBytes); histogramSerializationBuffer.clear(); stats.endToEndLatency.encodeIntoCompressedByteBuffer(histogramSerializationBuffer); stats.endToEndLatencyBytes = new byte[histogramSerializationBuffer.position()]; histogramSerializationBuffer.flip(); histogramSerializationBuffer.get(stats.endToEndLatencyBytes); } ctx.result(writer.writeValueAsString(stats)); }
Example #16
Source File: RestHandler.java From openmessaging-connect-runtime with Apache License 2.0 | 6 votes |
private void handleCreateConnector(Context context) { String connectorName = context.param("connectorName"); String arg = context.queryParam("config"); Map keyValue = JSON.parseObject(arg, Map.class); ConnectKeyValue configs = new ConnectKeyValue(); for(Object key : keyValue.keySet()){ configs.put((String)key, (String)keyValue.get(key)); } try { String result = connectController.getConfigManagementService().putConnectorConfig(connectorName, configs); if(result != null && result.length() > 0){ context.result(result); }else{ context.result("success"); } } catch (Exception e) { context.result("failed"); } }
Example #17
Source File: WorkerHandler.java From openmessaging-benchmark with Apache License 2.0 | 6 votes |
private void handlePeriodStats(Context ctx) throws Exception { PeriodStats stats = localWorker.getPeriodStats(); // Serialize histograms synchronized (histogramSerializationBuffer) { histogramSerializationBuffer.clear(); stats.publishLatency.encodeIntoCompressedByteBuffer(histogramSerializationBuffer); stats.publishLatencyBytes = new byte[histogramSerializationBuffer.position()]; histogramSerializationBuffer.flip(); histogramSerializationBuffer.get(stats.publishLatencyBytes); histogramSerializationBuffer.clear(); stats.endToEndLatency.encodeIntoCompressedByteBuffer(histogramSerializationBuffer); stats.endToEndLatencyBytes = new byte[histogramSerializationBuffer.position()]; histogramSerializationBuffer.flip(); histogramSerializationBuffer.get(stats.endToEndLatencyBytes); } ctx.result(writer.writeValueAsString(stats)); }
Example #18
Source File: RestHandler.java From openmessaging-connect-runtime with Apache License 2.0 | 5 votes |
private void getAllocatedInfo(Context context){ Set<WorkerConnector> workerConnectors = connectController.getWorker().getWorkingConnectors(); Set<Runnable> workerSourceTasks = connectController.getWorker().getWorkingTasks(); StringBuilder sb = new StringBuilder(); sb.append("working connectors:\n"); for(WorkerConnector workerConnector : workerConnectors){ sb.append(workerConnector.toString()+"\n"); } sb.append("working tasks:\n"); for(Runnable runnable : workerSourceTasks){ sb.append(runnable.toString()+"\n"); } context.result(sb.toString()); }
Example #19
Source File: WorkerHandler.java From openmessaging-benchmark with Apache License 2.0 | 5 votes |
private void handleInitializeDriver(Context ctx) throws Exception { // Save config to temp file File tempFile = File.createTempFile("driver-configuration", "conf"); Files.write(ctx.bodyAsBytes(), tempFile); localWorker.initializeDriver(tempFile); tempFile.delete(); }
Example #20
Source File: WorkerHandler.java From openmessaging-benchmark with Apache License 2.0 | 5 votes |
private void handleStartLoad(Context ctx) throws Exception { ProducerWorkAssignment producerWorkAssignment = mapper.readValue(ctx.body(), ProducerWorkAssignment.class); log.info("Start load publish-rate: {} msg/s -- payload-size: {}", producerWorkAssignment.publishRate, producerWorkAssignment.payloadData.length); localWorker.startLoad(producerWorkAssignment); }
Example #21
Source File: FileSystemViewHandler.java From hudi with Apache License 2.0 | 5 votes |
private void writeValueAsString(Context ctx, Object obj) throws JsonProcessingException { boolean prettyPrint = ctx.queryParam("pretty") != null; long beginJsonTs = System.currentTimeMillis(); String result = prettyPrint ? OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(obj) : OBJECT_MAPPER.writeValueAsString(obj); long endJsonTs = System.currentTimeMillis(); LOG.debug("Jsonify TimeTaken=" + (endJsonTs - beginJsonTs)); ctx.result(result); }
Example #22
Source File: ReportPropertiesController.java From maestro-java with Apache License 2.0 | 5 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("id")); Report report = reportDao.fetch(id); String location = report.getLocation(); File file = new File(location, "test.properties"); TestProperties tp = new TestProperties(); List<ExtendedTestProperties> testPropertiesList = new LinkedList<>(); if (HostTypes.isWorker(report.getTestHostRole())) { PropertyReader reader = new PropertyReader(); reader.read(file, tp); ExtendedTestProperties etp = new ExtendedTestProperties(tp); etp.setRole(report.getTestHostRole()); testPropertiesList.add(etp); context.json(testPropertiesList); } else { context.status(500); context.result(String.format("Unhandled node type for the report: %s", report.getTestHostRole())); } } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { logger.error(t.getMessage(), t); context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #23
Source File: AggregatedRateReportController.java From maestro-java with Apache License 2.0 | 5 votes |
@Override public void handle(Context context) { try { int testId = Integer.parseInt( Objects.requireNonNull(context.param("id"), "The ID must be provided")); int testNumber = Integer.parseInt( Objects.requireNonNull(context.param("number"), "The test number must be provided")); String hostRole = context.param("role"); Report report = reportDao.fetchAggregated(testId, testNumber); SingleData<Long> rateData = processReport(report, hostRole); RateResponse rateResponse = new RateResponse(); rateResponse.setPeriods(rateData.getPeriods()); rateResponse.setRate(rateData.getValues()); context.json(rateResponse); } catch (DataNotFoundException e) { context.status(404); context.result(String.format("Not found: %s", e.getMessage())); } catch (Throwable t) { context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #24
Source File: TestPropertiesController.java From maestro-java with Apache License 2.0 | 5 votes |
@Override public void handle(Context context) { try { int id = Integer.parseInt(context.param("test")); int number = Integer.parseInt(context.param("number")); List<Report> reports = reportDao.fetch(id, number); List<ExtendedTestProperties> testPropertiesList = new LinkedList<>(); for (Report report : reports) { String location = report.getLocation(); File file = new File(location, "test.properties"); TestProperties tp = new TestProperties(); if (HostTypes.isWorker(report.getTestHostRole())) { PropertyReader reader = new PropertyReader(); reader.read(file, tp); ExtendedTestProperties etp = new ExtendedTestProperties(tp); etp.setRole(report.getTestHostRole()); testPropertiesList.add(etp); } } context.json(testPropertiesList); } catch (Throwable t) { logger.error(t.getMessage(), t); context.status(500); context.result(String.format("Internal server error: %s", t.getMessage())); } }
Example #25
Source File: RestHandler.java From openmessaging-connect-runtime with Apache License 2.0 | 5 votes |
private void handleStopConnector(Context context){ String connectorName = context.param("connectorName"); try { connectController.getConfigManagementService().removeConnectorConfig(connectorName); context.result("success"); } catch (Exception e) { context.result("failed"); } }
Example #26
Source File: RestHandler.java From openmessaging-connect-runtime with Apache License 2.0 | 5 votes |
private void handleQueryConnectorStatus(Context context){ String connectorName = context.param("connectorName"); Map<String, ConnectKeyValue> connectorConfigs = connectController.getConfigManagementService().getConnectorConfigs(); if(connectorConfigs.containsKey(connectorName)){ context.result("running"); }else{ context.result("not running"); } }
Example #27
Source File: RestHandler.java From openmessaging-connect-runtime with Apache License 2.0 | 5 votes |
private void handleQueryConnectorConfig(Context context){ String connectorName = context.param("connectorName"); Map<String, ConnectKeyValue> connectorConfigs = connectController.getConfigManagementService().getConnectorConfigs(); Map<String, List<ConnectKeyValue>> taskConfigs = connectController.getConfigManagementService().getTaskConfigs(); StringBuilder sb = new StringBuilder(); sb.append("ConnectorConfigs:") .append(JSON.toJSONString(connectorConfigs.get(connectorName))) .append("\n") .append("TaskConfigs:") .append(JSON.toJSONString(taskConfigs.get(connectorName))); context.result(sb.toString()); }
Example #28
Source File: WorkerHandler.java From openmessaging-benchmark with Apache License 2.0 | 4 votes |
private void handleResetStats(Context ctx) throws Exception { log.info("Reset stats"); localWorker.resetStats(); }
Example #29
Source File: WorkerHandler.java From openmessaging-benchmark with Apache License 2.0 | 4 votes |
private void handleCountersStats(Context ctx) throws Exception { ctx.result(writer.writeValueAsString(localWorker.getCountersStats())); }
Example #30
Source File: FileSystemViewHandler.java From hudi with Apache License 2.0 | 4 votes |
private static boolean isRefreshCheckDisabledInQuery(Context ctxt) { return Boolean.parseBoolean(ctxt.queryParam(RemoteHoodieTableFileSystemView.REFRESH_OFF)); }