-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement getCompactionJob async RPC using Jetty and REST #5018
Draft
cshannon
wants to merge
3
commits into
apache:main
Choose a base branch
from
cshannon:accumulo-5000-jetty
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
83 changes: 83 additions & 0 deletions
83
server/base/src/main/java/org/apache/accumulo/server/rest/ThriftDeserializer.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,83 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.accumulo.server.rest; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.apache.accumulo.server.rest.ThriftSerializer.ENCODED; | ||
import static org.apache.accumulo.server.rest.ThriftSerializer.TYPE; | ||
|
||
import java.io.IOException; | ||
import java.lang.reflect.Constructor; | ||
|
||
import org.apache.thrift.TBase; | ||
import org.apache.thrift.TDeserializer; | ||
import org.apache.thrift.TException; | ||
import org.apache.thrift.protocol.TJSONProtocol; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
/** | ||
* Jackson deserializer for thrift objects that delegates the deserialization of thrift to | ||
* {@link TDeserializer}. It handles previously encoded serialized objects from | ||
* {@link ThriftSerializer} | ||
*/ | ||
public class ThriftDeserializer<T extends TBase<?,?>> extends JsonDeserializer<T> { | ||
@Override | ||
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { | ||
JsonNode tree = p.readValueAsTree(); | ||
|
||
try { | ||
var thriftClassName = tree.get(TYPE).asText(); | ||
var encoded = tree.get(ENCODED).asText(); | ||
|
||
Constructor<T> constructor = getThriftClass(thriftClassName).getDeclaredConstructor(); | ||
T obj = constructor.newInstance(); | ||
deserialize(obj, encoded); | ||
|
||
return obj; | ||
} catch (ReflectiveOperationException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
private Class<T> getThriftClass(String className) throws ClassNotFoundException { | ||
var clazz = Class.forName(className, false, ThriftDeserializer.class.getClassLoader()); | ||
// Note: This check is important to prevent potential security issues | ||
// We don't want to allow arbitrary classes to be loaded | ||
if (!TBase.class.isAssignableFrom(clazz)) { | ||
throw new IllegalArgumentException("Class " + clazz + " is not assignable to TBase"); | ||
} | ||
return (Class<T>) clazz; | ||
} | ||
|
||
// TODO: It doesn't seem like TDeserializer is thread safe, is there a way | ||
// to prevent creating a new deserializer for every object? | ||
private static <T extends TBase<?,?>> void deserialize(T obj, String json) throws IOException { | ||
try { | ||
final TDeserializer deserializer = new TDeserializer(new TJSONProtocol.Factory()); | ||
deserializer.deserialize(obj, json, UTF_8.name()); | ||
} catch (TException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
server/base/src/main/java/org/apache/accumulo/server/rest/ThriftMixIn.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,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.accumulo.server.rest; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
|
||
@JsonSerialize(using = ThriftSerializer.class) | ||
@JsonDeserialize(using = ThriftDeserializer.class) | ||
public abstract class ThriftMixIn { | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
server/base/src/main/java/org/apache/accumulo/server/rest/ThriftSerializer.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,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.accumulo.server.rest; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.thrift.TBase; | ||
import org.apache.thrift.TException; | ||
import org.apache.thrift.TSerializer; | ||
import org.apache.thrift.protocol.TJSONProtocol; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
|
||
/** | ||
* Jackson serializer for thrift objects that delegates the serialization of thrift to | ||
* {@link TSerializer} and also includes the serialized type for the deserializer to use | ||
*/ | ||
public class ThriftSerializer<T extends TBase<?,?>> extends JsonSerializer<T> { | ||
|
||
static final String TYPE = "type"; | ||
static final String ENCODED = "encoded"; | ||
|
||
@Override | ||
public void serialize(T value, JsonGenerator gen, SerializerProvider serializers) | ||
throws IOException { | ||
gen.writeStartObject(); | ||
gen.writeObjectField(TYPE, value.getClass()); | ||
gen.writeStringField(ENCODED, serialize(value)); | ||
gen.writeEndObject(); | ||
} | ||
|
||
// TODO: It doesn't seem like TSerializer is thread safe, is there a way | ||
// to prevent creating a new serializer for every object? | ||
private static <T extends TBase<?,?>> String serialize(T obj) throws IOException { | ||
try { | ||
final TSerializer serializer = new TSerializer(new TJSONProtocol.Factory()); | ||
return serializer.toString(obj); | ||
} catch (TException e) { | ||
throw new IOException(e); | ||
} | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
...r/base/src/main/java/org/apache/accumulo/server/rest/request/GetCompactionJobRequest.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,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.accumulo.server.rest.request; | ||
|
||
import org.apache.accumulo.core.clientImpl.thrift.TInfo; | ||
import org.apache.accumulo.core.securityImpl.thrift.TCredentials; | ||
|
||
public class GetCompactionJobRequest { | ||
|
||
private TInfo tinfo; | ||
private TCredentials credentials; | ||
private String groupName; | ||
private String compactorAddress; | ||
private String externalCompactionId; | ||
|
||
public GetCompactionJobRequest() {} | ||
|
||
public GetCompactionJobRequest(TInfo tinfo, TCredentials credentials, String groupName, | ||
String compactorAddress, String externalCompactionId) { | ||
this.tinfo = tinfo; | ||
this.credentials = credentials; | ||
this.groupName = groupName; | ||
this.compactorAddress = compactorAddress; | ||
this.externalCompactionId = externalCompactionId; | ||
} | ||
|
||
public TInfo getTinfo() { | ||
return tinfo; | ||
} | ||
|
||
public void setTinfo(TInfo tinfo) { | ||
this.tinfo = tinfo; | ||
} | ||
|
||
public TCredentials getCredentials() { | ||
return credentials; | ||
} | ||
|
||
public void setCredentials(TCredentials credentials) { | ||
this.credentials = credentials; | ||
} | ||
|
||
public String getGroupName() { | ||
return groupName; | ||
} | ||
|
||
public void setGroupName(String groupName) { | ||
this.groupName = groupName; | ||
} | ||
|
||
public String getCompactorAddress() { | ||
return compactorAddress; | ||
} | ||
|
||
public void setCompactorAddress(String compactorAddress) { | ||
this.compactorAddress = compactorAddress; | ||
} | ||
|
||
public String getExternalCompactionId() { | ||
return externalCompactionId; | ||
} | ||
|
||
public void setExternalCompactionId(String externalCompactionId) { | ||
this.externalCompactionId = externalCompactionId; | ||
} | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Factory is thread-safe, right? I can imagine that the Deserializer is not. You could put the TDeserializer and TSerializers in a ThreadLocal. It looks like they reset their internals for reuse.