Examples of ClusterController


Examples of com.linkedin.helix.mock.controller.ClusterController

    // start distributed cluster controllers
    ClusterController[] controllers = new ClusterController[n];
    for (int i = 0; i < n; i++)
    {
      controllers[i] =
          new ClusterController(controllerClusterName,
                                "controller_" + i,
                                ZK_ADDR,
                                HelixControllerMain.DISTRIBUTED.toString());
      controllers[i].syncStart();
    }
View Full Code Here

Examples of org.apache.ambari.server.controller.spi.ClusterController

  private static final Logger logger = Logger
      .getLogger(AmbariInternalClient.class);

  @Override
  public AmbariCluster getCluster(AmbariClusterInfo clusterInfo) {
    ClusterController clusterController = ClusterControllerHelper
        .getClusterController();
    try {
      EqualsPredicate<String> clusterPredicate = new EqualsPredicate<String>(
          "Clusters/cluster_name", clusterInfo.getName());
      Set<Resource> clusterResources = clusterController.getResources(
          Resource.Type.Cluster, PropertyHelper.getReadRequest(),
          clusterPredicate);
      if (!clusterResources.isEmpty()) {
        Resource clusterResource = clusterResources.iterator().next();
        AmbariCluster cluster = new AmbariCluster();
        cluster.setName(clusterResource.getPropertyValue(
            "Clusters/cluster_name").toString());
        cluster.setVersion(clusterResource.getPropertyValue("Clusters/version")
            .toString());
        Map<String, String> desiredConfigsMap = new HashMap<String, String>();
        Map<String, Object> desiredConfigsMapResource = clusterResource
            .getPropertiesMap().get("Clusters/desired_configs");
        for (Map.Entry<String, Object> siteEntry : desiredConfigsMapResource
            .entrySet()) {
          desiredConfigsMap.put(siteEntry.getKey(),
              ((DesiredConfig) siteEntry.getValue()).getVersion());
        }
        cluster.setDesiredConfigs(desiredConfigsMap);

        EqualsPredicate<String> serviceClusterPredicate = new EqualsPredicate<String>(
            "ServiceInfo/cluster_name", cluster.getName());
        EqualsPredicate<String> hostClusterPredicate = new EqualsPredicate<String>(
            "Hosts/cluster_name", cluster.getName());
        Set<Resource> serviceResources = clusterController.getResources(
            Resource.Type.Service, PropertyHelper.getReadRequest(),
            serviceClusterPredicate);
        Set<Resource> hostResources = clusterController.getResources(
            Resource.Type.Host, PropertyHelper.getReadRequest(),
            hostClusterPredicate);
        List<AmbariServiceInfo> servicesList = new ArrayList<AmbariServiceInfo>();
        List<AmbariHostInfo> hostsList = new ArrayList<AmbariHostInfo>();
        for (Resource serviceResource : serviceResources) {
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

  // start admin thread
  // AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
  // adminThread.start();

  // start controller
  ClusterController controller = new ClusterController(clusterName,
    "controller_0", ZK_ADDR);
  controller.syncStart();

  Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>();
  errPartitions.put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
  errPartitions.put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));

  // start mock participants
  MockParticipant[] participants = new MockParticipant[n];
  for (int i = 0; i < n; i++) {
      String instanceName = "localhost_" + (12918 + i);

      if (i == 0) {
    participants[i] = new MockParticipant(clusterName,
      instanceName, ZK_ADDR, new ErrTransition(errPartitions));
      } else {
    participants[i] = new MockParticipant(clusterName,
      instanceName, ZK_ADDR);
      }
      participants[i].syncStart();
  }

  // verify cluster
  Map<String, Map<String, String>> errStateMap = new HashMap<String, Map<String, String>>();
  errStateMap.put("TestDB0", new HashMap<String, String>());
  errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
  errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
  boolean result = ClusterStateVerifier
    .verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
      ZK_ADDR, clusterName, errStateMap)));
  Assert.assertTrue(result, "Cluster verification fails");

  // reset a non-exist partition, should throw exception
  String hostName = "localhost_12918";
  String instanceUrl = getInstanceUrl(clusterName, hostName);

  Map<String, String> paramMap = new HashMap<String, String>();
  paramMap.put(JsonParameters.MANAGEMENT_COMMAND,
    ClusterSetup.resetPartition);
  paramMap.put(JsonParameters.PARTITION, "TestDB0_nonExist");
  paramMap.put(JsonParameters.RESOURCE, "TestDB0");
  LOG.info("IGNORABLE exception: test reset non-exist partition");
  TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl,
    paramMap, true);

  // reset 2 error partitions
  errPartitions.clear();
  participants[0].setTransition(new ErrTransitionWithResetCnt(
    errPartitions));
  clearStatusUpdate(clusterName, "localhost_12918", "TestDB0",
    "TestDB0_4");
  _errToOfflineInvoked.set(0);

  paramMap.put(JsonParameters.PARTITION, "TestDB0_4 TestDB0_8");
  TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl,
    paramMap, false);

  for (int i = 0; i < 10; i++) {
      Thread.sleep(400); // wait reset to be done
      LOG.info("IGNORABLE exception: test reset non-error partition");
      TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl,
        paramMap, true);

      result = ClusterStateVerifier
        .verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
          ZK_ADDR, clusterName));
      if (result == true) {
    break;
      }
  }
 
  Assert.assertTrue(result);
  Assert.assertEquals(_errToOfflineInvoked.get(), 2,
    "reset() should be invoked 2 times");

  // clean up
  // wait for all zk callbacks done
  Thread.sleep(1000);
  // adminThread.stop();
  controller.syncStop();
  for (int i = 0; i < 5; i++) {
      participants[i].syncStop();
  }

  System.out.println("END " + clusterName + " at "
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

    // start admin thread
//    AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
//    adminThread.start();

    // start controller
    ClusterController controller =
        new ClusterController(clusterName, "controller_0", ZK_ADDR);
    controller.syncStart();

    Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>()
    {
      {
        put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
        put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
      }
    };

    // start mock participants
    MockParticipant[] participants = new MockParticipant[n];
    for (int i = 0; i < n; i++)
    {
      String instanceName = "localhost_" + (12918 + i);

      if (i == 0)
      {
        participants[i] =
            new MockParticipant(clusterName,
                                instanceName,
                                ZK_ADDR,
                                new ErrTransition(errPartitions));
      }
      else
      {
        participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
      }
      participants[i].syncStart();
    }

    // verify cluster
    Map<String, Map<String, String>> errStateMap =
        new HashMap<String, Map<String, String>>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
    boolean result =
        ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                                       clusterName,
                                                                                                       errStateMap)));
    Assert.assertTrue(result, "Cluster verification fails");
   
    // reset resource "TestDB0"
    participants[0].setTransition(null);
    String resourceName = "TestDB0";
    String resourceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups/" + resourceName;

    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.resetResource);
    TestHelixAdminScenariosRest.assertSuccessPostOperation(resourceUrl, paramMap, false);

    result =
        ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                                       clusterName)));
    Assert.assertTrue(result, "Cluster verification fails");
   
    // clean up
    // wait for all zk callbacks done
    Thread.sleep(1000);
