Search in sources :

Example 1 with InternalConfigurationData

use of org.apache.pulsar.common.conf.InternalConfigurationData in project incubator-pulsar by apache.

the class FunctionMetadataSetup method setupFunctionMetadata.

/**
 * Setup function metadata.
 *
 * @param workerConfig worker config
 * @return dlog uri for store function jars
 * @throws InterruptedException interrupted at setting up metadata
 * @throws PulsarAdminException when encountering exception on pulsar admin operation
 * @throws IOException when create dlog namespace for storing function jars.
 */
public static URI setupFunctionMetadata(WorkerConfig workerConfig) throws InterruptedException, PulsarAdminException, IOException {
    // initializing pulsar functions namespace
    PulsarAdmin admin = Utils.getPulsarAdminClient(workerConfig.getPulsarWebServiceUrl());
    InternalConfigurationData internalConf;
    // make sure pulsar broker is up
    log.info("Checking if pulsar service at {} is up...", workerConfig.getPulsarWebServiceUrl());
    int maxRetries = workerConfig.getInitialBrokerReconnectMaxRetries();
    int retries = 0;
    while (true) {
        try {
            admin.clusters().getClusters();
            break;
        } catch (PulsarAdminException e) {
            log.warn("Failed to retrieve clusters from pulsar service", e);
            log.warn("Retry to connect to Pulsar service at {}", workerConfig.getPulsarWebServiceUrl());
            if (retries >= maxRetries) {
                log.error("Failed to connect to Pulsar service at {} after {} attempts", workerConfig.getPulsarFunctionsNamespace(), maxRetries);
                throw e;
            }
            retries++;
            Thread.sleep(1000);
        }
    }
    // getting namespace policy
    log.info("Initializing Pulsar Functions namespace...");
    try {
        try {
            admin.namespaces().getPolicies(workerConfig.getPulsarFunctionsNamespace());
        } catch (PulsarAdminException e) {
            if (e.getStatusCode() == Response.Status.NOT_FOUND.getStatusCode()) {
                // if not found than create
                try {
                    admin.namespaces().createNamespace(workerConfig.getPulsarFunctionsNamespace());
                } catch (PulsarAdminException e1) {
                    // prevent race condition with other workers starting up
                    if (e1.getStatusCode() != Response.Status.CONFLICT.getStatusCode()) {
                        log.error("Failed to create namespace {} for pulsar functions", workerConfig.getPulsarFunctionsNamespace(), e1);
                        throw e1;
                    }
                }
                try {
                    admin.namespaces().setRetention(workerConfig.getPulsarFunctionsNamespace(), new RetentionPolicies(Integer.MAX_VALUE, Integer.MAX_VALUE));
                } catch (PulsarAdminException e1) {
                    log.error("Failed to set retention policy for pulsar functions namespace", e);
                    throw new RuntimeException(e1);
                }
            } else {
                log.error("Failed to get retention policy for pulsar function namespace {}", workerConfig.getPulsarFunctionsNamespace(), e);
                throw e;
            }
        }
        try {
            internalConf = admin.brokers().getInternalConfigurationData();
        } catch (PulsarAdminException e) {
            log.error("Failed to retrieve broker internal configuration", e);
            throw e;
        }
    } finally {
        admin.close();
    }
    // TODO: move this as part of pulsar cluster initialization later
    try {
        return Utils.initializeDlogNamespace(internalConf.getZookeeperServers(), internalConf.getLedgersRootPath());
    } catch (IOException ioe) {
        log.error("Failed to initialize dlog namespace at zookeeper {} for storing function packages", internalConf.getZookeeperServers(), ioe);
        throw ioe;
    }
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) InternalConfigurationData(org.apache.pulsar.common.conf.InternalConfigurationData) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) IOException(java.io.IOException)

Example 2 with InternalConfigurationData

use of org.apache.pulsar.common.conf.InternalConfigurationData in project incubator-pulsar by apache.

the class AdminTest method internalConfiguration.

@Test
void internalConfiguration() throws Exception {
    InternalConfigurationData expectedData = new InternalConfigurationData(pulsar.getConfiguration().getZookeeperServers(), pulsar.getConfiguration().getGlobalZookeeperServers(), new ClientConfiguration().getZkLedgersRootPath());
    assertEquals(brokers.getInternalConfigurationData(), expectedData);
}
Also used : InternalConfigurationData(org.apache.pulsar.common.conf.InternalConfigurationData) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Aggregations

InternalConfigurationData (org.apache.pulsar.common.conf.InternalConfigurationData)2 IOException (java.io.IOException)1 ClientConfiguration (org.apache.bookkeeper.conf.ClientConfiguration)1 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)1 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)1 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)1 Test (org.testng.annotations.Test)1