org.apache.helix.model.builder.HelixConfigScopeBuilder Java Examples

The following examples show how to use org.apache.helix.model.builder.HelixConfigScopeBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterSetup.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * get configs
 * @param type config-scope-type, e.g. CLUSTER, RESOURCE, etc.
 * @param scopeArgsCsv csv-formatted scope-args, e.g myCluster,testDB
 * @param keysCsv csv-formatted keys. e.g. k1,k2
 * @return json-formated key-value pairs, e.g. {k1=v1,k2=v2}
 */
public String getConfig(ConfigScopeProperty type, String scopeArgsCsv, String keysCsv) {
  // ConfigScope scope = new ConfigScopeBuilder().build(scopesStr);

  String[] scopeArgs = scopeArgsCsv.split("[\\s,]");
  HelixConfigScope scope = new HelixConfigScopeBuilder(type, scopeArgs).build();

  String[] keys = keysCsv.split("[\\s,]");
  // parse keys
  // String[] keys = keysStr.split("[\\s,]");
  // Set<String> keysSet = new HashSet<String>(Arrays.asList(keys));

  Map<String, String> keyValueMap = _admin.getConfig(scope, Arrays.asList(keys));
  ZNRecord record = new ZNRecord(type.toString());
  // record.setMapField(scopesStr, propertiesMap);
  record.getSimpleFields().putAll(keyValueMap);
  ZNRecordSerializer serializer = new ZNRecordSerializer();
  return new String(serializer.serialize(record));
}
 
Example #2
Source File: HelixVcrPopulateTool.java    From ambry with Apache License 2.0 6 votes vote down vote up
/**
 * Create a helix cluster with given information.
 * @param destZkString the cluster's zk string
 * @param destClusterName the cluster's name
 */
static void createCluster(String destZkString, String destClusterName) {
  HelixZkClient destZkClient = getHelixZkClient(destZkString);
  HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
  if (ZKUtil.isClusterSetup(destClusterName, destZkClient)) {
    errorAndExit("Failed to create cluster because " + destClusterName + " already exist.");
  }
  ClusterSetup clusterSetup = new ClusterSetup.Builder().setZkAddress(destZkString).build();
  clusterSetup.addCluster(destClusterName, true);

  // set ALLOW_PARTICIPANT_AUTO_JOIN
  HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).
      forCluster(destClusterName).build();
  Map<String, String> helixClusterProperties = new HashMap<>();
  helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
  destAdmin.setConfig(configScope, helixClusterProperties);

  setClusterConfig(destZkClient, destClusterName, false);
  System.out.println("Cluster " + destClusterName + " is created successfully!");
}
 
Example #3
Source File: ControllerTest.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
protected void addFakeServerInstanceToAutoJoinHelixCluster(String instanceId, boolean isSingleTenant, int adminPort)
    throws Exception {
  HelixManager helixManager = HelixManagerFactory
      .getZKHelixManager(getHelixClusterName(), instanceId, InstanceType.PARTICIPANT, ZkStarter.DEFAULT_ZK_STR);
  helixManager.getStateMachineEngine()
      .registerStateModelFactory(FakeSegmentOnlineOfflineStateModelFactory.STATE_MODEL_DEF,
          FakeSegmentOnlineOfflineStateModelFactory.FACTORY_INSTANCE);
  helixManager.connect();
  HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
  if (isSingleTenant) {
    helixAdmin.addInstanceTag(getHelixClusterName(), instanceId, TagNameUtils.getOfflineTagForTenant(null));
    helixAdmin.addInstanceTag(getHelixClusterName(), instanceId, TagNameUtils.getRealtimeTagForTenant(null));
  } else {
    helixAdmin.addInstanceTag(getHelixClusterName(), instanceId, UNTAGGED_SERVER_INSTANCE);
  }
  HelixConfigScope configScope =
      new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.PARTICIPANT, getHelixClusterName())
          .forParticipant(instanceId).build();
  helixAdmin.setConfig(configScope, Collections.singletonMap(ADMIN_PORT_KEY, Integer.toString(adminPort)));
  _fakeInstanceHelixManagers.add(helixManager);
}
 
