-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature usage actions for archive (#83931)
Relates #81210
- Loading branch information
Showing
17 changed files
with
331 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...lugin/core/src/main/java/org/elasticsearch/xpack/core/archive/ArchiveFeatureSetUsage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.archive; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.ToXContent; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
import org.elasticsearch.xpack.core.XPackFeatureSet; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class ArchiveFeatureSetUsage extends XPackFeatureSet.Usage { | ||
|
||
private final int numberOfArchiveIndices; | ||
|
||
public ArchiveFeatureSetUsage(StreamInput input) throws IOException { | ||
super(input); | ||
numberOfArchiveIndices = input.readVInt(); | ||
} | ||
|
||
@Override | ||
public Version getMinimalSupportedVersion() { | ||
return Version.V_8_2_0; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeVInt(numberOfArchiveIndices); | ||
} | ||
|
||
public ArchiveFeatureSetUsage(boolean available, int numberOfArchiveIndices) { | ||
super(XPackField.ARCHIVE, available, true); | ||
this.numberOfArchiveIndices = numberOfArchiveIndices; | ||
} | ||
|
||
public int getNumberOfArchiveIndices() { | ||
return numberOfArchiveIndices; | ||
} | ||
|
||
@Override | ||
protected void innerXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
super.innerXContent(builder, params); | ||
builder.field("indices_count", numberOfArchiveIndices); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(available, enabled, numberOfArchiveIndices); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
ArchiveFeatureSetUsage other = (ArchiveFeatureSetUsage) obj; | ||
return available == other.available && enabled == other.enabled && numberOfArchiveIndices == other.numberOfArchiveIndices; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
.../core/src/test/java/org/elasticsearch/xpack/core/archive/ArchiveFeatureSetUsageTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.core.archive; | ||
|
||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class ArchiveFeatureSetUsageTests extends AbstractWireSerializingTestCase<ArchiveFeatureSetUsage> { | ||
|
||
@Override | ||
protected ArchiveFeatureSetUsage createTestInstance() { | ||
boolean available = randomBoolean(); | ||
return new ArchiveFeatureSetUsage(available, randomIntBetween(0, 100000)); | ||
} | ||
|
||
@Override | ||
protected ArchiveFeatureSetUsage mutateInstance(ArchiveFeatureSetUsage instance) throws IOException { | ||
boolean available = instance.available(); | ||
int numArchiveIndices = instance.getNumberOfArchiveIndices(); | ||
switch (between(0, 1)) { | ||
case 0 -> available = available == false; | ||
case 1 -> numArchiveIndices = randomValueOtherThan(numArchiveIndices, () -> randomIntBetween(0, 100000)); | ||
default -> throw new AssertionError("Illegal randomisation branch"); | ||
} | ||
return new ArchiveFeatureSetUsage(available, numArchiveIndices); | ||
} | ||
|
||
@Override | ||
protected Writeable.Reader<ArchiveFeatureSetUsage> instanceReader() { | ||
return ArchiveFeatureSetUsage::new; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...versions/src/main/java/org/elasticsearch/xpack/lucene/bwc/ArchiveInfoTransportAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.lucene.bwc; | ||
|
||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.license.XPackLicenseState; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.XPackField; | ||
import org.elasticsearch.xpack.core.action.XPackInfoFeatureAction; | ||
import org.elasticsearch.xpack.core.action.XPackInfoFeatureTransportAction; | ||
|
||
import static org.elasticsearch.xpack.lucene.bwc.OldLuceneVersions.ARCHIVE_FEATURE; | ||
|
||
public class ArchiveInfoTransportAction extends XPackInfoFeatureTransportAction { | ||
|
||
private final XPackLicenseState licenseState; | ||
|
||
@Inject | ||
public ArchiveInfoTransportAction(TransportService transportService, ActionFilters actionFilters, XPackLicenseState licenseState) { | ||
super(XPackInfoFeatureAction.ARCHIVE.name(), transportService, actionFilters); | ||
this.licenseState = licenseState; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return XPackField.ARCHIVE; | ||
} | ||
|
||
@Override | ||
public boolean available() { | ||
return ARCHIVE_FEATURE.checkWithoutTracking(licenseState); | ||
} | ||
|
||
@Override | ||
public boolean enabled() { | ||
return true; | ||
} | ||
} |
Oops, something went wrong.