Search in sources :

Example 46 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class SLAMonitoringTest method createProperty.

private void createProperty(PulsarAdmin pulsarAdmin) throws PulsarClientException, MalformedURLException, PulsarAdminException {
    ClusterData clusterData = new ClusterData();
    clusterData.setServiceUrl(pulsarAdmin.getServiceUrl().toString());
    pulsarAdmins[0].clusters().createCluster("my-cluster", clusterData);
    Set<String> allowedClusters = new HashSet<>();
    allowedClusters.add("my-cluster");
    PropertyAdmin adminConfig = new PropertyAdmin();
    adminConfig.setAllowedClusters(allowedClusters);
    List<String> adminRoles = new ArrayList<>();
    adminRoles.add("");
    adminConfig.setAdminRoles(adminRoles);
    pulsarAdmin.properties().createProperty("sla-monitor", adminConfig);
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 47 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class AdminApiTest2 method clusterFailureDomain.

@Test
public void clusterFailureDomain() throws PulsarAdminException {
    final String cluster = pulsar.getConfiguration().getClusterName();
    admin.clusters().createCluster(cluster, new ClusterData(pulsar.getWebServiceAddress(), pulsar.getWebServiceAddressTls()));
    // create
    FailureDomain domain = new FailureDomain();
    domain.setBrokers(Sets.newHashSet("b1", "b2", "b3"));
    admin.clusters().createFailureDomain(cluster, "domain-1", domain);
    admin.clusters().updateFailureDomain(cluster, "domain-1", domain);
    assertEquals(admin.clusters().getFailureDomain(cluster, "domain-1"), domain);
    Map<String, FailureDomain> domains = admin.clusters().getFailureDomains(cluster);
    assertEquals(domains.size(), 1);
    assertTrue(domains.containsKey("domain-1"));
    try {
        // try to create domain with already registered brokers
        admin.clusters().createFailureDomain(cluster, "domain-2", domain);
        fail("should have failed because of brokers are already registered");
    } catch (PulsarAdminException.ConflictException e) {
    // Ok
    }
    admin.clusters().deleteFailureDomain(cluster, "domain-1");
    assertTrue(admin.clusters().getFailureDomains(cluster).isEmpty());
    admin.clusters().createFailureDomain(cluster, "domain-2", domain);
    domains = admin.clusters().getFailureDomains(cluster);
    assertEquals(domains.size(), 1);
    assertTrue(domains.containsKey("domain-2"));
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) FailureDomain(org.apache.pulsar.common.policies.data.FailureDomain) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 48 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class AdminApiTest2 method setup.

@BeforeMethod
@Override
public void setup() throws Exception {
    conf.setLoadBalancerEnabled(true);
    super.internalSetup();
    // create otherbroker to test redirect on calls that need
    // namespace ownership
    mockPulsarSetup = new MockedPulsarService(this.conf);
    mockPulsarSetup.setup();
    // Setup namespaces
    admin.clusters().createCluster("use", new ClusterData("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT));
    PropertyAdmin propertyAdmin = new PropertyAdmin(Lists.newArrayList("role1", "role2"), Sets.newHashSet("use"));
    admin.properties().createProperty("prop-xyz", propertyAdmin);
    admin.namespaces().createNamespace("prop-xyz/use/ns1");
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) MockedPulsarService(org.apache.pulsar.broker.admin.AdminApiTest.MockedPulsarService) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 49 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class AdminApiTest2 method testPeerCluster.

@Test
public void testPeerCluster() throws Exception {
    admin.clusters().createCluster("us-west1", new ClusterData("http://broker.messaging.west1.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().createCluster("us-west2", new ClusterData("http://broker.messaging.west2.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().createCluster("us-east1", new ClusterData("http://broker.messaging.east1.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().createCluster("us-east2", new ClusterData("http://broker.messaging.east2.example.com" + ":" + BROKER_WEBSERVICE_PORT));
    admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west2")));
    assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), Lists.newArrayList("us-west2"));
    assertEquals(admin.clusters().getCluster("us-west2").getPeerClusterNames(), null);
    // update cluster with duplicate peer-clusters in the list
    admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west2", "us-east1", "us-west2", "us-east1", "us-west2", "us-east1")));
    assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), Lists.newArrayList("us-west2", "us-east1"));
    admin.clusters().updatePeerClusterNames("us-west1", null);
    assertEquals(admin.clusters().getCluster("us-west1").getPeerClusterNames(), null);
    // Check name validation
    try {
        admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("invalid-cluster")));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertTrue(e instanceof PreconditionFailedException);
    }
    // Cluster itselft can't be part of peer-list
    try {
        admin.clusters().updatePeerClusterNames("us-west1", Sets.newLinkedHashSet(Lists.newArrayList("us-west1")));
        fail("should have failed");
    } catch (PulsarAdminException e) {
        assertTrue(e instanceof PreconditionFailedException);
    }
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) PreconditionFailedException(org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedException) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 50 with ClusterData

