-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new intercept for QueryHandler.parse which is new in 4.0
- Loading branch information
Showing
13 changed files
with
233 additions
and
17 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
70 changes: 70 additions & 0 deletions
70
...-api-agent/src/main/java/com/datastax/mgmtapi/interceptors/QueryHandlerInterceptor4x.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,70 @@ | ||
/** | ||
* Copyright DataStax, Inc. | ||
* | ||
* Please see the included license file for details. | ||
*/ | ||
package com.datastax.mgmtapi.interceptors; | ||
|
||
import java.util.concurrent.Callable; | ||
import java.util.regex.Matcher; | ||
|
||
import com.datastax.mgmtapi.ShimLoader; | ||
import net.bytebuddy.agent.builder.AgentBuilder; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.dynamic.DynamicType; | ||
import net.bytebuddy.implementation.MethodDelegation; | ||
import net.bytebuddy.implementation.bind.annotation.AllArguments; | ||
import net.bytebuddy.implementation.bind.annotation.RuntimeType; | ||
import net.bytebuddy.implementation.bind.annotation.SuperCall; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
import net.bytebuddy.matcher.ElementMatchers; | ||
import net.bytebuddy.utility.JavaModule; | ||
import org.apache.cassandra.cql3.QueryHandler; | ||
import org.apache.cassandra.service.QueryState; | ||
|
||
import static com.datastax.mgmtapi.interceptors.QueryHandlerInterceptor.handlePrefix; | ||
import static com.datastax.mgmtapi.interceptors.QueryHandlerInterceptor.opsPattern; | ||
|
||
public class QueryHandlerInterceptor4x | ||
{ | ||
public static ElementMatcher<? super TypeDescription> type() | ||
{ | ||
return ElementMatchers.isSubTypeOf(QueryHandler.class); | ||
} | ||
|
||
public static AgentBuilder.Transformer transformer() | ||
{ | ||
return new AgentBuilder.Transformer() | ||
{ | ||
@Override | ||
public DynamicType.Builder<?> transform(DynamicType.Builder<?> builder, TypeDescription typeDescription, ClassLoader classLoader, JavaModule javaModule) | ||
{ | ||
return builder.method(ElementMatchers.named("parse")).intercept(MethodDelegation.to(QueryHandlerInterceptor4x.class)); | ||
} | ||
}; | ||
} | ||
|
||
@RuntimeType | ||
public static Object intercept(@AllArguments Object[] allArguments, @SuperCall Callable<Object> zuper) throws Throwable | ||
{ | ||
if (allArguments.length > 0 && allArguments[0] != null && allArguments[0] instanceof String) | ||
{ | ||
String query = (String) allArguments[0]; | ||
if (query.startsWith(handlePrefix)) | ||
{ | ||
QueryState state = (QueryState) allArguments[1]; | ||
|
||
if (state.getClientState().isInternal) | ||
{ | ||
Matcher m = opsPattern.matcher(query); | ||
if (m.matches()) | ||
{ | ||
return ShimLoader.instance.get().makeRpcStatement(m.group(1), m.group(2).trim().isEmpty() ? new String[]{} : m.group(2).split("\\s*,\\s*")); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return zuper.call(); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
management-api-common/src/main/java/com/datastax/mgmtapi/shims/RpcStatementShim.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,14 @@ | ||
/** | ||
* Copyright DataStax, Inc. | ||
* | ||
* Please see the included license file for details. | ||
*/ | ||
package com.datastax.mgmtapi.shims; | ||
|
||
import org.apache.cassandra.cql3.CQLStatement; | ||
|
||
public interface RpcStatementShim extends CQLStatement | ||
{ | ||
String getMethod(); | ||
String[] getParams(); | ||
} |
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
70 changes: 70 additions & 0 deletions
70
management-api-shim-4.x/src/main/java/com/datastax/mgmtapi/shim/RpcStatement.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,70 @@ | ||
package com.datastax.mgmtapi.shim; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import com.datastax.mgmtapi.shims.RpcStatementShim; | ||
import org.apache.cassandra.audit.AuditLogContext; | ||
import org.apache.cassandra.cql3.CQLStatement; | ||
import org.apache.cassandra.cql3.ColumnSpecification; | ||
import org.apache.cassandra.cql3.QueryOptions; | ||
import org.apache.cassandra.exceptions.InvalidRequestException; | ||
import org.apache.cassandra.service.ClientState; | ||
import org.apache.cassandra.service.QueryState; | ||
import org.apache.cassandra.transport.messages.ResultMessage; | ||
|
||
public class RpcStatement implements RpcStatementShim | ||
{ | ||
private final String method; | ||
private final String[] params; | ||
|
||
public RpcStatement(String method, String[] params) | ||
{ | ||
this.method = method; | ||
this.params = params; | ||
} | ||
|
||
@Override | ||
public void authorize(ClientState clientState) | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public void validate(ClientState clientState) | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public ResultMessage execute(QueryState queryState, QueryOptions queryOptions, long l) | ||
{ | ||
return new ResultMessage.Void(); | ||
} | ||
|
||
@Override | ||
public ResultMessage executeLocally(QueryState queryState, QueryOptions queryOptions) | ||
{ | ||
return new ResultMessage.Void(); | ||
} | ||
|
||
@Override | ||
public AuditLogContext getAuditLogContext() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getMethod() | ||
{ | ||
return method; | ||
} | ||
|
||
@Override | ||
public String[] getParams() | ||
{ | ||
return params; | ||
} | ||
} |
Oops, something went wrong.