Example #4
Source File: HelixSetupUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
private static void setupHelixClusterIfNeeded(String helixClusterName, String zkPath) {
  HelixAdmin admin = new ZKHelixAdmin(zkPath);
  if (admin.getClusters().contains(helixClusterName)) {
    LOGGER.info("Helix cluster: {} already exists", helixClusterName);
  } else {
    LOGGER.info("Creating a new Helix cluster: {}", helixClusterName);
    admin.addCluster(helixClusterName, false);
    // Enable Auto-Join for the cluster
    HelixConfigScope configScope =
        new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(helixClusterName).build();
    Map<String, String> configMap = new HashMap<>();
    configMap.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, Boolean.toString(true));
    configMap.put(ENABLE_CASE_INSENSITIVE_KEY, Boolean.toString(false));
    configMap.put(DEFAULT_HYPERLOGLOG_LOG2M_KEY, Integer.toString(DEFAULT_HYPERLOGLOG_LOG2M));
    configMap.put(CommonConstants.Broker.CONFIG_OF_ENABLE_QUERY_LIMIT_OVERRIDE, Boolean.toString(false));
    admin.setConfig(configScope, configMap);
    LOGGER.info("New Helix cluster: {} created", helixClusterName);
  }
}
 
Example #5
Source File: PinotClusterConfigs.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@DELETE
@Path("/cluster/configs/{configName}")
@ApiOperation(value = "Delete cluster configuration")
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Server error deleting configuration")})
public SuccessResponse deleteClusterConfig(
    @ApiParam(value = "Name of the config to delete", required = true) @PathParam("configName") String configName) {
  try {
    HelixAdmin admin = pinotHelixResourceManager.getHelixAdmin();
    HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER)
        .forCluster(pinotHelixResourceManager.getHelixClusterName()).build();
    admin.removeConfig(configScope, Arrays.asList(configName));
    return new SuccessResponse("Deleted cluster config: " + configName);
  } catch (Exception e) {
    String errStr = "Failed to delete cluster config: " + configName;
    throw new ControllerApplicationException(LOGGER, errStr, Response.Status.INTERNAL_SERVER_ERROR, e);
  }
}
 
Example #6
Source File: PinotClusterConfigs.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/cluster/configs")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List cluster configurations", notes = "List cluster level configurations")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Success"), @ApiResponse(code = 500, message = "Internal server error")})
public String listClusterConfigs() {
  HelixAdmin helixAdmin = pinotHelixResourceManager.getHelixAdmin();
  HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER)
      .forCluster(pinotHelixResourceManager.getHelixClusterName()).build();
  List<String> configKeys = helixAdmin.getConfigKeys(configScope);
  ObjectNode ret = JsonUtils.newObjectNode();
  Map<String, String> configs = helixAdmin.getConfig(configScope, configKeys);
  for (String key : configs.keySet()) {
    ret.put(key, configs.get(key));
  }
  return ret.toString();
}
 
Example #7
Source File: IntegrationTest.java    From helix with Apache License 2.0 6 votes vote down vote up
private static void addConfiguration(ClusterSetup setup, String baseDir, String clusterName,
    String instanceName) throws IOException {
  Map<String, String> properties = new HashMap<String, String>();
  HelixConfigScopeBuilder builder = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT);
  HelixConfigScope instanceScope =
      builder.forCluster(clusterName).forParticipant(instanceName).build();
  properties.put("change_log_dir", baseDir + instanceName + "/translog");
  properties.put("file_store_dir", baseDir + instanceName + "/filestore");
  properties.put("check_point_dir", baseDir + instanceName + "/checkpoint");
  setup.getClusterManagementTool().setConfig(instanceScope, properties);
  FileUtils.deleteDirectory(new File(properties.get("change_log_dir")));
  FileUtils.deleteDirectory(new File(properties.get("file_store_dir")));
  FileUtils.deleteDirectory(new File(properties.get("check_point_dir")));
  new File(properties.get("change_log_dir")).mkdirs();
  new File(properties.get("file_store_dir")).mkdirs();
  new File(properties.get("check_point_dir")).mkdirs();
}
 
