// CHECKSTYLE:OFF
 @SuppressWarnings("PMD.ExcessiveParameterList")
 @DataBoundConstructor
 public WarningsPublisher(
     final String healthy,
     final String unHealthy,
     final String thresholdLimit,
     final String defaultEncoding,
     final boolean useDeltaValues,
     final String unstableTotalAll,
     final String unstableTotalHigh,
     final String unstableTotalNormal,
     final String unstableTotalLow,
     final String unstableNewAll,
     final String unstableNewHigh,
     final String unstableNewNormal,
     final String unstableNewLow,
     final String failedTotalAll,
     final String failedTotalHigh,
     final String failedTotalNormal,
     final String failedTotalLow,
     final String failedNewAll,
     final String failedNewHigh,
     final String failedNewNormal,
     final String failedNewLow,
     final boolean canRunOnFailed,
     final boolean canScanConsole,
     final String pattern,
     final String includePattern,
     final String excludePattern) {
   super(
       healthy,
       unHealthy,
       thresholdLimit,
       defaultEncoding,
       useDeltaValues,
       unstableTotalAll,
       unstableTotalHigh,
       unstableTotalNormal,
       unstableTotalLow,
       unstableNewAll,
       unstableNewHigh,
       unstableNewNormal,
       unstableNewLow,
       failedTotalAll,
       failedTotalHigh,
       failedTotalNormal,
       failedTotalLow,
       failedNewAll,
       failedNewHigh,
       failedNewNormal,
       failedNewLow,
       canRunOnFailed,
       "WARNINGS");
   this.pattern = pattern;
   ignoreConsole = !canScanConsole;
   this.includePattern = StringUtils.stripToNull(includePattern);
   this.excludePattern = StringUtils.stripToNull(excludePattern);
 }
  /**
   * Our rule is that least significant date unit determines the resolution.
   *
   * @param durationStr the duration string to check
   * @return the data unit
   */
  Precision reverseParseAtlassianDuration(String durationStr) {
    Precision rank = null;

    Matcher matcher = DURATION_PATTERN.matcher(durationStr);
    while (matcher.find()) {
      Precision current;
      String util = StringUtils.stripToNull(matcher.group(1));
      if (util == null || util.equals("m")) {
        // If we find minutes then just return immediately.
        return Precision.MINUTES;
      } else if (util.equals("h")) {
        current = Precision.HOURS;
      } else if (util.equals("d") || util.equals("w")) {
        current = Precision.DAYS;
      } else {
        // Assume minutes in the worst possible case.
        return Precision.MINUTES;
      }

      if (rank == null || rank.compareTo(current) > 0) {
        rank = current;
      }
    }
    return rank == null ? Precision.MINUTES : rank;
  }
  /**
   * @param db
   * @param table
   * @param filter
   * @param jobConf
   * @return A list of locations
   */
  public static List<String> getDataStorageLocation(
      String db, String table, String filter, JobConf jobConf) {
    Preconditions.checkNotNull(table, "Table name must not be null");

    HiveMetaStoreClient client = null;
    List<String> locations = new ArrayList<String>();

    try {
      client = getHiveMetaStoreClient(jobConf);
      Table hiveTable = HCatUtil.getTable(client, db, table);

      if (hiveTable.isPartitioned()) {
        List<Partition> parts = null;
        if (null != StringUtils.stripToNull(filter)) {
          parts = client.listPartitionsByFilter(db, table, filter, (short) -1);
        } else {
          parts = client.listPartitions(db, table, (short) -1);
        }

        if (parts.size() > 0) {
          // Return more than one partitions when filter is
          // something
          // like ds >= 1234
          for (Partition part : parts) {
            locations.addAll(getFilesInHivePartition(part, jobConf));
          }
        } else {
          logError(
              "Table "
                  + hiveTable.getTableName()
                  + " doesn't have the specified partition:"
                  + filter,
              null);
        }

      } else {
        locations.add(hiveTable.getTTable().getSd().getLocation());
      }
    } catch (IOException e) {
      logError("Error occured when getting hiveconf", e);
    } catch (MetaException e) {
      logError("Error occured when getting HiveMetaStoreClient", e);
    } catch (NoSuchObjectException e) {
      logError("Table doesn't exist in HCatalog: " + table, e);
    } catch (TException e) {
      logError("Error occured when getting Table", e);
    } finally {
      HCatUtil.closeHiveClientQuietly(client);
    }

    return locations;
  }
