com.google.api.gax.rpc.NotFoundException Java Examples

The following examples show how to use com.google.api.gax.rpc.NotFoundException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PubsubHelper.java    From flink with Apache License 2.0 6 votes vote down vote up
public void deleteTopic(ProjectTopicName topicName) throws IOException {
	TopicAdminClient adminClient = getTopicAdminClient();
	try {
		adminClient.getTopic(topicName);
	} catch (NotFoundException e) {
		// Doesn't exist. Good.
		return;
	}

	// If it exists we delete all subscriptions and the topic itself.
	LOG.info("DeleteTopic {} first delete old subscriptions.", topicName);
	adminClient
		.listTopicSubscriptions(topicName)
		.iterateAllAsProjectSubscriptionName()
		.forEach(subscriptionAdminClient::deleteSubscription);
	LOG.info("DeleteTopic {}", topicName);
	adminClient
		.deleteTopic(topicName);
}
 
Example #2
Source File: PubsubHelper.java    From flink with Apache License 2.0 6 votes vote down vote up
public void deleteTopic(ProjectTopicName topicName) throws IOException {
	TopicAdminClient adminClient = getTopicAdminClient();
	try {
		adminClient.getTopic(topicName);
	} catch (NotFoundException e) {
		// Doesn't exist. Good.
		return;
	}

	// If it exists we delete all subscriptions and the topic itself.
	LOG.info("DeleteTopic {} first delete old subscriptions.", topicName);
	adminClient
		.listTopicSubscriptions(topicName)
		.iterateAllAsProjectSubscriptionName()
		.forEach(subscriptionAdminClient::deleteSubscription);
	LOG.info("DeleteTopic {}", topicName);
	adminClient
		.deleteTopic(topicName);
}
 
Example #3
Source File: SamplesTest.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteOccurrence() throws Exception {
  Occurrence o = CreateOccurrence.createOccurrence(imageUrl, noteId, PROJECT_ID, PROJECT_ID);
  String occName = o.getName();
  String[] nameArr = occName.split("/");
  String occId = nameArr[nameArr.length - 1];

  DeleteOccurrence.deleteOccurrence(occId, PROJECT_ID);

  try {
    GetOccurrence.getOccurrence(occId, PROJECT_ID);
    // getOccurrence should fail, because occurrence was deleted
    Assert.fail("failed to delete occurrence");
  } catch (NotFoundException e) {
    // test passes
  }
}
 