Example #8
Source File: TaskStateModel.java    From helix with Apache License 2.0 6 votes vote down vote up
@Transition(to = "ONLINE", from = "OFFLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context)
    throws Exception {
  LOG.debug(_workerId + " becomes ONLINE from OFFLINE for " + _partition);
  ConfigAccessor clusterConfig = context.getManager().getConfigAccessor();
  HelixManager manager = context.getManager();
  HelixConfigScope clusterScope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(
          manager.getClusterName()).build();
  String json = clusterConfig.get(clusterScope, message.getResourceName());
  Dag.Node node = Dag.Node.fromJson(json);
  Set<String> parentIds = node.getParentIds();
  String resourceName = message.getResourceName();
  int numPartitions = node.getNumPartitions();
  Task task = _taskFactory.createTask(resourceName, parentIds, manager, _taskResultStore);
  manager.addExternalViewChangeListener(task);

  LOG.debug("Starting task for " + _partition + "...");
  int partitionNum = Integer.parseInt(_partition.split("_")[1]);
  task.execute(resourceName, numPartitions, partitionNum);
  LOG.debug("Task for " + _partition + " done");
}
 
Example #9
Source File: TestConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetRestConfig() {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;

  ZKHelixAdmin admin = new ZKHelixAdmin(ZK_ADDR);
  admin.addCluster(clusterName, true);
  ConfigAccessor configAccessor = new ConfigAccessor(ZK_ADDR);
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.REST).forCluster(clusterName).build();
  Assert.assertNull(configAccessor.getRESTConfig(clusterName));

  RESTConfig restConfig = new RESTConfig(clusterName);
  restConfig.set(RESTConfig.SimpleFields.CUSTOMIZED_HEALTH_URL, "TEST_URL");
  configAccessor.setRESTConfig(clusterName, restConfig);
  Assert.assertEquals(restConfig, configAccessor.getRESTConfig(clusterName));
}
 
Example #10
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
private void updateInstanceConfig(String clusterName, String instanceName,
    InstanceConfig instanceConfig, boolean overwrite) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName)
          .forParticipant(instanceName).build();
  String zkPath = scope.getZkPath();

  if (!_zkClient.exists(zkPath)) {
    throw new HelixException(
        "updateInstanceConfig failed. Given InstanceConfig does not already exist. instance: "
            + instanceName);
  }

  if (overwrite) {
    ZKUtil.createOrReplace(_zkClient, zkPath, instanceConfig.getRecord(), true);
  } else {
    ZKUtil.createOrUpdate(_zkClient, zkPath, instanceConfig.getRecord(), true, true);
  }
}
 
Example #11
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * Get instance config for given resource in given cluster.
 *
 * @param clusterName
 * @param instanceName
 *
 * @return
 */
public InstanceConfig getInstanceConfig(String clusterName, String instanceName) {
  if (!ZKUtil.isInstanceSetup(_zkClient, clusterName, instanceName, InstanceType.PARTICIPANT)) {
    throw new HelixException(
        "fail to get config. instance: " + instanceName + " is NOT setup in cluster: "
            + clusterName);
  }

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT).forCluster(clusterName)
          .forParticipant(instanceName).build();
  ZNRecord record = getConfigZnRecord(scope);

  if (record == null) {
    LOG.warn("No config found at {}.", scope.getZkPath());
    return null;
  }

  return new InstanceConfig(record);
}
 
Example #12
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
private void updateResourceConfig(String clusterName, String resourceName,
    ResourceConfig resourceConfig, boolean overwrite) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("fail to setup config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
          .forResource(resourceName).build();
  String zkPath = scope.getZkPath();

  if (overwrite) {
    ZKUtil.createOrReplace(_zkClient, zkPath, resourceConfig.getRecord(), true);
  } else {
    ZKUtil.createOrUpdate(_zkClient, zkPath, resourceConfig.getRecord(), true, true);
  }
}
 
