Search in sources :

Example 21 with PropertyKey

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

the class HelixTaskExecutor method updateMessageState.

private void updateMessageState(List<Message> readMsgs, HelixDataAccessor accessor, String instanceName) {
    Builder keyBuilder = accessor.keyBuilder();
    List<PropertyKey> readMsgKeys = new ArrayList<>();
    for (Message msg : readMsgs) {
        readMsgKeys.add(msg.getKey(keyBuilder, instanceName));
        _knownMessageIds.add(msg.getId());
    }
    accessor.setChildren(readMsgKeys, readMsgs);
}
Also used : Message(org.apache.helix.model.Message) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) Builder(org.apache.helix.PropertyKey.Builder) ArrayList(java.util.ArrayList) PropertyKey(org.apache.helix.PropertyKey)

Example 22 with PropertyKey

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

the class BatchMessageHandler method postHandleMessage.

public void postHandleMessage() {
    if (_message.getBatchMessageMode() == true && _batchMsgWrapper != null) {
        _batchMsgWrapper.end(_message, _notificationContext);
    }
    // update currentState
    HelixManager manager = _notificationContext.getManager();
    HelixDataAccessor accessor = manager.getHelixDataAccessor();
    ConcurrentHashMap<String, CurrentStateUpdate> csUpdateMap = (ConcurrentHashMap<String, CurrentStateUpdate>) _notificationContext.get(MapKey.CURRENT_STATE_UPDATE.toString());
    if (csUpdateMap != null) {
        Map<PropertyKey, CurrentState> csUpdate = mergeCurStateUpdate(csUpdateMap);
        // TODO: change to use asyncSet
        for (PropertyKey key : csUpdate.keySet()) {
            // curStateMap.get(key));
            if (!accessor.updateProperty(key, csUpdate.get(key))) {
                LOG.error("Fails to persist current state to ZK for key " + key);
            }
        }
    }
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) HelixManager(org.apache.helix.HelixManager) CurrentState(org.apache.helix.model.CurrentState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PropertyKey(org.apache.helix.PropertyKey)

Example 23 with PropertyKey

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

the class TestSchemataSM method testSchemataSM.

@Test
public void testSchemataSM() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    String clusterName = className + "_" + methodName;
    int n = 5;
    MockParticipantManager[] participants = new MockParticipantManager[n];
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    // participant start port
    TestHelper.setupCluster(// participant start port
    clusterName, // participant start port
    ZK_ADDR, // participant start port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestSchemata", // resources
    1, // partitions per resource
    1, // number of nodes
    n, // replicas
    0, "STORAGE_DEFAULT_SM_SCHEMATA", // don't rebalance
    false);
    // rebalance ideal-state to use ANY_LIVEINSTANCE for preference list
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    PropertyKey key = keyBuilder.idealStates("TestSchemata0");
    IdealState idealState = accessor.getProperty(key);
    idealState.setReplicas(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString());
    idealState.getRecord().setListField("TestSchemata0_0", Arrays.asList(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString()));
    accessor.setProperty(key, idealState);
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
    controller.syncStart();
    // start n-1 participants
    for (int i = 1; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].syncStart();
    }
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // start the remaining 1 participant
    participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
    participants[0].syncStart();
    // make sure we have all participants in MASTER state
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    key = keyBuilder.externalView("TestSchemata0");
    ExternalView externalView = accessor.getProperty(key);
    Map<String, String> stateMap = externalView.getStateMap("TestSchemata0_0");
    Assert.assertNotNull(stateMap);
    Assert.assertEquals(stateMap.size(), n, "all " + n + " participants should be in Master state");
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        Assert.assertNotNull(stateMap.get(instanceName));
        Assert.assertEquals(stateMap.get(instanceName), "MASTER");
    }
    // clean up
    controller.syncStop();
    for (int i = 0; i < n; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ExternalView(org.apache.helix.model.ExternalView) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) IdealState(org.apache.helix.model.IdealState) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZNRecord(org.apache.helix.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 24 with PropertyKey

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

the class TestResourceValidationStage method createISSpec.

private void createISSpec(HelixDataAccessor accessor, String specId, String stateModelDefRef, RebalanceMode rebalanceMode) {
    PropertyKey propertyKey = accessor.keyBuilder().clusterConfig();
    HelixProperty property = accessor.getProperty(propertyKey);
    if (property == null) {
        property = new HelixProperty("sampleClusterConfig");
    }
    String key = "IdealStateRule!" + specId;
    String value = IdealStateProperty.REBALANCE_MODE.toString() + "=" + rebalanceMode.toString() + "," + IdealStateProperty.STATE_MODEL_DEF_REF.toString() + "=" + stateModelDefRef;
    property.getRecord().setSimpleField(key, value);
    accessor.setProperty(propertyKey, property);
}
Also used : HelixProperty(org.apache.helix.HelixProperty) PropertyKey(org.apache.helix.PropertyKey)

Example 25 with PropertyKey

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

the class TaskTestUtil method pollForAllTasksBlock.

public static boolean pollForAllTasksBlock(HelixDataAccessor accessor, String instance, int numTask, long timeout) throws InterruptedException {
    PropertyKey propertyKey = accessor.keyBuilder().messages(instance);
    long startTime = System.currentTimeMillis();
    while (true) {
        List<Message> messages = accessor.getChildValues(propertyKey);
        if (allTasksBlock(messages, numTask)) {
            return true;
        } else if (startTime + timeout < System.currentTimeMillis()) {
            return false;
        } else {
            Thread.sleep(100);
        }
    }
}
Also used : Message(org.apache.helix.model.Message) PropertyKey(org.apache.helix.PropertyKey)

Aggregations

PropertyKey (org.apache.helix.PropertyKey)65 HelixDataAccessor (org.apache.helix.HelixDataAccessor)34 ZNRecord (org.apache.helix.ZNRecord)24 ArrayList (java.util.ArrayList)19 Test (org.testng.annotations.Test)17 Builder (org.apache.helix.PropertyKey.Builder)16 Message (org.apache.helix.model.Message)16 HelixManager (org.apache.helix.HelixManager)15 IdealState (org.apache.helix.model.IdealState)10 CurrentState (org.apache.helix.model.CurrentState)9 LiveInstance (org.apache.helix.model.LiveInstance)9 StringWriter (java.io.StringWriter)8 Criteria (org.apache.helix.Criteria)8 HelixProperty (org.apache.helix.HelixProperty)8 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)7 ExternalView (org.apache.helix.model.ExternalView)7 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)7 SerializationConfig (org.codehaus.jackson.map.SerializationConfig)7 HashSet (java.util.HashSet)6 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)6