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; }
public boolean launchVM(int vms, CloudElement c) { CloudElement cloud; if (c == null) { cloud = Config.cloudMan.findCloudSystem(vms); } else { cloud = c; } CloudType ctype = cloud.getCloudType(); switch (ctype) { case PRIVATE: return OCALaunch(cloud, vms); case PUBLIC: return RESTLaunch(cloud, vms); } return true; }