Example #13
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
private void updateClusterConfig(String clusterName, ClusterConfig clusterConfig,
    boolean overwrite) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("fail to update config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
  String zkPath = scope.getZkPath();

  if (overwrite) {
    ZKUtil.createOrReplace(_zkClient, zkPath, clusterConfig.getRecord(), true);
  } else {
    ZKUtil.createOrUpdate(_zkClient, zkPath, clusterConfig.getRecord(), true, true);
  }
}
 
Example #14
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
private void updateRESTConfig(String clusterName, RESTConfig restConfig, boolean overwrite) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("Fail to update REST config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.REST).forCluster(clusterName).build();
  String zkPath = scope.getZkPath();

  // Create "/{clusterId}/CONFIGS/REST" if it does not exist
  String parentPath = HelixUtil.getZkParentPath(zkPath);
  if (!_zkClient.exists(parentPath)) {
    ZKUtil.createOrMerge(_zkClient, parentPath, new ZNRecord(parentPath), true, true);
  }

  if (overwrite) {
    ZKUtil.createOrReplace(_zkClient, zkPath, restConfig.getRecord(), true);
  } else {
    ZKUtil.createOrUpdate(_zkClient, zkPath, restConfig.getRecord(), true, true);
  }
}
 
Example #15
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * Get CustomizedStateConfig of the given cluster.
 * @param clusterName
 * @return The instance of {@link CustomizedStateConfig}
 */
public CustomizedStateConfig getCustomizedStateConfig(String clusterName) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException(String.format("Failed to get config. cluster: %s is not setup.", clusterName));
  }
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CUSTOMIZED_STATE).forCluster(clusterName).build();
  ZNRecord record = getConfigZnRecord(scope);

  if (record == null) {
    LOG.warn("No customized state aggregation config found at {}.", scope.getZkPath());
    return null;
  }

  return new CustomizedStateConfig.Builder(record).build();
}
 
Example #16
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * Get ClusterConfig of the given cluster.
 *
 * @param clusterName
 *
 * @return
 */
public ClusterConfig getClusterConfig(String clusterName) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("fail to get config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(clusterName).build();
  ZNRecord record = getConfigZnRecord(scope);

  if (record == null) {
    LOG.warn("No config found at {}.", scope.getZkPath());
    return null;
  }

  return new ClusterConfig(record);
}
 
Example #17
Source File: ConfigAccessor.java    From helix with Apache License 2.0 6 votes vote down vote up
/**
 * Get CloudConfig of the given cluster.
 * @param clusterName
 * @return The instance of {@link CloudConfig}
 */
public CloudConfig getCloudConfig(String clusterName) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException(
        String.format("Failed to get config. cluster: %s is not setup.", clusterName));
  }
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLOUD).forCluster(clusterName).build();
  ZNRecord record = getConfigZnRecord(scope);

  if (record == null) {
    LOG.warn("No cloud config found at {}.", scope.getZkPath());
    return null;
  }

  return new CloudConfig(record);
}
 
Example #18
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Get resource config for given resource in given cluster.
 *
 * @param clusterName
 * @param resourceName
 *
 * @return
 */
public ResourceConfig getResourceConfig(String clusterName, String resourceName) {
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
          .forResource(resourceName).build();
  ZNRecord record = getConfigZnRecord(scope);

  if (record == null) {
    LOG.warn("No config found at {}.", scope.getZkPath());
    return null;
  }

  return new ResourceConfig(record);
}
 
Example #19
Source File: VcrTestUtil.java    From ambry with Apache License 2.0 5 votes vote down vote up
/**
 * Populate info on ZooKeeper server and start {@link HelixControllerManager}.
 * @param zkConnectString zk connect string to zk server.
 * @param vcrClusterName the vcr cluster name.
 * @param clusterMap the {@link ClusterMap} to use.
 * @return the created {@link HelixControllerManager}.
 */
