/** Tears down external resources that can be deleted upon the example's completion. */ private void tearDown() { pendingMessages.add("*************************Tear Down*************************"); ExamplePubsubTopicOptions pubsubTopicOptions = options.as(ExamplePubsubTopicOptions.class); if (!pubsubTopicOptions.getPubsubTopic().isEmpty()) { try { deletePubsubTopic(pubsubTopicOptions.getPubsubTopic()); pendingMessages.add( "The Pub/Sub topic has been deleted: " + pubsubTopicOptions.getPubsubTopic()); } catch (IOException e) { pendingMessages.add( "Failed to delete the Pub/Sub topic : " + pubsubTopicOptions.getPubsubTopic()); } } ExampleBigQueryTableOptions bigQueryTableOptions = options.as(ExampleBigQueryTableOptions.class); if (bigQueryTableOptions.getBigQueryDataset() != null && bigQueryTableOptions.getBigQueryTable() != null && bigQueryTableOptions.getBigQuerySchema() != null) { pendingMessages.add( "The BigQuery table might contain the example's output, " + "and it is not deleted automatically: " + bigQueryTableOptions.getProject() + ":" + bigQueryTableOptions.getBigQueryDataset() + "." + bigQueryTableOptions.getBigQueryTable()); pendingMessages.add( "Please go to the Developers Console to delete it manually." + " Otherwise, you may be charged for its usage."); } }
/** * Sets up the BigQuery table with the given schema. * * <p>If the table already exists, the schema has to match the given one. Otherwise, the example * will throw a RuntimeException. If the table doesn't exist, a new table with the given schema * will be created. * * @throws IOException if there is a problem setting up the BigQuery table */ public void setupBigQueryTable() throws IOException { ExampleBigQueryTableOptions bigQueryTableOptions = options.as(ExampleBigQueryTableOptions.class); if (bigQueryTableOptions.getBigQueryDataset() != null && bigQueryTableOptions.getBigQueryTable() != null && bigQueryTableOptions.getBigQuerySchema() != null) { pendingMessages.add("******************Set Up Big Query Table*******************"); setupBigQueryTable( bigQueryTableOptions.getProject(), bigQueryTableOptions.getBigQueryDataset(), bigQueryTableOptions.getBigQueryTable(), bigQueryTableOptions.getBigQuerySchema()); pendingMessages.add( "The BigQuery table has been set up for this example: " + bigQueryTableOptions.getProject() + ":" + bigQueryTableOptions.getBigQueryDataset() + "." + bigQueryTableOptions.getBigQueryTable()); } }