use of org.apache.helix.HelixManager 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.HelixManager in project helix by apache.
the class StartClusterManager method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("USAGE: java StartClusterManager zookeeperAddress (e.g. localhost:2181)");
System.exit(1);
}
final String clusterName = SetupCluster.DEFAULT_CLUSTER_NAME;
final String zkAddr = args[0];
try {
final HelixManager manager = HelixControllerMain.startHelixController(zkAddr, clusterName, null, HelixControllerMain.STANDALONE);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Shutting down cluster manager: " + manager.getInstanceName());
manager.disconnect();
}
});
Thread.currentThread().join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class LockManagerDemo method main.
/**
* LockManagerDemo clusterName, numInstances, lockGroupName, numLocks
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
final String zkAddress = "localhost:2199";
final String clusterName = "lock-manager-demo";
final String lockGroupName = "lock-group";
final int numInstances = 3;
final int numPartitions = 12;
final boolean startController = false;
HelixManager controllerManager = null;
Thread[] processArray;
processArray = new Thread[numInstances];
try {
startLocalZookeeper(2199);
HelixAdmin admin = new ZKHelixAdmin(zkAddress);
admin.addCluster(clusterName, true);
StateModelConfigGenerator generator = new StateModelConfigGenerator();
admin.addStateModelDef(clusterName, "OnlineOffline", new StateModelDefinition(generator.generateConfigForOnlineOffline()));
admin.addResource(clusterName, lockGroupName, numPartitions, "OnlineOffline", RebalanceMode.FULL_AUTO.toString());
admin.rebalance(clusterName, lockGroupName, 1);
for (int i = 0; i < numInstances; i++) {
final String instanceName = "localhost_" + (12000 + i);
processArray[i] = new Thread(new Runnable() {
@Override
public void run() {
LockProcess lockProcess = null;
try {
lockProcess = new LockProcess(clusterName, zkAddress, instanceName, startController);
lockProcess.start();
Thread.currentThread().join();
} catch (InterruptedException e) {
System.out.println(instanceName + "Interrupted");
if (lockProcess != null) {
lockProcess.stop();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
processArray[i].start();
}
Thread.sleep(3000);
controllerManager = HelixControllerMain.startHelixController(zkAddress, clusterName, "controller", HelixControllerMain.STANDALONE);
Thread.sleep(5000);
printStatus(admin, clusterName, lockGroupName);
System.out.println("Stopping localhost_12000");
processArray[0].interrupt();
Thread.sleep(3000);
printStatus(admin, clusterName, lockGroupName);
Thread.currentThread().join();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (controllerManager != null) {
controllerManager.disconnect();
}
for (Thread process : processArray) {
if (process != null) {
process.interrupt();
}
}
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class StartClusterManager method main.
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("USAGE: java StartClusterManager zookeeperAddress (e.g. localhost:2181)");
System.exit(1);
}
final String clusterName = SetupConsumerCluster.DEFAULT_CLUSTER_NAME;
final String zkAddr = args[0];
try {
final HelixManager manager = HelixControllerMain.startHelixController(zkAddr, clusterName, null, HelixControllerMain.STANDALONE);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
System.out.println("Shutting down cluster manager: " + manager.getInstanceName());
manager.disconnect();
}
});
Thread.currentThread().join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class WorkflowsResource method post.
@Override
public Representation post(Representation entity) {
try {
String clusterName = (String) getRequest().getAttributes().get("clusterName");
Form form = new Form(entity);
// Get the workflow and submit it
if (form.size() < 1) {
throw new HelixException("yaml workflow is required!");
}
Parameter payload = form.get(0);
String yamlPayload = payload.getName();
if (yamlPayload == null) {
throw new HelixException("yaml workflow is required!");
}
String zkAddr = (String) getContext().getAttributes().get(RestAdminApplication.ZKSERVERADDRESS);
HelixManager manager = HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR, zkAddr);
manager.connect();
try {
Workflow workflow = Workflow.parse(yamlPayload);
TaskDriver driver = new TaskDriver(manager);
driver.start(workflow);
} finally {
manager.disconnect();
}
getResponse().setEntity(getHostedEntitiesRepresentation(clusterName));
getResponse().setStatus(Status.SUCCESS_OK);
} catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("Error in posting " + entity, e);
}
return null;
}
Aggregations