Projects >> legacy-jclouds >>af662850a919f48bf09e9593c1fed1ca623cb04b

Chunk
Conflicting content
 */
package org.jclouds.virtualbox.domain;

<<<<<<< HEAD
=======
import static com.google.common.base.Preconditions.checkArgument;
>>>>>>> f86d8c531f949b3d917d4804a0ac5693d7d6676a
import static com.google.common.base.Preconditions.checkNotNull;

import java.util.ArrayList;
Solution content
 */
package org.jclouds.virtualbox.domain;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

import java.util.ArrayList;
File
NetworkSpec.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
import java.util.List;

import com.google.common.base.Objects;
<<<<<<< HEAD
=======
import com.google.common.collect.ImmutableList;
>>>>>>> f86d8c531f949b3d917d4804a0ac5693d7d6676a

/**
 * Describes the network configuration for a VirtualBox machine.
Solution content
import java.util.List;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;


/**
 * Describes the network configuration for a VirtualBox machine.
File
NetworkSpec.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
@Singleton
public class CreateAndInstallVm implements Function {

<<<<<<< HEAD
  @Resource
  @Named(ComputeServiceConstants.COMPUTE_LOGGER)
  protected Logger                                                logger = Logger.NULL;

  private final ComputeServiceContext                             vboxHostContext;
  private final Supplier                       manager;
  private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;

  private final Predicate                              sshResponds;
  private final ExecutionType                                     executionType;

  private LoadingCache                              preConfiguration;

  private final Function                     sshClientForIMachine;

  private final MachineUtils                                      machineUtils;

  @Inject
  public CreateAndInstallVm(@Host ComputeServiceContext vboxHostContext, Supplier manager,
      CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
      Predicate sshResponds, Function sshClientForIMachine,
      ExecutionType executionType, MachineUtils machineUtils,
      @Preconfiguration LoadingCache preConfiguration) {
    this.vboxHostContext = vboxHostContext;
    this.manager = manager;
    this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
    this.sshResponds = sshResponds;
    this.sshClientForIMachine = sshClientForIMachine;
    this.executionType = executionType;
    this.machineUtils = machineUtils;
    this.preConfiguration = preConfiguration;
  }

  @Override
  public IMachine apply(MasterSpec masterSpec) {

    VmSpec vmSpec = masterSpec.getVmSpec();
    IsoSpec isoSpec = masterSpec.getIsoSpec();
    String vmName = vmSpec.getVmName();

    final IMachine vm = createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(masterSpec);

    // Launch machine and wait for it to come online
    ensureMachineIsLaunched(vmName);

    URI uri = preConfiguration.getUnchecked(isoSpec);
    String installationKeySequence = isoSpec.getInstallationKeySequence().replace("PRECONFIGURATION_URL",
        uri.toASCIIString());

    configureOsInstallationWithKeyboardSequence(vmName, installationKeySequence);
    SshClient client = sshClientForIMachine.apply(vm);
    logger.debug(">> awaiting installation to finish node(%s)", vmName);

    checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", vmName);

    logger.debug(">> awaiting installation of guest additions on vm: %s", vmName);
    checkState(new GuestAdditionsInstaller(vboxHostContext).apply(vmName));

    logger.debug(">> awaiting post-installation actions on vm: %s", vmName);
    ListenableFuture execFuture = vboxHostContext.getComputeService().submitScriptOnNode(vmName,
        call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
    ExecResponse execResponse = Futures.getUnchecked(execFuture);
    checkState(execResponse.getExitCode() == 0);

    logger.debug("<< installation of image complete. Powering down node(%s)", vmName);
    ensureMachineHasPowerDown(vmName);
    return vm;
  }

  private void configureOsInstallationWithKeyboardSequence(String vmName, String installationKeySequence) {
    Iterable> scancodelist = transform(Splitter.on(" ").split(installationKeySequence),
        new StringToKeyCode());

    for (List scancodes : scancodelist) {
      machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new SendScancodes(scancodes));
    }
  }

  private void ensureMachineHasPowerDown(String vmName) {
    machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function() {
      @Override
      public Void apply(ISession session) {
        IProgress powerDownProgress = session.getConsole().powerDown();
        powerDownProgress.waitForCompletion(-1);
        return null;
      }
    });
  }

  private void ensureMachineIsLaunched(String vmName) {
    machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), executionType, ""));
  }
=======
   @Resource
   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
   protected Logger logger = Logger.NULL;
   
   private final ComputeServiceContext context;
   private final Supplier manager;
   private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;

   private final Predicate sshResponds;
   private final ExecutionType executionType;

   private LoadingCache preConfiguration;

   private final Function sshClientForIMachine;

   private final MachineUtils machineUtils;

   @Inject
   public CreateAndInstallVm(ComputeServiceContext context, Supplier manager,
         CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
         Predicate sshResponds, Function sshClientForIMachine,
         ExecutionType executionType, MachineUtils machineUtils, @Preconfiguration LoadingCache preConfiguration) {
      this.context = context;
      this.manager = manager;
      this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
      this.sshResponds = sshResponds;
      this.sshClientForIMachine = sshClientForIMachine;
      this.executionType = executionType;
      this.machineUtils = machineUtils;
      this.preConfiguration = preConfiguration;
   }
   
   @Override
   public IMachine apply(MasterSpec masterSpec) {

      VmSpec vmSpec = masterSpec.getVmSpec();
      IsoSpec isoSpec = masterSpec.getIsoSpec();
      String vmName = vmSpec.getVmName();
      
      final IMachine vm = createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(masterSpec);

      // Launch machine and wait for it to come online
      ensureMachineIsLaunched(vmName);
    
      URI uri = preConfiguration.getUnchecked(isoSpec);
      String installationKeySequence = isoSpec.getInstallationKeySequence().replace("PRECONFIGURATION_URL",
            uri.toASCIIString());

      configureOsInstallationWithKeyboardSequence(vmName, installationKeySequence);
      SshClient client = sshClientForIMachine.apply(vm);
      logger.debug(">> awaiting installation to finish node(%s)", vmName);

      checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", vmName);
      
      logger.debug(">> awaiting installation of guest additions on vm: %s", vmName);
      checkState(new GuestAdditionsInstaller(context).apply(vmName));
      
      logger.debug(">> awaiting post-installation actions on vm: %s", vmName);
      ListenableFuture execFuture = context.getComputeService().submitScriptOnNode(vmName,
            call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
      ExecResponse execResponse = Futures.getUnchecked(execFuture);
      checkState(execResponse.getExitCode() == 0);
      
      logger.debug("<< installation of image complete. Powering down node(%s)", vmName);
      ensureMachineHasPowerDown(vmName);
      return vm;
   }

   private void configureOsInstallationWithKeyboardSequence(String vmName, String installationKeySequence) {
      Iterable> scancodelist =
            transform(Splitter.on(" ").split(installationKeySequence), new StringToKeyCode());

      for (List scancodes : scancodelist) {
         machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new SendScancodes(scancodes));
      }
   }

   /**
    * ensureMachineHasPowerDown needs to have this delay just to ensure that the machine is completely powered off
    * 
    * @param vmName
    */
   private void ensureMachineHasPowerDown(String vmName) {
	   while(!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.POWERED_OFF)) {
		   machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function() {
         @Override
         public Void apply(ISession session) {
            IProgress powerDownProgress = session.getConsole().powerDown();
            powerDownProgress.waitForCompletion(-1);
            return null;
         }
      });
		   try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			Throwables.propagate(e);
		}
	   }
   }

   private void ensureMachineIsLaunched(String vmName) {
      machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), executionType, ""));
   }
