Package org.apache.helix.api.id

Examples of org.apache.helix.api.id.ParticipantId


    final String VALUE1 = "value1";
    final String KEY2 = "key2";
    final String VALUE2 = "value2";

    // add key1 through user config, key2 through instance config, hostname through user config
    ParticipantId participantId = ParticipantId.from("participantId");
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setSimpleField(KEY1, VALUE1);
    InstanceConfig instanceConfig = new InstanceConfig(participantId);
    instanceConfig.setHostName("localhost");
    instanceConfig.addNamespacedConfig(userConfig);
View Full Code Here


   */
  @Test
  public void testRecreateParticipant() {
    final String MODIFIER = "modifier";
    final ClusterId clusterId = ClusterId.from("testCluster");
    final ParticipantId participantId = ParticipantId.from("testParticipant");

    // connect
    boolean connected = _gZkClient.waitUntilConnected(30000, TimeUnit.MILLISECONDS);
    if (!connected) {
      LOG.warn("Connection not established");
      return;
    }
    BaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
    HelixDataAccessor helixAccessor = new ZKHelixDataAccessor(clusterId.stringify(), baseAccessor);
    ClusterAccessor accessor = new ClusterAccessor(clusterId, helixAccessor);

    // create the cluster
    boolean clusterCreated = createCluster(clusterId, accessor, MODIFIER, 0);
    Assert.assertTrue(clusterCreated);

    // create the participant
    boolean created = createParticipant(participantId, accessor, MODIFIER, 1);
    Assert.assertTrue(created);

    // read the participant
    ParticipantAccessor participantAccessor = new ParticipantAccessor(helixAccessor);
    Participant participantSnapshot = participantAccessor.readParticipant(participantId);
    Assert.assertEquals(participantSnapshot.getUserConfig().getIntField(MODIFIER, -1), 1);

    // create a participant with the same id
    boolean created2 = createParticipant(participantId, accessor, MODIFIER, 2);
    Assert.assertFalse(created2); // should fail since participant exists

    // remove a required property
    helixAccessor.removeProperty(helixAccessor.keyBuilder().messages(participantId.stringify()));

    // try again, should work this time
    created2 = createParticipant(participantId, accessor, MODIFIER, 2);
    Assert.assertTrue(created2);

View Full Code Here

        }
      }
      if (stateCount > -1) {
        int count = 0;
        for (int i = 0; i < participantPreferenceList.size(); i++) {
          ParticipantId participantId = participantPreferenceList.get(i);

          boolean notInErrorState =
              currentStateMap == null
                  || currentStateMap.get(participantId) == null
                  || !currentStateMap.get(participantId)
View Full Code Here

    final String TAG2 = "tag2";
    final String TAG3 = "tag3";
    final PartitionId partition1 = PartitionId.from("resource_1");
    final PartitionId partition2 = PartitionId.from("resource_2");
    final PartitionId partition3 = PartitionId.from("resource_3");
    final ParticipantId participantId = ParticipantId.from("participant");

    // start: add a user config, set host & port, add 2 tags and 2 disabled partition, start
    // disabled
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setSimpleField("key1", "value1");
View Full Code Here

    HelixDataAccessor accessor = _participants[0].getHelixDataAccessor();

    Builder kb = accessor.keyBuilder();
    ExternalView ev = accessor.getProperty(kb.externalView(TEST_DB));
    for (PartitionId p : idealState.getPartitionIdSet()) {
      ParticipantId idealMaster = idealState.getPreferenceList(p).get(0);
      Assert.assertTrue(ev.getStateMap(p).get(idealMaster).equals(State.from("ERROR")));

      TimeOutStateModel model = factories.get(idealMaster.stringify()).getStateModel(p.stringify());
      Assert.assertEquals(model._errorCallcount, 1);
      Assert.assertEquals(model._error.getCode(), ErrorCode.TIMEOUT);
    }
  }
View Full Code Here

      InstanceConfig instanceConfig = instanceConfigMap.get(participantName);
      UserConfig userConfig = instanceConfig.getUserConfig();
      LiveInstance liveInstance = liveInstanceMap.get(participantName);
      Map<String, Message> instanceMsgMap = messageMap.get(participantName);

      ParticipantId participantId = ParticipantId.from(participantName);

      participantMap.put(participantId, ParticipantAccessor.createParticipant(participantId,
          instanceConfig, userConfig, liveInstance, instanceMsgMap,
          currentStateMap.get(participantName)));
    }
