[Rollup] Register FeatureSetUsage with xpack, add tests (elastic/x-pack-elasticsearch#4040)
We had a Usage class before, but weren't registering it with XPack. Would be nice to add more usage info in the future (like the running jobs on each node), but unclear the best way to do it since we'd need to filter through the list of allocated tasks. Original commit: elastic/x-pack-elasticsearch@5207d2758b
This commit is contained in:
parent
1ed31af2c6
commit
aa877161ff
|
@ -92,6 +92,7 @@ import org.elasticsearch.persistent.PersistentTasksNodeService;
|
|||
import org.elasticsearch.persistent.RemovePersistentTaskAction;
|
||||
import org.elasticsearch.persistent.StartPersistentTaskAction;
|
||||
import org.elasticsearch.persistent.UpdatePersistentTaskStatusAction;
|
||||
import org.elasticsearch.xpack.core.rollup.RollupFeatureSetUsage;
|
||||
import org.elasticsearch.xpack.core.rollup.RollupField;
|
||||
import org.elasticsearch.xpack.core.rollup.action.DeleteRollupJobAction;
|
||||
import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction;
|
||||
|
@ -344,6 +345,7 @@ public class XPackClientPlugin extends Plugin implements ActionPlugin, NetworkPl
|
|||
new NamedWriteableRegistry.Entry(MetaData.Custom.class, LicensesMetaData.TYPE, LicensesMetaData::new),
|
||||
new NamedWriteableRegistry.Entry(NamedDiff.class, LicensesMetaData.TYPE, LicensesMetaData::readDiffFrom),
|
||||
//rollup
|
||||
new NamedWriteableRegistry.Entry(XPackFeatureSet.Usage.class, XPackField.ROLLUP, RollupFeatureSetUsage::new),
|
||||
new NamedWriteableRegistry.Entry(PersistentTaskParams.class, RollupJob.NAME, RollupJob::new),
|
||||
new NamedWriteableRegistry.Entry(Task.Status.class, RollupJobStatus.NAME, RollupJobStatus::new)
|
||||
);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* 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.core.rollup;
|
||||
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.xpack.core.XPackFeatureSet;
|
||||
import org.elasticsearch.xpack.core.XPackField;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RollupFeatureSetUsage extends XPackFeatureSet.Usage {
|
||||
|
||||
public RollupFeatureSetUsage(StreamInput input) throws IOException {
|
||||
super(input);
|
||||
}
|
||||
|
||||
public RollupFeatureSetUsage(boolean available, boolean enabled) {
|
||||
super(XPackField.ROLLUP, available, enabled);
|
||||
}
|
||||
}
|
|
@ -8,14 +8,13 @@ package org.elasticsearch.xpack.rollup;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.xpack.core.XPackFeatureSet;
|
||||
import org.elasticsearch.xpack.core.XPackField;
|
||||
import org.elasticsearch.xpack.core.XPackSettings;
|
||||
import org.elasticsearch.xpack.core.rollup.RollupFeatureSetUsage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class RollupFeatureSet implements XPackFeatureSet {
|
||||
|
@ -56,17 +55,7 @@ public class RollupFeatureSet implements XPackFeatureSet {
|
|||
|
||||
@Override
|
||||
public void usage(ActionListener<XPackFeatureSet.Usage> listener) {
|
||||
listener.onResponse(new RollupFeatureSet.Usage(available(), enabled()));
|
||||
}
|
||||
|
||||
public static class Usage extends XPackFeatureSet.Usage {
|
||||
|
||||
public Usage(StreamInput input) throws IOException {
|
||||
super(input);
|
||||
}
|
||||
|
||||
public Usage(boolean available, boolean enabled) {
|
||||
super(XPackField.ROLLUP, available, enabled);
|
||||
}
|
||||
// TODO expose the currently running rollup tasks on this node? Unclear the best way to do that
|
||||
listener.onResponse(new RollupFeatureSetUsage(available(), enabled()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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.rollup;
|
||||
|
||||
import org.elasticsearch.action.support.PlainActionFuture;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.XPackLicenseState;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.core.XPackFeatureSet;
|
||||
import org.elasticsearch.xpack.core.rollup.RollupFeatureSetUsage;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class RollupFeatureSetTests extends ESTestCase {
|
||||
private XPackLicenseState licenseState;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
licenseState = mock(XPackLicenseState.class);
|
||||
}
|
||||
|
||||
public void testAvailable() {
|
||||
RollupFeatureSet featureSet = new RollupFeatureSet(Settings.EMPTY, licenseState);
|
||||
boolean available = randomBoolean();
|
||||
when(licenseState.isRollupAllowed()).thenReturn(available);
|
||||
assertThat(featureSet.available(), is(available));
|
||||
}
|
||||
|
||||
public void testEnabledSetting() {
|
||||
boolean enabled = randomBoolean();
|
||||
Settings.Builder settings = Settings.builder();
|
||||
settings.put("xpack.rollup.enabled", enabled);
|
||||
RollupFeatureSet featureSet = new RollupFeatureSet(settings.build(), licenseState);
|
||||
assertThat(featureSet.enabled(), is(enabled));
|
||||
}
|
||||
|
||||
public void testEnabledDefault() {
|
||||
RollupFeatureSet featureSet = new RollupFeatureSet(Settings.EMPTY, licenseState);
|
||||
assertThat(featureSet.enabled(), is(true));
|
||||
}
|
||||
|
||||
public void testUsage() throws ExecutionException, InterruptedException, IOException {
|
||||
RollupFeatureSet featureSet = new RollupFeatureSet(Settings.EMPTY, licenseState);
|
||||
PlainActionFuture<XPackFeatureSet.Usage> future = new PlainActionFuture<>();
|
||||
featureSet.usage(future);
|
||||
XPackFeatureSet.Usage rollupUsage = future.get();
|
||||
BytesStreamOutput out = new BytesStreamOutput();
|
||||
rollupUsage.writeTo(out);
|
||||
XPackFeatureSet.Usage serializedUsage = new RollupFeatureSetUsage(out.bytes().streamInput());
|
||||
for (XPackFeatureSet.Usage usage : Arrays.asList(rollupUsage, serializedUsage)) {
|
||||
assertThat(usage.name(), is(featureSet.name()));
|
||||
assertThat(usage.enabled(), is(featureSet.enabled()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue