Esempio n. 1
0
 /**
  * Check the compatibility of the action with a source configuration. The hosting node must be
  * online and hosting the sleeping the virtual machine
  *
  * @param src the configuration to check
  * @return {@code true} if the action is compatible
  */
 @Override
 public boolean isCompatibleWith(Configuration src) {
   return (src.isOnline(getHost())
       && src.isSleeping(getVirtualMachine())
       && src.getLocation(getVirtualMachine()).equals(getHost())
       && src.isOnline(getDestination()));
 }
  /* (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 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();
      }
    }
  }
  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();
  }
Esempio n. 6
0
  private void make(Configuration cfg) {

    VJob v = new BasicPlasmaVJob("vappHA");

    ManagedElementSet<VirtualMachine> t1 = new SimpleManagedElementSet<VirtualMachine>();
    t1.add(cfg.getAllVirtualMachines().get("vappHA.VM1"));
    t1.add(cfg.getAllVirtualMachines().get("vappHA.VM2"));
    t1.add(cfg.getAllVirtualMachines().get("vappHA.VM3"));
    v.addConstraint(new ContinuousSpread(t1));
    v.addVirtualMachine(cfg.getAllVirtualMachines().get("vappHA.VM10"));
    v.addVirtualMachine(cfg.getAllVirtualMachines().get("vappHA.top"));
    v.addVirtualMachine(cfg.getAllVirtualMachines().get("vappHA.middle"));
    ManagedElementSet<Node> ns = new SimpleManagedElementSet<Node>();
    ns.add(cfg.getOnlines().get("node-1"));
    ns.add(cfg.getOnlines().get("node-2"));
    v.addConstraint(new Capacity(ns, 15));

    ManagedElementSet<Node> ns2 = new SimpleManagedElementSet<Node>();
    ns2.add(cfg.getOnlines().get("node-3"));
    ns2.add(cfg.getOnlines().get("node-4"));
    Set<ManagedElementSet<Node>> x = new HashSet<ManagedElementSet<Node>>();
    x.add(ns);
    x.add(ns2);
    v.addConstraint(new Among(t1, x));
    v.addConstraint(new Ban(t1, ns2));
    try {
      ProtobufVJobSerializer.getInstance().write(v, RESOURCE);
    } catch (Exception e) {
      Assert.fail(e.getMessage(), e);
    }
  }
Esempio n. 7
0
  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;
  }
Esempio n. 8
0
  /**
   * The node is not known
   *
   * @throws VJobBuilderException
   */
  @Test(expectedExceptions = {VJobBuilderException.class})
  public void testUnknownNode() throws VJobBuilderException {
    Configuration cfg = makeConfiguration();
    // make(cfg);
    cfg.remove(cfg.getAllNodes().get("node-4"));
    VJobElementBuilder eB = new DefaultVJobElementBuilder(null);
    eB.useConfiguration(cfg);
    ProtobufVJobBuilder builder = new ProtobufVJobBuilder(eB);
    DefaultPBConstraintsCatalog c = new DefaultPBConstraintsCatalog();
    c.add(new AmongBuilder());
    c.add(new LonelyBuilder());
    c.add(new BanBuilder());
    c.add(new CapacityBuilder());
    c.add(new ContinuousSpreadBuilder());
    builder.setConstraintCatalog(c);

    try {
      VJob v = builder.build(new File(RESOURCE));
      System.out.println(v);
    } catch (IOException e) {
      Assert.fail(e.getMessage(), e);
    }
  }
  public void test() {
    Configuration src = TestHelper.readConfiguration(RESOURCES_DIR + "sample.txt");
    ConfigurationSampler s = new CPUSampler(1000);
    Configuration res = s.sample(src);
    Assert.assertEquals(res.getOnlines().get("N1").getCPUCapacity(), 1);
    Assert.assertEquals(res.getOnlines().get("N2").getCPUCapacity(), 2);
    Assert.assertEquals(res.getOnlines().get("N3").getCPUCapacity(), 3);
    Assert.assertEquals(res.getOfflines().get("N4").getCPUCapacity(), 4);

    Assert.assertEquals(res.getRunnings().get("VM1").getCPUConsumption(), 1);
    Assert.assertEquals(res.getRunnings().get("VM2").getCPUConsumption(), 2);
    Assert.assertEquals(res.getSleepings().get("VM3").getCPUConsumption(), 3);
    Assert.assertEquals(res.getWaitings().get("VM4").getCPUConsumption(), 4);
  }
Esempio n. 10
0
 /**
  * Check the compatibility of the action with a source and a destination configuration.
  * Destination node must be online and running the VM on the destination configuration while VM
  * must be sleeping on the hosting node on the source configuration The VM must be waiting in the
  * source configuration.
  *
  * @param src the source configuration
  * @param dst the configuration to reach
  * @return true if the action is compatible with the configurations
  */
 @Override
 public boolean isCompatibleWith(Configuration src, Configuration dst) {
   if (!src.isOnline(getHost())
       || !src.isSleeping(getVirtualMachine())
       || !src.getLocation(getVirtualMachine()).equals(getHost())) {
     return false;
   }
   if (!dst.isOnline(getDestination())
       || !dst.isRunning(getVirtualMachine())
       || !dst.getLocation(getVirtualMachine()).equals(getDestination())) {
     return false;
   }
   return true;
 }
 /** 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);
   }
 }
 public void insertVMtoAllocate(Configuration config, RequestType request) {
   VirtualMachine VM = getVM(request);
   config.addWaiting(VM);
 }
Esempio n. 13
0
 @Override
 public boolean apply(Configuration c) {
   return c.setRunOn(this.getVirtualMachine(), this.getDestination());
 }