Skip to content

Commit

Permalink
Replace Streamable w/ Writeable in RoleDescriptor (#34544)
Browse files Browse the repository at this point in the history
This commit replaces usage of Streamable with Writeable within the
RoleDescriptor class (and inner classes).

Relates: #34389
  • Loading branch information
tvernum committed Oct 18, 2018
1 parent 9200e15 commit 47e9082
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ public void readFrom(StreamInput in) throws IOException {
int indicesSize = in.readVInt();
indicesPrivileges = new ArrayList<>(indicesSize);
for (int i = 0; i < indicesSize; i++) {
indicesPrivileges.add(RoleDescriptor.IndicesPrivileges.createFrom(in));
indicesPrivileges.add(new RoleDescriptor.IndicesPrivileges(in));
}
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
applicationPrivileges = in.readList(RoleDescriptor.ApplicationResourcePrivileges::createFrom);
applicationPrivileges = in.readList(RoleDescriptor.ApplicationResourcePrivileges::new);
conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
}
runAs = in.readStringArray();
Expand All @@ -186,7 +186,7 @@ public void writeTo(StreamOutput out) throws IOException {
index.writeTo(out);
}
if (out.getVersion().onOrAfter(Version.V_6_4_0)) {
out.writeStreamableList(applicationPrivileges);
out.writeList(applicationPrivileges);
ConditionalClusterPrivileges.writeArray(out, this.conditionalClusterPrivileges);
}
out.writeStringArray(runAs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ public void readFrom(StreamInput in) throws IOException {
int indexSize = in.readVInt();
indexPrivileges = new RoleDescriptor.IndicesPrivileges[indexSize];
for (int i = 0; i < indexSize; i++) {
indexPrivileges[i] = RoleDescriptor.IndicesPrivileges.createFrom(in);
indexPrivileges[i] = new RoleDescriptor.IndicesPrivileges(in);
}
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
applicationPrivileges = in.readArray(ApplicationResourcePrivileges::createFrom, ApplicationResourcePrivileges[]::new);
applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.ObjectParser;
Expand Down Expand Up @@ -238,7 +238,7 @@ public static RoleDescriptor readFrom(StreamInput in) throws IOException {
int size = in.readVInt();
IndicesPrivileges[] indicesPrivileges = new IndicesPrivileges[size];
for (int i = 0; i < size; i++) {
indicesPrivileges[i] = IndicesPrivileges.createFrom(in);
indicesPrivileges[i] = new IndicesPrivileges(in);
}
String[] runAs = in.readStringArray();
Map<String, Object> metadata = in.readMap();
Expand All @@ -248,7 +248,7 @@ public static RoleDescriptor readFrom(StreamInput in) throws IOException {
final ApplicationResourcePrivileges[] applicationPrivileges;
final ConditionalClusterPrivilege[] conditionalClusterPrivileges;
if (in.getVersion().onOrAfter(Version.V_6_4_0)) {
applicationPrivileges = in.readArray(ApplicationResourcePrivileges::createFrom, ApplicationResourcePrivileges[]::new);
applicationPrivileges = in.readArray(ApplicationResourcePrivileges::new, ApplicationResourcePrivileges[]::new);
conditionalClusterPrivileges = ConditionalClusterPrivileges.readArray(in);
} else {
applicationPrivileges = ApplicationResourcePrivileges.NONE;
Expand Down Expand Up @@ -581,7 +581,7 @@ private static ApplicationResourcePrivileges parseApplicationPrivilege(String ro
* A class representing permissions for a group of indices mapped to
* privileges, field permissions, and a query.
*/
public static class IndicesPrivileges implements ToXContentObject, Streamable {
public static class IndicesPrivileges implements ToXContentObject, Writeable {

private static final IndicesPrivileges[] NONE = new IndicesPrivileges[0];

Expand All @@ -594,6 +594,23 @@ public static class IndicesPrivileges implements ToXContentObject, Streamable {
private IndicesPrivileges() {
}

public IndicesPrivileges(StreamInput in) throws IOException {
this.indices = in.readStringArray();
this.grantedFields = in.readOptionalStringArray();
this.deniedFields = in.readOptionalStringArray();
this.privileges = in.readStringArray();
this.query = in.readOptionalBytesReference();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeStringArray(indices);
out.writeOptionalStringArray(grantedFields);
out.writeOptionalStringArray(deniedFields);
out.writeStringArray(privileges);
out.writeOptionalBytesReference(query);
}

public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -722,30 +739,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.endObject();
}

public static IndicesPrivileges createFrom(StreamInput in) throws IOException {
IndicesPrivileges ip = new IndicesPrivileges();
ip.readFrom(in);
return ip;
}

@Override
public void readFrom(StreamInput in) throws IOException {
this.indices = in.readStringArray();
this.grantedFields = in.readOptionalStringArray();
this.deniedFields = in.readOptionalStringArray();
this.privileges = in.readStringArray();
this.query = in.readOptionalBytesReference();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeStringArray(indices);
out.writeOptionalStringArray(grantedFields);
out.writeOptionalStringArray(deniedFields);
out.writeStringArray(privileges);
out.writeOptionalBytesReference(query);
}

public static class Builder {

private IndicesPrivileges indicesPrivileges = new IndicesPrivileges();
Expand Down Expand Up @@ -802,7 +795,7 @@ public IndicesPrivileges build() {
}
}

public static class ApplicationResourcePrivileges implements ToXContentObject, Streamable {
public static class ApplicationResourcePrivileges implements ToXContentObject, Writeable {

private static final ApplicationResourcePrivileges[] NONE = new ApplicationResourcePrivileges[0];
private static final ObjectParser<ApplicationResourcePrivileges.Builder, Void> PARSER = new ObjectParser<>("application",
Expand All @@ -821,6 +814,19 @@ public static class ApplicationResourcePrivileges implements ToXContentObject, S
private ApplicationResourcePrivileges() {
}

public ApplicationResourcePrivileges(StreamInput in) throws IOException {
this.application = in.readString();
this.privileges = in.readStringArray();
this.resources = in.readStringArray();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(application);
out.writeStringArray(privileges);
out.writeStringArray(resources);
}

public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -882,26 +888,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
return builder.endObject();
}

public static ApplicationResourcePrivileges createFrom(StreamInput in) throws IOException {
ApplicationResourcePrivileges ip = new ApplicationResourcePrivileges();
ip.readFrom(in);
return ip;
}

@Override
public void readFrom(StreamInput in) throws IOException {
this.application = in.readString();
this.privileges = in.readStringArray();
this.resources = in.readStringArray();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(application);
out.writeStringArray(privileges);
out.writeStringArray(resources);
}

public static void write(StreamOutput out, ApplicationResourcePrivileges privileges) throws IOException {
privileges.writeTo(out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void testIndicesPrivilegesStreaming() throws IOException {
indicesPrivileges.build().writeTo(out);
out.close();
StreamInput in = out.bytes().streamInput();
RoleDescriptor.IndicesPrivileges readIndicesPrivileges = RoleDescriptor.IndicesPrivileges.createFrom(in);
RoleDescriptor.IndicesPrivileges readIndicesPrivileges = new RoleDescriptor.IndicesPrivileges(in);
assertEquals(readIndicesPrivileges, indicesPrivileges.build());

out = new BytesStreamOutput();
Expand All @@ -206,7 +206,7 @@ public void testIndicesPrivilegesStreaming() throws IOException {
out.close();
in = out.bytes().streamInput();
in.setVersion(Version.V_6_0_0);
RoleDescriptor.IndicesPrivileges readIndicesPrivileges2 = RoleDescriptor.IndicesPrivileges.createFrom(in);
RoleDescriptor.IndicesPrivileges readIndicesPrivileges2 = new RoleDescriptor.IndicesPrivileges(in);
assertEquals(readIndicesPrivileges, readIndicesPrivileges2);
}

Expand Down

0 comments on commit 47e9082

Please sign in to comment.