Search in sources :

Example 11 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class PulsarStandaloneStarter method start.

void start() throws Exception {
    if (config == null) {
        System.exit(1);
    }
    log.debug("--- setup PulsarStandaloneStarter ---");
    if (!onlyBroker) {
        // Start LocalBookKeeper
        bkEnsemble = new LocalBookkeeperEnsemble(numOfBk, zkPort, bkPort, zkDir, bkDir, wipeData);
        bkEnsemble.start();
    }
    if (noBroker) {
        return;
    }
    // Start Broker
    broker = new PulsarService(config);
    broker.start();
    // Create a sample namespace
    URL webServiceUrl = new URL(String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort()));
    String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(), config.getBrokerServicePort());
    admin = new PulsarAdmin(webServiceUrl, config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters());
    String property = "sample";
    String cluster = config.getClusterName();
    String namespace = property + "/" + cluster + "/ns1";
    try {
        ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, /* serviceUrlTls */
        brokerServiceUrl, null);
        if (!admin.clusters().getClusters().contains(cluster)) {
            admin.clusters().createCluster(cluster, clusterData);
        } else {
            admin.clusters().updateCluster(cluster, clusterData);
        }
        if (!admin.properties().getProperties().contains(property)) {
            admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList(config.getSuperUserRoles()), Sets.newHashSet(cluster)));
        }
        if (!admin.namespaces().getNamespaces(property).contains(namespace)) {
            admin.namespaces().createNamespace(namespace);
        }
    } catch (PulsarAdminException e) {
        log.info(e.getMessage());
    }
    log.debug("--- setup completed ---");
}
Also used : ClusterData(com.yahoo.pulsar.common.policies.data.ClusterData) PulsarService(com.yahoo.pulsar.broker.PulsarService) PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) LocalBookkeeperEnsemble(com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL)

Example 12 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class PulsarBrokerStatsClientTest method testServiceException.

@Test
public void testServiceException() throws Exception {
    URL url = new URL("http://localhost:15000");
    PulsarAdmin admin = new PulsarAdmin(url, (Authentication) null);
    BrokerStatsImpl client = (BrokerStatsImpl) spy(admin.brokerStats());
    try {
        client.getLoadReport();
    } catch (PulsarAdminException e) {
    // Ok
    }
    try {
        client.getPendingBookieOpsStats();
    } catch (PulsarAdminException e) {
    // Ok
    }
    try {
        client.getBrokerResourceAvailability("prop", "cluster", "ns");
    } catch (PulsarAdminException e) {
    // Ok
    }
    assertTrue(client.getApiException(new ClientErrorException(403)) instanceof NotAuthorizedException);
    assertTrue(client.getApiException(new ClientErrorException(404)) instanceof NotFoundException);
    assertTrue(client.getApiException(new ClientErrorException(409)) instanceof ConflictException);
    assertTrue(client.getApiException(new ClientErrorException(412)) instanceof PreconditionFailedException);
    assertTrue(client.getApiException(new ClientErrorException(400)) instanceof PulsarAdminException);
    assertTrue(client.getApiException(new ServerErrorException(500)) instanceof ServerSideErrorException);
    assertTrue(client.getApiException(new ServerErrorException(503)) instanceof PulsarAdminException);
    log.info("Client: ", client);
    admin.close();
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) BrokerStatsImpl(com.yahoo.pulsar.client.admin.internal.BrokerStatsImpl) ConflictException(com.yahoo.pulsar.client.admin.PulsarAdminException.ConflictException) ServerSideErrorException(com.yahoo.pulsar.client.admin.PulsarAdminException.ServerSideErrorException) ClientErrorException(javax.ws.rs.ClientErrorException) NotFoundException(com.yahoo.pulsar.client.admin.PulsarAdminException.NotFoundException) PreconditionFailedException(com.yahoo.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(com.yahoo.pulsar.client.admin.PulsarAdminException) NotAuthorizedException(com.yahoo.pulsar.client.admin.PulsarAdminException.NotAuthorizedException) ServerErrorException(javax.ws.rs.ServerErrorException) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 13 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class PulsarAdminToolTest method properties.

@Test
void properties() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    Properties mockProperties = mock(Properties.class);
    when(admin.properties()).thenReturn(mockProperties);
    CmdProperties properties = new CmdProperties(admin);
    properties.run(split("list"));
    verify(mockProperties).getProperties();
    PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
    properties.run(split("create property --admin-roles role1,role2 --allowed-clusters use"));
    verify(mockProperties).createProperty("property", propertyAdmin);
    propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("usw"));
    properties.run(split("update property --admin-roles role1,role2 --allowed-clusters usw"));
    verify(mockProperties).updateProperty("property", propertyAdmin);
    properties.run(split("get property"));
    verify(mockProperties).getPropertyAdmin("property");
    properties.run(split("delete property"));
    verify(mockProperties).deleteProperty("property");
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) PropertyAdmin(com.yahoo.pulsar.common.policies.data.PropertyAdmin) Properties(com.yahoo.pulsar.client.admin.Properties) Test(org.testng.annotations.Test)

