use of org.apache.asterix.event.model.ProcessInfo in project asterixdb by apache.
the class VerificationUtil method updateInstanceWithRuntimeDescription.
public static void updateInstanceWithRuntimeDescription(AsterixInstance instance, AsterixRuntimeState state, boolean expectedRunning) {
StringBuilder summary = new StringBuilder();
if (expectedRunning) {
if (!state.isCcRunning()) {
summary.append("Cluster Controller not running at " + instance.getCluster().getMasterNode().getId() + "\n");
instance.setState(State.UNUSABLE);
}
if (state.getFailedNCs() != null && !state.getFailedNCs().isEmpty()) {
summary.append("Node Controller not running at the following nodes" + "\n");
for (String failedNC : state.getFailedNCs()) {
summary.append(failedNC + "\n");
}
// instance.setState(State.UNUSABLE);
}
if (!(instance.getState().equals(State.UNUSABLE))) {
instance.setState(State.ACTIVE);
}
} else {
if (state.getProcesses() != null && state.getProcesses().size() > 0) {
summary.append("Following process still running " + "\n");
for (ProcessInfo pInfo : state.getProcesses()) {
summary.append(pInfo + "\n");
}
// instance.setState(State.UNUSABLE);
} else {
// instance.setState(State.INACTIVE);
}
}
state.setSummary(summary.toString());
instance.setAsterixRuntimeStates(state);
}
use of org.apache.asterix.event.model.ProcessInfo in project asterixdb by apache.
the class VerificationUtil method getAsterixRuntimeState.
public static AsterixRuntimeState getAsterixRuntimeState(AsterixInstance instance) throws Exception {
Cluster cluster = instance.getCluster();
List<String> args = new ArrayList<String>();
args.add(instance.getName());
args.add(instance.getCluster().getMasterNode().getClusterIp());
for (Node node : cluster.getNode()) {
args.add(node.getClusterIp());
args.add(instance.getName() + "_" + node.getId());
}
Thread.sleep(2000);
String output = AsterixEventServiceUtil.executeLocalScript(VERIFY_SCRIPT_PATH, args);
boolean ccRunning = true;
List<String> failedNCs = new ArrayList<String>();
String[] infoFields;
List<ProcessInfo> processes = new ArrayList<ProcessInfo>();
for (String line : output.split("\n")) {
String nodeid = null;
infoFields = line.split(":");
try {
int pid = Integer.parseInt(infoFields[3]);
if (infoFields[0].equals("NC")) {
nodeid = infoFields[2].split("_")[1];
} else {
nodeid = instance.getCluster().getMasterNode().getId();
}
processes.add(new ProcessInfo(infoFields[0], infoFields[1], nodeid, pid));
} catch (Exception e) {
if (infoFields[0].equalsIgnoreCase("CC")) {
ccRunning = false;
} else {
failedNCs.add(infoFields[1]);
}
}
}
return new AsterixRuntimeState(processes, failedNCs, ccRunning);
}
use of org.apache.asterix.event.model.ProcessInfo in project asterixdb by apache.
the class StartNodeConfig method execCommand.
@Override
protected void execCommand() throws Exception {
InstallerDriver.initConfig(true);
String asterixInstanceName = ((StartNodeConfig) config).name;
AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE, State.ACTIVE, State.UNUSABLE);
Cluster cluster = instance.getCluster();
List<Pattern> pl = new ArrayList<Pattern>();
AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
String[] nodesToBeAdded = ((StartNodeConfig) config).nodes.split(",");
List<String> aliveNodes = new ArrayList<String>();
for (ProcessInfo p : runtimeState.getProcesses()) {
aliveNodes.add(p.getNodeId());
}
List<Node> clusterNodes = cluster.getNode();
for (String n : nodesToBeAdded) {
if (aliveNodes.contains(n)) {
throw new InstallerException("Node: " + n + " is already alive");
}
for (Node node : clusterNodes) {
if (n.equals(node.getId())) {
String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
Pattern createNC = PatternCreator.INSTANCE.createNCStartPattern(cluster.getMasterNode().getClusterIp(), node.getId(), asterixInstanceName + "_" + node.getId(), iodevices, false);
pl.add(createNC);
break;
}
}
}
Patterns patterns = new Patterns(pl);
AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(cluster);
client.submit(patterns);
runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
VerificationUtil.updateInstanceWithRuntimeDescription(instance, runtimeState, true);
LOGGER.info(instance.getDescription(false));
ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
}
use of org.apache.asterix.event.model.ProcessInfo in project asterixdb by apache.
the class StopNodeConfig method execCommand.
@Override
protected void execCommand() throws Exception {
InstallerDriver.initConfig(true);
String asterixInstanceName = ((StopNodeConfig) config).name;
AsterixInstance asterixInstance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.ACTIVE, State.UNUSABLE);
AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(asterixInstance.getCluster());
String[] nodesToStop = ((StopNodeConfig) config).nodeList.split(",");
AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(asterixInstance);
List<String> aliveNodes = new ArrayList<String>();
for (ProcessInfo p : runtimeState.getProcesses()) {
aliveNodes.add(p.getNodeId());
}
List<String> validNodeIds = new ArrayList<String>();
for (Node node : asterixInstance.getCluster().getNode()) {
validNodeIds.add(node.getId());
}
List<Pattern> ncKillPatterns = new ArrayList<Pattern>();
for (String nodeId : nodesToStop) {
if (!nodeId.contains(nodeId)) {
throw new InstallerException("Invalid nodeId: " + nodeId);
}
if (!aliveNodes.contains(nodeId)) {
throw new InstallerException("Node: " + nodeId + " is not alive");
}
ncKillPatterns.add(PatternCreator.INSTANCE.createNCStopPattern(nodeId, asterixInstanceName + "_" + nodeId));
}
try {
client.submit(new Patterns(ncKillPatterns));
} catch (Exception e) {
// processes are already dead
LOGGER.debug("Attempt to kill non-existing processess");
}
asterixInstance.setStateChangeTimestamp(new Date());
ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(asterixInstance);
LOGGER.info("Stopped nodes " + ((StopNodeConfig) config).nodeList + " serving Asterix instance: " + asterixInstanceName);
}
Aggregations