All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nitorcreations.willow.metrics.MetricUtils Maven / Gradle / Ivy

package com.nitorcreations.willow.metrics;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.client.Client;

public abstract class MetricUtils {
  public static String[] getIndexes(long start, long end, Client client) {
    ArrayList ret = new ArrayList<>();
    Calendar startCal = Calendar.getInstance();
    startCal.setTime(new Date(start));
    startCal.set(Calendar.SECOND, 1);
    startCal.set(Calendar.MINUTE, 0);
    startCal.set(Calendar.HOUR_OF_DAY, 0);
    Calendar endCal = Calendar.getInstance();
    endCal.setTime(new Date(end));
    while (startCal.before(endCal)) {
      String next = String.format("%04d", startCal.get(Calendar.YEAR)) + "-" + String.format("%02d", (startCal.get(Calendar.MONTH) + 1)) + "-" + String.format("%02d", startCal.get(Calendar.DAY_OF_MONTH));
      client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
      ClusterStateResponse response = client.admin().cluster().prepareState().execute().actionGet();
      boolean hasIndex = response.getState().metaData().hasIndex(next);
      if (hasIndex) {
        ret.add(next);
      }
      startCal.add(Calendar.DAY_OF_YEAR, 1);
    }
    return ret.toArray(new String[ret.size()]);
  }
  @SuppressWarnings({ "rawtypes", "unchecked" })
  public static  Y median(List data) {
    Collections.sort(data);
    return data.get(data.size() / 2);
  }
  public static Long sumLong(List list) {
    Long sum= 0L;
    for (Long i:list) {
      sum = sum + i;
    }
    return sum;
  }
  public Double sumDouble(List list) {
    Double sum= 0D;
    for (Double i:list) {
      sum = sum + i;
    }
    return sum;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy