private IStatus runProvisionJob(IProgressMonitor monitor) { RuntimeElement rtInfo = resourceReq.getRuntimeInfo(); broadcastResourceStatus(RuntimeElementStatus.OFFLINE); Random r1 = new Random(); ScenarioSolver solver = new ScenarioSolver(); if (!solver.resourceRequestHasAllAssignementsResolved( scenario, resourceReq)) { // r1.nextInt(20)>5 ){//ResourceSettingsAreNotOK ){ broadcastResourceStatus(RuntimeElementStatus.WAITING); Random r = new Random(); this.schedule(1000 * r.nextInt(60) + 1000); // reschedule the job in 60random seconds System.out.println("RESCHEDULED : " + resourceReq.getName()); return Status.OK_STATUS; } monitor.beginTask("Provisioning " + resourceReq.getName(), 1); if (monitor.isCanceled()) { parentJob.NotifyResJobFinished(this); System.out.println("ProvisionResourceJob, Cancel provisioning : " + resourceReq.getName()); broadcastResourceStatus(RuntimeElementStatus.UNKNOWN); return Status.CANCEL_STATUS; } String guid = ""; String officeName = ((Office) resourceReq.getRefOfferedResource().getImplOfferedService().eContainer()) .getName(); for (IProvisionResource p : Activator.getDefault().getProvisionPlugins()) { if (p.supportsOffice(officeName)) { broadcastResourceStatus(RuntimeElementStatus.STARTING); guid = p.provisionResource(officeName, scenario, resourceReq); rtInfo.setGUID(guid); } } // try { // Random r = new Random(); // Thread.sleep(1000 * r.nextInt(10) ); // guid="temp"; // rtInfo.setGUID(guid+"."+resourceReq.getName()); // } catch (InterruptedException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } if ("".equals(guid)) broadcastResourceStatus(RuntimeElementStatus.ERROR); else broadcastResourceStatus(RuntimeElementStatus.ONLINE); monitor.worked(1); monitor.done(); parentJob.NotifyResJobFinished(this); return Status.OK_STATUS; }
private IStatus runShutDownResourceJob(IProgressMonitor monitor) { RuntimeElement rtInfo = resourceReq.getRuntimeInfo(); monitor.beginTask("Shutting down " + resourceReq.getName(), 1); if (monitor.isCanceled()) { parentJob.NotifyResJobFinished(this); System.out.println("ProvisionResourceJob, Cancel provisioning : " + resourceReq.getName()); broadcastResourceStatus(RuntimeElementStatus.UNKNOWN); ; return Status.CANCEL_STATUS; } String guid = ""; String officeName = ((Office) resourceReq.getRefOfferedResource().getImplOfferedService().eContainer()) .getName(); for (IProvisionResource p : Activator.getDefault().getProvisionPlugins()) { if (p.supportsOffice(officeName)) { if ((rtInfo.getStatus() != RuntimeElementStatus.NOT_EXISTS)) { try { Random r = new Random(); Thread.sleep(1000 * r.nextInt(60)); // sleep randomly..shutdown to avoid collisions. } catch (InterruptedException e) { e.printStackTrace(); } guid = p.deleteResource(officeName, scenario, resourceReq); } rtInfo.setGUID(guid); } } broadcastResourceStatus(RuntimeElementStatus.NOT_EXISTS); monitor.worked(1); monitor.done(); System.out.println("ProvisionResourceJob, OK Provisioning : " + resourceReq.getName()); parentJob.NotifyResJobFinished(this); return Status.OK_STATUS; }