Search in sources :

Example 1 with NamespaceOwnershipStatus

use of com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus in project pulsar by yahoo.

the class AdminApiTest method brokers.

@Test
public void brokers() throws Exception {
    List<String> list = admin.brokers().getActiveBrokers("use");
    Assert.assertNotNull(list);
    Assert.assertEquals(list.size(), 2);
    Map<String, NamespaceOwnershipStatus> nsMap = admin.brokers().getOwnedNamespaces("use", list.get(0));
    // since sla-monitor ns is not created nsMap.size() == 1 (for HeartBeat Namespace)
    Assert.assertEquals(1, nsMap.size());
    for (String ns : nsMap.keySet()) {
        NamespaceOwnershipStatus nsStatus = nsMap.get(ns);
        if (ns.equals(NamespaceService.getHeartbeatNamespace(pulsar.getAdvertisedAddress(), pulsar.getConfiguration()) + "/0x00000000_0xffffffff")) {
            assertEquals(nsStatus.broker_assignment, BrokerAssignment.shared);
            assertFalse(nsStatus.is_controlled);
            assertTrue(nsStatus.is_active);
        }
    }
    admin.namespaces().deleteNamespace("prop-xyz/use/ns1");
    admin.clusters().deleteCluster("use");
    assertEquals(admin.clusters().getClusters(), Lists.newArrayList());
}
Also used : NamespaceOwnershipStatus(com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus) Test(org.testng.annotations.Test) MockedPulsarServiceBaseTest(com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)

Example 2 with NamespaceOwnershipStatus

use of com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus in project pulsar by yahoo.

the class NamespaceService method getNamespaceOwnershipStatus.

private NamespaceOwnershipStatus getNamespaceOwnershipStatus(OwnedBundle nsObj, NamespaceIsolationPolicy nsIsolationPolicy) {
    NamespaceOwnershipStatus nsOwnedStatus = new NamespaceOwnershipStatus(BrokerAssignment.shared, false, nsObj.isActive());
    if (nsIsolationPolicy == null) {
        // no matching policy found, this namespace must be an uncontrolled one and using shared broker
        return nsOwnedStatus;
    }
    // found corresponding policy, set the status to controlled
    nsOwnedStatus.is_controlled = true;
    if (nsIsolationPolicy.isPrimaryBroker(pulsar.getAdvertisedAddress())) {
        nsOwnedStatus.broker_assignment = BrokerAssignment.primary;
    } else if (nsIsolationPolicy.isSecondaryBroker(pulsar.getAdvertisedAddress())) {
        nsOwnedStatus.broker_assignment = BrokerAssignment.secondary;
    }
    return nsOwnedStatus;
}
Also used : NamespaceOwnershipStatus(com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus)

Example 3 with NamespaceOwnershipStatus

use of com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus in project pulsar by yahoo.

the class NamespaceOwnershipStatusTest method testSerialization.

@Test
void testSerialization() throws Exception {
    String jsonStr = "{\"ns-1\":{\"broker_assignment\":\"shared\",\"is_controlled\":false,\"is_active\":true}," + "\"ns-2\":{\"broker_assignment\":\"primary\",\"is_controlled\":true,\"is_active\":false}," + "\"ns-3\":{\"broker_assignment\":\"secondary\",\"is_controlled\":true,\"is_active\":true}}";
    ObjectMapper jsonMapper = ObjectMapperFactory.create();
    Map<String, NamespaceOwnershipStatus> nsMap = jsonMapper.readValue(jsonStr.getBytes(), new TypeReference<Map<String, NamespaceOwnershipStatus>>() {
    });
    assertEquals(nsMap.size(), 3);
    for (String ns : nsMap.keySet()) {
        NamespaceOwnershipStatus nsStatus = nsMap.get(ns);
        if (ns.equals("ns-1")) {
            assertEquals(nsStatus.broker_assignment, BrokerAssignment.shared);
            assertFalse(nsStatus.is_controlled);
            assertTrue(nsStatus.is_active);
        } else if (ns.equals("ns-2")) {
            assertEquals(nsStatus.broker_assignment, BrokerAssignment.primary);
            assertTrue(nsStatus.is_controlled);
            assertFalse(nsStatus.is_active);
        } else if (ns.equals("ns-3")) {
            assertEquals(nsStatus.broker_assignment, BrokerAssignment.secondary);
            assertTrue(nsStatus.is_controlled);
            assertTrue(nsStatus.is_active);
        }
    }
    assertEquals(jsonMapper.writeValueAsString(nsMap), jsonStr);
}
Also used : NamespaceOwnershipStatus(com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 4 with NamespaceOwnershipStatus

use of com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus in project pulsar by yahoo.

the class NamespaceService method getOwnedNameSpacesStatus.

public Map<String, NamespaceOwnershipStatus> getOwnedNameSpacesStatus() throws Exception {
    NamespaceIsolationPolicies nsIsolationPolicies = this.getLocalNamespaceIsolationPolicies();
    Map<String, NamespaceOwnershipStatus> ownedNsStatus = new HashMap<String, NamespaceOwnershipStatus>();
    for (OwnedBundle nsObj : this.ownershipCache.getOwnedBundles().values()) {
        NamespaceOwnershipStatus nsStatus = this.getNamespaceOwnershipStatus(nsObj, nsIsolationPolicies.getPolicyByNamespace(nsObj.getNamespaceBundle().getNamespaceObject()));
        ownedNsStatus.put(nsObj.getNamespaceBundle().toString(), nsStatus);
    }
    return ownedNsStatus;
}
Also used : NamespaceIsolationPolicies(com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies) HashMap(java.util.HashMap) NamespaceOwnershipStatus(com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus)

Aggregations

NamespaceOwnershipStatus (com.yahoo.pulsar.common.policies.data.NamespaceOwnershipStatus)4 Test (org.testng.annotations.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MockedPulsarServiceBaseTest (com.yahoo.pulsar.broker.auth.MockedPulsarServiceBaseTest)1 NamespaceIsolationPolicies (com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1