예제 #1
0
  /**
   * After a *.info call, this method builds the internal xml representation of the pool.
   *
   * @param info The XML-RPC *.info response
   */
  protected void processInfo(OneResponse info) {
    if (info.isError()) {
      return;
    }
    // Added by Xiaoyi Lu for saving One's response message.
    this.info = info.getMessage();
    try {
      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document doc = builder.parse(new ByteArrayInputStream(info.getMessage().getBytes()));

      xml = doc.getDocumentElement();

    } catch (Exception e) {
    }
  }
예제 #2
0
  /** @throws java.lang.Exception */
  @Before
  public void setUp() throws Exception {
    res = VirtualRouter.allocate(client, template_str);

    int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
    vrouter = new VirtualRouter(oid, client);
  }
예제 #3
0
  /** @throws java.lang.Exception */
  @Before
  public void setUp() throws Exception {
    res = Host.allocate(client, name, "dummy", "dummy");

    int hid = !res.isError() ? Integer.parseInt(res.getMessage()) : -1;
    host = new Host(hid, client);
  }
예제 #4
0
  private boolean OCALaunch(CloudElement cloud, int numVMs) {

    Client oneClient = null;

    String account = "" + cloud.getAccessKey() + ":" + cloud.getSecretKey();
    try {
      oneClient = new Client(account, cloud.getEndPoint());
    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }

    for (int i = 0; i < numVMs; i++) {
      OneResponse rc = VirtualMachine.allocate(oneClient, vmTemplate);

      if (rc.isError()) {
        PrintMsg.print(DMsgType.ERROR, "failed to launch vms" + rc.getErrorMessage());
      }
      int newVMID = Integer.parseInt(rc.getMessage());
      vecTempID.add(newVMID);

      PrintMsg.print(DMsgType.MSG, "O.K. ID = " + newVMID);

      VMElement vmElement = new VMElement(newVMID, VMState.NOT_DEFINED);
      vmList.put(newVMID, vmElement);
    }

    /* this algorithm has to be modified for better
     * performance.
     *
     * it also has to handle only some vms running...
     */
    int sleepsec = 20; /* 20 seconds as default */

    while (!isAllVMRunning(oneClient)) {
      try {
        PrintMsg.print(DMsgType.MSG, "Going to sleep....");
        Thread.sleep(sleepsec * 1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
        return false;
      }
    }

    vecTempID.removeAllElements();
    PrintMsg.print(DMsgType.MSG, "All running.....");
    PrintMsg.print(DMsgType.MSG, "Notified to Monitor Manager");

    /* have to increase currently running vms
     * because all cloud systems have to be managed by cloud manager
     */
    Config.cloudMan.incCurrentVMs(cloud, numVMs);

    synchronized (Config.monMan) {
      Config.monMan.notify();
    }

    return true;
  }
예제 #5
0
  @Test
  public void chown() {
    // Create a new User and Group
    res = User.allocate(client, "template_test_user", "password");
    assertTrue(res.getErrorMessage(), !res.isError());

    int uid = Integer.parseInt(res.getMessage());

    res = Group.allocate(client, "template_test_group");
    assertTrue(res.getErrorMessage(), !res.isError());

    int gid = Integer.parseInt(res.getMessage());

    res = vrouter.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(vrouter.uid() == 0);
    assertTrue(vrouter.gid() == 0);

    res = vrouter.chown(uid, gid);
    assertTrue(res.getErrorMessage(), !res.isError());

    res = vrouter.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(vrouter.uid() == uid);
    assertTrue(vrouter.gid() == gid);

    res = vrouter.chgrp(0);

    res = vrouter.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(vrouter.uid() == uid);
    assertTrue(vrouter.gid() == 0);
  }
예제 #6
0
  @Test
  public void allocate() {
    vrouter.delete();

    res = VirtualRouter.allocate(client, template_str);
    assertTrue(res.getErrorMessage(), !res.isError());

    int oid = res.isError() ? -1 : Integer.parseInt(res.getMessage());
    vrouter = new VirtualRouter(oid, client);

    vrouterPool.info();

    boolean found = false;
    for (VirtualRouter temp : vrouterPool) {
      found = found || temp.getName().equals(name);
    }

    assertTrue(found);
  }
예제 #7
0
  @Test
  public void instantiate() {
    VirtualMachinePool vmPool = new VirtualMachinePool(client);

    res = vmPool.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(vmPool.getLength() == 0);

    String tmpl_str = "NAME = vrtemplate\n" + "CPU = 0.1\n" + "MEMORY = 64\n";

    res = Template.allocate(client, tmpl_str);
    assertTrue(res.getErrorMessage(), !res.isError());

    int tmplid = Integer.parseInt(res.getMessage());

    res = vrouter.instantiate(3, tmplid);
    assertTrue(res.getErrorMessage(), !res.isError());

    res = vmPool.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(vmPool.getLength() == 3);
  }