Added first model of Metric class
This commit is contained in:
parent
78015a5733
commit
8d96832cf6
|
@ -0,0 +1,14 @@
|
|||
package eu.dnetlib.dhp.monitor;
|
||||
|
||||
public class MonitorConstant {
|
||||
|
||||
public static String AGGREGATION_LABEL_NAME ="aggregation";
|
||||
public static String COLLECTION_LABEL_NAME ="collection";
|
||||
public static String TRANSFORM_LABEL_NAME ="transform";
|
||||
|
||||
public static String AGGREGATION_TRANSFORM_METRIC = String.format("%s-%s",AGGREGATION_LABEL_NAME,TRANSFORM_LABEL_NAME);
|
||||
|
||||
public static String AGGREGATION_COLLECTION_METRIC = String.format("%s-%s",AGGREGATION_LABEL_NAME,TRANSFORM_LABEL_NAME);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package eu.dnetlib.dhp.monitor.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The type Aggregation metric.
|
||||
*/
|
||||
public class AggregationMetric extends Metric <Long> {
|
||||
|
||||
private List<MetricLabel> labels;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new Aggregation metric.
|
||||
*/
|
||||
public AggregationMetric() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new Aggregation metric.
|
||||
*
|
||||
* @param name the name
|
||||
* @param isoDate the iso date
|
||||
* @param value the value
|
||||
* @param labels the labels
|
||||
*/
|
||||
public AggregationMetric(final String name, final String isoDate, final Long value, final List<MetricLabel> labels) {
|
||||
super(name, isoDate, value);
|
||||
this.labels = labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets labels.
|
||||
*
|
||||
* @return the labels
|
||||
*/
|
||||
public List<MetricLabel> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets labels.
|
||||
*
|
||||
* @param labels the labels
|
||||
* @return the labels
|
||||
*/
|
||||
public AggregationMetric setLabels(List<MetricLabel> labels) {
|
||||
this.labels = labels;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package eu.dnetlib.dhp.monitor.model;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* The type Metric.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
*/
|
||||
public class Metric<T extends Number> {
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
private String isoDate;
|
||||
private T total;
|
||||
|
||||
/**
|
||||
* Instantiates a new Metric.
|
||||
*/
|
||||
public Metric() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Metric.
|
||||
*
|
||||
* @param name the name
|
||||
* @param isoDate the iso date
|
||||
* @param total the total
|
||||
*/
|
||||
public Metric(final String name, final String isoDate, final T total) {
|
||||
this.name = name;
|
||||
setIsoDate(isoDate);
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets iso date.
|
||||
*
|
||||
* @return the iso date
|
||||
*/
|
||||
public String getIsoDate() {
|
||||
return isoDate;
|
||||
}
|
||||
|
||||
private String valiDate(final String aDate) {
|
||||
try {
|
||||
DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||
Date d1 = df1.parse(aDate);
|
||||
return df1.format(d1);
|
||||
} catch (ParseException e) {
|
||||
throw new MonitorException("Error the date is not in the format yyyy-MM-dd'T'HH:mm:ss ", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets name.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the name
|
||||
*/
|
||||
public Metric<T> setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets iso date.
|
||||
*
|
||||
* @param isoDate the iso date
|
||||
* @return the iso date
|
||||
*/
|
||||
public Metric<T> setIsoDate(String isoDate) {
|
||||
this.isoDate = valiDate(isoDate);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets total.
|
||||
*
|
||||
* @return the total
|
||||
*/
|
||||
public T getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets total.
|
||||
*
|
||||
* @param total the total
|
||||
* @return the total
|
||||
*/
|
||||
public Metric<T> setTotal(T total) {
|
||||
this.total = total;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package eu.dnetlib.dhp.monitor.model;
|
||||
|
||||
/**
|
||||
* The type Metric label.
|
||||
*/
|
||||
public class MetricLabel {
|
||||
|
||||
/**
|
||||
* The Name.
|
||||
*/
|
||||
public String name;
|
||||
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* Instantiates a new Metric label.
|
||||
*/
|
||||
public MetricLabel() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Metric label.
|
||||
*
|
||||
* @param name the name
|
||||
* @param value the value
|
||||
*/
|
||||
public MetricLabel(String name, String value) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets name.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the name
|
||||
*/
|
||||
public MetricLabel setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value.
|
||||
*
|
||||
* @param value the value
|
||||
* @return the value
|
||||
*/
|
||||
public MetricLabel setValue(String value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package eu.dnetlib.dhp.monitor.model;
|
||||
|
||||
/**
|
||||
* The type Monitor exception.
|
||||
*/
|
||||
public class MonitorException extends RuntimeException{
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new Monitor exception.
|
||||
*/
|
||||
public MonitorException() {super();}
|
||||
|
||||
/**
|
||||
* Instantiates a new Monitor exception.
|
||||
*
|
||||
* @param message the message
|
||||
*/
|
||||
public MonitorException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new Monitor exception.
|
||||
*
|
||||
* @param message the message
|
||||
* @param e the e
|
||||
*/
|
||||
public MonitorException(final String message, final Throwable e) {
|
||||
super(message,e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue