Search in sources :

Example 1 with CloudSqlCredential

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

the class UpdateConnectionIT method setUp.

@Before
public void setUp() throws IOException {
    bout = new ByteArrayOutputStream();
    out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    // create a temporary connection
    connectionId = "UPDATE_CONNECTION_TEST_" + UUID.randomUUID().toString().substring(0, 8);
    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();
    Connection connection = Connection.newBuilder().setCloudSql(cloudSqlProperties).build();
    CreateConnection.createConnection(PROJECT_ID, LOCATION, connectionId, connection);
}
Also used : PrintStream(java.io.PrintStream) CloudSqlCredential(com.google.cloud.bigquery.connection.v1.CloudSqlCredential) Connection(com.google.cloud.bigquery.connection.v1.Connection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CloudSqlProperties(com.google.cloud.bigquery.connection.v1.CloudSqlProperties) Before(org.junit.Before)

Example 2 with CloudSqlCredential

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

the class ListConnectionsIT method setUp.

@Before
public void setUp() throws IOException {
    bout = new ByteArrayOutputStream();
    out = new PrintStream(bout);
    originalPrintStream = System.out;
    System.setOut(out);
    // create a temporary connection
    connectionId = "LIST_CONNECTIONS_TEST_" + UUID.randomUUID().toString().substring(0, 8);
    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();
    Connection connection = Connection.newBuilder().setCloudSql(cloudSqlProperties).build();
    CreateConnection.createConnection(PROJECT_ID, LOCATION, connectionId, connection);
}
Also used : PrintStream(java.io.PrintStream) CloudSqlCredential(com.google.cloud.bigquery.connection.v1.CloudSqlCredential) Connection(com.google.cloud.bigquery.connection.v1.Connection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CloudSqlProperties(com.google.cloud.bigquery.connection.v1.CloudSqlProperties) Before(org.junit.Before)

Example 3 with CloudSqlCredential

use of com.google.cloud.bigquery.connection.v1.CloudSqlCredential 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 4 with CloudSqlCredential

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

the class CreateConnection method main.

public static void main(String[] args) throws IOException {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "MY_PROJECT_ID";
    String location = "MY_LOCATION";
    String connectionId = "MY_CONNECTION_ID";
    String database = "MY_DATABASE";
    String instance = "MY_INSTANCE";
    String instanceLocation = "MY_INSTANCE_LOCATION";
    String username = "MY_USERNAME";
    String password = "MY_PASSWORD";
    String instanceId = String.format("%s:%s:%s", projectId, instanceLocation, instance);
    CloudSqlCredential cloudSqlCredential = CloudSqlCredential.newBuilder().setUsername(username).setPassword(password).build();
    CloudSqlProperties cloudSqlProperties = CloudSqlProperties.newBuilder().setType(CloudSqlProperties.DatabaseType.MYSQL).setDatabase(database).setInstanceId(instanceId).setCredential(cloudSqlCredential).build();
    Connection connection = Connection.newBuilder().setCloudSql(cloudSqlProperties).build();
    createConnection(projectId, location, connectionId, connection);
}
Also used : CloudSqlCredential(com.google.cloud.bigquery.connection.v1.CloudSqlCredential) Connection(com.google.cloud.bigquery.connection.v1.Connection) CloudSqlProperties(com.google.cloud.bigquery.connection.v1.CloudSqlProperties)

Example 5 with CloudSqlCredential

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

the class CreateConnectionIT method testCreateConnection.

@Test
public void testCreateConnection() throws IOException {
    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();
    Connection connection = Connection.newBuilder().setFriendlyName(connectionId).setCloudSql(cloudSqlProperties).build();
    CreateConnection.createConnection(PROJECT_ID, LOCATION, connectionId, connection);
    assertThat(bout.toString()).contains("Connection created successfully :");
}
Also used : CloudSqlCredential(com.google.cloud.bigquery.connection.v1.CloudSqlCredential) Connection(com.google.cloud.bigquery.connection.v1.Connection) CloudSqlProperties(com.google.cloud.bigquery.connection.v1.CloudSqlProperties) Test(org.junit.Test)

Aggregations

CloudSqlCredential (com.google.cloud.bigquery.connection.v1.CloudSqlCredential)8 CloudSqlProperties (com.google.cloud.bigquery.connection.v1.CloudSqlProperties)8 Connection (com.google.cloud.bigquery.connection.v1.Connection)7 Before (org.junit.Before)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 PrintStream (java.io.PrintStream)5 CreateConnectionRequest (com.google.cloud.bigquery.connection.v1.CreateConnectionRequest)1 Test (org.junit.Test)1