示例#1
0
 public void testSubtractDays() {
   // This is a test for a bug in version 1.0. The dayOfMonth range
   // duration field did not match the monthOfYear duration field. This
   // caused an exception to be thrown when subtracting days.
   DateTime dt =
       new DateTime(1112306400000L, GJChronology.getInstance(DateTimeZone.forID("Europe/Berlin")));
   YearMonthDay ymd = dt.toYearMonthDay();
   while (ymd.toDateTimeAtMidnight().getDayOfWeek() != DateTimeConstants.MONDAY) {
     ymd = ymd.minus(Period.days(1));
   }
 }
  @Test
  public void test1() throws Exception {
    ObjectViews views = this.unmarshal("com/axelor/meta/WSTest.xml", ObjectViews.class);
    List<Action> actions = views.getActions();

    Assert.assertNotNull(actions);
    Assert.assertEquals(4, actions.size());

    MetaStore.resister(views);

    Action action = MetaStore.getAction("data.import.1");
    Map<String, Object> context = Maps.newHashMap();

    DateTime dt = new DateTime();
    dt = dt.plus(Period.days(20));

    context.put("dt", dt);

    ActionHandler handler = createHandler("data.import.1", context);
    action.evaluate(handler);
  }
public class ElasticsearchConfiguration {
  @Parameter(value = "elasticsearch_cluster_name")
  private String clusterName = "graylog2";

  @Parameter(value = "elasticsearch_node_name")
  private String nodeName = "graylog2-server";

  @Parameter(value = "elasticsearch_node_master")
  private boolean masterNode = false;

  @Parameter(value = "elasticsearch_node_data")
  private boolean dataNode = false;

  @Parameter(value = "elasticsearch_path_data")
  private String pathData = "data/elasticsearch";

  @Parameter(value = "elasticsearch_path_home")
  private String pathHome = "data/elasticsearch";

  @Parameter(value = "elasticsearch_transport_tcp_port", validator = InetPortValidator.class)
  private int transportTcpPort = 9350;

  @Parameter(value = "elasticsearch_http_enabled")
  private boolean httpEnabled = false;

  @Parameter(value = "elasticsearch_discovery_zen_ping_multicast_enabled")
  private boolean multicastDiscovery = true;

  @Parameter(
      value = "elasticsearch_discovery_zen_ping_unicast_hosts",
      converter = StringListConverter.class)
  private List<String> unicastHosts;

  @Parameter(value = "elasticsearch_discovery_initial_state_timeout")
  private String initialStateTimeout = "3s";

  @Parameter(value = "elasticsearch_network_host")
  private String networkHost;

  @Parameter(value = "elasticsearch_network_bind_host")
  private String networkBindHost;

  @Parameter(value = "elasticsearch_network_publish_host")
  private String networkPublishHost;

  @Parameter(
      value = "elasticsearch_cluster_discovery_timeout",
      validator = PositiveLongValidator.class)
  private long clusterDiscoveryTimeout = 5000;

  @Parameter(value = "elasticsearch_disable_version_check")
  private boolean disableVersionCheck = false;

  @Parameter(value = "elasticsearch_config_file", validator = FilePathReadableValidator.class)
  private Path configFile; // = "/etc/graylog/server/elasticsearch.yml";

  @Parameter(value = "elasticsearch_index_prefix", required = true)
  private String indexPrefix = "graylog2";

  @Parameter(
      value = "elasticsearch_max_number_of_indices",
      required = true,
      validator = PositiveIntegerValidator.class)
  private int maxNumberOfIndices = 20;

  @Parameter(
      value = "elasticsearch_max_docs_per_index",
      validator = PositiveIntegerValidator.class,
      required = true)
  private int maxDocsPerIndex = 80000000;

  @Parameter(
      value = "elasticsearch_max_size_per_index",
      validator = PositiveLongValidator.class,
      required = true)
  private long maxSizePerIndex = 1L * 1024 * 1024 * 1024; // 1GB

