Package org.apache.helix.model

Examples of org.apache.helix.model.ClusterConfiguration


  /**
   * create a new cluster, fail if it already exists
   * @return true if created, false if creation failed
   */
  public boolean createCluster(ClusterConfig cluster) {
    ClusterConfiguration configuration = _accessor.getProperty(_keyBuilder.clusterConfig());
    if (configuration != null && isClusterStructureValid()) {
      LOG.error("Cluster already created. Aborting.");
      return false;
    }
    clearClusterStructure();
    initClusterStructure();
    Map<StateModelDefId, StateModelDefinition> stateModelDefs = cluster.getStateModelMap();
    for (StateModelDefinition stateModelDef : stateModelDefs.values()) {
      addStateModelDefinition(stateModelDef);
    }
    Map<ResourceId, ResourceConfig> resources = cluster.getResourceMap();
    for (ResourceConfig resource : resources.values()) {
      addResource(resource);
    }
    Map<ParticipantId, ParticipantConfig> participants = cluster.getParticipantMap();
    for (ParticipantConfig participant : participants.values()) {
      addParticipant(participant);
    }
    _accessor.createProperty(_keyBuilder.constraints(), null);
    for (ClusterConstraints constraints : cluster.getConstraintMap().values()) {
      _accessor.setProperty(_keyBuilder.constraint(constraints.getType().toString()), constraints);
    }
    ClusterConfiguration clusterConfig =
        ClusterConfiguration.from(_clusterId, cluster.getUserConfig());
    if (cluster.autoJoinAllowed()) {
      clusterConfig.setAutoJoinAllowed(cluster.autoJoinAllowed());
    }
    if (cluster.isPaused()) {
      _accessor.createProperty(_keyBuilder.pause(), new PauseSignal("pause"));
    }
    _accessor.setProperty(_keyBuilder.clusterConfig(), clusterConfig);
View Full Code Here


    // read the pause status
    PauseSignal pauseSignal = _cache.getPauseSignal();
    boolean isPaused = pauseSignal != null;

    ClusterConfiguration clusterConfig = _cache.getClusterConfig();
    boolean autoJoinAllowed = false;
    UserConfig userConfig;
    if (clusterConfig != null) {
      userConfig = clusterConfig.getUserConfig();
      autoJoinAllowed = clusterConfig.autoJoinAllowed();
    } else {
      userConfig = new UserConfig(Scope.cluster(_clusterId));
    }

    // read the state model definitions
View Full Code Here

    // add the following: key1 straight to user config, key2 to cluster configuration,
    // allow auto join to cluster configuration
    ClusterId clusterId = ClusterId.from("clusterId");
    UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
    userConfig.setSimpleField(KEY1, VALUE1);
    ClusterConfiguration clusterConfiguration = new ClusterConfiguration(clusterId);
    clusterConfiguration.addNamespacedConfig(userConfig);
    clusterConfiguration.getRecord().setSimpleField(KEY2, VALUE2);
    clusterConfiguration.setAutoJoinAllowed(true);

    // there should be key1 and key2, but not auto join
    UserConfig result = clusterConfiguration.getUserConfig();
    Assert.assertEquals(result.getSimpleField(KEY1), VALUE1);
    Assert.assertEquals(result.getSimpleField(KEY2), VALUE2);
    Assert.assertNull(result.getSimpleField(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
  }
View Full Code Here

    // create some ideal state specs
    createISSpec(accessor, masterSlaveCustomResource + "_spec", "MasterSlave",
        RebalanceMode.CUSTOMIZED);
    createISSpec(accessor, onlineOfflineFullAutoResource + "_spec", "OnlineOffline",
        RebalanceMode.FULL_AUTO);
    ClusterConfiguration clusterConfiguration =
        accessor.getProperty(accessor.keyBuilder().clusterConfig());

    // add some state models
    addStateModels(accessor);

    // refresh the cache
    ClusterEvent event = new ClusterEvent("testEvent");
    ClusterId clusterId = new ClusterId("sampleClusterId");
    ClusterAccessor clusterAccessor = new MockClusterAccessor(clusterId, accessor);
    Cluster cluster = clusterAccessor.readCluster();
    event.addAttribute("Cluster", cluster);
    event.addAttribute(AttributeName.IDEAL_STATE_RULES.toString(),
        clusterConfiguration.getIdealStateRules());

    // run resource computation
    new ResourceComputationStage().process(event);
    Map<ResourceId, ResourceConfig> resourceMap =
        event.getAttribute(AttributeName.RESOURCES.toString());
View Full Code Here

    }
    ControllerContextProvider contextProvider = new ControllerContextProvider(persistedContexts);
    event.addAttribute(AttributeName.CONTEXT_PROVIDER.toString(), contextProvider);

    // read ideal state rules (if any)
    ClusterConfiguration clusterConfiguration =
        accessor.getProperty(accessor.keyBuilder().clusterConfig());
    if (clusterConfiguration == null) {
      clusterConfiguration = new ClusterConfiguration(cluster.getId());
    }
    event.addAttribute(AttributeName.IDEAL_STATE_RULES.toString(),
        clusterConfiguration.getIdealStateRules());

    long endTime = System.currentTimeMillis();
    LOG.info("END ReadClusterDataStage.process(). took: " + (endTime - startTime) + " ms");
  }
