Java Code Examples for org.apache.pulsar.client.admin.PulsarAdminException#NotFoundException

The following examples show how to use org.apache.pulsar.client.admin.PulsarAdminException#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: AdminApiSchemaValidationEnforced.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableSchemaValidationEnforcedNoSchema() throws Exception {
    admin.namespaces().createNamespace("schema-validation-enforced/default-no-schema");
    String namespace = "schema-validation-enforced/default-no-schema";
    String topicName = "persistent://schema-validation-enforced/default-no-schema/test";
    assertFalse(admin.namespaces().getSchemaValidationEnforced(namespace));
    admin.namespaces().setSchemaValidationEnforced(namespace, false);
    try {
        admin.schemas().getSchemaInfo(topicName);
    } catch (PulsarAdminException.NotFoundException e) {
        assertTrue(e.getMessage().contains("HTTP 404 Not Found"));
    }
    try (Producer p = pulsarClient.newProducer().topic(topicName).create()) {
        p.send("test schemaValidationEnforced".getBytes());
    }
}
 
Example 2
Source File: AdminApiSchemaValidationEnforced.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testDisableSchemaValidationEnforcedHasSchema() throws Exception {
    admin.namespaces().createNamespace("schema-validation-enforced/default-has-schema");
    String namespace = "schema-validation-enforced/default-has-schema";
    String topicName = "persistent://schema-validation-enforced/default-has-schema/test";
    assertFalse(admin.namespaces().getSchemaValidationEnforced(namespace));
    admin.namespaces().setSchemaValidationEnforced(namespace, false);
    try {
        admin.schemas().getSchemaInfo(topicName);
    } catch (PulsarAdminException.NotFoundException e) {
        assertTrue(e.getMessage().contains("HTTP 404 Not Found"));
    }
    Map<String, String> properties = Maps.newHashMap();
    SchemaInfo schemaInfo = new SchemaInfo();
    schemaInfo.setType(SchemaType.STRING);
    schemaInfo.setProperties(properties);
    schemaInfo.setName("test");
    schemaInfo.setSchema("".getBytes());
    PostSchemaPayload postSchemaPayload = new PostSchemaPayload("STRING", "", properties);
    admin.schemas().createSchema(topicName, postSchemaPayload);
    try (Producer p = pulsarClient.newProducer().topic(topicName).create()) {
        p.send("test schemaValidationEnforced".getBytes());
    }
    assertEquals(admin.schemas().getSchemaInfo(topicName), schemaInfo);
}
 
Example 3
Source File: AdminApiSchemaValidationEnforced.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnableSchemaValidationEnforcedNoSchema() throws Exception {
    admin.namespaces().createNamespace("schema-validation-enforced/enable-no-schema");
    String namespace = "schema-validation-enforced/enable-no-schema";
    String topicName = "persistent://schema-validation-enforced/enable-no-schema/test";
    assertFalse(admin.namespaces().getSchemaValidationEnforced(namespace));
    admin.namespaces().setSchemaValidationEnforced(namespace,true);
    try {
        admin.schemas().getSchemaInfo(topicName);
    } catch (PulsarAdminException.NotFoundException e) {
        assertTrue(e.getMessage().contains("HTTP 404 Not Found"));
    }
    try (Producer p = pulsarClient.newProducer().topic(topicName).create()) {
        p.send("test schemaValidationEnforced".getBytes());
    }
}
 
Example 4
Source File: AdminApiSchemaValidationEnforced.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnableSchemaValidationEnforcedHasSchemaMatch() throws Exception {
    admin.namespaces().createNamespace("schema-validation-enforced/enable-has-schema-match");
    String namespace = "schema-validation-enforced/enable-has-schema-match";
    String topicName = "persistent://schema-validation-enforced/enable-has-schema-match/test";
    assertFalse(admin.namespaces().getSchemaValidationEnforced(namespace));
    try {
        admin.schemas().getSchemaInfo(topicName);
    } catch (PulsarAdminException.NotFoundException e) {
        assertTrue(e.getMessage().contains("HTTP 404 Not Found"));
    }
    admin.namespaces().setSchemaValidationEnforced(namespace,true);
    Map<String, String> properties = Maps.newHashMap();
    SchemaInfo schemaInfo = new SchemaInfo();
    schemaInfo.setType(SchemaType.STRING);
    schemaInfo.setProperties(properties);
    schemaInfo.setName("test");
    schemaInfo.setSchema("".getBytes());
    PostSchemaPayload postSchemaPayload = new PostSchemaPayload("STRING", "", properties);
    admin.schemas().createSchema(topicName, postSchemaPayload);
    try (Producer<String> p = pulsarClient.newProducer(Schema.STRING).topic(topicName).create()) {
        p.send("test schemaValidationEnforced");
    }
    assertEquals(admin.schemas().getSchemaInfo(topicName).getName(), schemaInfo.getName());
    assertEquals(admin.schemas().getSchemaInfo(topicName).getType(), schemaInfo.getType());
}
 
Example 5
Source File: PulsarMetadataReader.java    From pulsar-flink with Apache License 2.0 5 votes vote down vote up
public boolean namespaceExists(String ns) throws PulsarAdminException {
    try {
        admin.namespaces().getTopics(ns);
    } catch (PulsarAdminException.NotFoundException e) {
        return false;
    }
    return true;
}
 
Example 6
Source File: ComponentImpl.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public boolean isAuthorizedRole(String tenant, String namespace, String clientRole,
                                AuthenticationDataSource authenticationData) throws PulsarAdminException {
    if (worker().getWorkerConfig().isAuthorizationEnabled()) {
        // skip authorization if client role is super-user
        if (isSuperUser(clientRole)) {
            return true;
        }

        if (clientRole != null) {
            try {
                TenantInfo tenantInfo = worker().getBrokerAdmin().tenants().getTenantInfo(tenant);
                if (tenantInfo != null && worker().getAuthorizationService().isTenantAdmin(tenant, clientRole, tenantInfo, authenticationData).get()) {
                    return true;
                }
            } catch (PulsarAdminException.NotFoundException | InterruptedException | ExecutionException e) {

            }
        }

        // check if role has permissions granted
        if (clientRole != null && authenticationData != null) {
            return allowFunctionOps(NamespaceName.get(tenant, namespace), clientRole, authenticationData);
        } else {
            return false;
        }
    }
    return true;
}