use of org.apache.helix.HelixManager in project helix by apache.
the class DummyProcess method main.
public static void main(String[] args) throws Exception {
String cmType = "zk";
String zkConnectString = "localhost:2181";
String clusterName = "testCluster";
String instanceName = "localhost_8900";
String cvFileStr = null;
// String rootNs = null;
int delay = 0;
if (args.length > 0) {
CommandLine cmd = processCommandLineArgs(args);
zkConnectString = cmd.getOptionValue(zkServer);
clusterName = cmd.getOptionValue(cluster);
String host = cmd.getOptionValue(hostAddress);
String portString = cmd.getOptionValue(hostPort);
int port = Integer.parseInt(portString);
instanceName = host + "_" + port;
cmType = cmd.getOptionValue(helixManagerType);
if (cmd.hasOption(transDelay)) {
try {
delay = Integer.parseInt(cmd.getOptionValue(transDelay));
if (delay < 0) {
throw new Exception("delay must be positive");
}
} catch (Exception e) {
e.printStackTrace();
delay = 0;
}
}
}
// Espresso_driver.py will consume this
logger.info("Dummy process started, instanceName:" + instanceName);
DummyProcess process = new DummyProcess(zkConnectString, clusterName, instanceName, cmType, delay);
HelixManager manager = process.start();
try {
Thread.currentThread().join();
} catch (InterruptedException e) {
// ClusterManagerFactory.disconnectManagers(instanceName);
logger.info("participant:" + instanceName + ", " + Thread.currentThread().getName() + " interrupted");
// if (manager != null)
// {
// manager.disconnect();
// }
} finally {
if (manager != null) {
manager.disconnect();
}
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class StoreAccessDiffNodeTransition method doTransition.
@Override
public void doTransition(Message message, NotificationContext context) {
HelixManager manager = context.getManager();
ZkHelixPropertyStore<ZNRecord> store = manager.getHelixPropertyStore();
final String setPath = "/TEST_PERF/set/" + message.getPartitionName();
final String updatePath = "/TEST_PERF/update/" + message.getPartitionName();
// final String key = message.getPartitionName();
try {
// get/set once
ZNRecord record = null;
try {
record = store.get(setPath, null, 0);
} catch (ZkNoNodeException e) {
// record = new ZNRecord(setPath);
}
if (record == null) {
record = new ZNRecord(setPath);
}
record.setSimpleField("setTimestamp", "" + System.currentTimeMillis());
store.set(setPath, record, AccessOption.PERSISTENT);
// update once
store.update(updatePath, new DataUpdater<ZNRecord>() {
@Override
public ZNRecord update(ZNRecord currentData) {
if (currentData == null) {
currentData = new ZNRecord(updatePath);
}
currentData.setSimpleField("updateTimestamp", "" + System.currentTimeMillis());
return currentData;
}
}, AccessOption.PERSISTENT);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class StoreAccessOneNodeTransition method doTransition.
@Override
public void doTransition(Message message, NotificationContext context) {
HelixManager manager = context.getManager();
ZkHelixPropertyStore<ZNRecord> store = manager.getHelixPropertyStore();
final String setPath = "/TEST_PERF/set";
final String updatePath = "/TEST_PERF/update";
final String key = message.getPartitionName();
try {
// get/set once
ZNRecord record = null;
try {
record = store.get(setPath, null, 0);
} catch (ZkNoNodeException e) {
record = new ZNRecord(setPath);
}
record.setSimpleField("setTimestamp", "" + System.currentTimeMillis());
store.set(setPath, record, AccessOption.PERSISTENT);
// update once
store.update(updatePath, new DataUpdater<ZNRecord>() {
@Override
public ZNRecord update(ZNRecord currentData) {
if (currentData == null) {
currentData = new ZNRecord(updatePath);
}
currentData.setSimpleField(key, "" + System.currentTimeMillis());
return currentData;
}
}, AccessOption.PERSISTENT);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.apache.helix.HelixManager in project helix by apache.
the class TaskAdmin method main.
/**
* Parses the first argument as a driver command and the rest of the
* arguments are parsed based on that command. Constructs a Helix
* message and posts it to the controller
*/
public static void main(String[] args) throws Exception {
String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length);
CommandLine cl = parseOptions(cmdArgs, constructOptions(), args[0]);
String zkAddr = cl.getOptionValue(ZK_ADDRESS);
String clusterName = cl.getOptionValue(CLUSTER_NAME_OPTION);
String workflow = cl.getOptionValue(RESOURCE_OPTION);
if (zkAddr == null || clusterName == null || workflow == null) {
printUsage(constructOptions(), "[cmd]");
throw new IllegalArgumentException("zk, cluster, and resource must all be non-null for all commands");
}
HelixManager helixMgr = HelixManagerFactory.getZKHelixManager(clusterName, "Admin", InstanceType.ADMINISTRATOR, zkAddr);
helixMgr.connect();
TaskDriver driver = new TaskDriver(helixMgr);
try {
TaskDriver.DriverCommand cmd = TaskDriver.DriverCommand.valueOf(args[0]);
switch(cmd) {
case start:
if (cl.hasOption(WORKFLOW_FILE_OPTION)) {
driver.start(Workflow.parse(new File(cl.getOptionValue(WORKFLOW_FILE_OPTION))));
} else {
throw new IllegalArgumentException("Workflow file is required to start flow.");
}
break;
case stop:
driver.stop(workflow);
break;
case resume:
driver.resume(workflow);
break;
case delete:
driver.delete(workflow);
break;
case list:
list(driver, workflow);
break;
case flush:
driver.flushQueue(workflow);
break;
case clean:
driver.cleanupQueue(workflow);
break;
default:
throw new IllegalArgumentException("Unknown command " + args[0]);
}
} catch (IllegalArgumentException e) {
LOG.error("Unknown driver command " + args[0]);
throw e;
}
helixMgr.disconnect();
}
use of org.apache.helix.HelixManager in project helix by apache.
the class HelixStateTransitionHandler method handleMessage.
@Override
public HelixTaskResult handleMessage() {
NotificationContext context = _notificationContext;
Message message = _message;
synchronized (_stateModel) {
HelixTaskResult taskResult = new HelixTaskResult();
HelixManager manager = context.getManager();
_statusUpdateUtil.logInfo(message, HelixStateTransitionHandler.class, "Message handling task begin execute", manager);
message.setExecuteStartTimeStamp(new Date().getTime());
try {
preHandleMessage();
invoke(manager, context, taskResult, message);
} catch (HelixStateMismatchException e) {
// Simply log error and return from here if State mismatch.
// The current state of the state model is intact.
taskResult.setSuccess(false);
taskResult.setMessage(e.toString());
taskResult.setException(e);
} catch (Exception e) {
String errorMessage = "Exception while executing a state transition task " + message.getPartitionName();
logger.error(errorMessage, e);
if (e.getCause() != null && e.getCause() instanceof InterruptedException) {
e = (InterruptedException) e.getCause();
}
if (e instanceof HelixRollbackException || (e.getCause() != null && e.getCause() instanceof HelixRollbackException)) {
// TODO : Support cancel to any state
logger.info("Rollback happened of state transition on resource \"" + _message.getResourceName() + "\" partition \"" + _message.getPartitionName() + "\" from \"" + _message.getFromState() + "\" to \"" + _message.getToState() + "\"");
taskResult.setCancelled(true);
} else {
_statusUpdateUtil.logError(message, HelixStateTransitionHandler.class, e, errorMessage, manager);
taskResult.setSuccess(false);
taskResult.setMessage(e.toString());
taskResult.setException(e);
taskResult.setInterrupted(e instanceof InterruptedException);
}
}
taskResult.setCompleteTime(System.currentTimeMillis());
// add task result to context for postHandling
context.add(MapKey.HELIX_TASK_RESULT.toString(), taskResult);
postHandleMessage();
return taskResult;
}
}
Aggregations