@Test public void isBetterDeploymentPlan() { List<Vm> vms = new ArrayList<>(); vms.add(new Vm("vm1", "image", 2, 2048, 2, null, "app1")); vms.add(new Vm("vm2", "image", 1, 1024, 1, null, "app2")); vms.add(new Vm("vm3", "image", 1, 1024, 1, null, "app1")); List<VmAssignmentToHost> assignmentsPlan1 = new ArrayList<>(); assignmentsPlan1.add(new VmAssignmentToHost(vms.get(0), hosts.get(0))); assignmentsPlan1.add(new VmAssignmentToHost(vms.get(1), hosts.get(1))); assignmentsPlan1.add(new VmAssignmentToHost(vms.get(2), hosts.get(0))); DeploymentPlan deploymentPlan1 = new DeploymentPlan(assignmentsPlan1); List<VmAssignmentToHost> assignmentsPlan2 = new ArrayList<>(); assignmentsPlan2.add(new VmAssignmentToHost(vms.get(0), hosts.get(1))); assignmentsPlan2.add(new VmAssignmentToHost(vms.get(1), hosts.get(0))); assignmentsPlan2.add(new VmAssignmentToHost(vms.get(2), hosts.get(1))); DeploymentPlan deploymentPlan2 = new DeploymentPlan(assignmentsPlan2); List<DeploymentPlan> deploymentPlans = new ArrayList<>(); deploymentPlans.add(deploymentPlan1); deploymentPlans.add(deploymentPlan2); assertEquals(deploymentPlan1, scheduler.chooseBestDeploymentPlan(deploymentPlans, hosts, "testId")); }
@Override public DeploymentPlan chooseBestDeploymentPlan(List<DeploymentPlan> deploymentPlans, List<Host> hosts, String deploymentId) { DeploymentPlan bestDeploymentPlan = null; int vmsFriendsForBestDeploymentPlan = -1; for (DeploymentPlan deploymentPlan: deploymentPlans) { int vmsFriendsForDeploymentPlan = countVmsFriendsForDeploymentPlan(deploymentPlan); VMMLogger.logVmsSameAppInSameHost(deploymentPlan, vmsFriendsForDeploymentPlan, deploymentId); if (vmsFriendsForDeploymentPlan > vmsFriendsForBestDeploymentPlan) { bestDeploymentPlan = deploymentPlan; vmsFriendsForBestDeploymentPlan = vmsFriendsForDeploymentPlan; } else if (vmsFriendsForDeploymentPlan == vmsFriendsForBestDeploymentPlan) { if (Math.random() > 0.5) { bestDeploymentPlan = deploymentPlan; } } } return bestDeploymentPlan; }
SchedAlgGroupByApp implements SchedAlgorithm { @Override public DeploymentPlan chooseBestDeploymentPlan(List<DeploymentPlan> deploymentPlans, List<Host> hosts, String deploymentId) { DeploymentPlan bestDeploymentPlan = null; int vmsFriendsForBestDeploymentPlan = -1; for (DeploymentPlan deploymentPlan: deploymentPlans) { int vmsFriendsForDeploymentPlan = countVmsFriendsForDeploymentPlan(deploymentPlan); VMMLogger.logVmsSameAppInSameHost(deploymentPlan, vmsFriendsForDeploymentPlan, deploymentId); if (vmsFriendsForDeploymentPlan > vmsFriendsForBestDeploymentPlan) { bestDeploymentPlan = deploymentPlan; vmsFriendsForBestDeploymentPlan = vmsFriendsForDeploymentPlan; } else if (vmsFriendsForDeploymentPlan == vmsFriendsForBestDeploymentPlan) { if (Math.random() > 0.5) { bestDeploymentPlan = deploymentPlan; } } } return bestDeploymentPlan; } }
SchedAlgGroupByApp implements SchedAlgorithm { @Override public DeploymentPlan chooseBestDeploymentPlan(List<DeploymentPlan> deploymentPlans, List<Host> hosts, String deploymentId) { DeploymentPlan bestDeploymentPlan = null; int vmsFriendsForBestDeploymentPlan = -1; for (DeploymentPlan deploymentPlan: deploymentPlans) { int vmsFriendsForDeploymentPlan = countVmsFriendsForDeploymentPlan(deploymentPlan); VMMLogger.logVmsSameAppInSameHost(deploymentPlan, vmsFriendsForDeploymentPlan, deploymentId); if (vmsFriendsForDeploymentPlan > vmsFriendsForBestDeploymentPlan) { bestDeploymentPlan = deploymentPlan; vmsFriendsForBestDeploymentPlan = vmsFriendsForDeploymentPlan; } else if (vmsFriendsForDeploymentPlan == vmsFriendsForBestDeploymentPlan) { if (Math.random() > 0.5) { bestDeploymentPlan = deploymentPlan; } } } return bestDeploymentPlan; } SchedAlgGroupByApp(List<VmDeployed> vmsDeployed); }
SchedAlgGroupByApp implements SchedAlgorithm { @Override public DeploymentPlan chooseBestDeploymentPlan(List<DeploymentPlan> deploymentPlans, List<Host> hosts, String deploymentId) { DeploymentPlan bestDeploymentPlan = null; int vmsFriendsForBestDeploymentPlan = -1; for (DeploymentPlan deploymentPlan: deploymentPlans) { int vmsFriendsForDeploymentPlan = countVmsFriendsForDeploymentPlan(deploymentPlan); VMMLogger.logVmsSameAppInSameHost(deploymentPlan, vmsFriendsForDeploymentPlan, deploymentId); if (vmsFriendsForDeploymentPlan > vmsFriendsForBestDeploymentPlan) { bestDeploymentPlan = deploymentPlan; vmsFriendsForBestDeploymentPlan = vmsFriendsForDeploymentPlan; } else if (vmsFriendsForDeploymentPlan == vmsFriendsForBestDeploymentPlan) { if (Math.random() > 0.5) { bestDeploymentPlan = deploymentPlan; } } } return bestDeploymentPlan; } SchedAlgGroupByApp(List<VmDeployed> vmsDeployed); @Override DeploymentPlan chooseBestDeploymentPlan(List<DeploymentPlan> deploymentPlans, List<Host> hosts,
            String deploymentId); @Override SchedAlgorithmNameEnum getNameEnum(); }
