Пример #1
0
  protected boolean doBasicPathsMatch(final Path path1, final Path path2) {
    if (path1.equals(path2)) {
      return true;
    }
    // ignore count designators and attribute specifications whenc omparing paths
    // ie, /a/b[3]/c/@foo for our purposes is equivalent to /a/b/c

    String path1Relpaced =
        StringUtils.chomp(path1.toString().replaceAll("\\[.*\\]", "").replaceAll("/@.*$", ""), "/");
    String path2Replaced =
        StringUtils.chomp(path2.toString().replaceAll("\\[.*\\]", "").replaceAll("/@.*$", ""), "/");

    return path1Relpaced.equals(path2Replaced);
  }
Пример #2
0
 private String getRow(List<String> row) {
   StringBuffer sb = new StringBuffer();
   for (String data : row) {
     sb.append(data).append(seperator);
   }
   return StringUtils.chomp(sb.toString(), seperator);
 }
 public String getServerLink() {
   String url =
       StringUtils.defaultIfEmpty(
           StringUtils.trimToEmpty(getServerPublicUrl()), StringUtils.trimToEmpty(getServerUrl()));
   url = StringUtils.defaultIfEmpty(url, MagicNames.DEFAULT_SONAR_URL);
   return StringUtils.chomp(url, "/");
 }
Пример #4
0
 public ServerHttpClient(
     String remoteServerUrl, Integer connectTimeoutMiliseconds, Integer readTimeoutMiliseconds) {
   this.url = StringUtils.chomp(remoteServerUrl, "/");
   if (connectTimeoutMiliseconds != null) {
     this.connectTimeoutMiliseconds = connectTimeoutMiliseconds;
   }
   if (readTimeoutMiliseconds != null) {
     this.readTimeoutMiliseconds = readTimeoutMiliseconds;
   }
 }
Пример #5
0
  /**
   * Executes <code>commandLine</code>. Sometimes (especially observed on MacOS) the commandLine
   * isn't executed properly. In that cases another exec-method is to be used. To accomplish this
   * please use the special delimiter '<code>@@</code>'. If <code>commandLine</code> contains this
   * delimiter it is split into a String[] array and the special exec-method is used.
   *
   * <p>A possible {@link IOException} gets logged but no further processing is done.
   *
   * @param commandLine the command line to execute
   * @param timeout timeout for execution in milliseconds
   * @return response data from executed command line
   */
  public static String executeCommandLineAndWaitResponse(String commandLine, int timeout) {
    String retval = null;

    CommandLine cmdLine = null;

    if (commandLine.contains(CMD_LINE_DELIMITER)) {
      String[] cmdArray = commandLine.split(CMD_LINE_DELIMITER);
      cmdLine = new CommandLine(cmdArray[0]);

      for (int i = 1; i < cmdArray.length; i++) {
        cmdLine.addArgument(cmdArray[i], false);
      }
    } else {
      cmdLine = CommandLine.parse(commandLine);
    }

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();

    ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
    Executor executor = new DefaultExecutor();

    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    PumpStreamHandler streamHandler = new PumpStreamHandler(stdout);

    executor.setExitValue(1);
    executor.setStreamHandler(streamHandler);
    executor.setWatchdog(watchdog);

    try {
      executor.execute(cmdLine, resultHandler);
      logger.debug("executed commandLine '{}'", commandLine);
    } catch (ExecuteException e) {
      logger.error("couldn't execute commandLine '" + commandLine + "'", e);
    } catch (IOException e) {
      logger.error("couldn't execute commandLine '" + commandLine + "'", e);
    }

    // some time later the result handler callback was invoked so we
    // can safely request the exit code
    try {
      resultHandler.waitFor();
      int exitCode = resultHandler.getExitValue();
      retval = StringUtils.chomp(stdout.toString());
      if (resultHandler.getException() != null) {
        logger.warn(resultHandler.getException().getMessage());
      } else {
        logger.debug("exit code '{}', result '{}'", exitCode, retval);
      }

    } catch (InterruptedException e) {
      logger.error("Timeout occured when executing commandLine '" + commandLine + "'", e);
    }

    return retval;
  }