//    adminThread.stop();
    controller.syncStop();
    for (int i = 0; i < 5; i++)
    {
      participants[i].syncStop();
    }
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

//    // start admin thread
//    AdminThread adminThread = new AdminThread(ZK_ADDR, _port);
//    adminThread.start();

    // start controller
    ClusterController controller =
        new ClusterController(clusterName, "controller_0", ZK_ADDR);
    controller.syncStart();

    Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>()
    {
      {
        put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
        put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
      }
    };

    // start mock participants
    MockParticipant[] participants = new MockParticipant[n];
    for (int i = 0; i < n; i++)
    {
      String instanceName = "localhost_" + (12918 + i);

      if (i == 0)
      {
        participants[i] =
            new MockParticipant(clusterName,
                                instanceName,
                                ZK_ADDR,
                                new ErrTransition(errPartitions));
      }
      else
      {
        participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
      }
      participants[i].syncStart();
    }

    // verify cluster
    Map<String, Map<String, String>> errStateMap =
        new HashMap<String, Map<String, String>>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
    boolean result =
        ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                                       clusterName,
                                                                                                       errStateMap)));
    Assert.assertTrue(result, "Cluster verification fails");

    // reset node "localhost_12918"
    participants[0].setTransition(null);
    String hostName = "localhost_12918";
    String instanceUrl = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/instances/" + hostName;

    Map<String, String> paramMap = new HashMap<String, String>();
    paramMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.resetInstance);
    TestHelixAdminScenariosRest.assertSuccessPostOperation(instanceUrl, paramMap, false);
   
    result =
        ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                                       clusterName)));
    Assert.assertTrue(result, "Cluster verification fails");
   
    // clean up
    // wait for all zk callbacks done
    Thread.sleep(1000);