public static HelixControllerManager populateZkInfoAndStartController(String zkConnectString, String vcrClusterName,
    ClusterMap clusterMap) {
  HelixZkClient zkClient = DedicatedZkClientFactory.getInstance()
      .buildZkClient(new HelixZkClient.ZkConnectionConfig(zkConnectString), new HelixZkClient.ZkClientConfig());
  try {
    zkClient.setZkSerializer(new ZNRecordSerializer());
    ClusterSetup clusterSetup = new ClusterSetup(zkClient);
    clusterSetup.addCluster(vcrClusterName, true);
    HelixAdmin admin = new ZKHelixAdmin(zkClient);
    // set ALLOW_PARTICIPANT_AUTO_JOIN
    HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).
        forCluster(vcrClusterName).build();
    Map<String, String> helixClusterProperties = new HashMap<>();
    helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
    admin.setConfig(configScope, helixClusterProperties);
    // set PersistBestPossibleAssignment
    ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
    ClusterConfig clusterConfig = configAccessor.getClusterConfig(vcrClusterName);
    clusterConfig.setPersistBestPossibleAssignment(true);
    configAccessor.setClusterConfig(vcrClusterName, clusterConfig);

    FullAutoModeISBuilder builder = new FullAutoModeISBuilder(helixResource);
    builder.setStateModel(LeaderStandbySMD.name);
    for (PartitionId partitionId : clusterMap.getAllPartitionIds(null)) {
      builder.add(partitionId.toPathString());
    }
    builder.setRebalanceStrategy(CrushEdRebalanceStrategy.class.getName());
    IdealState idealState = builder.build();
    admin.addResource(vcrClusterName, helixResource, idealState);
    admin.rebalance(vcrClusterName, helixResource, 3, "", "");
    HelixControllerManager helixControllerManager = new HelixControllerManager(zkConnectString, vcrClusterName);
    helixControllerManager.syncStart();
    return helixControllerManager;
  } finally {
    zkClient.close();
  }
}
 
Example #20
Source File: ControllerTest.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
protected void startController(ControllerConf config) {
  Preconditions.checkState(_controllerStarter == null);

  _controllerPort = Integer.valueOf(config.getControllerPort());
  _controllerBaseApiUrl = "http://localhost:" + _controllerPort;
  _controllerRequestURLBuilder = ControllerRequestURLBuilder.baseUrl(_controllerBaseApiUrl);
  _controllerDataDir = config.getDataDir();

  _controllerStarter = getControllerStarter(config);
  _controllerStarter.start();
  _helixResourceManager = _controllerStarter.getHelixResourceManager();
  _helixManager = _controllerStarter.getHelixControllerManager();
  _helixDataAccessor = _helixManager.getHelixDataAccessor();
  ConfigAccessor configAccessor = _helixManager.getConfigAccessor();
  // HelixResourceManager is null in Helix only mode, while HelixManager is null in Pinot only mode.
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(getHelixClusterName())
          .build();
  switch (_controllerStarter.getControllerMode()) {
    case DUAL:
    case PINOT_ONLY:
      _helixAdmin = _helixResourceManager.getHelixAdmin();
      _propertyStore = _helixResourceManager.getPropertyStore();

      // TODO: Enable periodic rebalance per 10 seconds as a temporary work-around for the Helix issue:
      //       https://github.com/apache/helix/issues/331. Remove this after Helix fixing the issue.
      configAccessor.set(scope, ClusterConfig.ClusterConfigProperty.REBALANCE_TIMER_PERIOD.name(), "10000");
      break;
    case HELIX_ONLY:
      _helixAdmin = _helixManager.getClusterManagmentTool();
      _propertyStore = _helixManager.getHelixPropertyStore();
      break;
  }
  //enable case insensitive pql for test cases.
  configAccessor.set(scope, CommonConstants.Helix.ENABLE_CASE_INSENSITIVE_KEY, Boolean.toString(true));
  //Set hyperloglog log2m value to 12.
  configAccessor.set(scope, CommonConstants.Helix.DEFAULT_HYPERLOGLOG_LOG2M_KEY, Integer.toString(12));
}
 