  @Parameter(value = "elasticsearch_max_time_per_index", required = true)
  private Period maxTimePerIndex = Period.days(1);

  @Parameter(
      value = "elasticsearch_shards",
      validator = PositiveIntegerValidator.class,
      required = true)
  private int shards = 4;

  @Parameter(
      value = "elasticsearch_replicas",
      validator = PositiveIntegerValidator.class,
      required = true)
  private int replicas = 0;

  @Parameter(value = "elasticsearch_analyzer", required = true)
  private String analyzer = "standard";

  @Parameter(value = "no_retention")
  private boolean noRetention = false;

  @Parameter(value = "retention_strategy", required = true)
  private String retentionStrategy = "delete";

  @Parameter(value = "rotation_strategy")
  private String rotationStrategy = "count";

  @Parameter(value = "disable_index_optimization")
  private boolean disableIndexOptimization = false;

  @Parameter(
      value = "index_optimization_max_num_segments",
      validator = PositiveIntegerValidator.class)
  private int indexOptimizationMaxNumSegments = 1;

  @Parameter(value = "elasticsearch_request_timeout", validator = PositiveDurationValidator.class)
  private Duration requestTimeout = Duration.minutes(1L);

  public String getClusterName() {
    return clusterName;
  }

  public String getNodeName() {
    return nodeName;
  }

  public boolean isMasterNode() {
    return masterNode;
  }

  public boolean isDataNode() {
    return dataNode;
  }

  public boolean isClientNode() {
    return !isDataNode();
  }

  public int getTransportTcpPort() {
    return transportTcpPort;
  }

  public boolean isHttpEnabled() {
    return httpEnabled;
  }

  public boolean isMulticastDiscovery() {
    return multicastDiscovery;
  }

  public List<String> getUnicastHosts() {
    return unicastHosts;
  }

  public String getInitialStateTimeout() {
    return initialStateTimeout;
  }

  public String getNetworkHost() {
    return networkHost;
  }

  public String getNetworkBindHost() {
    return networkBindHost;
  }

  public String getNetworkPublishHost() {
    return networkPublishHost;
  }

  public long getClusterDiscoveryTimeout() {
    return clusterDiscoveryTimeout;
  }

  public boolean isDisableVersionCheck() {
    return disableVersionCheck;
  }

  public Path getConfigFile() {
    return configFile;
  }

  public String getIndexPrefix() {
    return indexPrefix.toLowerCase(Locale.ENGLISH);
  }

  public int getMaxNumberOfIndices() {
    return maxNumberOfIndices;
  }

  public int getMaxDocsPerIndex() {
    return maxDocsPerIndex;
  }

  public long getMaxSizePerIndex() {
    return maxSizePerIndex;
  }

  public Period getMaxTimePerIndex() {
    return maxTimePerIndex;
  }

  public int getShards() {
    return shards;
  }

  public int getReplicas() {
    return replicas;
  }

  public String getAnalyzer() {
    return analyzer;
  }

  public String getRotationStrategy() {
    return rotationStrategy;
  }

  public boolean performRetention() {
    return !noRetention;
  }

  public void setPerformRetention(boolean retention) {
    noRetention = !retention;
  }

  public String getRetentionStrategy() {
    return retentionStrategy;
  }

  public int getIndexOptimizationMaxNumSegments() {
    return indexOptimizationMaxNumSegments;
  }

  public boolean isDisableIndexOptimization() {
    return disableIndexOptimization;
  }

  public String getPathData() {
    return pathData;
  }

  public String getPathHome() {
    return pathHome;
  }

