Search in sources :

Example 1 with CreateConnectionRequest

use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method createConnectionTest.

@Test
public void createConnectionTest() throws Exception {
    Connection expectedResponse = Connection.newBuilder().setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString()).setFriendlyName("friendlyName461933014").setDescription("description-1724546052").setCreationTime(1932333101).setLastModifiedTime(-671513446).setHasCredential(true).build();
    mockConnectionService.addResponse(expectedResponse);
    LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
    Connection connection = Connection.newBuilder().build();
    String connectionId = "connectionId1923106969";
    Connection actualResponse = client.createConnection(parent, connection, connectionId);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateConnectionRequest actualRequest = ((CreateConnectionRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertEquals(connection, actualRequest.getConnection());
    Assert.assertEquals(connectionId, actualRequest.getConnectionId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Connection(com.google.cloud.bigquery.connection.v1.Connection) ByteString(com.google.protobuf.ByteString) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) LocationName(com.google.cloud.bigquery.connection.v1.LocationName) Test(org.junit.Test)

Example 2 with CreateConnectionRequest

use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.

the class CreateConnection method createConnection.

public static void createConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        LocationName parent = LocationName.of(projectId, location);
        CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();
        Connection response = client.createConnection(request);
        System.out.println("Connection created successfully :" + response.getName());
    }
}
Also used : ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) Connection(com.google.cloud.bigquery.connection.v1.Connection) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) LocationName(com.google.cloud.bigquery.connection.v1.LocationName)

Example 3 with CreateConnectionRequest

use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.

the class ConnectionServiceClientTest method createConnectionTest2.

@Test
public void createConnectionTest2() throws Exception {
    Connection expectedResponse = Connection.newBuilder().setName(ConnectionName.of("[PROJECT]", "[LOCATION]", "[CONNECTION]").toString()).setFriendlyName("friendlyName461933014").setDescription("description-1724546052").setCreationTime(1932333101).setLastModifiedTime(-671513446).setHasCredential(true).build();
    mockConnectionService.addResponse(expectedResponse);
    String parent = "parent-995424086";
    Connection connection = Connection.newBuilder().build();
    String connectionId = "connectionId1923106969";
    Connection actualResponse = client.createConnection(parent, connection, connectionId);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateConnectionRequest actualRequest = ((CreateConnectionRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertEquals(connection, actualRequest.getConnection());
    Assert.assertEquals(connectionId, actualRequest.getConnectionId());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) Connection(com.google.cloud.bigquery.connection.v1.Connection) ByteString(com.google.protobuf.ByteString) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) Test(org.junit.Test)

Example 4 with CreateConnectionRequest

use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.

the class ITSystemTest method setUp.

@Before
public void setUp() throws IOException {
    client = ConnectionServiceClient.create();
    // create a temporary connection to be deleted
    String instanceId = String.format("%s:%s:%s", PROJECT_ID, REGION, MY_SQL_INSTANCE);
    CloudSqlCredential cloudSqlCredential = CloudSqlCredential.newBuilder().setUsername(DB_USER).setPassword(DB_PWD).build();
    CloudSqlProperties cloudSqlProperties = CloudSqlProperties.newBuilder().setType(CloudSqlProperties.DatabaseType.MYSQL).setDatabase(MY_SQL_DATABASE).setInstanceId(instanceId).setCredential(cloudSqlCredential).build();
    CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(PARENT).setConnection(Connection.newBuilder().setCloudSql(cloudSqlProperties).build()).setConnectionId(CONNECTION_ID).build();
    connection = client.createConnection(request);
}
Also used : CloudSqlCredential(com.google.cloud.bigquery.connection.v1.CloudSqlCredential) CloudSqlProperties(com.google.cloud.bigquery.connection.v1.CloudSqlProperties) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) Before(org.junit.Before)

Example 5 with CreateConnectionRequest

use of com.google.cloud.bigquery.connection.v1.CreateConnectionRequest in project java-bigqueryconnection by googleapis.

the class CreateAwsConnection method createAwsConnection.

public static void createAwsConnection(String projectId, String location, String connectionId, Connection connection) throws IOException {
    try (ConnectionServiceClient client = ConnectionServiceClient.create()) {
        LocationName parent = LocationName.of(projectId, location);
        CreateConnectionRequest request = CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();
        Connection response = client.createConnection(request);
        AwsAccessRole role = response.getAws().getAccessRole();
        System.out.println("Aws connection created successfully : Aws userId :" + role.getIamRoleId() + " Aws externalId :" + role.getIdentity());
    }
}
Also used : ConnectionServiceClient(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient) AwsAccessRole(com.google.cloud.bigquery.connection.v1.AwsAccessRole) Connection(com.google.cloud.bigquery.connection.v1.Connection) CreateConnectionRequest(com.google.cloud.bigquery.connection.v1.CreateConnectionRequest) LocationName(com.google.cloud.bigquery.connection.v1.LocationName)

Aggregations

CreateConnectionRequest (com.google.cloud.bigquery.connection.v1.CreateConnectionRequest)5 Connection (com.google.cloud.bigquery.connection.v1.Connection)4 LocationName (com.google.cloud.bigquery.connection.v1.LocationName)3 ConnectionServiceClient (com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 ByteString (com.google.protobuf.ByteString)2 Test (org.junit.Test)2 AwsAccessRole (com.google.cloud.bigquery.connection.v1.AwsAccessRole)1 CloudSqlCredential (com.google.cloud.bigquery.connection.v1.CloudSqlCredential)1 CloudSqlProperties (com.google.cloud.bigquery.connection.v1.CloudSqlProperties)1 Before (org.junit.Before)1