private Configuration makeConfiguration() { Configuration cfg = new SimpleConfiguration(); for (int i = 1; i <= 20; i++) { VirtualMachine vm = new SimpleVirtualMachine("vappHA.VM" + i); cfg.addWaiting(vm); if (i % 2 == 0) { vm.setTemplate("foo"); } else { vm.setTemplate("bar"); } } VirtualMachine vmX = new SimpleVirtualMachine("vappHA.top"); vmX.setTemplate("foo"); cfg.addWaiting(vmX); VirtualMachine vmY = new SimpleVirtualMachine("vappHA.middle"); vmX.setTemplate("ttt"); cfg.addWaiting(vmY); for (int i = 1; i <= 20; i++) { Node n = new SimpleNode("node-" + i); cfg.addOnline(n); } cfg.addOnline(new SimpleNode("node-frontend")); return cfg; }
public void test() { Configuration cfg = new SimpleConfiguration(); Node n1 = new SimpleNode("N1", 1, 2, 3); Node n2 = new SimpleNode("N2", 1, 2, 3); Node n3 = new SimpleNode("N3", 1, 2, 3); Node n4 = new SimpleNode("N4", 1, 2, 3); cfg.addOnline(n1); cfg.addOnline(n2); cfg.addOnline(n3); cfg.addOffline(n4); VirtualMachine vm1 = new SimpleVirtualMachine("VM1", 1, 2, 3); VirtualMachine vm2 = new SimpleVirtualMachine("VM2", 1, 2, 3); VirtualMachine vm3 = new SimpleVirtualMachine("VM3", 1, 2, 3); VirtualMachine vm4 = new SimpleVirtualMachine("VM4", 1, 2, 3); VirtualMachine vm5 = new SimpleVirtualMachine("VM5", 1, 2, 3); VirtualMachine vm6 = new SimpleVirtualMachine("VM6", 1, 2, 3); VirtualMachine vm7 = new SimpleVirtualMachine("VM7", 1, 2, 3); cfg.setRunOn(vm1, n1); cfg.setRunOn(vm2, n1); cfg.setSleepOn(vm3, n2); cfg.setRunOn(vm4, n2); cfg.addWaiting(vm5); cfg.setRunOn(vm6, n3); cfg.setRunOn(vm7, n3); TimedReconfigurationPlan p = new DefaultTimedReconfigurationPlan(cfg); Assert.assertTrue(p.add(new Migration(vm1, n1, n2, 0, 5))); Assert.assertTrue(p.add(new Startup(n4, 0, 3))); Assert.assertTrue(p.add(new Migration(vm6, n3, n2, 2, 5))); Assert.assertTrue(p.add(new Suspend(vm7, n3, n4, 7, 10))); Assert.assertTrue(p.add(new Run(vm5, n4, 0, 1))); // Assert.assertTrue(p.add(new Pause(vm2, n1, 0, 5))); // Assert.assertTrue(p.add(new UnPause(vm3, n1, 10, 15))); Assert.assertTrue(p.add(new Stop(vm4, n2, 1, 2))); Assert.assertTrue(p.add(new Shutdown(n3, 10, 15))); ProtobufTimedReconfigurationPlanSerializer s = ProtobufTimedReconfigurationPlanSerializer.getInstance(); File tmpF = null; try { tmpF = File.createTempFile("out", "out"); s.write(p, tmpF.getAbsolutePath()); TimedReconfigurationPlan r = s.read(tmpF.getAbsolutePath()); Assert.assertEquals(r, p); } catch (IOException e) { Assert.fail(e.getMessage(), e); } catch (TimedReconfigurationPlanSerializerException e) { Assert.fail(e.getMessage(), e); } finally { if (tmpF != null && tmpF.exists()) { tmpF.delete(); } } }
/* (non-Javadoc) * @see entropy.monitoring.ConfigurationAdapter#extractConfiguration() */ @Override public Configuration extractConfiguration() { Configuration config = new SimpleConfiguration(); for (ServerType server : Utils.getAllServers(currentFit4Green)) { Node node = getNode(server); if (server.getStatus() == ServerStatusType.ON || server.getStatus() == ServerStatusType .POWERING_ON) { // POWERING_ON nodes are seen as ON by entropy as they will be // soon on. This avoids ping-pong effect on the state. config.addOnline(node); for (VirtualMachineType VM : Utils.getVMs(server)) { VirtualMachine vm = getVM(node, VM); config.setRunOn(vm, node); } } else { // OFF, POWERING_OFF config.addOffline(node); } } return config; }
public void testSimpleFence() { Configuration cfg = new SimpleConfiguration(); // Some nodes ExplodedSet<Node>[] parts = new ExplodedSet[4]; for (int i = 0; i < parts.length; i++) { parts[i] = new ExplodedSet<Node>("$P" + (i + 1)); for (int j = 0; j < 5; j++) { Node n = new SimpleNode("N" + (10 * i + j + 1), 10, 10, 10); parts[i].add(n); cfg.addOnline(n); } } // Some VMs ExplodedSet<VirtualMachine>[] apps = new ExplodedSet[5]; for (int i = 0; i < apps.length; i++) { apps[i] = new ExplodedSet<VirtualMachine>("$A" + (i + 1)); for (int j = 0; j < 10; j++) { VirtualMachine vm = new SimpleVirtualMachine("VM" + (i * 10 + j + 1), 1, 1, 1); apps[i].add(vm); cfg.addWaiting(vm); } } PlanPartitioner part = new OtherPartitioning(cfg); for (int i = 0; i < apps.length; i++) { Fence f = new Fence(apps[i], parts[i % parts.length]); try { part.part(f); } catch (PartitioningException e) { Assert.fail(); } } List<Partition> ps = part.getResultingPartitions(); Assert.assertEquals(ps.size(), 4); Assert.assertTrue( ps.get(0).getNodes().equals(parts[0]) && ps.get(0).getVirtualMachines().containsAll(apps[0]) && ps.get(0).getVirtualMachines().containsAll(apps[4])); Assert.assertTrue( ps.get(1).getNodes().equals(parts[1]) && ps.get(1).getVirtualMachines().containsAll(apps[1])); Assert.assertTrue( ps.get(2).getNodes().equals(parts[2]) && ps.get(2).getVirtualMachines().containsAll(apps[2])); Assert.assertTrue( ps.get(3).getNodes().equals(parts[3]) && ps.get(3).getVirtualMachines().containsAll(apps[3])); }
/** Test oneOf in presence of a fence constraint */ public void testFenceOneOf() { Configuration cfg = new SimpleConfiguration(); // Some nodes ExplodedSet<Node>[] parts = new ExplodedSet[2]; for (int i = 0; i < parts.length; i++) { parts[i] = new ExplodedSet<Node>("$P" + (i + 1)); for (int j = 0; j < 5; j++) { Node n = new SimpleNode("N" + (10 * i + j + 1), 10, 10, 10); parts[i].add(n); cfg.addOnline(n); } } // Some VMs ExplodedSet<VirtualMachine> app = new ExplodedSet<VirtualMachine>("$A"); ExplodedSet<VirtualMachine> sub = new ExplodedSet<VirtualMachine>("$A/2"); for (int i = 0; i < 10; i++) { VirtualMachine vm = new SimpleVirtualMachine("VM" + (i + 1), 1, 1, 1); cfg.addWaiting(vm); if (i < 5) { sub.add(vm); } app.add(vm); } PlanPartitioner part = new OtherPartitioning(cfg); ExplodedMultiSet<Node> m = new ExplodedMultiSet<Node>(); m.add(parts[0]); m.add(parts[1]); OneOf of = new OneOf(app, m); Fence f = new Fence(app, parts[0]); try { part.part(f); part.part(of); } catch (PartitioningException e) { Assert.fail(e.getMessage(), e); } part.getResultingPartitions(); }
/** Test serialization/unserialization */ public void test() { Configuration cfg = new SimpleConfiguration(); for (int i = 1; i <= 10; i++) { Node n = new SimpleNode("N" + i, i, i + 1, i + 2); if (i % 3 == 0) { cfg.addOffline(n); } else { cfg.addOnline(n); } } Random rnd = new Random(); for (int i = 1; i <= 20; i++) { VirtualMachine vm = new SimpleVirtualMachine("VM" + i, i, i + 1, i + 2); vm.setCPUDemand(i + 3); vm.setCPUMax(i + 7); Node n = cfg.getOnlines().get(rnd.nextInt(cfg.getOnlines().size())); if (i % 3 == 0) { cfg.setSleepOn(vm, n); } else if (i % 5 == 0) { cfg.addWaiting(vm); } else { cfg.setRunOn(vm, n); } } FileConfigurationSerializer s = PlainTextConfigurationSerializer.getInstance(); File tmpF; try { tmpF = File.createTempFile("out", "out"); tmpF.deleteOnExit(); s.write(cfg, tmpF.getAbsolutePath()); Configuration r = s.read(tmpF.getAbsolutePath()); Assert.assertEquals(r, cfg); } catch (IOException e) { Assert.fail(e.getMessage(), e); } catch (ConfigurationSerializerException e) { Assert.fail(e.getMessage(), e); } }