Search in sources :

Example 46 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class ZKHelixAdmin method setInstanceZoneId.

@Override
public void setInstanceZoneId(String clusterName, String instanceName, String zoneId) {
    if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
        throw new HelixException("cluster " + clusterName + " is not setup yet");
    }
    if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
        throw new HelixException("cluster " + clusterName + " instance " + instanceName + " is not setup yet");
    }
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();
    InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instanceName));
    config.setZoneId(zoneId);
    accessor.setProperty(keyBuilder.instanceConfig(instanceName), config);
}
Also used : HelixException(org.apache.helix.HelixException) HelixDataAccessor(org.apache.helix.HelixDataAccessor) InstanceConfig(org.apache.helix.model.InstanceConfig) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) ZNRecord(org.apache.helix.ZNRecord)

Example 47 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class ZKHelixAdmin method resetResource.

@Override
public void resetResource(String clusterName, List<String> resourceNames) {
    // TODO: not mp-safe
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();
    List<ExternalView> extViews = accessor.getChildValues(keyBuilder.externalViews());
    Set<String> resetResourceNames = new HashSet<String>(resourceNames);
    for (ExternalView extView : extViews) {
        if (!resetResourceNames.contains(extView.getResourceName())) {
            continue;
        }
        // instanceName -> list of resetPartitionNames
        Map<String, List<String>> resetPartitionNames = new HashMap<String, List<String>>();
        Map<String, Map<String, String>> stateMap = extView.getRecord().getMapFields();
        for (String partitionName : stateMap.keySet()) {
            Map<String, String> instanceStateMap = stateMap.get(partitionName);
            for (String instanceName : instanceStateMap.keySet()) {
                if (instanceStateMap.get(instanceName).equals(HelixDefinedState.ERROR.toString())) {
                    if (!resetPartitionNames.containsKey(instanceName)) {
                        resetPartitionNames.put(instanceName, new ArrayList<String>());
                    }
                    resetPartitionNames.get(instanceName).add(partitionName);
                }
            }
        }
        for (String instanceName : resetPartitionNames.keySet()) {
            resetPartition(clusterName, instanceName, extView.getResourceName(), resetPartitionNames.get(instanceName));
        }
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) HashMap(java.util.HashMap) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) HelixDataAccessor(org.apache.helix.HelixDataAccessor) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ZNRecord(org.apache.helix.ZNRecord) HashSet(java.util.HashSet)

Example 48 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class ZKHelixAdmin method resetInstance.

@Override
public void resetInstance(String clusterName, List<String> instanceNames) {
    // TODO: not mp-safe
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();
    List<ExternalView> extViews = accessor.getChildValues(keyBuilder.externalViews());
    Set<String> resetInstanceNames = new HashSet<String>(instanceNames);
    for (String instanceName : resetInstanceNames) {
        List<String> resetPartitionNames = new ArrayList<String>();
        for (ExternalView extView : extViews) {
            Map<String, Map<String, String>> stateMap = extView.getRecord().getMapFields();
            for (String partitionName : stateMap.keySet()) {
                Map<String, String> instanceStateMap = stateMap.get(partitionName);
                if (instanceStateMap.containsKey(instanceName) && instanceStateMap.get(instanceName).equals(HelixDefinedState.ERROR.toString())) {
                    resetPartitionNames.add(partitionName);
                }
            }
            resetPartition(clusterName, instanceName, extView.getResourceName(), resetPartitionNames);
        }
    }
}
Also used : ExternalView(org.apache.helix.model.ExternalView) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) ArrayList(java.util.ArrayList) HelixDataAccessor(org.apache.helix.HelixDataAccessor) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ZNRecord(org.apache.helix.ZNRecord) HashSet(java.util.HashSet)

Example 49 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class ZKHelixAdmin method getConstraints.

@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()));
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) ZNRecord(org.apache.helix.ZNRecord)

Example 50 with HelixDataAccessor

use of org.apache.helix.HelixDataAccessor in project helix by apache.

the class ZKHelixAdmin method enableMaintenanceMode.

@Override
public void enableMaintenanceMode(String clusterName, boolean enabled, String reason) {
    HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
    Builder keyBuilder = accessor.keyBuilder();
    if (!enabled) {
        accessor.removeProperty(keyBuilder.maintenance());
    } else {
        MaintenanceSignal maintenanceSignal = new MaintenanceSignal("maintenance");
        if (reason != null) {
            maintenanceSignal.setReason(reason);
        }
        if (!accessor.createMaintenance(maintenanceSignal)) {
            throw new HelixException("Failed to create maintenance signal");
        }
    }
}
Also used : HelixException(org.apache.helix.HelixException) HelixDataAccessor(org.apache.helix.HelixDataAccessor) Builder(org.apache.helix.PropertyKey.Builder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) MaintenanceSignal(org.apache.helix.model.MaintenanceSignal) ZNRecord(org.apache.helix.ZNRecord)

Aggregations

HelixDataAccessor (org.apache.helix.HelixDataAccessor)173 ZNRecord (org.apache.helix.ZNRecord)91 PropertyKey (org.apache.helix.PropertyKey)69 Test (org.testng.annotations.Test)67 Builder (org.apache.helix.PropertyKey.Builder)59 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)40 Date (java.util.Date)39 HelixManager (org.apache.helix.HelixManager)35 IdealState (org.apache.helix.model.IdealState)33 LiveInstance (org.apache.helix.model.LiveInstance)31 HashMap (java.util.HashMap)30 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)30 Message (org.apache.helix.model.Message)30 ArrayList (java.util.ArrayList)28 ExternalView (org.apache.helix.model.ExternalView)26 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)25 Map (java.util.Map)19 HelixException (org.apache.helix.HelixException)19 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)19 InstanceConfig (org.apache.helix.model.InstanceConfig)17