Example #21
Source File: HelixSetupUtils.java    From uReplicator with Apache License 2.0 5 votes vote down vote up
public static void createHelixClusterIfNeeded(String helixClusterName, String zkPath) {
  final HelixAdmin admin = new ZKHelixAdmin(zkPath);

  if (admin.getClusters().contains(helixClusterName)) {
    LOGGER.info("cluster already exist, skipping it.. ********************************************* ");
    return;
  }

  LOGGER.info("Creating a new cluster, as the helix cluster : " + helixClusterName
      + " was not found ********************************************* ");
  admin.addCluster(helixClusterName, false);

  LOGGER.info("Enable mirror maker machines auto join.");
  final HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER)
      .forCluster(helixClusterName).build();

  final Map<String, String> props = new HashMap<String, String>();
  props.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
  props.put(MessageType.STATE_TRANSITION + "." + HelixTaskExecutor.MAX_THREADS,
      String.valueOf(100));

  admin.setConfig(scope, props);

  LOGGER.info("Adding state model definition named : OnlineOffline generated using : "
      + OnlineOfflineStateModel.class.toString()
      + " ********************************************** ");

  // add state model definition
  admin.addStateModelDef(helixClusterName, "OnlineOffline", OnlineOfflineStateModel.build());
  LOGGER.info("New Cluster setup completed... ********************************************** ");
}
 
Example #22
Source File: ServiceDiscovery.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * @return returns true if
 */
public boolean start() throws Exception {
  // auto create cluster and allow nodes to automatically join the cluster
  admin =
      HelixManagerFactory.getZKHelixManager(cluster, "service-discovery",
          InstanceType.ADMINISTRATOR, zkAddress);
  admin.connect();
  admin.getClusterManagmentTool().addCluster(cluster, false);
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(cluster).build();

  Map<String, String> properties = new HashMap<String, String>();
  properties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
  admin.getClusterManagmentTool().setConfig(scope, properties);
  switch (mode) {
  case POLL:
    startBackgroundTask();
    break;
  case WATCH:
    setupWatcher();
    break;
  case NONE:// dont monitor changes, supports only registration

  }
  refreshCache();
  return true;
}
 
Example #23
Source File: TestResourceThreadpoolSize.java    From helix with Apache License 2.0 5 votes vote down vote up
private void setResourceThreadPoolSize(String resourceName, int threadPoolSize) {
  HelixManager manager = _participants[0];
  ConfigAccessor accessor = manager.getConfigAccessor();
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.RESOURCE)
          .forCluster(manager.getClusterName()).forResource(resourceName).build();
  accessor.set(scope, HelixTaskExecutor.MAX_THREADS, "" + threadPoolSize);
}
 
Example #24
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Delete cloud config fields (not the whole config)
 * @param clusterName
 * @param cloudConfig
 */
public void deleteCloudConfigFields(String clusterName, CloudConfig cloudConfig) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("fail to delete cloud config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLOUD).forCluster(clusterName).build();
  remove(scope, cloudConfig.getRecord());
}
 
Example #25
Source File: TestZkHelixAdmin.java    From helix with Apache License 2.0 5 votes vote down vote up
@Test
public void testDropResource() {
  String className = TestHelper.getTestClassName();
  String methodName = TestHelper.getTestMethodName();
  String clusterName = className + "_" + methodName;

  System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));

  HelixAdmin tool = new ZKHelixAdmin(_gZkClient);
  tool.addCluster(clusterName, true);
  Assert.assertTrue(ZKUtil.isClusterSetup(clusterName, _gZkClient), "Cluster should be setup");

  tool.addStateModelDef(clusterName, "MasterSlave",
      new StateModelDefinition(StateModelConfigGenerator.generateConfigForMasterSlave()));
  tool.addResource(clusterName, "test-db", 4, "MasterSlave");
  Map<String, String> resourceConfig = new HashMap<>();
  resourceConfig.put("key1", "value1");
  tool.setConfig(new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(clusterName)
      .forResource("test-db").build(), resourceConfig);

  PropertyKey.Builder keyBuilder = new PropertyKey.Builder(clusterName);
  Assert.assertTrue(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()),
      "test-db ideal-state should exist");
  Assert.assertTrue(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()),
      "test-db resource config should exist");

  tool.dropResource(clusterName, "test-db");
  Assert.assertFalse(_gZkClient.exists(keyBuilder.idealStates("test-db").getPath()),
      "test-db ideal-state should be dropped");
  Assert.assertFalse(_gZkClient.exists(keyBuilder.resourceConfig("test-db").getPath()),
      "test-db resource config should be dropped");

  tool.dropCluster(clusterName);
  System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
 