>>>>>>> f86d8c531f949b3d917d4804a0ac5693d7d6676a

}
Solution content
@Singleton
public class CreateAndInstallVm implements Function {

   @Resource
   @Named(ComputeServiceConstants.COMPUTE_LOGGER)
   protected Logger logger = Logger.NULL;
   
   private final ComputeServiceContext context;
   private final Supplier manager;
   private final CreateAndRegisterMachineFromIsoIfNotAlreadyExists createAndRegisterMachineFromIsoIfNotAlreadyExists;

   private final Predicate sshResponds;
   private final ExecutionType executionType;

   private LoadingCache preConfiguration;

   private final Function sshClientForIMachine;

   private final MachineUtils machineUtils;

   @Inject
   public CreateAndInstallVm(@Host ComputeServiceContext context, Supplier manager,
         CreateAndRegisterMachineFromIsoIfNotAlreadyExists CreateAndRegisterMachineFromIsoIfNotAlreadyExists,
         Predicate sshResponds, Function sshClientForIMachine,
         ExecutionType executionType, MachineUtils machineUtils, @Preconfiguration LoadingCache preConfiguration) {
      this.context = context;
      this.manager = manager;
      this.createAndRegisterMachineFromIsoIfNotAlreadyExists = CreateAndRegisterMachineFromIsoIfNotAlreadyExists;
      this.sshResponds = sshResponds;
      this.sshClientForIMachine = sshClientForIMachine;
      this.executionType = executionType;
      this.machineUtils = machineUtils;
      this.preConfiguration = preConfiguration;
   }
   
   @Override
   public IMachine apply(MasterSpec masterSpec) {

      VmSpec vmSpec = masterSpec.getVmSpec();
      IsoSpec isoSpec = masterSpec.getIsoSpec();
      String vmName = vmSpec.getVmName();
      
      final IMachine vm = createAndRegisterMachineFromIsoIfNotAlreadyExists.apply(masterSpec);

      // Launch machine and wait for it to come online
      ensureMachineIsLaunched(vmName);
    
      URI uri = preConfiguration.getUnchecked(isoSpec);
      String installationKeySequence = isoSpec.getInstallationKeySequence().replace("PRECONFIGURATION_URL",
            uri.toASCIIString());

      configureOsInstallationWithKeyboardSequence(vmName, installationKeySequence);
      SshClient client = sshClientForIMachine.apply(vm);
      logger.debug(">> awaiting installation to finish node(%s)", vmName);

      checkState(sshResponds.apply(client), "timed out waiting for guest %s to be accessible via ssh", vmName);
      
      logger.debug(">> awaiting installation of guest additions on vm: %s", vmName);
      checkState(new GuestAdditionsInstaller(context).apply(vmName));
      
      logger.debug(">> awaiting post-installation actions on vm: %s", vmName);
      ListenableFuture execFuture = context.getComputeService().submitScriptOnNode(vmName,
            call("cleanupUdevIfNeeded"), RunScriptOptions.NONE);
      ExecResponse execResponse = Futures.getUnchecked(execFuture);
      checkState(execResponse.getExitCode() == 0);
      
      logger.debug("<< installation of image complete. Powering down node(%s)", vmName);
      ensureMachineHasPowerDown(vmName);
      return vm;
   }

   private void configureOsInstallationWithKeyboardSequence(String vmName, String installationKeySequence) {
      Iterable> scancodelist =
            transform(Splitter.on(" ").split(installationKeySequence), new StringToKeyCode());

      for (List scancodes : scancodelist) {
         machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new SendScancodes(scancodes));
      }
   }

   /**
    * ensureMachineHasPowerDown needs to have this delay just to ensure that the machine is completely powered off
    * 
    * @param vmName
    */
   private void ensureMachineHasPowerDown(String vmName) {
	   while(!manager.get().getVBox().findMachine(vmName).getState().equals(MachineState.POWERED_OFF)) {
		   machineUtils.lockSessionOnMachineAndApply(vmName, LockType.Shared, new Function() {
         @Override
         public Void apply(ISession session) {
            IProgress powerDownProgress = session.getConsole().powerDown();
            powerDownProgress.waitForCompletion(-1);
            return null;
         }
      });
		   try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			Throwables.propagate(e);
		}
	   }
   }

   private void ensureMachineIsLaunched(String vmName) {
      machineUtils.applyForMachine(vmName, new LaunchMachineIfNotAlreadyRunning(manager.get(), executionType, ""));
   }

}
File
CreateAndInstallVm.java
Developer's decision
Manual
Kind of conflict
Annotation
Attribute
Comment
Method declaration
Chunk
Conflicting content
import static com.google.common.base.Preconditions.checkNotNull;

import java.io.File;
<<<<<<< HEAD
import java.util.Map;
=======
>>>>>>> f86d8c531f949b3d917d4804a0ac5693d7d6676a
import java.util.Set;

import javax.annotation.Nullable;
Solution content
import static com.google.common.base.Preconditions.checkNotNull;

import java.io.File;
import java.util.Set;

import javax.annotation.Nullable;
File
CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.IsoImage;
import org.jclouds.virtualbox.domain.MasterSpec;
<<<<<<< HEAD
import org.jclouds.virtualbox.domain.NatAdapter;
=======
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
>>>>>>> f86d8c531f949b3d917d4804a0ac5693d7d6676a
import org.jclouds.virtualbox.domain.NetworkSpec;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
Solution content
import org.jclouds.virtualbox.domain.HardDisk;
import org.jclouds.virtualbox.domain.IsoImage;
import org.jclouds.virtualbox.domain.MasterSpec;
import org.jclouds.virtualbox.domain.NetworkInterfaceCard;
import org.jclouds.virtualbox.domain.NetworkSpec;
import org.jclouds.virtualbox.domain.StorageController;
import org.jclouds.virtualbox.domain.VmSpec;
File
CreateAndRegisterMachineFromIsoIfNotAlreadyExists.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
package org.jclouds.virtualbox.functions;

import static org.easymock.EasyMock.createMock;
<<<<<<< HEAD
import static org.easymock.EasyMock.createNiceMock;
=======
>>>>>>> f86d8c531f949b3d917d4804a0ac5693d7d6676a
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
Solution content
package org.jclouds.virtualbox.functions;

import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
File
AttachBridgedAdapterToMachineTest.java
Developer's decision
Version 2
Kind of conflict
Import