SchedAlgGroupByApp implements SchedAlgorithm { @Override public DeploymentPlan chooseBestDeploymentPlan(List<DeploymentPlan> deploymentPlans, List<Host> hosts, String deploymentId) { DeploymentPlan bestDeploymentPlan = null; int vmsFriendsForBestDeploymentPlan = -1; for (DeploymentPlan deploymentPlan: deploymentPlans) { int vmsFriendsForDeploymentPlan = countVmsFriendsForDeploymentPlan(deploymentPlan); VMMLogger.logVmsSameAppInSameHost(deploymentPlan, vmsFriendsForDeploymentPlan, deploymentId); if (vmsFriendsForDeploymentPlan > vmsFriendsForBestDeploymentPlan) { bestDeploymentPlan = deploymentPlan; vmsFriendsForBestDeploymentPlan = vmsFriendsForDeploymentPlan; } else if (vmsFriendsForDeploymentPlan == vmsFriendsForBestDeploymentPlan) { if (Math.random() > 0.5) { bestDeploymentPlan = deploymentPlan; } } } return bestDeploymentPlan; } SchedAlgGroupByApp(List<VmDeployed> vmsDeployed); @Override DeploymentPlan chooseBestDeploymentPlan(List<DeploymentPlan> deploymentPlans, List<Host> hosts,
            String deploymentId); @Override SchedAlgorithmNameEnum getNameEnum();  }