use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestClusterAccessor method testUpdateConfigFields.
@Test(dependsOnMethods = "testAddConfigFields")
public void testUpdateConfigFields() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();
ClusterConfig config = getClusterConfigFromRest(cluster);
ZNRecord record = config.getRecord();
String key = record.getSimpleFields().keySet().iterator().next();
String value = record.getSimpleField(key);
record.getSimpleFields().clear();
record.setSimpleField(key, value + "--updated");
key = record.getListFields().keySet().iterator().next();
List<String> list = record.getListField(key);
list.remove(0);
list.add("newValue--updated");
record.getListFields().clear();
record.setListField(key, list);
key = record.getMapFields().keySet().iterator().next();
Map<String, String> map = record.getMapField(key);
Iterator it = map.entrySet().iterator();
it.next();
it.remove();
map.put("newKey--updated", "newValue--updated");
record.getMapFields().clear();
record.setMapField(key, map);
ClusterConfig prevConfig = getClusterConfigFromRest(cluster);
updateClusterConfigFromRest(cluster, config, Command.update);
ClusterConfig newConfig = getClusterConfigFromRest(cluster);
prevConfig.getRecord().update(config.getRecord());
Assert.assertEquals(newConfig, prevConfig, "cluster config from response: " + newConfig + " vs cluster config actually: " + prevConfig);
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestClusterAccessor method testAddConfigFields.
@Test(dependsOnMethods = "testGetClusters")
public void testAddConfigFields() throws IOException {
System.out.println("Start test :" + TestHelper.getTestMethodName());
String cluster = _clusters.iterator().next();
ClusterConfig oldConfig = getClusterConfigFromRest(cluster);
ClusterConfig configDelta = new ClusterConfig(cluster);
configDelta.getRecord().setSimpleField("newField", "newValue");
configDelta.getRecord().setListField("newList", Arrays.asList("newValue1", "newValue2"));
configDelta.getRecord().setMapField("newMap", new HashMap<String, String>() {
{
put("newkey1", "newvalue1");
put("newkey2", "newvalue2");
}
});
updateClusterConfigFromRest(cluster, configDelta, Command.update);
ClusterConfig newConfig = getClusterConfigFromRest(cluster);
oldConfig.getRecord().update(configDelta.getRecord());
Assert.assertEquals(newConfig, oldConfig, "cluster config from response: " + newConfig + " vs cluster config actually: " + oldConfig);
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestClusterAccessor method getClusterConfigFromRest.
private ClusterConfig getClusterConfigFromRest(String cluster) throws IOException {
String body = get("clusters/" + cluster + "/configs", Response.Status.OK.getStatusCode(), true);
ZNRecord record = new ObjectMapper().reader(ZNRecord.class).readValue(body);
ClusterConfig clusterConfigRest = new ClusterConfig(record);
ClusterConfig clusterConfigZk = _configAccessor.getClusterConfig(cluster);
Assert.assertEquals(clusterConfigZk, clusterConfigRest, "cluster config from response: " + clusterConfigRest + " vs cluster config actually: " + clusterConfigZk);
return clusterConfigRest;
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class TestClusterVerifier method beforeMethod.
@BeforeMethod
public void beforeMethod() throws InterruptedException {
final int NUM_PARTITIONS = 10;
final int NUM_REPLICAS = 3;
// Cluster and resource setup
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
_clusterName = className + "_" + methodName;
_setupTool = new ClusterSetup(ZK_ADDR);
_admin = _setupTool.getClusterManagementTool();
_setupTool.addCluster(_clusterName, true);
_setupTool.addResourceToCluster(_clusterName, RESOURCES[0], NUM_PARTITIONS, BuiltInStateModelDefinitions.MasterSlave.name(), RebalanceMode.SEMI_AUTO.toString());
_setupTool.addResourceToCluster(_clusterName, RESOURCES[1], NUM_PARTITIONS, BuiltInStateModelDefinitions.OnlineOffline.name(), RebalanceMode.SEMI_AUTO.toString());
_setupTool.addResourceToCluster(_clusterName, RESOURCES[2], NUM_PARTITIONS, BuiltInStateModelDefinitions.MasterSlave.name(), RebalanceMode.FULL_AUTO.toString());
_setupTool.addResourceToCluster(_clusterName, RESOURCES[3], NUM_PARTITIONS, BuiltInStateModelDefinitions.OnlineOffline.name(), RebalanceMode.FULL_AUTO.toString());
// Enable persist best possible assignment
ConfigAccessor configAccessor = new ConfigAccessor(_gZkClient);
ClusterConfig clusterConfig = configAccessor.getClusterConfig(_clusterName);
clusterConfig.setPersistBestPossibleAssignment(true);
configAccessor.setClusterConfig(_clusterName, clusterConfig);
// Configure and start the participants
_participants = new MockParticipantManager[RESOURCES.length];
for (int i = 0; i < _participants.length; i++) {
String host = "localhost";
int port = 12918 + i;
String id = host + '_' + port;
_setupTool.addInstanceToCluster(_clusterName, id);
_participants[i] = new MockParticipantManager(ZK_ADDR, _clusterName, id);
_participants[i].syncStart();
}
// Rebalance the resources
for (int i = 0; i < RESOURCES.length; i++) {
_setupTool.rebalanceResource(_clusterName, RESOURCES[i], NUM_REPLICAS);
}
// Start the controller
_controller = new ClusterControllerManager(ZK_ADDR, _clusterName, "controller_0");
_controller.syncStart();
Thread.sleep(1000);
}
use of org.apache.helix.model.ClusterConfig in project helix by apache.
the class InstanceAccessor method getInstances.
@GET
public Response getInstances(@PathParam("clusterId") String clusterId) {
HelixDataAccessor accessor = getDataAccssor(clusterId);
ObjectNode root = JsonNodeFactory.instance.objectNode();
root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId));
ArrayNode instancesNode = root.putArray(InstanceProperties.instances.name());
ArrayNode onlineNode = root.putArray(InstanceProperties.online.name());
ArrayNode disabledNode = root.putArray(InstanceProperties.disabled.name());
List<String> instances = accessor.getChildNames(accessor.keyBuilder().instanceConfigs());
if (instances != null) {
instancesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(instances));
} else {
return notFound();
}
List<String> liveInstances = accessor.getChildNames(accessor.keyBuilder().liveInstances());
ClusterConfig clusterConfig = accessor.getProperty(accessor.keyBuilder().clusterConfig());
for (String instanceName : instances) {
InstanceConfig instanceConfig = accessor.getProperty(accessor.keyBuilder().instanceConfig(instanceName));
if (instanceConfig != null) {
if (!instanceConfig.getInstanceEnabled() || (clusterConfig.getDisabledInstances() != null && clusterConfig.getDisabledInstances().containsKey(instanceName))) {
disabledNode.add(JsonNodeFactory.instance.textNode(instanceName));
}
if (liveInstances.contains(instanceName)) {
onlineNode.add(JsonNodeFactory.instance.textNode(instanceName));
}
}
}
return JSONRepresentation(root);
}
Aggregations