Beispiel #4
0
  /**
   * Adds a populated terminating field to the ends of CSV entries. If the last entry in a CSV row
   * is empty, the CSV library has difficulty understanding that is the end of the row.
   *
   * @param is the CSV file as an inputstream
   * @param separator The field separator
   * @param charset The charset
   * @return An inputstream that is the same as is, but each line has a populated line termination
   *     entry
   * @throws IOException
   */
  public static InputStream terminateLines(
      final InputStream is, final char separator, final String charset) throws IOException {

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(baos);

    final LineIterator lineIterator = IOUtils.lineIterator(is, charset);

    while (lineIterator.hasNext()) {
      String line = StringUtils.stripToNull(lineIterator.next());

      if (line != null) {
        line += separator + TERMINATED;
        printStream.println(line);
      }
    }

    return new ByteArrayInputStream(baos.toByteArray());
  }
  private InputStream stripLineEnds(InputStream is, String charset, char chartoStrip)
      throws IOException {
    log.debug("Stripping [ {} ] from the end of lines.", chartoStrip);

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final PrintStream printStream = new PrintStream(baos);

    final LineIterator lineIterator = IOUtils.lineIterator(is, charset);

    while (lineIterator.hasNext()) {
      String line = StringUtils.stripToNull(lineIterator.next());
      if (line != null) {
        line = StringUtils.stripEnd(line, String.valueOf(chartoStrip));
        printStream.println(line);
      }
    }

    return new ByteArrayInputStream(baos.toByteArray());
  }
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public Response getJSON(@Context Request request) {
   EntityTag etag = new EntityTag(data().getConfig().getUniqueId().toString());
   ResponseBuilder builder = request.evaluatePreconditions(etag);
   if (builder != null) {
     return builder.build();
   }
   FlexiBean out = createRootData();
   ConfigDocument doc = data().getConfig();
   String jsonConfig = StringUtils.stripToNull(toJSON(doc.getConfig().getValue(), doc.getType()));
   if (jsonConfig != null) {
     out.put("configJSON", jsonConfig);
   } else {
     out.put("configXML", StringEscapeUtils.escapeJavaScript(createXML(doc)));
   }
   out.put("type", doc.getType().getName());
   String json = getFreemarker().build("configs/jsonconfig.ftl", out);
   return Response.ok(json).tag(etag).build();
 }
  /**
   * Разбор строки тегов. Error при ошибках
   *
   * @param tags список тегов через запятую
   * @param errors класс для ошибок валидации (параметр 'tags')
   * @return список тегов
   */
  public ImmutableList<String> parseTags(String tags, Errors errors) {
    Set<String> tagSet = new HashSet<>();

    // Теги разделяютчя пайпом или запятой
    tags = tags.replaceAll("\\|", ",");
    String[] tagsArr = tags.split(",");

    if (tagsArr.length == 0) {
      return ImmutableList.of();
    }

    for (String aTagsArr : tagsArr) {
      String tag = StringUtils.stripToNull(aTagsArr.toLowerCase());
      // плохой тег - выбрасываем
      if (tag == null) {
        continue;
      }

      // обработка тега: только буквы/цифры/пробелы, никаких спецсимволов, запятых, амперсандов и <>
      if (tag.length() > TagService.MAX_TAG_LENGTH) {
        errors.rejectValue(
            "tags",
            null,
            "Слишком длиный тег: '"
                + tag
                + "\' (максимум "
                + TagService.MAX_TAG_LENGTH
                + " символов)");
      } else if (!TagService.isGoodTag(tag)) {
        errors.rejectValue("tags", null, "Некорректный тег: '" + tag + '\'');
      }

      tagSet.add(tag);
    }

    if (tagSet.size() > MAX_TAGS_PER_TOPIC) {
      errors.rejectValue("tags", null, "Слишком много тегов (максимум " + MAX_TAGS_PER_TOPIC + ')');
    }

    return ImmutableList.copyOf(tagSet);
  }