//    adminThread.stop();
    controller.syncStop();
    for (int i = 0; i < 5; i++)
    {
      participants[i].syncStop();
    }
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

    setupTool.getClusterManagementTool()
             .addAlert(clusterName,
                       "EXP(decay(1.0)(*.defaultPerfCounters@defaultPerfCounters.availableCPUs))CMP(GREATER)CON(2)");

    // start controller
    ClusterController controller =
        new ClusterController(clusterName, "controller_0", ZK_ADDR);
    controller.syncStart();

   
    // start participants
    for (int i = 0; i < n; i++)
    {
      String instanceName = "localhost_" + (12918 + i);

      participants[i] =
          new MockParticipant(clusterName,
                              instanceName,
                              ZK_ADDR,
                              new DummyAlertsTransition());
      participants[i].syncStart();
    }

    boolean result =
        ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR,
                                                                              clusterName));
    Assert.assertTrue(result);

    result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                 clusterName));
    Assert.assertTrue(result);

    // other verifications go here
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();

    for (int i = 0; i < n; i++)
    {
      String instance = "localhost_" + (12918 + i);
      ZNRecord record = null;
      for(int j = 0; j < 10; j++)
      {
        record =
            accessor.getProperty(keyBuilder.healthReport(instance, "mockAlerts")).getRecord();
        if(record.getId().equals("mockAlerts4"))
        {
          break;
        }
        else
        {
          Thread.sleep(500);
        }
      }
      Assert.assertEquals(record.getId(), "mockAlerts4");
    }

    // clean up
    Thread.sleep(1000);
    controller.syncStop();
    for (int i = 0; i < 5; i++)
    {
      participants[i].syncStop();
    }
   
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

      participants[i].syncStart();
  }

  // start controller nodes
  for (int i = 0; i < 2; i++) {
      controllers[i] = new ClusterController(grandClusterName, "controller_900" + i, ZK_ADDR,
        HelixControllerMain.DISTRIBUTED);
      controllers[i].syncStart();
  }

  Thread.sleep(100);
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

                            3, // replicas
                            "MasterSlave",
                            true); // do rebalance

    // start controller
    ClusterController controller =
        new ClusterController(clusterName, "controller_0", ZK_ADDR);
    controller.syncStart();

    // start participants
    for (int i = 0; i < 5; i++)
    {
      String instanceName = "localhost_" + (12918 + i);

      participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
      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
    for (int i = 0; i < 5; i++)
    {
      participants[i].syncStop();
    }

    Thread.sleep(2000);
    controller.syncStop();

    System.out.println("END " + clusterName + " at "
        + new Date(System.currentTimeMillis()));
  }
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

    String idealStatePath = PropertyPathConfig.getPath(PropertyType.IDEALSTATES, clusterName, "TestDB0");
    ZNRecord idealState = _gZkClient.readData(idealStatePath);
    idealState.getSimpleFields().remove(IdealState.IdealStateProperty.REPLICAS.toString());
    _gZkClient.writeData(idealStatePath, idealState);
   
    ClusterController controller = new ClusterController(clusterName, "controller_0", ZK_ADDR);
    controller.syncStart();
   
    // start participants
    for (int i = 0; i < 5; i++)
    {
      String instanceName = "localhost_" + (12918 + i);

      participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
      participants[i].syncStart();
    }

    boolean result =
        ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                 clusterName));
    Assert.assertTrue(result);

    // clean up
    for (int i = 0; i < 5; i++)
    {
      participants[i].syncStop();
    }
   
    Thread.sleep(2000);
    controller.syncStop();

    System.out.println("END " + clusterName + " at "
        + new Date(System.currentTimeMillis()));
  }
View Full Code Here

Examples of org.apache.helix.mock.controller.ClusterController

                            3, // replicas
                            "MasterSlave",
                            true); // do rebalance

    // start controller
    ClusterController controller =
        new ClusterController(clusterName, "controller_0", ZK_ADDR);
    controller.syncStart();

    Map<String, Set<String>> errPartitions = new HashMap<String, Set<String>>()
    {
      {
        put("SLAVE-MASTER", TestHelper.setOf("TestDB0_4"));
        put("OFFLINE-SLAVE", TestHelper.setOf("TestDB0_8"));
      }
    };

    // start mock participants
    MockParticipant[] participants = new MockParticipant[n];
    for (int i = 0; i < n; i++)
    {
      String instanceName = "localhost_" + (12918 + i);

      if (i == 0)
      {
        participants[i] =
            new MockParticipant(clusterName,
                                instanceName,
                                ZK_ADDR,
                                new ErrTransition(errPartitions));
      }
      else
      {
        participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR);
      }
      participants[i].syncStart();
    }

    // verify cluster
    Map<String, Map<String, String>> errStateMap =
        new HashMap<String, Map<String, String>>();
    errStateMap.put("TestDB0", new HashMap<String, String>());
    errStateMap.get("TestDB0").put("TestDB0_4", "localhost_12918");
    errStateMap.get("TestDB0").put("TestDB0_8", "localhost_12918");
    boolean result =
        ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                                       clusterName,
                                                                                                       errStateMap)));
    Assert.assertTrue(result, "Cluster verification fails");
   
    // reset resource "TestDB0"
    participants[0].setTransition(null);
    String command =
        "--zkSvr " + ZK_ADDR + " --resetResource " + clusterName
            + " TestDB0";
    ClusterSetup.processCommandLineArgs(command.split("\\s+"));

    result =
        ClusterStateVerifier.verifyByZkCallback((new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
                                                                                                       clusterName)));
    Assert.assertTrue(result, "Cluster verification fails");
   
    // clean up
    // wait for all zk callbacks done
    Thread.sleep(1000);
    controller.syncStop();
    for (int i = 0; i < 5; i++)
    {
      participants[i].syncStop();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.