Search in sources :

Example 21 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class StateModelConfigGenerator method main.

public static void main(String[] args) {
    ZNRecordSerializer serializer = new ZNRecordSerializer();
    System.out.println(new String(serializer.serialize(generateConfigForMasterSlave())));
}
Also used : ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 22 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestZnodeModify method testDataTriggerWithTimeout.

@Test()
public void testDataTriggerWithTimeout() throws Exception {
    logger.info("RUN: " + new Date(System.currentTimeMillis()));
    List<TestCommand> commandList = new ArrayList<TestCommand>();
    // test case for data trigger with timeout
    final String pathChild1 = PREFIX + "/dataTriggerWithTimeout_child1";
    final ZNRecord record = getExampleZNRecord();
    ZNRecord recordNew = new ZNRecord(record);
    recordNew.setSimpleField(IdealStateProperty.REBALANCE_MODE.toString(), RebalanceMode.SEMI_AUTO.toString());
    ZnodeOpArg arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.ZNODE, "+", recordNew);
    TestCommand command1 = new TestCommand(CommandType.MODIFY, new TestTrigger(0, 8000, record), arg1);
    commandList.add(command1);
    arg1 = new ZnodeOpArg(pathChild1, ZnodePropertyType.ZNODE, "==");
    command1 = new TestCommand(CommandType.VERIFY, new TestTrigger(9000, 500, recordNew), arg1);
    commandList.add(command1);
    // start a separate thread to change znode at pathChild1
    new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(3000);
                final ZkClient zkClient = new ZkClient(ZK_ADDR);
                zkClient.setZkSerializer(new ZNRecordSerializer());
                zkClient.createPersistent(pathChild1, true);
                zkClient.writeData(pathChild1, record);
            } catch (InterruptedException e) {
                logger.error("Interrupted sleep", e);
            }
        }
    }.start();
    Map<TestCommand, Boolean> results = TestExecutor.executeTest(commandList, ZK_ADDR);
    for (Map.Entry<TestCommand, Boolean> entry : results.entrySet()) {
        Assert.assertTrue(entry.getValue());
    // System.out.println(entry.getValue() + ":" + entry.getKey());
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ArrayList(java.util.ArrayList) ZnodeOpArg(org.apache.helix.tools.ZnodeOpArg) Date(java.util.Date) TestTrigger(org.apache.helix.tools.TestTrigger) TestCommand(org.apache.helix.tools.TestCommand) HashMap(java.util.HashMap) Map(java.util.Map) ZNRecord(org.apache.helix.ZNRecord) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) Test(org.testng.annotations.Test)

Example 23 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestPauseSignal method testPauseSignal.

@Test()
public void testPauseSignal() throws Exception {
    // Logger.getRootLogger().setLevel(Level.INFO);
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    final String clusterName = className + "_" + methodName;
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[5];
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    10, // number of nodes
    5, // replicas
    3, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    for (int i = 0; i < 5; 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);
    // pause the cluster and make sure pause is persistent
    ZkClient zkClient = new ZkClient(ZK_ADDR);
    zkClient.setZkSerializer(new ZNRecordSerializer());
    final HelixDataAccessor tmpAccessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
    String cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " false";
    ClusterSetup.processCommandLineArgs(cmd.split(" "));
    tmpAccessor.setProperty(tmpAccessor.keyBuilder().pause(), new PauseSignal("pause"));
    zkClient.close();
    // wait for controller to be signaled by pause
    Thread.sleep(1000);
    // add a new resource group
    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
    setupTool.addResourceToCluster(clusterName, "TestDB1", 10, "MasterSlave");
    setupTool.rebalanceStorageCluster(clusterName, "TestDB1", 3);
    // make sure TestDB1 external view is empty
    TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView", 1000, clusterName, "TestDB1", TestHelper.<String>setOf("localhost_12918", "localhost_12919", "localhost_12920", "localhost_12921", "localhost_12922"), ZK_ADDR);
    // resume controller
    final HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    cmd = "-zkSvr " + ZK_ADDR + " -enableCluster " + clusterName + " true";
    ClusterSetup.processCommandLineArgs(cmd.split(" "));
    result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    // clean up
    controller.syncStop();
    for (int i = 0; i < 5; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) MockParticipantManager(org.apache.helix.integration.manager.MockParticipantManager) ClusterSetup(org.apache.helix.tools.ClusterSetup) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ClusterControllerManager(org.apache.helix.integration.manager.ClusterControllerManager) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) HelixDataAccessor(org.apache.helix.HelixDataAccessor) PauseSignal(org.apache.helix.model.PauseSignal) ZNRecord(org.apache.helix.ZNRecord) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) ZKHelixDataAccessor(org.apache.helix.manager.zk.ZKHelixDataAccessor) Test(org.testng.annotations.Test)