View Full Code Here

     * @param accessor the physical cluster accessor
     */
    public void merge(HelixDataAccessor accessor) {
      // Update the main config
      final ClusterConfig deltaConfig = _builder.build();
      ClusterConfiguration config = new ClusterConfiguration(deltaConfig.getId());
      config.setAutoJoinAllowed(deltaConfig.autoJoinAllowed());
      if (deltaConfig.getUserConfig() != null) {
        config.addNamespacedConfig(deltaConfig.getUserConfig());
      }
      accessor.updateProperty(accessor.keyBuilder().clusterConfig(), config);

      // Update paused status
      if (_paused != null) {
View Full Code Here

    // add the following: key1 straight to user config, key2 to cluster configuration,
    // allow auto join to cluster configuration
    ClusterId clusterId = ClusterId.from("clusterId");
    UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
    userConfig.setSimpleField(KEY1, VALUE1);
    ClusterConfiguration clusterConfiguration = new ClusterConfiguration(clusterId);
    clusterConfiguration.addNamespacedConfig(userConfig);
    clusterConfiguration.getRecord().setSimpleField(KEY2, VALUE2);
    clusterConfiguration.setAutoJoinAllowed(true);

    // there should be key1 and key2, but not auto join
    UserConfig result = clusterConfiguration.getUserConfig();
    Assert.assertEquals(result.getSimpleField(KEY1), VALUE1);
    Assert.assertEquals(result.getSimpleField(KEY2), VALUE2);
    Assert.assertNull(result.getSimpleField(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN));
  }
View Full Code Here

  /**
   * create a new cluster, fail if it already exists
   * @return true if created, false if creation failed
   */
  public boolean createCluster(ClusterConfig cluster) {
    ClusterConfiguration configuration = _accessor.getProperty(_keyBuilder.clusterConfig());
    if (configuration != null && isClusterStructureValid()) {
      LOG.error("Cluster already created. Aborting.");
      return false;
    }
    clearClusterStructure();
    initClusterStructure();
    Map<StateModelDefId, StateModelDefinition> stateModelDefs = cluster.getStateModelMap();
    for (StateModelDefinition stateModelDef : stateModelDefs.values()) {
      addStateModelDefinitionToCluster(stateModelDef);
    }
    Map<ResourceId, ResourceConfig> resources = cluster.getResourceMap();
    for (ResourceConfig resource : resources.values()) {
      addResourceToCluster(resource);
    }
    Map<ParticipantId, ParticipantConfig> participants = cluster.getParticipantMap();
    for (ParticipantConfig participant : participants.values()) {
      addParticipantToCluster(participant);
    }
    _accessor.createProperty(_keyBuilder.constraints(), null);
    for (ClusterConstraints constraints : cluster.getConstraintMap().values()) {
      _accessor.setProperty(_keyBuilder.constraint(constraints.getType().toString()), constraints);
    }
    ClusterConfiguration clusterConfig = ClusterConfiguration.from(cluster.getUserConfig());
    if (cluster.autoJoinAllowed()) {
      clusterConfig.setAutoJoinAllowed(cluster.autoJoinAllowed());
    }
    if (cluster.getStats() != null && !cluster.getStats().getMapFields().isEmpty()) {
      _accessor.setProperty(_keyBuilder.persistantStat(), cluster.getStats());
    }
    if (cluster.isPaused()) {
View Full Code Here

   */
  private boolean setBasicClusterConfig(ClusterConfig config) {
    if (config == null) {
      return false;
    }
    ClusterConfiguration configuration = ClusterConfiguration.from(config.getUserConfig());
    configuration.setAutoJoinAllowed(config.autoJoinAllowed());
    _accessor.setProperty(_keyBuilder.clusterConfig(), configuration);
    Map<ConstraintType, ClusterConstraints> constraints = config.getConstraintMap();
    for (ConstraintType type : constraints.keySet()) {
      ClusterConstraints constraint = constraints.get(type);
      _accessor.setProperty(_keyBuilder.constraint(type.toString()), constraint);
View Full Code Here

    // read the pause status
    PauseSignal pauseSignal = _accessor.getProperty(_keyBuilder.pause());
    boolean isPaused = pauseSignal != null;

    ClusterConfiguration clusterConfig = _accessor.getProperty(_keyBuilder.clusterConfig());
    boolean autoJoinAllowed = false;
    UserConfig userConfig;
    if (clusterConfig != null) {
      userConfig = clusterConfig.getUserConfig();
      autoJoinAllowed = clusterConfig.autoJoinAllowed();
    } else {
      userConfig = new UserConfig(Scope.cluster(_clusterId));
    }

    // read the state model definitions
View Full Code Here

TOP

Related Classes of org.apache.helix.model.ClusterConfiguration

Copyright © 2018 www.massapicom. 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.