Package org.virtualbox_4_0

Examples of org.virtualbox_4_0.ISession


               + 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

   @Test
   public void testLaunchIfNotStarted() throws Exception {

      final String type = "gui";
      final String environment = "";
      ISession session = createMock(ISession.class);
      VirtualBoxManager manager = createMock(VirtualBoxManager.class);
      IMachine machine = createMock(IMachine.class);
      IProgress progress = createMock(IProgress.class);

      expect(manager.getSessionObject()).andReturn(session).anyTimes();
      expect(machine.launchVMProcess(session, type, environment)).andReturn(progress);
      progress.waitForCompletion(-1);
      expect(session.getState()).andReturn(SessionState.Locked);
      session.unlockMachine();

      replay(manager, machine, session, progress);

      new LaunchMachineIfNotAlreadyRunning(manager, ExecutionType.GUI, "").apply(machine);
View Full Code Here

TOP

Related Classes of org.virtualbox_4_0.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.