Пример #6
0
  /**
   * Executes the query against the specified index, and returns a bounded collection of sentences
   * ordered by document id (so the sentence ordering is preserved in the collection).
   *
   * @param query the Boolean OR query computed from the top terms.
   * @param weights the target location for the calculated weights.
   * @return an array of sentences.
   * @throws Exception if one is thrown.
   */
  protected Double[] searchIndex(Query query, Double[] weights) throws Exception {
    IndexReader reader = IndexReader.open(ramdir);
    IndexSearcher searcher = new IndexSearcher(reader);

    TopDocs topDocs = searcher.search(query, structure.getNumSentences());

    for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
      Document doc = searcher.doc(scoreDoc.doc);
      String sentence = StringUtils.chomp(doc.get("text"));
      weights[sentenceMap.get(sentence)] = (double) scoreDoc.score;
    }

    searcher.close();
    return weights;
  }
Пример #7
0
 public static Object readObject(InputStream in, boolean allowJsonResolve)
     throws ClassNotFoundException, IOException {
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   IOUtils.copy(in, baos);
   in.close();
   byte[] bytes = baos.toByteArray();
   try {
     char[] buffer = StringUtils.chomp(readString(bytes)).toCharArray();
     return parseObject(buffer, 0, buffer.length, allowJsonResolve);
   } catch (Exception e) {
   }
   ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(bytes));
   Serializable value = (Serializable) oin.readObject();
   oin.close();
   return value;
 }
Пример #8
0
  /**
   * Strip byte count from the bytebuffer. IRTrans devices include the number of bytes sent in each
   * response it sends back to the connected host. This is a simple error checking mechanism - we do
   * need that information, and so, we strip it
   *
   * @param byteBuffer the byte buffer
   * @return the string
   */
  protected String stripByteCount(ByteBuffer byteBuffer) {
    /** {@link Pattern} which matches a binding configuration part */
    Pattern RESPONSE_PATTERN = Pattern.compile("..(\\d{5}) (.*)");
    String message = null;

    String response = new String(byteBuffer.array(), 0, byteBuffer.limit());
    response = StringUtils.chomp(response);

    Matcher matcher = RESPONSE_PATTERN.matcher(response);
    if (matcher.matches()) {
      String byteCountAsString = matcher.group(1);
      int byteCount = Integer.parseInt(byteCountAsString);
      message = matcher.group(2);
    }

    return message;
  }
Пример #9
0
 public String forBrokerTenantCreate(String tenantName) {
   return StringUtil.join(
       "/", StringUtils.chomp(_baseUrl, "/"), "tenants", tenantName, "instances?type=broker");
 }
Пример #10
0
 public String forServerTenantCreate() {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "tenants?type=server");
 }
Пример #11
0
 // V2 API started
 public String forTenantCreate() {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "tenants/");
 }
Пример #12
0
 public String forInstanceBulkCreate() {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "instances", "bulkAdd");
 }
Пример #13
0
 public String forTableCreate() {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "tables");
 }
 public String getResponseString() throws UnsupportedEncodingException {
   return StringUtils.chomp(
       new String(
           getResponseBytes(), getResponseOffset(), getResponseLength(), getValidCharset()));
 }
Пример #15
0
 public String forBrokerTenantGet(String tenantName) {
   return StringUtil.join(
       "/", StringUtils.chomp(_baseUrl, "/"), "tenants", tenantName, "?type=broker");
 }
Пример #16
0
 public String forTableDelete(String tableName) {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "tables", tableName);
 }
Пример #17
0
 public String forResourceCreate() {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "dataresources");
 }
Пример #18
0
 public String forTableGet(String tableName) {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "tables", tableName, "instances");
 }
Пример #19
0
 public String forTableGetBrokerInstances(String tableName) {
   return StringUtil.join(
       "/", StringUtils.chomp(_baseUrl, "/"), "tables", tableName, "instances?type=broker");
 }
Пример #20
0
 public String forTableGetConfig(String tableName) {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "tables", tableName, "configs");
 }
Пример #21
0
 public String forTenantGet(String tenantName) {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "tenants", tenantName);
 }
Пример #22
0
 public String forDataFileUpload() {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "segments");
 }
Пример #23
0
 @Override
 public String getValue() {
   return StringUtils.chomp(Arrays.toString(values).substring(1), "]");
 }
Пример #24
0
 public String forInstanceCreate() {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "instances/");
 }
