private boolean isAllVMRunning(Client oneClient) { int vmID; boolean allRunning = true; for (int i = 0; i < vecTempID.size(); i++) { vmID = vecTempID.elementAt(i).intValue(); VirtualMachine vm = new VirtualMachine(vmID, oneClient); /* to load the data first using the info method */ OneResponse rc = vm.info(); String status = vm.status(); PrintMsg.print( DMsgType.MSG, "vm " + vm.getName() + ", id " + vm.getId() + ", status = " + status); VMElement element = findVMElement(vmID); VMState newVMState = getVMState(status); if (newVMState != element.getState()) { PrintMsg.print(DMsgType.MSG, "state update: " + element.getState() + " --> " + newVMState); /* update vm state */ updateVMState(vmList.get(vmID), newVMState); PrintMsg.print(DMsgType.MSG, "new state, " + vmList.get(vmID).getState()); } if (status == null || !status.equalsIgnoreCase("runn")) allRunning = false; } return allRunning; }
private boolean OCALaunch(CloudElement cloud, int numVMs) { Client oneClient = null; String account = "" + cloud.getAccessKey() + ":" + cloud.getSecretKey(); try { oneClient = new Client(account, cloud.getEndPoint()); } catch (Exception e) { e.printStackTrace(); return false; } for (int i = 0; i < numVMs; i++) { OneResponse rc = VirtualMachine.allocate(oneClient, vmTemplate); if (rc.isError()) { PrintMsg.print(DMsgType.ERROR, "failed to launch vms" + rc.getErrorMessage()); } int newVMID = Integer.parseInt(rc.getMessage()); vecTempID.add(newVMID); PrintMsg.print(DMsgType.MSG, "O.K. ID = " + newVMID); VMElement vmElement = new VMElement(newVMID, VMState.NOT_DEFINED); vmList.put(newVMID, vmElement); } /* this algorithm has to be modified for better * performance. * * it also has to handle only some vms running... */ int sleepsec = 20; /* 20 seconds as default */ while (!isAllVMRunning(oneClient)) { try { PrintMsg.print(DMsgType.MSG, "Going to sleep...."); Thread.sleep(sleepsec * 1000); } catch (InterruptedException e) { e.printStackTrace(); return false; } } vecTempID.removeAllElements(); PrintMsg.print(DMsgType.MSG, "All running....."); PrintMsg.print(DMsgType.MSG, "Notified to Monitor Manager"); /* have to increase currently running vms * because all cloud systems have to be managed by cloud manager */ Config.cloudMan.incCurrentVMs(cloud, numVMs); synchronized (Config.monMan) { Config.monMan.notify(); } return true; }