[ML] Delete unused AuditActivity class (elastic/x-pack-elasticsearch#672)

Original commit: elastic/x-pack-elasticsearch@185ceab4b4
This commit is contained in:
David Kyle 2017-03-01 10:42:27 +00:00 committed by GitHub
parent 094be3c28b
commit 4edfbe664f
5 changed files with 1 additions and 265 deletions

View File

@ -35,7 +35,6 @@ import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelState;
import org.elasticsearch.xpack.ml.job.process.autodetect.state.Quantiles;
import org.elasticsearch.xpack.ml.job.results.CategoryDefinition;
import org.elasticsearch.xpack.ml.job.results.Result;
import org.elasticsearch.xpack.ml.notifications.AuditActivity;
import org.elasticsearch.xpack.ml.notifications.AuditMessage;
import org.elasticsearch.xpack.ml.notifications.Auditor;
@ -222,7 +221,6 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen
templateRequest.patterns(Collections.singletonList(Auditor.NOTIFICATIONS_INDEX));
templateRequest.settings(mlNotificationIndexSettings());
templateRequest.mapping(AuditMessage.TYPE.getPreferredName(), ElasticsearchMappings.auditMessageMapping());
templateRequest.mapping(AuditActivity.TYPE.getPreferredName(), ElasticsearchMappings.auditActivityMapping());
templateRequest.version(Version.CURRENT.id);
client.admin().indices().putTemplate(templateRequest,
ActionListener.wrap(r -> listener.accept(true, null), e -> listener.accept(false, e)));

View File

@ -24,7 +24,6 @@ import org.elasticsearch.xpack.ml.job.results.ModelDebugOutput;
import org.elasticsearch.xpack.ml.job.results.PerPartitionMaxProbabilities;
import org.elasticsearch.xpack.ml.job.results.ReservedFieldNames;
import org.elasticsearch.xpack.ml.job.results.Result;
import org.elasticsearch.xpack.ml.notifications.AuditActivity;
import org.elasticsearch.xpack.ml.notifications.AuditMessage;
import java.io.IOException;
@ -668,17 +667,4 @@ public class ElasticsearchMappings {
.endObject()
.endObject();
}
public static XContentBuilder auditActivityMapping() throws IOException {
return jsonBuilder()
.startObject()
.startObject(AuditActivity.TYPE.getPreferredName())
.startObject(PROPERTIES)
.startObject(AuditActivity.TIMESTAMP.getPreferredName())
.field(TYPE, DATE)
.endObject()
.endObject()
.endObject()
.endObject();
}
}

View File

@ -1,168 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.ml.notifications;
import org.elasticsearch.action.support.ToXContentToBytes;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.ObjectParser;
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser.Token;
import org.elasticsearch.xpack.ml.utils.time.TimeUtils;
import java.io.IOException;
import java.util.Date;
import java.util.Objects;
public class AuditActivity extends ToXContentToBytes implements Writeable {
public static final ParseField TYPE = new ParseField("audit_activity");
public static final ParseField TOTAL_JOBS = new ParseField("total_jobs");
public static final ParseField TOTAL_DETECTORS = new ParseField("total_detectors");
public static final ParseField RUNNING_JOBS = new ParseField("running_jobs");
public static final ParseField RUNNING_DETECTORS = new ParseField("running_detectors");
public static final ParseField TIMESTAMP = new ParseField("timestamp");
public static final ObjectParser<AuditActivity, Void> PARSER = new ObjectParser<>(TYPE.getPreferredName(),
AuditActivity::new);
static {
PARSER.declareInt(AuditActivity::setTotalJobs, TOTAL_JOBS);
PARSER.declareInt(AuditActivity::setTotalDetectors, TOTAL_DETECTORS);
PARSER.declareInt(AuditActivity::setRunningJobs, RUNNING_JOBS);
PARSER.declareInt(AuditActivity::setRunningDetectors, RUNNING_DETECTORS);
PARSER.declareField(AuditActivity::setTimestamp, p -> {
if (p.currentToken() == Token.VALUE_NUMBER) {
return new Date(p.longValue());
} else if (p.currentToken() == Token.VALUE_STRING) {
return new Date(TimeUtils.dateStringToEpoch(p.text()));
}
throw new IllegalArgumentException("unexpected token [" + p.currentToken() + "] for [" + TIMESTAMP.getPreferredName() + "]");
}, TIMESTAMP, ValueType.VALUE);
}
private int totalJobs;
private int totalDetectors;
private int runningJobs;
private int runningDetectors;
private Date timestamp;
public AuditActivity() {
}
private AuditActivity(int totalJobs, int totalDetectors, int runningJobs, int runningDetectors) {
this.totalJobs = totalJobs;
this.totalDetectors = totalDetectors;
this.runningJobs = runningJobs;
this.runningDetectors = runningDetectors;
timestamp = new Date();
}
public AuditActivity(StreamInput in) throws IOException {
totalJobs = in.readInt();
totalDetectors = in.readInt();
runningJobs = in.readInt();
runningDetectors = in.readInt();
if (in.readBoolean()) {
timestamp = new Date(in.readLong());
}
}
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeInt(totalJobs);
out.writeInt(totalDetectors);
out.writeInt(runningJobs);
out.writeInt(runningDetectors);
boolean hasTimestamp = timestamp != null;
out.writeBoolean(hasTimestamp);
if (hasTimestamp) {
out.writeLong(timestamp.getTime());
}
}
public int getTotalJobs() {
return totalJobs;
}
public void setTotalJobs(int totalJobs) {
this.totalJobs = totalJobs;
}
public int getTotalDetectors() {
return totalDetectors;
}
public void setTotalDetectors(int totalDetectors) {
this.totalDetectors = totalDetectors;
}
public int getRunningJobs() {
return runningJobs;
}
public void setRunningJobs(int runningJobs) {
this.runningJobs = runningJobs;
}
public int getRunningDetectors() {
return runningDetectors;
}
public void setRunningDetectors(int runningDetectors) {
this.runningDetectors = runningDetectors;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public static AuditActivity newActivity(int totalJobs, int totalDetectors, int runningJobs, int runningDetectors) {
return new AuditActivity(totalJobs, totalDetectors, runningJobs, runningDetectors);
}
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(TOTAL_JOBS.getPreferredName(), totalJobs);
builder.field(TOTAL_DETECTORS.getPreferredName(), totalDetectors);
builder.field(RUNNING_JOBS.getPreferredName(), runningJobs);
builder.field(RUNNING_DETECTORS.getPreferredName(), runningDetectors);
if (timestamp != null) {
builder.field(TIMESTAMP.getPreferredName(), timestamp.getTime());
}
builder.endObject();
return builder;
}
@Override
public int hashCode() {
return Objects.hash(totalDetectors, totalJobs, runningDetectors, runningJobs, timestamp);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AuditActivity other = (AuditActivity) obj;
return Objects.equals(totalDetectors, other.totalDetectors) &&
Objects.equals(totalJobs, other.totalJobs) &&
Objects.equals(runningDetectors, other.runningDetectors) &&
Objects.equals(runningJobs, other.runningJobs) &&
Objects.equals(timestamp, other.timestamp);
}
}