Пример #25
0
  public HelixBrokerStarter(
      String helixClusterName, String zkServer, Configuration pinotHelixProperties)
      throws Exception {
    _liveInstancesListener = new LiveInstancesChangeListenerImpl(helixClusterName);

    _pinotHelixProperties = DefaultHelixBrokerConfig.getDefaultBrokerConf(pinotHelixProperties);
    final String brokerId =
        _pinotHelixProperties.getString(
            "instanceId",
            CommonConstants.Helix.PREFIX_OF_BROKER_INSTANCE
                + NetUtil.getHostAddress()
                + "_"
                + _pinotHelixProperties.getInt(
                    CommonConstants.Helix.KEY_OF_BROKER_QUERY_PORT,
                    CommonConstants.Helix.DEFAULT_BROKER_QUERY_PORT));

    _pinotHelixProperties.addProperty("pinot.broker.id", brokerId);
    RoutingTableBuilder defaultOfflineRoutingTableBuilder =
        getRoutingTableBuilder(
            _pinotHelixProperties.subset(DEFAULT_OFFLINE_ROUTING_TABLE_BUILDER_KEY));
    RoutingTableBuilder defaultRealtimeRoutingTableBuilder =
        getRoutingTableBuilder(
            _pinotHelixProperties.subset(DEFAULT_REALTIME_ROUTING_TABLE_BUILDER_KEY));
    Map<String, RoutingTableBuilder> tableToRoutingTableBuilderMap =
        getTableToRoutingTableBuilderMap(_pinotHelixProperties.subset(ROUTING_TABLE_BUILDER_KEY));
    ZkClient zkClient =
        new ZkClient(
            StringUtil.join(
                "/", StringUtils.chomp(zkServer, "/"), helixClusterName, "PROPERTYSTORE"),
            ZkClient.DEFAULT_SESSION_TIMEOUT,
            ZkClient.DEFAULT_CONNECTION_TIMEOUT,
            new ZNRecordSerializer());
    _propertyStore =
        new ZkHelixPropertyStore<ZNRecord>(new ZkBaseDataAccessor<ZNRecord>(zkClient), "/", null);
    _helixExternalViewBasedRouting =
        new HelixExternalViewBasedRouting(
            defaultOfflineRoutingTableBuilder,
            defaultRealtimeRoutingTableBuilder,
            tableToRoutingTableBuilderMap,
            _propertyStore);

    // _brokerServerBuilder = startBroker();
    _brokerServerBuilder = startBroker(_pinotHelixProperties);
    _helixManager =
        HelixManagerFactory.getZKHelixManager(
            helixClusterName, brokerId, InstanceType.PARTICIPANT, zkServer);
    final StateMachineEngine stateMachineEngine = _helixManager.getStateMachineEngine();
    final StateModelFactory<?> stateModelFactory =
        new BrokerResourceOnlineOfflineStateModelFactory(
            _helixManager, _helixExternalViewBasedRouting);
    stateMachineEngine.registerStateModelFactory(
        BrokerResourceOnlineOfflineStateModelFactory.getStateModelDef(), stateModelFactory);
    _helixManager.connect();
    _helixAdmin = _helixManager.getClusterManagmentTool();
    _helixBrokerRoutingTable =
        new HelixBrokerRoutingTable(_helixExternalViewBasedRouting, brokerId, _helixManager);
    addInstanceTagIfNeeded(helixClusterName, brokerId);
    _helixManager.addExternalViewChangeListener(_helixBrokerRoutingTable);
    _helixManager.addInstanceConfigChangeListener(_helixBrokerRoutingTable);
    _helixManager.addLiveInstanceChangeListener(_liveInstancesListener);
  }
Пример #26
0
 public String forInstanceEnable(String instanceName) {
   return StringUtil.join(
       "/", StringUtils.chomp(_baseUrl, "/"), "instances", instanceName, "?state=enable");
 }
Пример #27
0
 public String forResourceGet(String resourceName) {
   return StringUtil.join("/", StringUtils.chomp(_baseUrl, "/"), "dataresources", resourceName);
 }
Пример #28
0
 public String forServerTenantDelete(String tenantName) {
   return StringUtil.join(
       "/", StringUtils.chomp(_baseUrl, "/"), "tenants", tenantName, "?type=server");
 }