Exemplo n.º 1
0
  @Test
  public void info() {
    res = vrouter.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(vrouter.getName().equals(name));
  }
Exemplo n.º 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);
  }
Exemplo n.º 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);
  }
Exemplo n.º 4
0
  @Test
  public void attributes() {
    res = vrouter.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(vrouter.xpath("NAME").equals(name));
  }
Exemplo n.º 5
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;
  }
Exemplo n.º 6
0
  @Test
  public void enable() {
    res = host.enable();
    assertTrue(res.getErrorMessage(), !res.isError());

    host.info();
    assertTrue(host.isEnabled());
  }
Exemplo n.º 7
0
  @Test
  public void publish() {
    res = vrouter.publish();
    assertTrue(res.getErrorMessage(), !res.isError());

    vrouter.info();
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1"));
  }
Exemplo n.º 8
0
  @Test
  public void delete() {
    res = vrouter.delete();
    assertTrue(res.getErrorMessage(), !res.isError());

    res = vrouter.info();
    assertTrue(res.isError());
  }
Exemplo n.º 9
0
  @Test
  public void info() {
    res = host.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    //        assertTrue( host.getId().equals("0") );
    assertTrue(host.id() >= 0);

    //        assertTrue( host.shortStateStr().equals("on") );
  }
Exemplo n.º 10
0
 /**
  * Gets list of Acls. We are not mapping the OpenNebula's Acl class. Acls are used only in
  * AuthorizationManager class.
  *
  * @return the list of Acls
  */
 @Override
 public List<Acl> getAcls() {
   List<Acl> acls = new ArrayList<>();
   OneResponse aclpr = aclpool.info();
   if (aclpr.isError()) {
     log.error(aclpr.getErrorMessage());
   }
   Iterator<Acl> itr = aclpool.iterator();
   while (itr.hasNext()) {
     Acl el = itr.next();
     System.out.println("Acl rule number: " + el.getId() + " toString: " + el.toString());
     acls.add(el);
   }
   return acls;
 }
Exemplo n.º 11
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) {
    }
  }
Exemplo n.º 12
0
  @Test
  public void allocate() {
    String name = "allocate_test";

    res = Host.allocate(client, name, "im_dummy", "vmm_dummy");
    assertTrue(res.getErrorMessage(), !res.isError());
    //        assertTrue( res.getMessage().equals("0") );

    hostPool.info();

    boolean found = false;
    for (Host h : hostPool) {
      found = found || h.getName().equals(name);
    }

    assertTrue(found);
  }
Exemplo n.º 13
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);
  }
Exemplo n.º 14
0
  @Test
  public void delete() {
    String name = host.getName();

    res = host.delete();
    assertTrue(res.getErrorMessage(), !res.isError());

    res = host.info();
    assertTrue(res.isError());

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

    boolean found = false;
    for (Host h : hostPool) {
      found = found || h.getName().equals(name);
    }

    assertTrue(!found);
  }
Exemplo n.º 15
0
  @Test
  public void chmod_octet() {
    res = vrouter.info();
    assertTrue(res.getErrorMessage(), !res.isError());

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

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

    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_U").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_M").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_A").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_M").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_A").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_U").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_M").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_A").equals("0"));

    res = vrouter.chmod("147");
    assertTrue(res.getErrorMessage(), !res.isError());

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

    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_U").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_M").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_A").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_M").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_A").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_U").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_M").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_A").equals("1"));
  }
Exemplo n.º 16
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);
  }
Exemplo n.º 17
0
  @Test
  public void update() {
    res = host.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    assertTrue(host.xpath("TEMPLATE/ATT1").equals(""));
    assertTrue(host.xpath("TEMPLATE/ATT2").equals(""));

    String new_template = "ATT2 = NEW_VAL\n" + "ATT3 = VAL3";

    res = host.update(new_template);
    assertTrue(res.getErrorMessage(), !res.isError());

    res = host.info();
    assertTrue(res.getErrorMessage(), !res.isError());
    assertTrue(host.xpath("TEMPLATE/ATT1").equals(""));
    assertTrue(host.xpath("TEMPLATE/ATT2").equals("NEW_VAL"));
    assertTrue(host.xpath("TEMPLATE/ATT3").equals("VAL3"));
  }
Exemplo n.º 18
0
  @Test
  public void chmod() {
    res = vrouter.info();
    assertTrue(res.getErrorMessage(), !res.isError());

    String owner_a = vrouter.xpath("PERMISSIONS/OWNER_A");
    String group_a = vrouter.xpath("PERMISSIONS/GROUP_A");

    res = vrouter.chmod(0, 1, -1, 1, 0, -1, 1, 1, 0);
    assertTrue(res.getErrorMessage(), !res.isError());

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

    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_U").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_M").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/OWNER_A").equals(owner_a));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_U").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_M").equals("0"));
    assertTrue(vrouter.xpath("PERMISSIONS/GROUP_A").equals(group_a));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_U").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_M").equals("1"));
    assertTrue(vrouter.xpath("PERMISSIONS/OTHER_A").equals("0"));
  }
Exemplo n.º 19
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);
  }