use of com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies in project pulsar by yahoo.
the class Clusters method deleteCluster.
@DELETE
@Path("/{cluster}")
@ApiOperation(value = "Delete an existing cluster")
@ApiResponses(value = { @ApiResponse(code = 204, message = "Cluster has been updated"), @ApiResponse(code = 403, message = "Don't have admin permission"), @ApiResponse(code = 404, message = "Cluster doesn't exist"), @ApiResponse(code = 412, message = "Cluster is not empty") })
public void deleteCluster(@PathParam("cluster") String cluster) {
validateSuperUserAccess();
validatePoliciesReadOnlyAccess();
// Check that the cluster is not used by any property (eg: no namespaces provisioned there)
boolean isClusterUsed = false;
try {
for (String property : globalZk().getChildren(path("policies"), false)) {
if (globalZk().exists(path("policies", property, cluster), false) == null) {
continue;
}
if (!globalZk().getChildren(path("policies", property, cluster), false).isEmpty()) {
// We found a property that has at least a namespace in this cluster
isClusterUsed = true;
break;
}
}
// check the namespaceIsolationPolicies associated with the cluster
String path = path("clusters", cluster, "namespaceIsolationPolicies");
Optional<NamespaceIsolationPolicies> nsIsolationPolicies = namespaceIsolationPoliciesCache().get(path);
// Need to delete the isolation policies if present
if (nsIsolationPolicies.isPresent()) {
if (nsIsolationPolicies.get().getPolicies().isEmpty()) {
globalZk().delete(path, -1);
namespaceIsolationPoliciesCache().invalidate(path);
} else {
isClusterUsed = true;
}
}
} catch (Exception e) {
log.error("[{}] Failed to get cluster usage {}", clientAppId(), cluster, e);
throw new RestException(e);
}
if (isClusterUsed) {
log.warn("[{}] Failed to delete cluster {} - Cluster not empty", clientAppId(), cluster);
throw new RestException(Status.PRECONDITION_FAILED, "Cluster not empty");
}
try {
String clusterPath = path("clusters", cluster);
globalZk().delete(clusterPath, -1);
globalZkCache().invalidate(clusterPath);
log.info("[{}] Deleted cluster {}", clientAppId(), cluster);
} catch (KeeperException.NoNodeException e) {
log.warn("[{}] Failed to delete cluster {} - Does not exist", clientAppId(), cluster);
throw new RestException(Status.NOT_FOUND, "Cluster does not exist");
} catch (Exception e) {
log.error("[{}] Failed to delete cluster {}", clientAppId(), cluster, e);
throw new RestException(e);
}
}
use of com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies 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;
}
use of com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies in project pulsar by yahoo.
the class LoadBalancerTest method createNamespacePolicies.
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
// // prepare three policies for the namespace isolation
NamespaceIsolationPolicies policies = new NamespaceIsolationPolicies();
// set up policy that use this broker as primary
NamespaceIsolationData policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/primary-ns.*");
policyData.primary = new ArrayList<String>();
for (int i = 0; i < BROKER_COUNT; i++) {
policyData.primary.add(lookupAddresses[i]);
}
policyData.secondary = new ArrayList<String>();
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("primaryBrokerPolicy", policyData);
// set up policy that use this broker as secondary
policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/secondary-ns.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add(lookupAddresses[0]);
policyData.secondary = new ArrayList<String>();
for (int i = 1; i < BROKER_COUNT; i++) {
policyData.secondary.add(lookupAddresses[i]);
}
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("secondaryBrokerPolicy", policyData);
// set up policy that do not use this broker (neither primary nor secondary)
policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/shared-ns.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add(lookupAddresses[0]);
policyData.secondary = new ArrayList<String>();
for (int i = 1; i < BROKER_COUNT; i++) {
policyData.secondary.add(lookupAddresses[i]);
}
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("otherBrokerPolicy", policyData);
ObjectMapper jsonMapper = ObjectMapperFactory.create();
ZooKeeper globalZk = pulsar.getGlobalZkCache().getZooKeeper();
ZkUtils.createFullPathOptimistic(globalZk, AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
byte[] content = jsonMapper.writeValueAsBytes(policies.getPolicies());
globalZk.setData(AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), content, -1);
}
use of com.yahoo.pulsar.common.policies.impl.NamespaceIsolationPolicies in project pulsar by yahoo.
the class SimpleLoadManagerImplTest method createNamespacePolicies.
private void createNamespacePolicies(PulsarService pulsar) throws Exception {
NamespaceIsolationPolicies policies = new NamespaceIsolationPolicies();
// set up policy that use this broker as primary
NamespaceIsolationData policyData = new NamespaceIsolationData();
policyData.namespaces = new ArrayList<String>();
policyData.namespaces.add("pulsar/use/primary-ns.*");
policyData.primary = new ArrayList<String>();
policyData.primary.add(pulsar1.getAdvertisedAddress() + "*");
policyData.secondary = new ArrayList<String>();
policyData.secondary.add("prod2-broker([78]).messaging.usw.example.co.*");
policyData.auto_failover_policy = new AutoFailoverPolicyData();
policyData.auto_failover_policy.policy_type = AutoFailoverPolicyType.min_available;
policyData.auto_failover_policy.parameters = new HashMap<String, String>();
policyData.auto_failover_policy.parameters.put("min_limit", "1");
policyData.auto_failover_policy.parameters.put("usage_threshold", "100");
policies.setPolicy("primaryBrokerPolicy", policyData);
ObjectMapper jsonMapper = ObjectMapperFactory.create();
ZooKeeper globalZk = pulsar.getGlobalZkCache().getZooKeeper();
ZkUtils.createFullPathOptimistic(globalZk, AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
byte[] content = jsonMapper.writeValueAsBytes(policies.getPolicies());
globalZk.setData(AdminResource.path("clusters", "use", "namespaceIsolationPolicies"), content, -1);
}
Aggregations