Example #26
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
public void deleteRESTConfig(String clusterName) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("Fail to delete REST config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.REST).forCluster(clusterName).build();
  String zkPath = scope.getZkPath();

  // Check if "/{clusterId}/CONFIGS/REST" exists
  String parentPath = HelixUtil.getZkParentPath(zkPath);
  if (!_zkClient.exists(parentPath)) {
    throw new HelixException("Fail to delete REST config. cluster: " + clusterName + " does not have a rest config.");    }

  ZKUtil.dropChildren(_zkClient, parentPath, new ZNRecord(clusterName));
}
 
Example #27
Source File: ClusterSetup.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * remove configs
 * @param type config-scope type, e.g. CLUSTER, RESOURCE, etc.
 * @param scopeArgsCsv csv-formatted scope-args, e.g myCluster,testDB
 * @param keysCsv csv-formatted keys. e.g. k1,k2
 */
public void removeConfig(ConfigScopeProperty type, String scopeArgsCsv, String keysCsv) {
  // ConfigScope scope = new ConfigScopeBuilder().build(scopesStr);
  //
  // // parse keys
  // String[] keys = keysStr.split("[\\s,]");
  // Set<String> keysSet = new HashSet<String>(Arrays.asList(keys));

  String[] scopeArgs = scopeArgsCsv.split("[\\s,]");
  HelixConfigScope scope = new HelixConfigScopeBuilder(type, scopeArgs).build();

  String[] keys = keysCsv.split("[\\s,]");

  _admin.removeConfig(scope, Arrays.asList(keys));
}
 
Example #28
Source File: ClusterSetup.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * set configs
 * @param type config-scope type, e.g. CLUSTER, RESOURCE, etc.
 * @param scopeArgsCsv scopeArgsCsv csv-formatted scope-args, e.g myCluster,testDB
 * @param keyValuePairs csv-formatted key-value pairs. e.g. k1=v1,k2=v2
 */
public void setConfig(ConfigScopeProperty type, String scopeArgsCsv, String keyValuePairs) {
  // ConfigScope scope = new ConfigScopeBuilder().build(scopesKeyValuePairs);
  String[] scopeArgs = scopeArgsCsv.split("[\\s,]");
  HelixConfigScope scope = new HelixConfigScopeBuilder(type, scopeArgs).build();

  Map<String, String> keyValueMap = HelixUtil.parseCsvFormatedKeyValuePairs(keyValuePairs);
  _admin.setConfig(scope, keyValueMap);
}
 
Example #29
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Get RestConfig of the given cluster.
 * @param clusterName The cluster
 * @return The instance of {@link RESTConfig}
 */
public RESTConfig getRESTConfig(String clusterName) {
  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.REST).forCluster(clusterName).build();
  ZNRecord record = getConfigZnRecord(scope);

  if (record == null) {
    LOG.warn("No rest config found at {}.", scope.getZkPath());
    return null;
  }

  return new RESTConfig(record);
}
 
Example #30
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
private void updateCloudConfig(String clusterName, CloudConfig cloudConfig, boolean overwrite) {
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("Fail to update cloud config. cluster: " + clusterName + " is NOT setup.");
  }

  HelixConfigScope scope =
      new HelixConfigScopeBuilder(ConfigScopeProperty.CLOUD).forCluster(clusterName).build();
  String zkPath = scope.getZkPath();

  if (overwrite) {
    ZKUtil.createOrReplace(_zkClient, zkPath, cloudConfig.getRecord(), true);
  } else {
    ZKUtil.createOrUpdate(_zkClient, zkPath, cloudConfig.getRecord(), true, true);
  }
}