View Full Code Here

      LOG.error("Cluster: " + _clusterId + " structure is not valid");
      return false;
    }

    ParticipantAccessor participantAccessor = new ParticipantAccessor(_accessor);
    ParticipantId participantId = participant.getId();
    InstanceConfig existConfig =
        _accessor.getProperty(_keyBuilder.instanceConfig(participantId.stringify()));
    if (existConfig != null && participantAccessor.isParticipantStructureValid(participantId)) {
      LOG.error("Config for participant: " + participantId + " already exists in cluster: "
          + _clusterId);
      return false;
    }

    // clear and rebuild the participant structure
    participantAccessor.clearParticipantStructure(participantId);
    participantAccessor.initParticipantStructure(participantId);

    // add the config
    InstanceConfig instanceConfig = new InstanceConfig(participant.getId());
    instanceConfig.setHostName(participant.getHostName());
    instanceConfig.setPort(Integer.toString(participant.getPort()));
    instanceConfig.setInstanceEnabled(participant.isEnabled());
    UserConfig userConfig = participant.getUserConfig();
    instanceConfig.addNamespacedConfig(userConfig);
    Set<String> tags = participant.getTags();
    for (String tag : tags) {
      instanceConfig.addTag(tag);
    }
    Set<PartitionId> disabledPartitions = participant.getDisabledPartitions();
    for (PartitionId partitionId : disabledPartitions) {
      instanceConfig.setParticipantEnabledForPartition(partitionId, false);
    }
    _accessor.setProperty(_keyBuilder.instanceConfig(participantId.stringify()), instanceConfig);
    return true;
  }
View Full Code Here

    ResourceId resourceId = ResourceId.from("testResource");
    PartitionId partitionId = PartitionId.from(resourceId, "0");
    partitionMap.put(partitionId, new Partition(partitionId));
    context.setPartitionMap(partitionMap);
    Map<PartitionId, Map<ParticipantId, State>> preferenceMaps = Maps.newHashMap();
    ParticipantId participant1 = ParticipantId.from("participant1");
    ParticipantId participant2 = ParticipantId.from("participant2");
    Map<ParticipantId, State> preferenceMap =
        ImmutableMap.of(participant1, State.from("MASTER"), participant2, State.from("SLAVE"));
    preferenceMaps.put(partitionId, preferenceMap);
    context.setPreferenceMaps(preferenceMaps);
    context.setReplicaCount(3);
View Full Code Here

    Map<ParticipantId, Participant> participants = Maps.newHashMap();
    ParticipantAccessor accessor =
        new AtomicParticipantAccessor(_clusterId, _accessor, _lockProvider);
    List<String> participantNames = _accessor.getChildNames(_keyBuilder.instanceConfigs());
    for (String participantName : participantNames) {
      ParticipantId participantId = ParticipantId.from(participantName);
      Participant participant = accessor.readParticipant(participantId);
      if (participant != null) {
        participants.put(participantId, participant);
      }
    }
View Full Code Here

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

    String zkAddr = ZK_ADDR;
    ClusterId clusterId = ClusterId.from(clusterName);
    ControllerId controllerId = ControllerId.from("controller");
    final ParticipantId participantId = ParticipantId.from("participant1");

    ResourceId resourceId = ResourceId.from("testDB");
    State master = State.from("MASTER");
    State slave = State.from("SLAVE");
    State offline = State.from("OFFLINE");
View Full Code Here

TOP

Related Classes of org.apache.helix.api.id.ParticipantId

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.