public static void createTar(File sourceDirectory, File tarFile) throws CommandFailedException { Preconditions.checkNotNull(sourceDirectory, "sourceDirectory is null"); Preconditions.checkArgument(sourceDirectory.isDirectory(), "sourceDirectory is not a directory: " + sourceDirectory.getAbsolutePath()); Preconditions.checkNotNull(tarFile, "tarFile is null"); tarFile.getParentFile().mkdirs(); new Command("tar", "zcf", tarFile.getAbsolutePath(), sourceDirectory.getName()) .setDirectory(sourceDirectory.getParent()) .setTimeLimit(5, TimeUnit.MINUTES) .execute(executor); }
public static void createSymbolicLink(File source, File target) throws CommandFailedException { Preconditions.checkNotNull(source, "source is null"); Preconditions.checkArgument(source.exists(), "source does not exist: " + source.getAbsolutePath()); Preconditions.checkNotNull(target, "source is null"); Preconditions.checkArgument(!target.exists(), "target already exists: " + target.getAbsolutePath()); target.getParentFile().mkdirs(); new Command("ln", "-s", source.getAbsolutePath(), target.getAbsolutePath()) .setDirectory(target.getParent()) .setTimeLimit(5, TimeUnit.MINUTES) .execute(executor); }
public static void extractTar(File tarFile, File targetDirectory, Duration timeLimit) throws CommandFailedException { Preconditions.checkNotNull(tarFile, "tarFile is null"); Preconditions.checkNotNull(targetDirectory, "targetDirectory is null"); Preconditions.checkArgument(targetDirectory.isDirectory(), "targetDirectory is not a directory: " + targetDirectory.getAbsolutePath()); new Command("tar", "zxf", tarFile.getAbsolutePath()) .setDirectory(targetDirectory) .setTimeLimit(timeLimit) .execute(executor); }
@Override public SlotLifecycleState stop(Deployment deployment) { updateNodeConfig(deployment); try { createCommand("stop", deployment, stopTimeout).execute(executor); return STOPPED; } catch (CommandFailedException e) { throw new RuntimeException("stop failed: " + e.getMessage()); } }
@Override public SlotLifecycleState restart(Deployment deployment) { updateNodeConfig(deployment); try { Command command = createCommand("restart", deployment, stopTimeout); command.execute(executor); return RUNNING; } catch (CommandFailedException e) { throw new RuntimeException("restart failed: " + e.getMessage()); } }
@Override public SlotLifecycleState status(Deployment deployment) { try { int exitCode = createCommand("status", deployment, launcherTimeout) .setSuccessfulExitCodes(0, 1, 2, 3) .execute(executor); if (exitCode == 0) { return RUNNING; } else { return STOPPED; } } catch (CommandFailedException e) { return UNKNOWN; } }
@Override public SlotLifecycleState start(Deployment deployment) { updateNodeConfig(deployment); Command command = createCommand("start", deployment, launcherTimeout); try { command.execute(executor); return RUNNING; } catch (CommandFailedException e) { log.error("ENVIRONMENT:\n %s", Joiner.on("\n ").withKeyValueSeparator("=").join(command.getEnvironment())); throw new RuntimeException("start failed: " + e.getMessage()); } }