Java Code Examples for io.javalin.Context#queryParam()

The following examples show how to use io.javalin.Context#queryParam() . 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: RestHandler.java    From openmessaging-connect-runtime with Apache License 2.0 6 votes vote down vote up
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 2
Source File: FileSystemViewHandler.java    From hudi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: FileSystemViewHandler.java    From hudi with Apache License 2.0 6 votes vote down vote up
/**
 * 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 4
Source File: FileSystemViewHandler.java    From hudi with Apache License 2.0 5 votes vote down vote up
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 5
Source File: FileSystemViewHandler.java    From hudi with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(@NotNull Context context) throws Exception {
  boolean success = true;
  long beginTs = System.currentTimeMillis();
  boolean synced = false;
  boolean refreshCheck = performRefreshCheck && !isRefreshCheckDisabledInQuery(context);
  long refreshCheckTimeTaken = 0;
  long handleTimeTaken = 0;
  long finalCheckTimeTaken = 0;
  try {
    if (refreshCheck) {
      long beginRefreshCheck = System.currentTimeMillis();
      synced = syncIfLocalViewBehind(context);
      long endRefreshCheck = System.currentTimeMillis();
      refreshCheckTimeTaken = endRefreshCheck - beginRefreshCheck;
    }

    long handleBeginMs = System.currentTimeMillis();
    handler.handle(context);
    long handleEndMs = System.currentTimeMillis();
    handleTimeTaken = handleEndMs - handleBeginMs;

    if (refreshCheck) {
      long beginFinalCheck = System.currentTimeMillis();
      String errMsg =
          "Last known instant from client was "
              + context.queryParam(RemoteHoodieTableFileSystemView.LAST_INSTANT_TS,
                  HoodieTimeline.INVALID_INSTANT_TS)
              + " but server has the following timeline "
              + viewManager.getFileSystemView(context.queryParam(RemoteHoodieTableFileSystemView.BASEPATH_PARAM))
                  .getTimeline().getInstants().collect(Collectors.toList());
      ValidationUtils.checkArgument(!isLocalViewBehind(context), errMsg);
      long endFinalCheck = System.currentTimeMillis();
      finalCheckTimeTaken = endFinalCheck - beginFinalCheck;
    }
  } catch (RuntimeException re) {
    success = false;
    LOG.error("Got runtime exception servicing request " + context.queryString(), re);
    throw re;
  } finally {
    long endTs = System.currentTimeMillis();
    long timeTakenMillis = endTs - beginTs;
    LOG.info(String.format(
            "TimeTakenMillis[Total=%d, Refresh=%d, handle=%d, Check=%d], "
                + "Success=%s, Query=%s, Host=%s, synced=%s",
            timeTakenMillis, refreshCheckTimeTaken, handleTimeTaken, finalCheckTimeTaken, success,
            context.queryString(), context.host(), synced));
  }
}