我一直在尝试在累加的自定义约束工作。我通过实现org.apache.accumulo.core.constraints.Constraint .
创建了约束。但是当它应用到表时,我得到以下错误
下面是我的代码片段约束失败:ConstraintViolationSummary(constrainClass:org.apache.accumulo.tserver.constraints)。unsatisableconstraint,violationCode:-1,violationDescription:加载约束失败,不接受突变。, numberOfViolatingMutations: 1)
package samplepackageforconstraints;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.accumulo.core.constraints.Constraint;
import org.apache.accumulo.core.data.ColumnUpdate;
import org.apache.accumulo.core.data.Mutation;
public class LengthConstraintsTest implements Constraint{
private static final short NOT_ENOUGH_LENGTH = 1;
@Override
public List<Short> check(Environment env, Mutation mutation) {
List<Short> violations = null;
Collection<ColumnUpdate> updates = mutation.getUpdates();
for (ColumnUpdate columnUpdate : updates) {
if (!isLessThanThree(columnUpdate.getValue()))
violations = addViolation(violations, NOT_ENOUGH_LENGTH);
}
return violations;
}
@Override
public String getViolationDescription(short violationCode) {
switch (violationCode) {
case NOT_ENOUGH_LENGTH:
return "Value should be more than 3 character";
}
return null;
}
private List<Short> addViolation(List<Short> violations, short violation) {
if (violations == null) {
violations = new ArrayList<Short>();
violations.add(violation);
} else if (!violations.contains(violation)) {
violations.add(violation);
}
return violations;
}
private boolean isLessThanThree(byte[] value) {
if(value.length <3)
return false;
else
return true;
}
}
我遵循了蓄电池1.7版用户手册中给出的步骤还有用于加载约束
的cloudera我使用的是版本:1.6.0-cdh5.1.4的accumulo
提前感谢:)
当不能加载约束时,这意味着从类路径加载类存在问题(通常),或者(不太可能)类不对应于Constraint
接口。
您需要将包含自定义约束的jar添加到每个tablet服务器的类路径中。