Package org.apache.helix.model

Examples of org.apache.helix.model.InstanceConfig


      boolean wantEnabled) {
    ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(zkClient));
    Builder keyBuilder = accessor.keyBuilder();

    InstanceConfig config = accessor.getProperty(keyBuilder.instanceConfig(instance));
    AssertJUnit.assertEquals(wantEnabled, config.getInstanceEnabled());
  }
View Full Code Here


  private static void addNode() throws Exception {

    NUM_NODES = NUM_NODES + 1;
    int port = 12000 + NUM_NODES - 1;
    InstanceConfig instanceConfig = new InstanceConfig("localhost_" + port);
    instanceConfig.setHostName("localhost");
    instanceConfig.setPort("" + port);
    instanceConfig.setInstanceEnabled(true);
    echo("ADDING NEW NODE :" + instanceConfig.getInstanceName()
        + ". Partitions will move from old nodes to the new node.");
    admin.addInstance(CLUSTER_NAME, instanceConfig);
    INSTANCE_CONFIG_LIST.add(instanceConfig);
    MyProcess process = new MyProcess(instanceConfig.getInstanceName());
    PROCESS_LIST.add(process);
    admin.rebalance(CLUSTER_NAME, RESOURCE_NAME, 3);
    process.start();
  }
View Full Code Here

              ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
      ZKHelixAdmin admin = new ZKHelixAdmin(zkclient);

      List<String> nodes = admin.getInstancesInCluster(clusterName);
      if (!nodes.contains("consumer_" + consumerId)) {
        InstanceConfig config = new InstanceConfig("consumer_" + consumerId);
        config.setHostName("localhost");
        config.setInstanceEnabled(true);
        admin.addInstance(clusterName, config);
      }

      // start consumer
      final Consumer consumer =
View Full Code Here

      }
    }
    routingTable = connection.getRoutingTable();

    if (scope.getSourceInstance() != null) {
      InstanceConfig config = routingTable.getInstanceConfig(scope.getSourceInstance());
      String ipcPort = config.getRecord().getSimpleField(IPC_PORT);
      if (ipcPort == null) {
        throw new IllegalStateException("No IPC address registered for source instance "
            + scope.getSourceInstance());
      }
      return new HelixAddress(scope, scope.getSourceInstance(), new InetSocketAddress(
          config.getHostName(), Integer.valueOf(ipcPort)));
    }

    return null;
  }
View Full Code Here

      int[] instances) {
    ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
    PropertyKey.Builder keyBuilder = accessor.keyBuilder();
    for (int i = 0; i < instances.length; i++) {
      String instance = "localhost_" + instances[i];
      InstanceConfig instanceConfig = new InstanceConfig(instance);
      instanceConfig.setHostName("localhost");
      instanceConfig.setPort("" + instances[i]);
      instanceConfig.setInstanceEnabled(true);
      accessor.setProperty(keyBuilder.instanceConfig(instance), instanceConfig);
    }
  }
View Full Code Here

    final List<String> testListValue = ImmutableList.of("testValue");
    final Map<String, String> testMapValue = ImmutableMap.of("testInnerKey", "testValue");

    // first, add Helix configuration to an InstanceConfig
    ParticipantId participantId = ParticipantId.from("testParticipant");
    InstanceConfig instanceConfig = new InstanceConfig(participantId);
    instanceConfig.setHostName("localhost");

    // now, add user configuration
    UserConfig userConfig = new UserConfig(Scope.participant(participantId));
    userConfig.setSimpleField(testKey, testSimpleValue);
    userConfig.setListField(testKey, testListValue);
    userConfig.setMapField(testKey, testMapValue);

    // add the user configuration to the Helix configuration
    instanceConfig.addNamespacedConfig(userConfig);

    // get the user configuration back from the property
    UserConfig retrievedConfig = UserConfig.from(instanceConfig);

    // check that the property still has the host name
    Assert.assertTrue(instanceConfig.getHostName().equals("localhost"));

    // check that the retrieved config does not contain the host name
    Assert.assertEquals(retrievedConfig.getStringField(
        InstanceConfigProperty.HELIX_HOST.toString(), "not localhost"), "not localhost");

    // check that both the retrieved config and the original config have the added properties
    Assert.assertEquals(userConfig.getSimpleField(testKey), testSimpleValue);
    Assert.assertEquals(userConfig.getListField(testKey), testListValue);
    Assert.assertEquals(userConfig.getMapField(testKey), testMapValue);
    Assert.assertEquals(retrievedConfig.getSimpleField(testKey), testSimpleValue);
    Assert.assertEquals(retrievedConfig.getListField(testKey), testListValue);
    Assert.assertEquals(retrievedConfig.getMapField(testKey), testMapValue);

    // test that the property has the user config, but prefixed
    Assert.assertEquals(instanceConfig.getRecord().getSimpleField(prefixedKey), testSimpleValue);
    Assert.assertEquals(instanceConfig.getRecord().getListField(prefixedKey), testListValue);
    Assert.assertEquals(instanceConfig.getRecord().getMapField(prefixedKey), testMapValue);
  }
