use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class IntegrationTest method main.
public static void main(String[] args) throws InterruptedException {
ZkServer server = null;
;
try {
String baseDir = "/tmp/IntegrationTest/";
final String dataDir = baseDir + "zk/dataDir";
final String logDir = baseDir + "/tmp/logDir";
FileUtils.deleteDirectory(new File(dataDir));
FileUtils.deleteDirectory(new File(logDir));
IDefaultNameSpace defaultNameSpace = new IDefaultNameSpace() {
@Override
public void createDefaultNameSpace(ZkClient zkClient) {
}
};
int zkPort = 2199;
final String zkAddress = "localhost:" + zkPort;
server = new ZkServer(dataDir, logDir, defaultNameSpace, zkPort);
server.start();
ClusterSetup setup = new ClusterSetup(zkAddress);
final String clusterName = "file-store-test";
setup.deleteCluster(clusterName);
setup.addCluster(clusterName, true);
setup.addInstanceToCluster(clusterName, "localhost_12001");
setup.addInstanceToCluster(clusterName, "localhost_12002");
setup.addInstanceToCluster(clusterName, "localhost_12003");
setup.addResourceToCluster(clusterName, "repository", 1, "MasterSlave");
setup.rebalanceResource(clusterName, "repository", 3);
// Set the configuration
final String instanceName1 = "localhost_12001";
addConfiguration(setup, baseDir, clusterName, instanceName1);
final String instanceName2 = "localhost_12002";
addConfiguration(setup, baseDir, clusterName, instanceName2);
final String instanceName3 = "localhost_12003";
addConfiguration(setup, baseDir, clusterName, instanceName3);
Thread thread1 = new Thread(new Runnable() {
@Override
public void run() {
FileStore fileStore = null;
try {
fileStore = new FileStore(zkAddress, clusterName, instanceName1);
fileStore.connect();
} catch (Exception e) {
System.err.println("Exception" + e);
fileStore.disconnect();
}
}
});
// START NODES
Thread thread2 = new Thread(new Runnable() {
@Override
public void run() {
FileStore fileStore = new FileStore(zkAddress, clusterName, instanceName2);
fileStore.connect();
}
});
// START NODES
Thread thread3 = new Thread(new Runnable() {
@Override
public void run() {
FileStore fileStore = new FileStore(zkAddress, clusterName, instanceName3);
fileStore.connect();
}
});
System.out.println("STARTING NODES");
thread1.start();
thread2.start();
thread3.start();
// Start Controller
final HelixManager manager = HelixControllerMain.startHelixController(zkAddress, clusterName, "controller", HelixControllerMain.STANDALONE);
Thread.sleep(5000);
printStatus(manager);
listFiles(baseDir);
System.out.println("Writing files a.txt and b.txt to current master " + baseDir + "localhost_12001" + "/filestore");
FileUtils.writeStringToFile(new File(baseDir + "localhost_12001" + "/filestore/a.txt"), "some_data in a");
FileUtils.writeStringToFile(new File(baseDir + "localhost_12001" + "/filestore/b.txt"), "some_data in b");
Thread.sleep(10000);
listFiles(baseDir);
Thread.sleep(5000);
System.out.println("Stopping the MASTER node:" + "localhost_12001");
thread1.interrupt();
Thread.sleep(10000);
printStatus(manager);
System.out.println("Writing files c.txt and d.txt to current master " + baseDir + "localhost_12002" + "/filestore");
FileUtils.writeStringToFile(new File(baseDir + "localhost_12002" + "/filestore/c.txt"), "some_data in c");
FileUtils.writeStringToFile(new File(baseDir + "localhost_12002" + "/filestore/d.txt"), "some_data in d");
Thread.sleep(10000);
listFiles(baseDir);
System.out.println("Create or modify any files under " + baseDir + "localhost_12002" + "/filestore" + " and it should get replicated to " + baseDir + "localhost_12003" + "/filestore");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (server != null) {
// server.shutdown();
}
}
Thread.currentThread().join();
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ClusterAccessor method updateCluster.
@POST
@Path("{clusterId}")
public Response updateCluster(@PathParam("clusterId") String clusterId, @QueryParam("command") String commandStr, @QueryParam("superCluster") String superCluster, String content) {
Command command;
try {
command = getCommand(commandStr);
} catch (HelixException ex) {
return badRequest(ex.getMessage());
}
ClusterSetup clusterSetup = getClusterSetup();
HelixAdmin helixAdmin = getHelixAdmin();
switch(command) {
case activate:
if (superCluster == null) {
return badRequest("Super Cluster name is missing!");
}
try {
clusterSetup.activateCluster(clusterId, superCluster, true);
} catch (Exception ex) {
_logger.error("Failed to add cluster " + clusterId + " to super cluster " + superCluster);
return serverError(ex);
}
break;
case expand:
try {
clusterSetup.expandCluster(clusterId);
} catch (Exception ex) {
_logger.error("Failed to expand cluster " + clusterId);
return serverError(ex);
}
break;
case enable:
try {
helixAdmin.enableCluster(clusterId, true);
} catch (Exception ex) {
_logger.error("Failed to enable cluster " + clusterId);
return serverError(ex);
}
break;
case disable:
try {
helixAdmin.enableCluster(clusterId, false);
} catch (Exception ex) {
_logger.error("Failed to disable cluster " + clusterId);
return serverError(ex);
}
break;
case enableMaintenanceMode:
try {
helixAdmin.enableMaintenanceMode(clusterId, true, content);
} catch (Exception ex) {
_logger.error("Failed to enable maintenance mode " + clusterId);
return serverError(ex);
}
break;
case disableMaintenanceMode:
try {
helixAdmin.enableMaintenanceMode(clusterId, false);
} catch (Exception ex) {
_logger.error("Failed to disable maintenance mode " + clusterId);
return serverError(ex);
}
break;
default:
return badRequest("Unsupported command " + command);
}
return OK();
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class AdminTestBase method beforeSuite.
@BeforeSuite
public void beforeSuite() throws Exception {
// TODO: use logging.properties file to config java.util.logging.Logger levels
java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
topJavaLogger.setLevel(Level.WARNING);
// start zk
_zkServer = TestHelper.startZkServer(ZK_ADDR);
AssertJUnit.assertTrue(_zkServer != null);
ZKClientPool.reset();
_gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
_gSetupTool = new ClusterSetup(_gZkClient);
// start admin
_adminThread = new AdminThread(ZK_ADDR, ADMIN_PORT);
_adminThread.start();
// create a client
_gClient = new Client(Protocol.HTTP);
// wait for the web service to start
Thread.sleep(100);
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ClusterResource method getClusterRepresentation.
StringRepresentation getClusterRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException {
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
List<String> instances = setupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
ZNRecord clusterSummayRecord = new ZNRecord("Cluster Summary");
clusterSummayRecord.setListField("participants", instances);
List<String> resources = setupTool.getClusterManagementTool().getResourcesInCluster(clusterName);
clusterSummayRecord.setListField("resources", resources);
List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName);
clusterSummayRecord.setListField("stateModelDefs", models);
HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader != null) {
clusterSummayRecord.setSimpleField("LEADER", leader.getInstanceName());
} else {
clusterSummayRecord.setSimpleField("LEADER", "");
}
StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clusterSummayRecord), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.tools.ClusterSetup in project helix by apache.
the class ConfigResource method getConfigKeys.
StringRepresentation getConfigKeys(ConfigScopeProperty scopeProperty, String... keys) throws Exception {
StringRepresentation representation = null;
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
HelixAdmin admin = setupTool.getClusterManagementTool();
ZNRecord record = new ZNRecord(scopeProperty + " Config");
HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
List<String> configKeys = admin.getConfigKeys(scope);
record.setListField(scopeProperty.toString(), configKeys);
representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record), MediaType.APPLICATION_JSON);
return representation;
}
Aggregations