Skip to content

Commit

Permalink
Replace Streamable w/ Writeable in RoleDescriptor
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: elastic#34389
  • Loading branch information
tvernum committed Oct 17, 2018
1 parent b3be96a commit f73e2a7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 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,14 @@ 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();
}

public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -722,21 +730,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);
Expand Down Expand Up @@ -798,7 +791,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 @@ -817,6 +810,12 @@ 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();
}

public static Builder builder() {
return new Builder();
}
Expand Down Expand Up @@ -878,19 +877,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);
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 f73e2a7

Please sign in to comment.