View Full Code Here

    // 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);
    instanceConfig.getRecord().setSimpleField(KEY2, VALUE2);

    // should have key1 and key2, not hostname
    UserConfig result = instanceConfig.getUserConfig();
    Assert.assertEquals(result.getSimpleField(KEY1), VALUE1);
    Assert.assertEquals(result.getSimpleField(KEY2), VALUE2);
    Assert.assertNull(result.getSimpleField(InstanceConfig.InstanceConfigProperty.HELIX_HOST
        .toString()));
  }
View Full Code Here

    for (int i = 0; i < NUM_PARTICIPANTS; i++) {
      String host = "localhost";
      int port = i;
      int ipcPort = i + 100;
      String instanceName = host + "_" + port;
      InstanceConfig config = new InstanceConfig(instanceName);
      config.setHostName(host);
      config.setPort(Integer.toString(port));
      config.getRecord().setSimpleField("IPC_PORT", Integer.toString(ipcPort));
      admin.addInstance(CLUSTER_NAME, config);
      _socketMap.put(instanceName, new InetSocketAddress(host, ipcPort));
      _participants[i] = new MockParticipant(_zkaddr, CLUSTER_NAME, instanceName);
      _participants[i].syncStart();
    }
View Full Code Here

      Assert
          .fail("Except fail to set participant-config because participant: localhost_12918 is not added to cluster yet");
    } catch (HelixException e) {
      // OK
    }
    admin.addInstance(clusterName, new InstanceConfig("localhost_12918"));

    try {
      configAccessor.set(participantScope, "participantConfigKey", "participantConfigValue");
    } catch (Exception e) {
      Assert
View Full Code Here

          new PerInstanceResourceMonitor(_clusterName, beanName.instanceName(),
              beanName.resourceName());
      StateModelDefId stateModelDefId =
          resourceMap.get(ResourceId.from(beanName.resourceName())).getIdealState()
              .getStateModelDefId();
      InstanceConfig config = instanceConfigMap.get(beanName.instanceName());
      bean.update(beanMap.get(beanName), Sets.newHashSet(config.getTags()),
          stateModelDefMap.get(stateModelDefId.toString()));
      monitorsToRegister.add(bean);
    }
    try {
      registerPerInstanceResources(monitorsToRegister);
    } catch (MalformedObjectNameException e) {
      LOG.error("Fail to register per-instance resource with MBean server: " + toRegister, e);
    }
    // Update existing beans
    for (PerInstanceResourceMonitor.BeanName beanName : _perInstanceResourceMap.keySet()) {
      PerInstanceResourceMonitor bean = _perInstanceResourceMap.get(beanName);
      StateModelDefId stateModelDefId =
          resourceMap.get(ResourceId.from(beanName.resourceName())).getIdealState()
              .getStateModelDefId();
      InstanceConfig config = instanceConfigMap.get(beanName.instanceName());
      bean.update(beanMap.get(beanName), Sets.newHashSet(config.getTags()),
          stateModelDefMap.get(stateModelDefId.toString()));
    }
  }
View Full Code Here

TOP

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

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.