  public Duration getRequestTimeout() {
    return requestTimeout;
  }
}
@JsonAutoDetect
@AutoValue
public abstract class SearchesClusterConfig {
  private static final Period DEFAULT_QUERY_TIME_RANGE_LIMIT = Period.ZERO;
  private static final Map<Period, String> DEFAULT_RELATIVE_TIMERANGE_OPTIONS =
      ImmutableMap.<Period, String>builder()
          .put(Period.minutes(5), "Search in the last 5 minutes")
          .put(Period.minutes(15), "Search in the last 15 minutes")
          .put(Period.minutes(30), "Search in the last 30 minutes")
          .put(Period.hours(1), "Search in the last 1 hour")
          .put(Period.hours(2), "Search in the last 2 hours")
          .put(Period.hours(8), "Search in the last 8 hours")
          .put(Period.days(1), "Search in the last 1 day")
          .put(Period.days(2), "Search in the last 2 days")
          .put(Period.days(5), "Search in the last 5 days")
          .put(Period.days(7), "Search in the last 7 days")
          .put(Period.days(14), "Search in the last 14 days")
          .put(Period.days(30), "Search in the last 30 days")
          .put(Period.ZERO, "Search in all messages")
          .build();
  private static final Map<Period, String> DEFAULT_SURROUNDING_TIMERANGE_OPTIONS =
      ImmutableMap.<Period, String>builder()
          .put(Period.seconds(1), "1 second")
          .put(Period.seconds(5), "5 seconds")
          .put(Period.seconds(10), "10 seconds")
          .put(Period.seconds(30), "30 seconds")
          .put(Period.minutes(1), "1 minute")
          .put(Period.minutes(5), "5 minutes")
          .build();
  private static final Set<String> DEFAULT_SURROUNDING_FILTER_FIELDS =
      ImmutableSet.<String>builder()
          .add("source")
          .add("gl2_source_input")
          .add("file")
          .add("source_file")
          .build();

  @JsonProperty("query_time_range_limit")
  public abstract Period queryTimeRangeLimit();

  @JsonProperty("relative_timerange_options")
  public abstract Map<Period, String> relativeTimerangeOptions();

  @JsonProperty("surrounding_timerange_options")
  public abstract Map<Period, String> surroundingTimerangeOptions();

  @JsonProperty("surrounding_filter_fields")
  public abstract Set<String> surroundingFilterFields();

  @JsonCreator
  public static SearchesClusterConfig create(
      @JsonProperty("query_time_range_limit") Period queryTimeRangeLimit,
      @JsonProperty("relative_timerange_options") Map<Period, String> relativeTimerangeOptions,
      @JsonProperty("surrounding_timerange_options")
          Map<Period, String> surroundingTimerangeOptions,
      @JsonProperty("surrounding_filter_fields") Set<String> surroundingFilterFields) {
    return builder()
        .queryTimeRangeLimit(queryTimeRangeLimit)
        .relativeTimerangeOptions(relativeTimerangeOptions)
        .surroundingTimerangeOptions(surroundingTimerangeOptions)
        .surroundingFilterFields(surroundingFilterFields)
        .build();
  }

  public static SearchesClusterConfig createDefault() {
    return builder()
        .queryTimeRangeLimit(DEFAULT_QUERY_TIME_RANGE_LIMIT)
        .relativeTimerangeOptions(DEFAULT_RELATIVE_TIMERANGE_OPTIONS)
        .surroundingTimerangeOptions(DEFAULT_SURROUNDING_TIMERANGE_OPTIONS)
        .surroundingFilterFields(DEFAULT_SURROUNDING_FILTER_FIELDS)
        .build();
  }

  public static Builder builder() {
    return new AutoValue_SearchesClusterConfig.Builder();
  }

  public abstract Builder toBuilder();

  @AutoValue.Builder
  public abstract static class Builder {
    public abstract Builder queryTimeRangeLimit(Period queryTimeRangeLimit);

    public abstract Builder relativeTimerangeOptions(Map<Period, String> relativeTimerangeOptions);

    public abstract Builder surroundingTimerangeOptions(
        Map<Period, String> surroundingTimerangeOptions);

    public abstract Builder surroundingFilterFields(Set<String> surroundingFilterFields);

    public abstract SearchesClusterConfig build();
  }
}
示例#5
0
 @Override
 public Period byAmount(int amount) {
   return Period.days(amount);
 }