Example 24 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class TestParticipantManager method testSessionExpiryInTransition.

@Test
public void testSessionExpiryInTransition() throws Exception {
    String className = TestHelper.getTestClassName();
    String methodName = TestHelper.getTestMethodName();
    final String clusterName = className + "_" + methodName;
    int n = 1;
    CountDownLatch startCountdown = new CountDownLatch(1);
    CountDownLatch endCountdown = new CountDownLatch(1);
    System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
    MockParticipantManager[] participants = new MockParticipantManager[n];
    // participant port
    TestHelper.setupCluster(// participant port
    clusterName, // participant port
    ZK_ADDR, // participant port
    12918, // participant name prefix
    "localhost", // resource name prefix
    "TestDB", // resources
    1, // partitions per resource
    1, // number of nodes
    n, // replicas
    1, "MasterSlave", // do rebalance
    true);
    // start controller
    ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
    controller.syncStart();
    // start participants
    for (int i = 0; i < n; i++) {
        String instanceName = "localhost_" + (12918 + i);
        participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
        participants[i].setTransition(new SessionExpiryTransition(startCountdown, endCountdown));
        participants[i].syncStart();
    }
    // wait transition happens to trigger session expiry
    startCountdown.await();
    String oldSessionId = participants[0].getSessionId();
    System.out.println("oldSessionId: " + oldSessionId);
    ZkTestHelper.expireSession(participants[0].getZkClient());
    boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
    Assert.assertTrue(result);
    String newSessionId = participants[0].getSessionId();
    Assert.assertNotSame(newSessionId, oldSessionId);
    // assert interrupt exception error in old session
    String errPath = PropertyPathBuilder.instanceError(clusterName, "localhost_12918", oldSessionId, "TestDB0", "TestDB0_0");
    ZNRecord error = _gZkClient.readData(errPath);
    Assert.assertNotNull(error, "InterruptedException should happen in old session since task is being cancelled during handleNewSession");
    String errString = new String(new ZNRecordSerializer().serialize(error));
    Assert.assertTrue(errString.indexOf("InterruptedException") != -1);
    // cleanup
    controller.syncStop();
    for (int i = 0; i < n; i++) {
        participants[i].syncStop();
    }
    System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) BestPossAndExtViewZkVerifier(org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier) Date(java.util.Date) ZNRecord(org.apache.helix.ZNRecord) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) Test(org.testng.annotations.Test)

Example 25 with ZNRecordSerializer

use of org.apache.helix.manager.zk.ZNRecordSerializer in project helix by apache.

the class ZkIntegrationTestBase method beforeSuite.

@BeforeSuite
public void beforeSuite() throws Exception {
    // TODO: use logging.properties file to config java.util.logging.Logger levels
    java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
    topJavaLogger.setLevel(Level.WARNING);
    // Due to ZOOKEEPER-2693 fix, we need to specify whitelist for execute zk commends
    System.setProperty("zookeeper.4lw.commands.whitelist", "*");
    _zkServer = TestHelper.startZkServer(ZK_ADDR);
    AssertJUnit.assertTrue(_zkServer != null);
    ZKClientPool.reset();
    _gZkClient = new ZkClient(ZK_ADDR);
    _gZkClient.setZkSerializer(new ZNRecordSerializer());
    _gSetupTool = new ClusterSetup(_gZkClient);
    _baseAccessor = new ZkBaseDataAccessor<>(_gZkClient);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)59 ZkClient (org.apache.helix.manager.zk.ZkClient)39 ZNRecord (org.apache.helix.ZNRecord)23 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)12 Test (org.testng.annotations.Test)11 IdealState (org.apache.helix.model.IdealState)10 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)9 Date (java.util.Date)7 InstanceConfig (org.apache.helix.model.InstanceConfig)7 ClusterSetup (org.apache.helix.tools.ClusterSetup)7 Builder (org.apache.helix.PropertyKey.Builder)6 StateModelDefinition (org.apache.helix.model.StateModelDefinition)6 HelixDataAccessor (org.apache.helix.HelixDataAccessor)5 ExternalView (org.apache.helix.model.ExternalView)5 PropertyKey (org.apache.helix.PropertyKey)4 BeforeClass (org.testng.annotations.BeforeClass)4 BeforeSuite (org.testng.annotations.BeforeSuite)4 File (java.io.File)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3