use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyType in project pulsar by apache.
the class CmdNamespaceIsolationPolicy method createNamespaceIsolationData.
private NamespaceIsolationData createNamespaceIsolationData(List<String> namespaces, List<String> primary, List<String> secondary, String autoFailoverPolicyTypeName, Map<String, String> autoFailoverPolicyParams) {
// validate
namespaces = validateList(namespaces);
if (namespaces.isEmpty()) {
throw new ParameterException("unable to parse namespaces parameter list: " + namespaces);
}
primary = validateList(primary);
if (primary.isEmpty()) {
throw new ParameterException("unable to parse primary parameter list: " + namespaces);
}
secondary = validateList(secondary);
// System.out.println("namespaces = " + namespaces);
// System.out.println("primary = " + primary);
// System.out.println("secondary = " + secondary);
// System.out.println("autoFailoverPolicyTypeName = " + autoFailoverPolicyTypeName);
// System.out.println("autoFailoverPolicyParams = " + autoFailoverPolicyParams);
NamespaceIsolationData.Builder nsIsolationDataBuilder = NamespaceIsolationData.builder();
if (namespaces != null) {
nsIsolationDataBuilder.namespaces(namespaces);
}
if (primary != null) {
nsIsolationDataBuilder.primary(primary);
}
if (secondary != null) {
nsIsolationDataBuilder.secondary(secondary);
}
AutoFailoverPolicyType policyType = AutoFailoverPolicyType.fromString(autoFailoverPolicyTypeName);
nsIsolationDataBuilder.autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(policyType).parameters(autoFailoverPolicyParams).build());
// validation if necessary
if (policyType == AutoFailoverPolicyType.min_available) {
// ignore
boolean error = true;
String[] expectParamKeys = { "min_limit", "usage_threshold" };
if (autoFailoverPolicyParams.size() == expectParamKeys.length) {
for (String paramKey : expectParamKeys) {
if (!autoFailoverPolicyParams.containsKey(paramKey)) {
break;
}
}
error = false;
}
if (error) {
throw new ParameterException("Unknown auto failover policy params specified : " + autoFailoverPolicyParams);
}
} else {
// either we don't handle the new type or user has specified a bad type
throw new ParameterException("Unknown auto failover policy type specified : " + autoFailoverPolicyTypeName);
}
return nsIsolationDataBuilder.build();
}
use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyType in project pulsar by yahoo.
the class CmdNamespaceIsolationPolicy method createNamespaceIsolationData.
private NamespaceIsolationData createNamespaceIsolationData(List<String> namespaces, List<String> primary, List<String> secondary, String autoFailoverPolicyTypeName, Map<String, String> autoFailoverPolicyParams) {
// validate
namespaces = validateList(namespaces);
if (namespaces.isEmpty()) {
throw new ParameterException("unable to parse namespaces parameter list: " + namespaces);
}
primary = validateList(primary);
if (primary.isEmpty()) {
throw new ParameterException("unable to parse primary parameter list: " + namespaces);
}
secondary = validateList(secondary);
// System.out.println("namespaces = " + namespaces);
// System.out.println("primary = " + primary);
// System.out.println("secondary = " + secondary);
// System.out.println("autoFailoverPolicyTypeName = " + autoFailoverPolicyTypeName);
// System.out.println("autoFailoverPolicyParams = " + autoFailoverPolicyParams);
NamespaceIsolationData.Builder nsIsolationDataBuilder = NamespaceIsolationData.builder();
if (namespaces != null) {
nsIsolationDataBuilder.namespaces(namespaces);
}
if (primary != null) {
nsIsolationDataBuilder.primary(primary);
}
if (secondary != null) {
nsIsolationDataBuilder.secondary(secondary);
}
AutoFailoverPolicyType policyType = AutoFailoverPolicyType.fromString(autoFailoverPolicyTypeName);
nsIsolationDataBuilder.autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(policyType).parameters(autoFailoverPolicyParams).build());
// validation if necessary
if (policyType == AutoFailoverPolicyType.min_available) {
// ignore
boolean error = true;
String[] expectParamKeys = { "min_limit", "usage_threshold" };
if (autoFailoverPolicyParams.size() == expectParamKeys.length) {
for (String paramKey : expectParamKeys) {
if (!autoFailoverPolicyParams.containsKey(paramKey)) {
break;
}
}
error = false;
}
if (error) {
throw new ParameterException("Unknown auto failover policy params specified : " + autoFailoverPolicyParams);
}
} else {
// either we don't handle the new type or user has specified a bad type
throw new ParameterException("Unknown auto failover policy type specified : " + autoFailoverPolicyTypeName);
}
return nsIsolationDataBuilder.build();
}
use of org.apache.pulsar.common.policies.data.AutoFailoverPolicyType in project incubator-pulsar by apache.
the class CmdNamespaceIsolationPolicy method createNamespaceIsolationData.
private NamespaceIsolationData createNamespaceIsolationData(List<String> namespaces, List<String> primary, List<String> secondary, String autoFailoverPolicyTypeName, Map<String, String> autoFailoverPolicyParams) {
// validate
namespaces = validateList(namespaces);
if (namespaces.isEmpty()) {
throw new ParameterException("unable to parse namespaces parameter list: " + namespaces);
}
primary = validateList(primary);
if (primary.isEmpty()) {
throw new ParameterException("unable to parse primary parameter list: " + namespaces);
}
secondary = validateList(secondary);
// System.out.println("namespaces = " + namespaces);
// System.out.println("primary = " + primary);
// System.out.println("secondary = " + secondary);
// System.out.println("autoFailoverPolicyTypeName = " + autoFailoverPolicyTypeName);
// System.out.println("autoFailoverPolicyParams = " + autoFailoverPolicyParams);
NamespaceIsolationData.Builder nsIsolationDataBuilder = NamespaceIsolationData.builder();
if (namespaces != null) {
nsIsolationDataBuilder.namespaces(namespaces);
}
if (primary != null) {
nsIsolationDataBuilder.primary(primary);
}
if (secondary != null) {
nsIsolationDataBuilder.secondary(secondary);
}
AutoFailoverPolicyType policyType = AutoFailoverPolicyType.fromString(autoFailoverPolicyTypeName);
nsIsolationDataBuilder.autoFailoverPolicy(AutoFailoverPolicyData.builder().policyType(policyType).parameters(autoFailoverPolicyParams).build());
// validation if necessary
if (policyType == AutoFailoverPolicyType.min_available) {
// ignore
boolean error = true;
String[] expectParamKeys = { "min_limit", "usage_threshold" };
if (autoFailoverPolicyParams.size() == expectParamKeys.length) {
for (String paramKey : expectParamKeys) {
if (!autoFailoverPolicyParams.containsKey(paramKey)) {
break;
}
}
error = false;
}
if (error) {
throw new ParameterException("Unknown auto failover policy params specified : " + autoFailoverPolicyParams);
}
} else {
// either we don't handle the new type or user has specified a bad type
throw new ParameterException("Unknown auto failover policy type specified : " + autoFailoverPolicyTypeName);
}
return nsIsolationDataBuilder.build();
}
Aggregations