use of org.apache.asterix.event.management.AsterixEventServiceClient 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);
}
use of org.apache.asterix.event.management.AsterixEventServiceClient in project asterixdb by apache.
the class LogConfig method execCommand.
@Override
protected void execCommand() throws Exception {
InstallerDriver.initConfig(true);
String asterixInstanceName = ((LogConfig) config).name;
AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE, State.UNUSABLE, State.ACTIVE);
PatternCreator pc = PatternCreator.INSTANCE;
AsterixEventServiceClient eventrixClient = AsterixEventService.getAsterixEventServiceClient(instance.getCluster(), true, false);
String outputDir = ((LogConfig) config).outputDir == null ? InstallerDriver.getManagixHome() + File.separator + "logdump" : ((LogConfig) config).outputDir;
File f = new File(outputDir);
String outputDirPath = f.getAbsolutePath();
if (!f.exists()) {
boolean success = f.mkdirs();
if (!success) {
throw new InstallerException("Unable to create output directory:" + outputDirPath);
}
}
Patterns transferLogPattern = pc.getGenerateLogPattern(instance.getCluster(), outputDirPath);
eventrixClient.submit(transferLogPattern);
File outputDirFile = new File(outputDirPath);
final String destFileName = "log_" + new Date().toString().replace(' ', '_') + ".zip";
File destFile = new File(outputDirFile, destFileName);
AsterixEventServiceUtil.zipDir(outputDirFile, destFile);
String[] filesToDelete = outputDirFile.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !name.equals(destFileName);
}
});
for (String fileS : filesToDelete) {
f = new File(outputDirFile, fileS);
if (f.isDirectory()) {
FileUtils.deleteDirectory(f);
} else {
f.delete();
}
}
LOGGER.info("Log zip archive created at " + destFile.getAbsolutePath());
}
Aggregations