View File

@ -33,7 +33,6 @@ import org.elasticsearch.xpack.ml.job.process.autodetect.state.ModelState;
import org.elasticsearch.xpack.ml.job.process.autodetect.state.Quantiles;
import org.elasticsearch.xpack.ml.job.results.CategoryDefinition;
import org.elasticsearch.xpack.ml.job.results.Result;
import org.elasticsearch.xpack.ml.notifications.AuditActivity;
import org.elasticsearch.xpack.ml.notifications.AuditMessage;
import org.elasticsearch.xpack.ml.notifications.Auditor;
import org.junit.Before;
@ -201,8 +200,7 @@ public class MachineLearningTemplateRegistryTests extends ESTestCase {
assertNotNull(request);
assertEquals(templateRegistry.mlNotificationIndexSettings().build(), request.settings());
assertTrue(request.mappings().containsKey(AuditMessage.TYPE.getPreferredName()));
assertTrue(request.mappings().containsKey(AuditActivity.TYPE.getPreferredName()));
assertEquals(2, request.mappings().size());
assertEquals(1, request.mappings().size());
assertEquals(Collections.singletonList(Auditor.NOTIFICATIONS_INDEX), request.patterns());
assertEquals(new Integer(Version.CURRENT.id), request.version());
});

View File

@ -1,78 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.ml.notifications;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.ml.support.AbstractSerializingTestCase;
import org.elasticsearch.xpack.ml.utils.time.TimeUtils;
import org.junit.Before;
import java.util.Date;
public class AuditActivityTests extends AbstractSerializingTestCase<AuditActivity> {
private long startMillis;
@Before
public void setStartTime() {
startMillis = System.currentTimeMillis();
}
public void testDefaultConstructor() {
AuditActivity activity = new AuditActivity();
assertEquals(0, activity.getTotalJobs());
assertEquals(0, activity.getTotalDetectors());
assertEquals(0, activity.getRunningJobs());
assertEquals(0, activity.getRunningDetectors());
assertNull(activity.getTimestamp());
}
public void testNewActivity() {
AuditActivity activity = AuditActivity.newActivity(10, 100, 5, 50);
assertEquals(10, activity.getTotalJobs());
assertEquals(100, activity.getTotalDetectors());
assertEquals(5, activity.getRunningJobs());
assertEquals(50, activity.getRunningDetectors());
assertDateBetweenStartAndNow(activity.getTimestamp());
}
private void assertDateBetweenStartAndNow(Date timestamp) {
long timestampMillis = timestamp.getTime();
assertTrue(timestampMillis >= startMillis);
assertTrue(timestampMillis <= System.currentTimeMillis());
}
@Override
protected AuditActivity parseInstance(XContentParser parser) {
return AuditActivity.PARSER.apply(parser, null);
}
@Override
protected AuditActivity createTestInstance() {
AuditActivity message = new AuditActivity();
if (randomBoolean()) {
message.setRunningJobs(randomInt());
}
if (randomBoolean()) {
message.setRunningDetectors(randomInt());
}
if (randomBoolean()) {
message.setTotalJobs(randomInt());
}
if (randomBoolean()) {
message.setTotalDetectors(randomInt());
}
if (randomBoolean()) {
message.setTimestamp(new Date(TimeUtils.dateStringToEpoch(randomTimeValue())));
}
return message;
}
@Override
protected Reader<AuditActivity> instanceReader() {
return AuditActivity::new;
}
}