Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Nov 7, 2022
1 parent 26ed4d1 commit 8cb1942
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 76 deletions.
2 changes: 2 additions & 0 deletions test-proxy/EnableAutoValue.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This is a marker file to trigger auto-value injection into the annotation processor path
https://github.com/googleapis/java-shared-config/blob/51c9f68ff1736761b21c921f078ab2c8675ff268/pom.xml#L758
65 changes: 54 additions & 11 deletions test-proxy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable-test-proxy</artifactId>
<version>1.0</version>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Google Cloud Bigtable Test Proxy</name>
<url>https://github.com/googleapis/java-bigtable</url>
<description>Cloud Bigtable Java Client test proxy for running conformance tests.</description>

<parent>
<artifactId>google-cloud-bigtable-parent</artifactId>
Expand All @@ -30,11 +31,6 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -55,10 +51,6 @@
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -91,7 +83,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -121,6 +112,58 @@
</execution>
</executions>
</plugin>
<!-- start skip publishing to maven central -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<configuration>
<skipNexusStagingDeployMojo>true</skipNexusStagingDeployMojo>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<configuration>
<skipDeploy>true</skipDeploy>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<configuration>
<skipSource>true</skipSource>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>clirr-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<!-- end skip publishing to maven central -->
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.ServerStream;
import com.google.auth.oauth2.ServiceAccountJwtAccessCredentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.auto.value.AutoValue;
import com.google.bigtable.v2.Column;
import com.google.bigtable.v2.Family;
Expand All @@ -42,6 +42,7 @@
import com.google.cloud.bigtable.data.v2.models.RowMutation;
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;
import com.google.cloud.bigtable.testproxy.CloudBigtableV2TestProxyGrpc.CloudBigtableV2TestProxyImplBase;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.google.protobuf.util.Durations;
import com.google.rpc.Code;
Expand Down Expand Up @@ -201,18 +202,12 @@ private CbtClient getClient(String id) throws StatusException {
@Override
public synchronized void createClient(
CreateClientRequest request, StreamObserver<CreateClientResponse> responseObserver) {
if (request.getClientId().isEmpty()
|| request.getProjectId().isEmpty()
|| request.getInstanceId().isEmpty()
|| request.getDataTarget().isEmpty()) {
responseObserver.onError(
Status.INVALID_ARGUMENT
.withDescription("clientId, projectId, instanceId, and dataTarget must be provided.")
.asException());
return;
}
Preconditions.checkArgument(!request.getClientId().isEmpty(), "client id must be provided");
Preconditions.checkArgument(!request.getProjectId().isEmpty(), "project id must be provided");
Preconditions.checkArgument(!request.getInstanceId().isEmpty(), "instance id must be provided");
Preconditions.checkArgument(!request.getDataTarget().isEmpty(), "data target must be provided");

if (idClientMap.get(request.getClientId()) != null) {
if (idClientMap.contains(request.getClientId())) {
responseObserver.onError(
Status.ALREADY_EXISTS
.withDescription("Client " + request.getClientId() + " already exists.")
Expand Down Expand Up @@ -257,12 +252,11 @@ public synchronized void createClient(
@Override
public void closeClient(
CloseClientRequest request, StreamObserver<CloseClientResponse> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -291,12 +285,11 @@ public void removeClient(
@Override
public void mutateRow(
MutateRowRequest request, StreamObserver<MutateRowResult> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -327,12 +320,11 @@ public void mutateRow(
@Override
public void bulkMutateRows(
MutateRowsRequest request, StreamObserver<MutateRowsResult> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -377,12 +369,11 @@ public void bulkMutateRows(

@Override
public void readRow(ReadRowRequest request, StreamObserver<RowResult> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -442,12 +433,11 @@ public void readRow(ReadRowRequest request, StreamObserver<RowResult> responseOb

@Override
public void readRows(ReadRowsRequest request, StreamObserver<RowsResult> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -558,12 +548,11 @@ private static RowsResult.Builder convertRowsResult(
@Override
public void sampleRowKeys(
SampleRowKeysRequest request, StreamObserver<SampleRowKeysResult> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -607,12 +596,11 @@ public void sampleRowKeys(
@Override
public void checkAndMutateRow(
CheckAndMutateRowRequest request, StreamObserver<CheckAndMutateRowResult> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -643,12 +631,11 @@ public void checkAndMutateRow(
@Override
public void readModifyWriteRow(
ReadModifyWriteRowRequest request, StreamObserver<RowResult> responseObserver) {
CbtClient client = idClientMap.get(request.getClientId());
if (client == null) {
responseObserver.onError(
Status.NOT_FOUND
.withDescription("Client " + request.getClientId() + " not found.")
.asException());
CbtClient client;
try {
client = getClient(request.getClientId());
} catch (StatusException e) {
responseObserver.onError(e);
return;
}

Expand Down Expand Up @@ -749,9 +736,9 @@ private CredentialsProvider getCredentialsProvider() throws IOException {
return NoCredentialsProvider.create();
}

final ServiceAccountJwtAccessCredentials creds =
ServiceAccountJwtAccessCredentials.fromStream(
new ByteArrayInputStream(credential.getBytes(UTF_8)));
final GoogleCredentials creds =
GoogleCredentials.fromStream(new ByteArrayInputStream(credential.getBytes(UTF_8)));

return FixedCredentialsProvider.create(creds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ private CbtTestProxyMain() {}
private static final Logger logger = Logger.getLogger(CbtTestProxyMain.class.getName());

public static void main(String[] args) throws InterruptedException, IOException {
int port = Integer.parseInt(System.getProperty("port", "9999"));
int port = Integer.getInteger("port", 9999);
if (port <= 0) {
throw new IllegalArgumentException(String.format("Port %d is not > 0.", port));
}

CbtTestProxy cbtTestProxy = CbtTestProxy.createUnencrypted();
CbtTestProxy cbtTestProxy;

// If encryption is specified
boolean encrypted = Boolean.getBoolean("encrypted");
Expand All @@ -41,6 +41,8 @@ public static void main(String[] args) throws InterruptedException, IOException
String sslTarget = System.getProperty("ssl.target");
String credentialJsonPath = System.getProperty("credential.json.path");
cbtTestProxy = CbtTestProxy.createEncrypted(rootCertsPemPath, sslTarget, credentialJsonPath);
} else {
cbtTestProxy = CbtTestProxy.createUnencrypted();
}

logger.info(String.format("Test proxy starting on %d", port));
Expand Down

0 comments on commit 8cb1942

Please sign in to comment.