Example #4
Source File: HelloWorld.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to read an entire table. */
public void readTable() {
  // [START bigtable_hw_scan_all_veneer]
  try {
    System.out.println("\nReading the entire table");
    Query query = Query.create(tableId);
    ServerStream<Row> rowStream = dataClient.readRows(query);
    for (Row r : rowStream) {
      System.out.println("Row Key: " + r.getKey().toStringUtf8());
      for (RowCell cell : r.getCells()) {
        System.out.printf(
            "Family: %s    Qualifier: %s    Value: %s%n",
            cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
      }
    }
  } catch (NotFoundException e) {
    System.err.println("Failed to read a non-existent table: " + e.getMessage());
  }
  // [END bigtable_hw_scan_all_veneer]
}
 
Example #5
Source File: HelloWorld.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to read a single row from a table. */
public void readSingleRow() {
  // [START bigtable_hw_get_by_key_veneer]
  try {
    System.out.println("\nReading a single row by row key");
    Row row = dataClient.readRow(tableId, ROW_KEY_PREFIX + 0);
    System.out.println("Row: " + row.getKey().toStringUtf8());
    for (RowCell cell : row.getCells()) {
      System.out.printf(
          "Family: %s    Qualifier: %s    Value: %s%n",
          cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
    }
  } catch (NotFoundException e) {
    System.err.println("Failed to read from a non-existent table: " + e.getMessage());
  }
  // [END bigtable_hw_get_by_key_veneer]
}
 
Example #6
Source File: HelloWorld.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to write some rows to a table. */
public void writeToTable() {
  // [START bigtable_hw_write_rows_veneer]
  try {
    System.out.println("\nWriting some greetings to the table");
    String[] greetings = {"Hello World!", "Hello Bigtable!", "Hello Java!"};
    for (int i = 0; i < greetings.length; i++) {
      RowMutation rowMutation =
          RowMutation.create(tableId, ROW_KEY_PREFIX + i)
              .setCell(COLUMN_FAMILY, COLUMN_QUALIFIER, greetings[i]);
      dataClient.mutateRow(rowMutation);
      System.out.println(greetings[i]);
    }
  } catch (NotFoundException e) {
    System.err.println("Failed to write to non-existent table: " + e.getMessage());
  }
  // [END bigtable_hw_write_rows_veneer]
}
 
Example #7
Source File: InstanceAdminExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to get an instance. */
public Instance getInstance() {
  System.out.println("\nGet Instance");
  // [START bigtable_get_instance]
  Instance instance = null;
  try {
    instance = adminClient.getInstance(instanceId);
    System.out.println("Instance ID: " + instance.getId());
    System.out.println("Display Name: " + instance.getDisplayName());
    System.out.print("Labels: ");
    Map<String, String> labels = instance.getLabels();
    for (String key : labels.keySet()) {
      System.out.printf("%s - %s", key, labels.get(key));
    }
    System.out.println("\nState: " + instance.getState());
    System.out.println("Type: " + instance.getType());
  } catch (NotFoundException e) {
    System.err.println("Failed to get non-existent instance: " + e.getMessage());
  }
  // [END bigtable_get_instance]
  return instance;
}
 
Example #8
Source File: TableAdminExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to print the modified column family. */
public void printModifiedColumnFamily() {
  System.out.printf("%nPrint updated GC rule for column family %s%n", COLUMN_FAMILY_1);
  // [START bigtable_family_get_gc_rule]
  try {
    Table table = adminClient.getTable(tableId);
    Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
    for (ColumnFamily columnFamily : columnFamilies) {
      if (columnFamily.getId().equals(COLUMN_FAMILY_1)) {
        System.out.printf(
            "Column family: %s%nGC Rule: %s%n",
            columnFamily.getId(), columnFamily.getGCRule().toString());
      }
    }
  } catch (NotFoundException e) {
    System.err.println("Failed to print a non-existent column family: " + e.getMessage());
  }
  // [END bigtable_family_get_gc_rule]
}
 
Example #9
Source File: TableAdminExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to modify a column family's rule. */
public void modifyColumnFamilyRule() {
  System.out.printf("%nUpdating column family %s GC rule%n", COLUMN_FAMILY_1);
  // [START bigtable_update_gc_rule]
  // Updates the column family metadata to update the GC rule.
  // Updates a column family GC rule.
  VersionRule versionRule = GCRULES.maxVersions(1);
  try {
    // ModifyColumnFamiliesRequest can be used both for adding and modifying families, here it is
    // being used to modify a family
    // Updates column family with given GC rule.
    ModifyColumnFamiliesRequest updateRequest =
        ModifyColumnFamiliesRequest.of(tableId).updateFamily(COLUMN_FAMILY_1, versionRule);
    adminClient.modifyFamilies(updateRequest);
    System.out.printf("Column family %s GC rule updated%n", COLUMN_FAMILY_1);
  } catch (NotFoundException e) {
    System.err.println("Failed to modify a non-existent column family: " + e.getMessage());
  }
  // [END bigtable_update_gc_rule]
}
 
Example #10
Source File: TableAdminExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to list a table's column families. */
public void listColumnFamilies() {
  System.out.println("\nPrinting ID and GC Rule for all column families");
  // [START bigtable_list_column_families]
  // Lists all families in the table with GC rules.
  try {
    Table table = adminClient.getTable(tableId);
    Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
    for (ColumnFamily columnFamily : columnFamilies) {
      System.out.printf(
          "Column family: %s%nGC Rule: %s%n",
          columnFamily.getId(), columnFamily.getGCRule().toString());
    }
  } catch (NotFoundException e) {
    System.err.println(
        "Failed to list column families from a non-existent table: " + e.getMessage());
  }
  // [END bigtable_list_column_families]
}
 
Example #11
Source File: TableAdminExample.java    From java-docs-samples with Apache License 2.0 6 votes vote down vote up
/** Demonstrates how to get a table's metadata. */
public void getTableMeta() {
  System.out.println("\nPrinting table metadata");
  // [START bigtable_get_table_metadata]
  // Gets table metadata, and applies a view to the table fields.
  try {
    Table table = adminClient.getTable(tableId);
    System.out.println("Table: " + table.getId());
    Collection<ColumnFamily> columnFamilies = table.getColumnFamilies();
    for (ColumnFamily columnFamily : columnFamilies) {
      System.out.printf(
          "Column family: %s%nGC Rule: %s%n",
          columnFamily.getId(), columnFamily.getGCRule().toString());
    }
  } catch (NotFoundException e) {
    System.err.println(
        "Failed to retrieve table metadata for a non-existent table: " + e.getMessage());
  }
  // [END bigtable_get_table_metadata]
}
 
Example #12
Source File: SecretManagerTest.java    From gcp-token-broker with Apache License 2.0 6 votes vote down vote up
/**
 * Check that there is a loud failure if a required secret is missing.
 */
@Test
public void testFailMissingRequired() throws IOException {
    Object downloads = ConfigFactory.parseString(
    AppSettings.SECRET_MANAGER_DOWNLOADS + "=[" +
        "{" +
            "secret = \"projects/" + projectId + "/secrets/missing-required/versions/latest\"," +
            "file = \"" + secretsDirectory.resolve("missing-required.txt") + "\"" +
        "}" +
    "]").getAnyRef(AppSettings.SECRET_MANAGER_DOWNLOADS);
    try(SettingsOverride override = SettingsOverride.apply(Map.of(AppSettings.SECRET_MANAGER_DOWNLOADS, downloads))) {
        try {
            SecretManager.downloadSecrets();
            fail();
        }
        catch (RuntimeException e) {
            // Expected
            assertTrue(e.getCause().getClass().equals(NotFoundException.class));
        }
    }
}
 
Example #13
Source File: PubSubConnector.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
private void createSubscription(final PubSubConfig config) {
    final SubscriptionAdminClient subscriptionAdminClient = pubSubManager.subscriptionAdminClient(config);

    final ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(config.getProjectId(),
            config.getSubscription());

    try {
        subscriptionAdminClient.getSubscription(subscriptionName);
    } catch (final NotFoundException e) {
        final PushConfig pushConfig = PushConfig.newBuilder()
                .build();

        final ProjectTopicName topicName = ProjectTopicName.of(config.getProjectId(), config.getTopic());

        subscriptionAdminClient.createSubscription(subscriptionName, topicName, pushConfig, 0);
    }
}
 
Example #14
Source File: InstanceAdminExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
/** Demonstrates how to delete an instance. */
public void deleteInstance() {
  System.out.println("\nDeleting Instance");
  // [START bigtable_delete_instance]
  try {
    adminClient.deleteInstance(instanceId);
    System.out.println("Instance deleted: " + instanceId);
  } catch (NotFoundException e) {
    System.err.println("Failed to delete non-existent instance: " + e.getMessage());
  }
  // [END bigtable_delete_instance]
}
 
Example #15
Source File: PubsubHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
public void deleteSubscription(ProjectSubscriptionName subscriptionName) throws IOException {
	SubscriptionAdminClient adminClient = getSubscriptionAdminClient();
	try {
		adminClient.getSubscription(subscriptionName);
		// If it already exists we must first delete it.
		LOG.info("DeleteSubscription {}", subscriptionName);
		adminClient.deleteSubscription(subscriptionName);
	} catch (NotFoundException e) {
		// Doesn't exist. Good.
	}
}
 
Example #16
Source File: PubSubIntegrationTest.java    From hedera-mirror-node with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setup() {
    String topicName = properties.getTopicName();
    // delete old topic and subscription if present
    try {
        pubSubAdmin.deleteTopic(topicName);
        pubSubAdmin.deleteSubscription(SUBSCRIPTION);
    } catch (NotFoundException e) {
        // ignored
    }
    pubSubAdmin.createTopic(topicName);
    pubSubAdmin.createSubscription(SUBSCRIPTION, topicName);
}
 
Example #17
Source File: PubsubHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
public void deleteSubscription(ProjectSubscriptionName subscriptionName) throws IOException {
	SubscriptionAdminClient adminClient = getSubscriptionAdminClient();
	try {
		adminClient.getSubscription(subscriptionName);
		// If it already exists we must first delete it.
		LOG.info("DeleteSubscription {}", subscriptionName);
		adminClient.deleteSubscription(subscriptionName);
	} catch (NotFoundException e) {
		// Doesn't exist. Good.
	}
}
 
Example #18
Source File: SamplesTest.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteNote() throws Exception {
  DeleteNote.deleteNote(noteId, PROJECT_ID);
  try {
    GetNote.getNote(noteId, PROJECT_ID);
    // above should throw, because note was deleted
    Assert.fail("note not deleted");
  } catch (NotFoundException e) {
    // test passes
  }
}
 
Example #19
Source File: InstanceAdminExampleTest.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
@Test(expected = NotFoundException.class)
public void testAddAndDeleteCluster() {
  // Adds a cluster.
  instanceAdmin.addCluster();
  Cluster cluster = adminClient.getCluster(instanceId, CLUSTER);
  assertNotNull(cluster);

  // Deletes a cluster.
  instanceAdmin.deleteCluster();
  adminClient.getCluster(instanceId, CLUSTER);
}
 
Example #20
Source File: HelloWorld.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
/** Demonstrates how to delete a table. */
public void deleteTable() {
  // [START bigtable_hw_delete_table_veneer]
  System.out.println("\nDeleting table: " + tableId);
  try {
    adminClient.deleteTable(tableId);
    System.out.printf("Table %s deleted successfully%n", tableId);
  } catch (NotFoundException e) {
    System.err.println("Failed to delete a non-existent table: " + e.getMessage());
  }
  // [END bigtable_hw_delete_table_veneer]
}
 
Example #21
Source File: PubSubConnector.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private void createTopic(final PubSubConfig config) {
    final TopicAdminClient topicAdminClient = pubSubManager.topicAdminClient(config);

    final ProjectTopicName topicName = ProjectTopicName.of(config.getProjectId(), config.getTopic());

    try {
        topicAdminClient.getTopic(topicName);
    } catch (final NotFoundException nf) {
        try {
            topicAdminClient.createTopic(topicName);
        } catch (final AlreadyExistsException ae) {
            log.topicExistAlready(topicName, ae);
        }
    }
}
 
Example #22
Source File: InstanceAdminExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
/** Demonstrates how to delete a cluster from an instance. */
public void deleteCluster() {
  System.out.printf("%nDeleting cluster: %s from instance: %s%n", CLUSTER, instanceId);
  // [START bigtable_delete_cluster]
  try {
    adminClient.deleteCluster(instanceId, CLUSTER);
    System.out.printf("Cluster: %s deleted successfully%n", CLUSTER);
  } catch (NotFoundException e) {
    System.err.println("Failed to delete a non-existent cluster: " + e.getMessage());
  }
  // [END bigtable_delete_cluster]
}
 
Example #23
Source File: DataCatalogTableProvider.java    From beam with Apache License 2.0 5 votes vote down vote up
private Table loadTableFromDC(String tableName) {
  try {
    return toCalciteTable(
        tableName,
        dataCatalog.lookupEntry(
            LookupEntryRequest.newBuilder().setSqlResource(tableName).build()));
  } catch (InvalidArgumentException | PermissionDeniedException | NotFoundException e) {
    throw new InvalidTableException("Could not resolve table in Data Catalog: " + tableName, e);
  }
}
 
Example #24
Source File: InstanceAdminExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
/** Demonstrates how to list clusters within an instance. */
public void listClusters() {
  System.out.println("\nListing Clusters");
  // [START bigtable_get_clusters]
  try {
    List<Cluster> clusters = adminClient.listClusters(instanceId);
    for (Cluster cluster : clusters) {
      System.out.println(cluster.getId());
    }
  } catch (NotFoundException e) {
    System.err.println("Failed to list clusters from a non-existent instance: " + e.getMessage());
  }
  // [END bigtable_get_clusters]
}
 
Example #25
Source File: SecretManagerTemplate.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
public boolean secretExists(String secretId, String projectId) {
	SecretName secretName = SecretName.of(projectId, secretId);
	try {
		this.secretManagerServiceClient.getSecret(secretName);
	}
	catch (NotFoundException ex) {
		return false;
	}

	return true;
}
 
Example #26
Source File: TableAdminExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
/** Demonstrates how to delete a table. */
public void deleteTable() {
  // [START bigtable_delete_table]
  // Deletes the entire table.
  System.out.println("\nDelete table: " + tableId);
  try {
    adminClient.deleteTable(tableId);
    System.out.printf("Table: %s deleted successfully%n", tableId);
  } catch (NotFoundException e) {
    System.err.println("Failed to delete a non-existent table: " + e.getMessage());
  }
  // [END bigtable_delete_table]
}
 
Example #27
Source File: TableAdminExample.java    From java-docs-samples with Apache License 2.0 5 votes vote down vote up
/** Demonstrates how to delete a column family. */
public void deleteColumnFamily() {
  System.out.println("\nDelete column family: " + COLUMN_FAMILY_2);
  // [START bigtable_delete_family]
  // Deletes a column family.
  try {
    ModifyColumnFamiliesRequest deleted =
        ModifyColumnFamiliesRequest.of(tableId).dropFamily(COLUMN_FAMILY_2);
    adminClient.modifyFamilies(deleted);
    System.out.printf("Column family %s deleted successfully%n", COLUMN_FAMILY_2);
  } catch (NotFoundException e) {
    System.err.println("Failed to delete a non-existent column family: " + e.getMessage());
  }
  // [END bigtable_delete_family]
}
 
Example #28
Source File: SecretManagerTemplateTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateSecretIfMissing() {
	// This means that no previous secrets exist.
	when(this.client.getSecret(any(SecretName.class))).thenThrow(NotFoundException.class);

	this.secretManagerTemplate.createSecret("my-secret", "hello world!");

	// Verify the secret is created correctly.
	verifyCreateSecretRequest("my-secret", "my-project");

	// Verifies the secret payload is added correctly.
	verifyAddSecretRequest("my-secret", "hello world!", "my-project");
}
 
Example #29
Source File: SecretManagerTemplateTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateSecretIfMissing_withProject() {
	when(this.client.getSecret(any(SecretName.class))).thenThrow(NotFoundException.class);

	this.secretManagerTemplate.createSecret(
			"my-secret", "hello world!".getBytes(), "custom-project");

	verifyCreateSecretRequest("my-secret", "custom-project");
	verifyAddSecretRequest("my-secret", "hello world!", "custom-project");
}
 
Example #30
Source File: SecretManagerTemplateTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateByteSecretIfMissing() {
	// This means that no previous secrets exist.
	when(this.client.getSecret(any(SecretName.class))).thenThrow(NotFoundException.class);

	this.secretManagerTemplate.createSecret("my-secret", "hello world!".getBytes());

	verifyCreateSecretRequest("my-secret", "my-project");
	verifyAddSecretRequest("my-secret", "hello world!", "my-project");
}