private static Machine[] getMachinesFromAgentUids( ProcessingUnit pu, Collection<String> agentUids) { final List<Machine> machines = new ArrayList<Machine>(); final GridServiceAgents gridServiceAgents = pu.getAdmin().getGridServiceAgents(); for (final String agentUid : agentUids) { final GridServiceAgent agent = gridServiceAgents.getAgentByUID(agentUid); if (agent == null) { throw new IllegalStateException("At this point agent " + agentUid + " must be discovered."); } machines.add(agent.getMachine()); } return machines.toArray(new Machine[machines.size()]); }
private void init() { admin = new AdminFactory().addGroup(group).addLocator(locator).createAdmin(); System.out.println(admin); GridServiceAgents agents = admin.getGridServiceAgents(); System.out.println(agents); agents.waitForAtLeastOne(10, TimeUnit.SECONDS); ElasticServiceManagers esms = admin.getElasticServiceManagers(); System.out.println(esms); esms.waitForAtLeastOne(10, TimeUnit.SECONDS); gsm = admin.getGridServiceManagers().waitForAtLeastOne(10, TimeUnit.SECONDS); ProcessingUnits pus = admin.getProcessingUnits(); System.out.println(pus); pu = pus.waitFor(processingUnitName, 5, TimeUnit.SECONDS); System.out.printf("Processing unit (null is acceptable): %s%n", pu); if (pu == null) { pu = gsm.deploy( new ElasticStatelessProcessingUnitDeployment(processingUnitName) // initial scale .scale( new ManualCapacityScaleConfigurer() // .numberOfCpuCores(1) .create())); try { monitorPUScaleProgress(pu, 1); } catch (Exception ignored) { } try { scale(pu, initialWorkers); } catch (Exception e) { e.printStackTrace(); } } else { initialWorkers = getPUWorkerCount(pu); } }