forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] Add usage to get ILM policy response (elastic#74518) (elastic#7…
- Loading branch information
Showing
9 changed files
with
422 additions
and
11 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
122 changes: 122 additions & 0 deletions
122
server/src/main/java/org/elasticsearch/cluster/metadata/ItemUsage.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,122 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.metadata; | ||
|
||
import org.elasticsearch.common.Strings; | ||
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.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.core.Nullable; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
/** | ||
* A class encapsulating the usage of a particular "thing" by something else | ||
*/ | ||
public class ItemUsage implements Writeable, ToXContentObject { | ||
|
||
private final Set<String> indices; | ||
private final Set<String> dataStreams; | ||
private final Set<String> composableTemplates; | ||
|
||
/** | ||
* Create a new usage, a {@code null} value indicates that the item *cannot* be used by the | ||
* thing, otherwise use an empty collection to indicate no usage. | ||
*/ | ||
public ItemUsage(@Nullable Collection<String> indices, | ||
@Nullable Collection<String> dataStreams, | ||
@Nullable Collection<String> composableTemplates) { | ||
this.indices = indices == null ? null : new HashSet<>(indices); | ||
this.dataStreams = dataStreams == null ? null : new HashSet<>(dataStreams); | ||
this.composableTemplates = composableTemplates == null ? null : new HashSet<>(composableTemplates); | ||
} | ||
|
||
public ItemUsage(StreamInput in) throws IOException { | ||
if (in.readBoolean()) { | ||
this.indices = in.readSet(StreamInput::readString); | ||
} else { | ||
this.indices = null; | ||
} | ||
if (in.readBoolean()) { | ||
this.dataStreams = in.readSet(StreamInput::readString); | ||
} else { | ||
this.dataStreams = null; | ||
} | ||
if (in.readBoolean()) { | ||
this.composableTemplates = in.readSet(StreamInput::readString); | ||
} else { | ||
this.composableTemplates = null; | ||
} | ||
} | ||
|
||
public Set<String> getIndices() { | ||
return indices; | ||
} | ||
|
||
public Set<String> getDataStreams() { | ||
return dataStreams; | ||
} | ||
|
||
public Set<String> getComposableTemplates() { | ||
return composableTemplates; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
if (this.indices != null) { | ||
builder.field("indices", this.indices); | ||
} | ||
if (this.dataStreams != null) { | ||
builder.field("data_streams", this.dataStreams); | ||
} | ||
if (this.composableTemplates != null) { | ||
builder.field("composable_templates", this.composableTemplates); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeOptionalStringCollection(this.indices); | ||
out.writeOptionalStringCollection(this.dataStreams); | ||
out.writeOptionalStringCollection(this.composableTemplates); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.indices, this.dataStreams, this.composableTemplates); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
ItemUsage other = (ItemUsage) obj; | ||
return Objects.equals(indices, other.indices) && | ||
Objects.equals(dataStreams, other.dataStreams) && | ||
Objects.equals(composableTemplates, other.composableTemplates); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Strings.toString(this); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
server/src/test/java/org/elasticsearch/cluster/metadata/ItemUsageTests.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,47 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.metadata; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.core.Nullable; | ||
import org.elasticsearch.test.AbstractWireTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class ItemUsageTests extends AbstractWireTestCase<ItemUsage> { | ||
|
||
public static ItemUsage randomUsage() { | ||
return new ItemUsage(randomStringList(), randomStringList(), randomStringList()); | ||
} | ||
|
||
@Nullable | ||
private static List<String> randomStringList() { | ||
if (randomBoolean()) { | ||
return null; | ||
} else { | ||
return randomList(0, 1, () -> randomAlphaOfLengthBetween(2, 10)); | ||
} | ||
} | ||
|
||
@Override | ||
protected ItemUsage createTestInstance() { | ||
return randomUsage(); | ||
} | ||
|
||
@Override | ||
protected ItemUsage copyInstance(ItemUsage instance, Version version) throws IOException { | ||
return new ItemUsage(instance.getIndices(), instance.getDataStreams(), instance.getComposableTemplates()); | ||
} | ||
|
||
@Override | ||
protected ItemUsage mutateInstance(ItemUsage instance) throws IOException { | ||
return super.mutateInstance(instance); | ||
} | ||
} |
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
Oops, something went wrong.