org.apache.helix.model.HelixConfigScope Java Examples

The following examples show how to use org.apache.helix.model.HelixConfigScope. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
Source File: ZKHelixAdmin.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
public boolean setInstanceConfig(String clusterName, String instanceName,
    InstanceConfig newInstanceConfig) {
  logger.info("Set instance config for instance {} to cluster {} with new InstanceConfig {}.",
      instanceName, clusterName,
      newInstanceConfig == null ? "NULL" : newInstanceConfig.toString());
  String instanceConfigPath = PropertyPathBuilder.getPath(PropertyType.CONFIGS, clusterName,
      HelixConfigScope.ConfigScopeProperty.PARTICIPANT.toString(), instanceName);
  if (!_zkClient.exists(instanceConfigPath)) {
    throw new HelixException(
        "instance" + instanceName + " does not exist in cluster " + clusterName);
  }

  HelixDataAccessor accessor =
      new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_zkClient));
  PropertyKey instanceConfigPropertyKey = accessor.keyBuilder().instanceConfig(instanceName);
  InstanceConfig currentInstanceConfig = accessor.getProperty(instanceConfigPropertyKey);
  if (!newInstanceConfig.getHostName().equals(currentInstanceConfig.getHostName())
      || !newInstanceConfig.getPort().equals(currentInstanceConfig.getPort())) {
    throw new HelixException(
        "Hostname and port cannot be changed, current hostname: " + currentInstanceConfig
            .getHostName() + " and port: " + currentInstanceConfig.getPort()
            + " is different from new hostname: " + newInstanceConfig.getHostName()
            + "and new port: " + newInstanceConfig.getPort());
  }
  return accessor.setProperty(instanceConfigPropertyKey, newInstanceConfig);
}
 
Example #19
Source File: HelixUtils.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * Create a Helix cluster for the Gobblin Cluster application.
 *
 * @param zkConnectionString the ZooKeeper connection string
 * @param clusterName the Helix cluster name
 * @param overwrite true to overwrite exiting cluster, false to reuse existing cluster
 */
public static void createGobblinHelixCluster(
    String zkConnectionString,
    String clusterName,
    boolean overwrite) {
  ClusterSetup clusterSetup = new ClusterSetup(zkConnectionString);
  // Create the cluster and overwrite if it already exists
  clusterSetup.addCluster(clusterName, overwrite);
  // Helix 0.6.x requires a configuration property to have the form key=value.
  String autoJoinConfig = ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN + "=true";
  clusterSetup.setConfig(HelixConfigScope.ConfigScopeProperty.CLUSTER, clusterName, autoJoinConfig);
}
 
Example #20
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
private ZNRecord getConfigZnRecord(HelixConfigScope scope) {
  String clusterName = scope.getClusterName();
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("fail to get configs. cluster " + clusterName + " is not setup yet");
  }

  return _zkClient.readData(scope.getZkPath(), true);
}
 
Example #21
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * get a single config entry
 * @param scope specification of the entity set to query
 *          (e.g. cluster, resource, participant, etc.)
 * @param key the identifier of the configuration entry
 * @return the configuration entry
 */
public String get(HelixConfigScope scope, String key) {
  Map<String, String> map = get(scope, Arrays.asList(key));
  if (map != null) {
    return map.get(key);
  }
  return null;
}
 
Example #22
Source File: ConfigAccessor.java    From helix with Apache License 2.0 5 votes vote down vote up
/**
 * Set multiple configs, creating them if they don't exist
 * @param scope scope specification of the entity set to query
 *          (e.g. cluster, resource, participant, etc.)
 * @param keyValueMap configurations organized by their identifiers
 */
public void set(HelixConfigScope scope, Map<String, String> keyValueMap) {
  if (scope == null || scope.getType() == null || !scope.isFullKey()) {
    LOG.error("fail to set config. invalid config scope. Scope: {}.", scope);
    return;
  }

  String clusterName = scope.getClusterName();
  if (!ZKUtil.isClusterSetup(clusterName, _zkClient)) {
    throw new HelixException("fail to set config. cluster: " + clusterName + " is NOT setup.");
  }

  if (scope.getType() == ConfigScopeProperty.PARTICIPANT) {
    if (!ZKUtil.isInstanceSetup(_zkClient, scope.getClusterName(), scope.getParticipantName(),
        InstanceType.PARTICIPANT)) {
      throw new HelixException("fail to set config. instance: " + scope.getParticipantName()
          + " is NOT setup in cluster: " + clusterName);
    }
  }

  String mapKey = scope.getMapKey();
  String zkPath = scope.getZkPath();
  String id = zkPath.substring(zkPath.lastIndexOf('/') + 1);
  ZNRecord update = new ZNRecord(id);
  if (mapKey == null) {
    update.getSimpleFields().putAll(keyValueMap);
  } else {
    update.setMapField(mapKey, keyValueMap);
  }

  ZKUtil.createOrMerge(_zkClient, zkPath, update, true, true);
}
 
Example #23
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 #24
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 #25
Source File: HelixHelper.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static void deleteResourcePropertyFromHelix(HelixAdmin admin, String clusterName, String resourceName,
    String configKey) {
  final List<String> keys = new ArrayList<String>();
  keys.add(configKey);

  final HelixConfigScope scope = getResourceScopeFor(clusterName, resourceName);
  admin.removeConfig(scope, keys);
}
 
Example #26
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 #27
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 #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: 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 #30
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);
}