Example 14 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class PulsarAdminToolTest method brokers.

@Test
void brokers() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    Brokers mockBrokers = mock(Brokers.class);
    doReturn(mockBrokers).when(admin).brokers();
    CmdBrokers brokers = new CmdBrokers(admin);
    brokers.run(split("list use"));
    verify(mockBrokers).getActiveBrokers("use");
    brokers.run(split("get-all-dynamic-config"));
    verify(mockBrokers).getAllDynamicConfigurations();
    brokers.run(split("list-dynamic-config"));
    verify(mockBrokers).getDynamicConfigurationNames();
    brokers.run(split("update-dynamic-config --config brokerShutdownTimeoutMs --value 100"));
    verify(mockBrokers).updateDynamicConfiguration("brokerShutdownTimeoutMs", "100");
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) Brokers(com.yahoo.pulsar.client.admin.Brokers) Test(org.testng.annotations.Test)

Example 15 with PulsarAdmin

use of com.yahoo.pulsar.client.admin.PulsarAdmin in project pulsar by yahoo.

the class PulsarAdminToolTest method getOwnedNamespaces.

@Test
void getOwnedNamespaces() throws Exception {
    PulsarAdmin admin = Mockito.mock(PulsarAdmin.class);
    Brokers mockBrokers = mock(Brokers.class);
    doReturn(mockBrokers).when(admin).brokers();
    CmdBrokers brokers = new CmdBrokers(admin);
    brokers.run(split("namespaces use --url http://my-service.url:4000"));
    verify(mockBrokers).getOwnedNamespaces("use", "http://my-service.url:4000");
}
Also used : PulsarAdmin(com.yahoo.pulsar.client.admin.PulsarAdmin) Brokers(com.yahoo.pulsar.client.admin.Brokers) Test(org.testng.annotations.Test)

Aggregations

PulsarAdmin (com.yahoo.pulsar.client.admin.PulsarAdmin)20 URL (java.net.URL)11 Test (org.testng.annotations.Test)8 Authentication (com.yahoo.pulsar.client.api.Authentication)7 PulsarService (com.yahoo.pulsar.broker.PulsarService)6 ServiceConfiguration (com.yahoo.pulsar.broker.ServiceConfiguration)6 ClusterData (com.yahoo.pulsar.common.policies.data.ClusterData)6 LocalBookkeeperEnsemble (com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble)6 PropertyAdmin (com.yahoo.pulsar.common.policies.data.PropertyAdmin)5 BeforeMethod (org.testng.annotations.BeforeMethod)4 Brokers (com.yahoo.pulsar.client.admin.Brokers)2 PulsarAdminException (com.yahoo.pulsar.client.admin.PulsarAdminException)2 ConflictException (com.yahoo.pulsar.client.admin.PulsarAdminException.ConflictException)2 IOException (java.io.IOException)2 Clusters (com.yahoo.pulsar.client.admin.Clusters)1 Lookup (com.yahoo.pulsar.client.admin.Lookup)1 Namespaces (com.yahoo.pulsar.client.admin.Namespaces)1 PersistentTopics (com.yahoo.pulsar.client.admin.PersistentTopics)1 Properties (com.yahoo.pulsar.client.admin.Properties)1 NotAuthorizedException (com.yahoo.pulsar.client.admin.PulsarAdminException.NotAuthorizedException)1