@Test(expectedExceptions = {SchedulerException.class}) public void testSolvingIncorrectPartitioning() throws SchedulerException { SynchronizedElementBuilder eb = new SynchronizedElementBuilder(new DefaultElementBuilder()); Model origin = new DefaultModel(eb); Node n1 = origin.newNode(); Node n2 = origin.newNode(); VM vm1 = origin.newVM(); VM vm2 = origin.newVM(); origin.getMapping().addOnlineNode(n1); origin.getMapping().addOfflineNode(n2); origin.getMapping().addReadyVM(vm1); origin.getMapping().addReadyVM(vm2); Model s1 = new SubModel(origin, eb, Collections.singletonList(n1), Collections.singleton(vm1)); Model s2 = new SubModel(origin, eb, Collections.singletonList(n2), Collections.singleton(vm2)); Instance i0 = new Instance(origin, new MinMTTR()); final Instance i1 = new Instance(s1, Running.newRunning(Collections.singletonList(vm1)), new MinMTTR()); final Instance i2 = new Instance(s2, new MinMTTR()); i2.getSatConstraints().add(new Running(vm1)); StaticPartitioning st = new StaticPartitioning() { @Override public List<Instance> split(Parameters ps, Instance i) throws SchedulerException { return Arrays.asList(i1, i2); } }; Parameters p = new DefaultChocoScheduler(); st.solve(p, i0); }
@Override public ReconfigurationPlan solve(Parameters cra, Instance orig) throws SchedulerException { stats = new StaticPartitioningStatistics(cra, orig, System.currentTimeMillis(), workersCount); long d = -System.currentTimeMillis(); List<Instance> partitions = split(cra, orig); d += System.currentTimeMillis(); stats.setSplittingStatistics(partitions.size(), d); ExecutorService exe = Executors.newFixedThreadPool(this.workersCount); CompletionService<SolvingStatistics> completionService = new ExecutorCompletionService<>(exe); List<SolvingStatistics> results = new ArrayList<>(partitions.size()); runners = new ArrayList<>(); long duration = -System.currentTimeMillis(); for (Instance partition : partitions) { InstanceSolverRunner runner = new InstanceSolverRunner(cra, partition); completionService.submit(runner); runners.add(runner); } for (int i = 0; i < partitions.size(); i++) { try { results.add(completionService.take().get()); } catch (ExecutionException ignore) { Throwable cause = ignore.getCause(); if (cause != null) { throw new SplitException(null, cause.getMessage(), ignore); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SplitException(orig.getModel(), e.getMessage(), e); } } duration += System.currentTimeMillis(); stats.setSolvingDuration(duration); exe.shutdown(); return merge(orig, results); }
StaticPartitioning implements InstanceSolver { @Override public ReconfigurationPlan solve(Parameters cra, Instance orig) throws SchedulerException { stats = new StaticPartitioningStatistics(cra, orig, System.currentTimeMillis(), workersCount); long d = -System.currentTimeMillis(); List<Instance> partitions = split(cra, orig); d += System.currentTimeMillis(); stats.setSplittingStatistics(partitions.size(), d); ExecutorService exe = Executors.newFixedThreadPool(this.workersCount); CompletionService<SolvingStatistics> completionService = new ExecutorCompletionService<>(exe); List<SolvingStatistics> results = new ArrayList<>(partitions.size()); runners = new ArrayList<>(); long duration = -System.currentTimeMillis(); for (Instance partition : partitions) { InstanceSolverRunner runner = new InstanceSolverRunner(cra, partition); completionService.submit(runner); runners.add(runner); } for (int i = 0; i < partitions.size(); i++) { try { results.add(completionService.take().get()); } catch (ExecutionException ignore) { Throwable cause = ignore.getCause(); if (cause != null) { throw new SplitException(null, cause.getMessage(), ignore); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SplitException(orig.getModel(), e.getMessage(), e); } } duration += System.currentTimeMillis(); stats.setSolvingDuration(duration); exe.shutdown(); return merge(orig, results); } }
StaticPartitioning implements InstanceSolver { @Override public ReconfigurationPlan solve(Parameters cra, Instance orig) throws SchedulerException { stats = new StaticPartitioningStatistics(cra, orig, System.currentTimeMillis(), workersCount); long d = -System.currentTimeMillis(); List<Instance> partitions = split(cra, orig); d += System.currentTimeMillis(); stats.setSplittingStatistics(partitions.size(), d); ExecutorService exe = Executors.newFixedThreadPool(this.workersCount); CompletionService<SolvingStatistics> completionService = new ExecutorCompletionService<>(exe); List<SolvingStatistics> results = new ArrayList<>(partitions.size()); runners = new ArrayList<>(); long duration = -System.currentTimeMillis(); for (Instance partition : partitions) { InstanceSolverRunner runner = new InstanceSolverRunner(cra, partition); completionService.submit(runner); runners.add(runner); } for (int i = 0; i < partitions.size(); i++) { try { results.add(completionService.take().get()); } catch (ExecutionException ignore) { Throwable cause = ignore.getCause(); if (cause != null) { throw new SplitException(null, cause.getMessage(), ignore); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SplitException(orig.getModel(), e.getMessage(), e); } } duration += System.currentTimeMillis(); stats.setSolvingDuration(duration); exe.shutdown(); return merge(orig, results); } StaticPartitioning(); }
StaticPartitioning implements InstanceSolver { @Override public ReconfigurationPlan solve(Parameters cra, Instance orig) throws SchedulerException { stats = new StaticPartitioningStatistics(cra, orig, System.currentTimeMillis(), workersCount); long d = -System.currentTimeMillis(); List<Instance> partitions = split(cra, orig); d += System.currentTimeMillis(); stats.setSplittingStatistics(partitions.size(), d); ExecutorService exe = Executors.newFixedThreadPool(this.workersCount); CompletionService<SolvingStatistics> completionService = new ExecutorCompletionService<>(exe); List<SolvingStatistics> results = new ArrayList<>(partitions.size()); runners = new ArrayList<>(); long duration = -System.currentTimeMillis(); for (Instance partition : partitions) { InstanceSolverRunner runner = new InstanceSolverRunner(cra, partition); completionService.submit(runner); runners.add(runner); } for (int i = 0; i < partitions.size(); i++) { try { results.add(completionService.take().get()); } catch (ExecutionException ignore) { Throwable cause = ignore.getCause(); if (cause != null) { throw new SplitException(null, cause.getMessage(), ignore); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SplitException(orig.getModel(), e.getMessage(), e); } } duration += System.currentTimeMillis(); stats.setSolvingDuration(duration); exe.shutdown(); return merge(orig, results); } StaticPartitioning(); int getWorkersCount(); void setWorkersCount(int s); @Override ReconfigurationPlan solve(Parameters cra, Instance orig); @Override StaticPartitioningStatistics getStatistics(); abstract List<Instance> split(Parameters ps, Instance i); @Override void stop(); }
StaticPartitioning implements InstanceSolver { @Override public ReconfigurationPlan solve(Parameters cra, Instance orig) throws SchedulerException { stats = new StaticPartitioningStatistics(cra, orig, System.currentTimeMillis(), workersCount); long d = -System.currentTimeMillis(); List<Instance> partitions = split(cra, orig); d += System.currentTimeMillis(); stats.setSplittingStatistics(partitions.size(), d); ExecutorService exe = Executors.newFixedThreadPool(this.workersCount); CompletionService<SolvingStatistics> completionService = new ExecutorCompletionService<>(exe); List<SolvingStatistics> results = new ArrayList<>(partitions.size()); runners = new ArrayList<>(); long duration = -System.currentTimeMillis(); for (Instance partition : partitions) { InstanceSolverRunner runner = new InstanceSolverRunner(cra, partition); completionService.submit(runner); runners.add(runner); } for (int i = 0; i < partitions.size(); i++) { try { results.add(completionService.take().get()); } catch (ExecutionException ignore) { Throwable cause = ignore.getCause(); if (cause != null) { throw new SplitException(null, cause.getMessage(), ignore); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new SplitException(orig.getModel(), e.getMessage(), e); } } duration += System.currentTimeMillis(); stats.setSolvingDuration(duration); exe.shutdown(); return merge(orig, results); } StaticPartitioning(); int getWorkersCount(); void setWorkersCount(int s); @Override ReconfigurationPlan solve(Parameters cra, Instance orig); @Override StaticPartitioningStatistics getStatistics(); abstract List<Instance> split(Parameters ps, Instance i); @Override void stop();  }