use of org.apache.pulsar.common.policies.data.ClusterData in project incubator-pulsar by apache.

the class BacklogQuotaManagerTest method setup.

@BeforeMethod
void setup() throws Exception {
    try {
        // start local bookie and zookeeper
        bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
        bkEnsemble.start();
        // start pulsar service
        config = new ServiceConfiguration();
        config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
        config.setAdvertisedAddress("localhost");
        config.setWebServicePort(BROKER_WEBSERVICE_PORT);
        config.setClusterName("usc");
        config.setBrokerServicePort(BROKER_SERVICE_PORT);
        config.setAuthorizationEnabled(false);
        config.setAuthenticationEnabled(false);
        config.setBacklogQuotaCheckIntervalInSeconds(TIME_TO_CHECK_BACKLOG_QUOTA);
        config.setManagedLedgerMaxEntriesPerLedger(5);
        config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
        pulsar = new PulsarService(config);
        pulsar.start();
        adminUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
        admin = new PulsarAdmin(adminUrl, (Authentication) null);
        admin.clusters().createCluster("usc", new ClusterData(adminUrl.toString()));
        admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("usc")));
        admin.namespaces().createNamespace("prop/usc/ns-quota");
        admin.namespaces().createNamespace("prop/usc/quotahold");
        admin.namespaces().createNamespace("prop/usc/quotaholdasync");
    } catch (Throwable t) {
        LOG.error("Error setting up broker test", t);
        Assert.fail("Broker test setup failed");
    }
}
Also used : ClusterData(org.apache.pulsar.common.policies.data.ClusterData) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) PulsarService(org.apache.pulsar.broker.PulsarService) PulsarAdmin(org.apache.pulsar.client.admin.PulsarAdmin) PropertyAdmin(org.apache.pulsar.common.policies.data.PropertyAdmin) Authentication(org.apache.pulsar.client.api.Authentication) LocalBookkeeperEnsemble(org.apache.pulsar.zookeeper.LocalBookkeeperEnsemble) URL(java.net.URL) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ClusterData (org.apache.pulsar.common.policies.data.ClusterData)53 PropertyAdmin (org.apache.pulsar.common.policies.data.PropertyAdmin)30 Test (org.testng.annotations.Test)23 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)13 BeforeMethod (org.testng.annotations.BeforeMethod)13 MockedPulsarServiceBaseTest (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest)11 PulsarAdmin (org.apache.pulsar.client.admin.PulsarAdmin)10 URL (java.net.URL)9 PulsarService (org.apache.pulsar.broker.PulsarService)9 RestException (org.apache.pulsar.broker.web.RestException)8 KeeperException (org.apache.zookeeper.KeeperException)8 IOException (java.io.IOException)7 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)7 URI (java.net.URI)6 AuthenticationTls (org.apache.pulsar.client.impl.auth.AuthenticationTls)6 Authentication (org.apache.pulsar.client.api.Authentication)5 Field (java.lang.reflect.Field)4 ExecutionException (java.util.concurrent.ExecutionException)4 AuthAction (org.apache.pulsar.common.policies.data.AuthAction)4 Policies (org.apache.pulsar.common.policies.data.Policies)4