diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstaller.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstaller.java index 05afd85a3a..4e258897f2 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstaller.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/predicates/GuestAdditionsInstaller.java @@ -1,26 +1,20 @@ package org.jclouds.virtualbox.predicates; -import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; - -import java.util.concurrent.ExecutionException; - import javax.annotation.Resource; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.RunScriptData; import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import org.jclouds.scriptbuilder.domain.StatementList; -import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.virtualbox.statements.InstallGuestAdditions; import com.google.common.base.Predicate; import com.google.common.base.Splitter; -import com.google.common.base.Throwables; import com.google.common.collect.Iterables; +import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; @@ -41,27 +35,11 @@ public class GuestAdditionsInstaller implements Predicate { @Override public boolean apply(String vmName) { - StatementList statementList = prepareStatementList(); - - ListenableFuture execFuture = context.getComputeService().submitScriptOnNode(vmName, statementList, - runAsRoot(true).wrapInInitScript(false)); - ExecResponse execResponse = null; - try { - execResponse = execFuture.get(); - } catch (InterruptedException e) { - Throwables.propagate(e); - } catch (ExecutionException e) { - Throwables.propagate(e); - } + vboxVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0); + ListenableFuture execFuture = context.getComputeService().submitScriptOnNode(vmName, + new InstallGuestAdditions(vboxVersion), RunScriptOptions.NONE); + ExecResponse execResponse = Futures.getUnchecked(execFuture); return execResponse == null ? false : execResponse.getExitCode() == 0; } - private StatementList prepareStatementList() { - vboxVersion = Iterables.get(Splitter.on('r').split(context.getProviderSpecificContext().getBuildVersion()), 0); - InstallGuestAdditions installGuestAdditions = new InstallGuestAdditions(vboxVersion); - StatementList statementList = new StatementList(Statements.exec(RunScriptData.aptInstallLazyUpgrade("curl")), - installGuestAdditions); - return statementList; - } - } \ No newline at end of file diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java index 3b0605d3cd..e66f2677f5 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/GuestAdditionsInstaller.java @@ -1,22 +1,16 @@ package org.jclouds.virtualbox.statements; -import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot; - -import java.util.concurrent.ExecutionException; - import javax.annotation.Resource; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.compute.ComputeServiceContext; -import org.jclouds.compute.RunScriptData; import org.jclouds.compute.callables.RunScriptOnNode.Factory; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; -import org.jclouds.scriptbuilder.domain.StatementList; -import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.ssh.SshClient; import org.jclouds.virtualbox.domain.ExecutionType; import org.jclouds.virtualbox.functions.CreateAndRegisterMachineFromIsoIfNotAlreadyExists; @@ -29,7 +23,7 @@ import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Supplier; -import com.google.common.base.Throwables; +import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Inject; @@ -48,7 +42,6 @@ public class GuestAdditionsInstaller implements Function { // TODO remove this hardcoded value private String vboxVersion = "4.1.6"; - @Inject public GuestAdditionsInstaller(ComputeServiceContext context, Supplier manager, CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists, @@ -66,26 +59,16 @@ public class GuestAdditionsInstaller implements Function { IMachine vm = manager.get().getVBox().findMachine(vmName); ensureMachineIsLaunched(vmName); - InstallGuestAdditions installGuestAdditions = new InstallGuestAdditions(vboxVersion); - StatementList statementList = new StatementList(Statements.exec(RunScriptData.aptInstallLazyUpgrade("curl")), - installGuestAdditions); - NodeMetadata vmMetadata = new IMachineToNodeMetadata().apply(vm); - ListenableFuture execFuture = context.getComputeService().submitScriptOnNode(vmMetadata.getId(), statementList, - runAsRoot(true).wrapInInitScript(false)); - try { - execFuture.get(); - } catch (InterruptedException e) { - Throwables.propagate(e); - } catch (ExecutionException e) { - Throwables.propagate(e); - } + ListenableFuture execFuture = context.getComputeService().submitScriptOnNode(vmMetadata.getId(), + new InstallGuestAdditions(vboxVersion), RunScriptOptions.NONE); + Futures.getUnchecked(execFuture); return vm; } private void ensureMachineIsLaunched(String vmName) { machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), executionType, "")); } - + } \ No newline at end of file