/** * Returns the ClusterConstraints for a given constraintType * @param type * @return */ public ClusterConstraints getConstraint(ConstraintType type) { if (_constraintMap != null) { return _constraintMap.get(type.toString()); } return null; }
/** * remove constraint * @param clusterName * @param constraintType * @param constraintId */ public void removeConstraint(String clusterName, String constraintType, String constraintId) { if (clusterName == null || constraintType == null || constraintId == null) { throw new IllegalArgumentException( "fail to remove constraint. missing clusterName|constraintType|constraintId"); } ConstraintType type = ConstraintType.valueOf(constraintType); _admin.removeConstraint(clusterName, type, constraintId); }
Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString()), new ClusterConstraints(record)); accessor.getProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString())) .getRecord(); ClusterConstraints constraint = new ClusterConstraints(record);
Builder keyBuilder = accessor.keyBuilder(); accessor.setProperty(keyBuilder.constraint(ConstraintType.STATE_CONSTRAINT.toString()), new ClusterConstraints(record)); accessor.getProperty(keyBuilder.constraint(ConstraintType.STATE_CONSTRAINT.toString())) .getRecord(); ClusterConstraints constraint = new ClusterConstraints(record);
ConstraintType constraintType = ConstraintType.valueOf(constraintTypeStr); ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName); constraints = accessor.getProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString())); Assert.assertNotNull(constraints, "message-constraint should exist"); ConstraintItem item = constraints.getConstraintItem("constraint1"); accessor.getProperty(keyBuilder.constraint(ConstraintType.MESSAGE_CONSTRAINT.toString())); Assert.assertNotNull(constraints, "message-constraint should exist"); item = constraints.getConstraintItem("constraint1");
/** * set constraint * @param clusterName * @param constraintType * @param constraintId * @param constraintAttributesMap : csv-formated constraint key-value pairs */ public void setConstraint(String clusterName, String constraintType, String constraintId, String constraintAttributesMap) { if (clusterName == null || constraintType == null || constraintId == null || constraintAttributesMap == null) { throw new IllegalArgumentException( "fail to set constraint. missing clusterName|constraintType|constraintId|constraintAttributesMap"); } ConstraintType type = ConstraintType.valueOf(constraintType); ConstraintItemBuilder builder = new ConstraintItemBuilder(); Map<String, String> constraintAttributes = HelixUtil.parseCsvFormatedKeyValuePairs(constraintAttributesMap); ConstraintItem constraintItem = builder.addConstraintAttributes(constraintAttributes).build(); _admin.setConstraint(clusterName, type, constraintId, constraintItem); }
/** * set constraint * @param clusterName * @param constraintType * @param constraintId * @param constraintAttributesMap : csv-formated constraint key-value pairs */ public void setConstraint(String clusterName, String constraintType, String constraintId, String constraintAttributesMap) { if (clusterName == null || constraintType == null || constraintId == null || constraintAttributesMap == null) { throw new IllegalArgumentException( "fail to set constraint. missing clusterName|constraintType|constraintId|constraintAttributesMap"); } ConstraintType type = ConstraintType.valueOf(constraintType); ConstraintItemBuilder builder = new ConstraintItemBuilder(); Map<String, String> constraintAttributes = HelixUtil.parseCsvFormatedKeyValuePairs(constraintAttributesMap); ConstraintItem constraintItem = builder.addConstraintAttributes(constraintAttributes).build(); _admin.setConstraint(clusterName, type, constraintId, constraintItem); }
@Override public void setConstraint(String clusterName, final ConstraintType constraintType, final String constraintId, final ConstraintItem constraintItem) { logger.info("Set constraint type {} with constraint id {} for cluster {}.", constraintType, constraintId, clusterName); BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient); Builder keyBuilder = new Builder(clusterName); String path = keyBuilder.constraint(constraintType.toString()).getPath(); baseAccessor.update(path, new DataUpdater<ZNRecord>() { @Override public ZNRecord update(ZNRecord currentData) { ClusterConstraints constraints = currentData == null ? new ClusterConstraints(constraintType) : new ClusterConstraints(currentData); constraints.addConstraintItem(constraintId, constraintItem); return constraints.getRecord(); } }, AccessOption.PERSISTENT); }
@Override public void removeConstraint(String clusterName, final ConstraintType constraintType, final String constraintId) { logger.info("Remove constraint type {} with constraint id {} for cluster {}.", constraintType, constraintId, clusterName); BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient); Builder keyBuilder = new Builder(clusterName); String path = keyBuilder.constraint(constraintType.toString()).getPath(); baseAccessor.update(path, new DataUpdater<ZNRecord>() { @Override public ZNRecord update(ZNRecord currentData) { if (currentData != null) { ClusterConstraints constraints = new ClusterConstraints(currentData); constraints.removeConstraintItem(constraintId); return constraints.getRecord(); } return null; } }, AccessOption.PERSISTENT); }
@Override public void removeConstraint(String clusterName, final ConstraintType constraintType, final String constraintId) { logger.info("Remove constraint type {} with constraint id {} for cluster {}.", constraintType, constraintId, clusterName); BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient); Builder keyBuilder = new Builder(clusterName); String path = keyBuilder.constraint(constraintType.toString()).getPath(); baseAccessor.update(path, new DataUpdater<ZNRecord>() { @Override public ZNRecord update(ZNRecord currentData) { if (currentData != null) { ClusterConstraints constraints = new ClusterConstraints(currentData); constraints.removeConstraintItem(constraintId); return constraints.getRecord(); } return null; } }, AccessOption.PERSISTENT); }
@Override public void setConstraint(String clusterName, final ConstraintType constraintType, final String constraintId, final ConstraintItem constraintItem) { logger.info("Set constraint type {} with constraint id {} for cluster {}.", constraintType, constraintId, clusterName); BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_zkClient); Builder keyBuilder = new Builder(clusterName); String path = keyBuilder.constraint(constraintType.toString()).getPath(); baseAccessor.update(path, new DataUpdater<ZNRecord>() { @Override public ZNRecord update(ZNRecord currentData) { ClusterConstraints constraints = currentData == null ? new ClusterConstraints(constraintType) : new ClusterConstraints(currentData); constraints.addConstraintItem(constraintId, constraintItem); return constraints.getRecord(); } }, AccessOption.PERSISTENT); }
/** * remove constraint * @param clusterName * @param constraintType * @param constraintId */ public void removeConstraint(String clusterName, String constraintType, String constraintId) { if (clusterName == null || constraintType == null || constraintId == null) { throw new IllegalArgumentException( "fail to remove constraint. missing clusterName|constraintType|constraintId"); } ConstraintType type = ConstraintType.valueOf(constraintType); _admin.removeConstraint(clusterName, type, constraintId); }
/** * get constraints associated with given type * @param constraintType : constraint-type. e.g. MESSAGE_CONSTRAINT * @return json-formated constraints */ public String getConstraints(String clusterName, String constraintType) { if (clusterName == null || constraintType == null) { throw new IllegalArgumentException( "fail to get constraint. missing clusterName|constraintType"); } ConstraintType type = ConstraintType.valueOf(constraintType); ClusterConstraints constraints = _admin.getConstraints(clusterName, type); return new String(constraints.serialize(new ZNRecordSerializer())); }
/** * get constraints associated with given type * @param constraintType : constraint-type. e.g. MESSAGE_CONSTRAINT * @return json-formated constraints */ public String getConstraints(String clusterName, String constraintType) { if (clusterName == null || constraintType == null) { throw new IllegalArgumentException( "fail to get constraint. missing clusterName|constraintType"); } ConstraintType type = ConstraintType.valueOf(constraintType); ClusterConstraints constraints = _admin.getConstraints(clusterName, type); return new String(constraints.serialize(new ZNRecordSerializer())); }
@Override public ClusterConstraints getConstraints(String clusterName, ConstraintType constraintType) { HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = new Builder(clusterName); return accessor.getProperty(keyBuilder.constraint(constraintType.toString())); }
@Override public ClusterConstraints getConstraints(String clusterName, ConstraintType constraintType) { HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient)); Builder keyBuilder = new Builder(clusterName); return accessor.getProperty(keyBuilder.constraint(constraintType.toString())); }
/** * Instantiate constraints as a given type * @param type {@link ConstraintType} representing what this constrains */ public ClusterConstraints(ConstraintType type) { super(type.toString()); }
/** * Instantiate constraints as a given type * @param type {@link ConstraintType} representing what this constrains */ public ClusterConstraints(ConstraintType type) { super(type.toString()); }