
org.kairosdb.rollup.RollupTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kairosdb Show documentation
Show all versions of kairosdb Show documentation
KairosDB is a time series database that stores numeric values along
with key/value tags to a nosql data store. Currently supported
backends are Cassandra and H2. An H2 implementation is provided
for development work.
The newest version!
package org.kairosdb.rollup;
import com.google.gson.annotations.SerializedName;
import org.apache.bval.constraints.NotEmpty;
import org.kairosdb.core.datastore.Duration;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkArgument;
import static java.util.Objects.requireNonNull;
import static org.kairosdb.util.Preconditions.requireNonNullOrEmpty;
/**
Roll up task.
*/
public class RollupTask
{
// todo regular expressions
// todo one time go back and redo option
// todo setup annotations for validation
// todo add tags
private final String id;
private final transient List rollups = new ArrayList<>();
@NotNull
@NotEmpty()
private String name;
@NotNull
@SerializedName("execution_interval")
private Duration executionInterval;
private long lastModified;
private String json;
public RollupTask()
{
id = UUID.randomUUID().toString();
}
public RollupTask(String name, Duration executionInterval, List rollups)
{
requireNonNull(rollups);
checkArgument(rollups.size() > 0);
id = UUID.randomUUID().toString();
initialize(name, executionInterval, rollups);
}
public RollupTask(String id, String name, Duration executionInterval, List rollups, String json)
{
requireNonNullOrEmpty(id);
requireNonNullOrEmpty(json);
requireNonNull(rollups);
checkArgument(rollups.size() > 0);
this.id = id;
this.json = json;
initialize(name, executionInterval, rollups);
}
private void initialize(String name, Duration executionInterval, List rollups)
{
this.name = requireNonNullOrEmpty(name);
this.rollups.addAll(rollups);
this.executionInterval = requireNonNull(executionInterval);
this.lastModified = System.currentTimeMillis();
}
public String getName()
{
return name;
}
public String getId()
{
return id;
}
public List getRollups()
{
return rollups;
}
public void addRollup(Rollup rollup)
{
rollups.add(rollup);
}
public void addJson(String json)
{
requireNonNullOrEmpty(json);
if (json.contains("\"id\":"))
{
// if id already exist in the json replace it
this.json = json.replaceFirst("\"id\":\".\",", "\"id\":\" + id + \"");
}
else
{
// if not add it
this.json = json.replaceFirst("\\{", "{\"id\":\"" + id + "\",");
}
}
public Duration getExecutionInterval()
{
return executionInterval;
}
public long getLastModified()
{
return lastModified;
}
public void setLastModified(long lastModified)
{
this.lastModified = lastModified;
}
public String getJson()
{
return json;
}
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RollupTask that = (RollupTask) o;
return !(id != null ? !id.equals(that.id) : that.id != null);
}
@Override
public int hashCode()
{
return id != null ? id.hashCode() : 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy