Package org.virtualbox_4_2

Examples of org.virtualbox_4_2.ISession


   }

   @Override
   public ISnapshot apply(IMachine machine) {
      // Snapshot a machine
      ISession session = null;
      ISnapshot snap = machine.getCurrentSnapshot();

      if (snap == null) {
         try {
            session = manager.get().openMachineSession(machine);
            int retries = 10;
            while (true) {
               try {

                  // running machines need to be pause before a snapshot can be taken
                  // due to a vbox bug see https://www.virtualbox.org/ticket/9255
                  boolean paused = false;
                  if (machine.getState() == MachineState.Running) {
                     session.getConsole().pause();
                     paused = true;
                  }

                  IProgress progress = session.getConsole().takeSnapshot(snapshotName, snapshotDesc);
                  progress.waitForCompletion(-1);

                  if (paused) {
                     session.getConsole().resume();
                  }

                  snap = machine.getCurrentSnapshot();
                  logger.debug("<< snapshot(%s) with description(%s) taken from master(%s)", snapshotName, snapshotDesc,
                           machine.getName());
View Full Code Here


               + nodeSpec.getTag() + VIRTUALBOX_NODE_NAME_SEPARATOR + nodeSpec.getName();
   }

   private void deleteExistingSnapshot(Master master) {
      if (master.getMachine().getCurrentSnapshot() != null) {
         ISession session;
         try {
            session = manager.get().getSessionObject();
            master.getMachine().lockMachine(session, LockType.Write);
            IProgress progress = session.getConsole().deleteSnapshot(master.getMachine().getCurrentSnapshot().getId());
            progress.waitForCompletion(-1);
            session.unlockMachine();
         } catch (Exception e) {
            throw new RuntimeException("error opening vbox machine session: " + e.getMessage(), e);
         }
         logger.debug("<< deleted an existing snapshot of vm(%s)", master.getMachine().getName());
      }
View Full Code Here

   }

   @Override
   public void resumeNode(String vmName) {
      IMachine machine = manager.get().getVBox().findMachine(vmName);
      ISession machineSession;
      try {
         machineSession = manager.get().openMachineSession(machine);
         machineSession.getConsole().resume();
         machineSession.unlockMachine();
      } catch (Exception e) {
         throw Throwables.propagate(e);
      }
   }
View Full Code Here

   }

   @Override
   public void suspendNode(String vmName) {
      IMachine machine = manager.get().getVBox().findMachine(vmName);
      ISession machineSession;
      try {
         machineSession = manager.get().openMachineSession(machine);
         machineSession.getConsole().pause();
         machineSession.unlockMachine();
      } catch (Exception e) {
         throw Throwables.propagate(e);
      }
   }
View Full Code Here

      this.environment = environment;
   }

   @Override
   public ISession apply(IMachine machine) {
      ISession session = manager.getSessionObject();
      try {
         final IProgress progress = machine
                 .launchVMProcess(session, type.stringValue(), environment);
         progress.waitForCompletion(-1);
      } catch (VBoxException e) {
         ErrorCode errorCode = ErrorCode.valueOf(e);
         switch (errorCode) {
            case VBOX_E_INVALID_OBJECT_STATE:
               logger.warn(e, "Could not start machine. Got error code %s from launchMachine(). "
                       + "The machine might already be running.", errorCode);
               break;
            default:
               propagate(e);
         }
      } finally {
         if (session.getState() == SessionState.Locked) {
            // Remove session lock taken by launchVmProcess()
            session.unlockMachine();
            // TODO this unlock is not IMMEDIATELY visible outside (vbox doc)
         }
      }
      return session;
   }
View Full Code Here

      clonedMachine = cloneFromMaster();
   }

   @Test
   public void testEnsureMachineisLaunchedAndSessionIsUnlocked() {
      ISession cloneMachineSession = machineController.ensureMachineIsLaunched(clonedMachine.getName());
      assertTrue(cloneMachineSession.getState() == SessionState.Unlocked);
      cloneMachineSession = machineController.ensureMachineHasPowerDown(clonedMachine.getName());
      SessionState state = cloneMachineSession.getState();
      assertEquals(SessionState.Unlocked, state);
   }
View Full Code Here

   }

   @Test(description = "write lock is acquired and released correctly")
   public void writeLockSessionOnMachine() {
      final IMachine clone = cloneFromMaster();
      ISession session = machineUtils.writeLockMachineAndApplyToSession(clone.getName(),
            new Function<ISession, ISession>() {
               @Override
               public ISession apply(ISession session) {
                  assertEquals(session.getMachine().getName(), clone.getName());
                  return session;
               }
            });
      checkState(session.getState().equals(SessionState.Unlocked));
      undoVm(clone.getName());
   }
View Full Code Here

   }

   @Test(dependsOnMethods = "writeLockSessionOnMachine", description = "shared lock is acquired and released correctly")
   public void sharedLockSessionOnMachine() {
      final IMachine clone = cloneFromMaster();
      ISession session = machineUtils.sharedLockMachineAndApplyToSession(clone.getName(),
            new Function<ISession, ISession>() {
               @Override
               public ISession apply(ISession session) {
                  assertEquals(session.getMachine().getName(), clone.getName());
                  return session;
               }
            });
      checkState(session.getState().equals(SessionState.Unlocked));
      undoVm(clone.getName());
   }
View Full Code Here

   @Test(dependsOnMethods = "sharedLockSessionOnMachine", description = "shared lock can be acquired after a write lock")
   public void sharedLockCanBeAcquiredAfterWriteLockSessionOnMachine() {
      final IMachine clone = cloneFromMaster();
      try {
         ISession writeSession = machineUtils.writeLockMachineAndApplyToSession(clone.getName(),
               new Function<ISession, ISession>() {
                  @Override
                  public ISession apply(ISession writeSession) {
                     checkState(writeSession.getState().equals(SessionState.Locked));
                     return writeSession;
                  }
               });
         checkState(writeSession.getState().equals(SessionState.Unlocked));
      } finally {
         undoVm(clone.getName());
      }
   }
View Full Code Here

   @Test(dependsOnMethods = "sharedLockCanBeAcquiredAfterWriteLockSessionOnMachine", description = "write lock cannot be acquired after a shared lock")
   public void writeLockCannotBeAcquiredAfterSharedLockSessionOnMachine() {
      final IMachine clone = cloneFromMaster();
      try {
         ISession sharedSession = machineUtils.sharedLockMachineAndApplyToSession(clone.getName(),
               new Function<ISession, ISession>() {
                  @Override
                  public ISession apply(ISession sharedSession) {
                     checkState(sharedSession.getState().equals(SessionState.Locked));
                     return sharedSession;
                  }
               });
         checkState(sharedSession.getState().equals(SessionState.Unlocked));
         ISession writeSession = machineUtils.writeLockMachineAndApplyToSession(clone.getName(),
               new Function<ISession, ISession>() {
                  @Override
                  public ISession apply(ISession writeSession) {
                     checkState(writeSession.getState().equals(SessionState.Locked));
                     assertEquals(writeSession.getMachine().getName(), clone.getName());
                     return writeSession;
                  }
               });
         checkState(writeSession.getState().equals(SessionState.Unlocked));
      } finally {
         undoVm(clone.getName());
      }
   }
View Full Code Here

TOP

Related Classes of org.virtualbox_4_2.ISession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.