Пример #1
0
  /**
   * Remove from DB the PhyisicalMachines from initPhysical implementation (actually remove
   * DataCenter @see dataCenter, for cascading delete physical machines disapear) Clean from DB the
   * scheduler test virtual datacenter, virtual application, icon and virtual images.
   *
   * @throws PersistenceException
   */
  public void clearCreatedDomainObjects() throws PersistenceException {
    if (dc == null) {
      return;
    }

    factorytest = HibernateDAOFactory.instance();
    DataCenterDAO daoDc = factorytest.getDataCenterDAO();
    VirtualDataCenterDAO daoVdc = factorytest.getVirtualDataCenterDAO();
    IconDAO daoIco = factorytest.getIconDAO();
    VirtualImageDAO daoVi = factorytest.getVirtualImageDAO();

    factorytest.beginConnection();

    log.debug("Cleaning all the created objects ");

    daoDc.makeTransient(dc);
    daoVdc.makeTransient(vdc);

    daoIco.makeTransient(icon);

    // TODO: create the speciphic method by description??
    // Criterion descriptionTest = Restrictions.eq("description", "test");
    // for (VirtualimageHB vi : daoVi.findByCriteria(descriptionTest))
    // {
    // HibernateUtil.getSession().delete(vi); // XXX use DAO
    // }

    factorytest.endConnection();
  }
Пример #2
0
  /** TODO VirtualmachineHB vMachine (can be null) */
  private NodeVirtualImageHB createNodeVirtualImage(
      VirtualimageHB vImage, VirtualmachineHB vMachine) throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    NodeVirtualImageDAO daoNVI = factorytest.getNodeVirtualImageDAO();

    factorytest.beginConnection();

    NodeVirtualImageHB nVi = new NodeVirtualImageHB();
    // XXX nVi.setIdNode(idNode);
    nVi.setIdVirtualApp(vApp.getIdVirtualApp());
    nVi.setVirtualImageHB(vImage);
    nVi.setVirtualMachineHB(vMachine);

    nVi.setType(NodeTypeEnum.VIRTUAL_IMAGE);

    nVi.setName("test");

    nVi.setPosX(10);
    nVi.setPosY(10);

    daoNVI.makePersistent(nVi);

    factorytest.endConnection();

    return nVi;
  }
Пример #3
0
  /**
   * VirtualImage Factory construction XXX is not stored on DB. (not an HB because it's not useful
   * the ''category''/''repository''...)
   *
   * @throws PersistenceException
   * @param name
   * @param cpu
   * @param ram
   * @param hd
   * @return a reference to the newly created VirtualimageHB persistent object
   * @throws PersistenceException
   */
  public VirtualimageHB createVirtualImage(String name, int cpu, int ram, long hd)
      throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    VirtualImageDAO daoVI = factorytest.getVirtualImageDAO();

    factorytest.beginConnection();

    VirtualimageHB vImage = new VirtualimageHB();

    vImage.setName(name);
    vImage.setDescription("test");

    vImage.setCpuRequired(cpu);
    vImage.setHdRequired(hd);
    vImage.setRamRequired(ram);

    vImage.setPathName("test");

    vImage.setIcon(icon);
    vImage.setCategory(category);
    vImage.setType(imageType);
    vImage.setRepository(repository);

    daoVI.makePersistent(vImage);

    vImagesCreated.add(vImage);

    factorytest.endConnection();

    return vImage;
  }
Пример #4
0
  /**
   * Creates nodes that correspond to the Virtualapp for the this object
   *
   * @throws PersistenceException
   */
  public void createNodes() throws PersistenceException {

    VirtualMachine virtualMachine = new VirtualMachine();
    factorytest = HibernateDAOFactory.instance();
    HyperVisorDAO dao = factorytest.getHyperVisorDAO();

    factorytest.beginConnection();

    virtualMachine.setAssignedTo(dao.findById(hypervisor.getIdHyper()).toPojo());
    virtualMachine.setHd(1);
    virtualMachine.setHighDisponibility(true);
    virtualMachine.setDescription("test-virtual machine");
    virtualMachine.setCpu(2);
    virtualMachine.setRam(256);
    virtualMachine.setUUID("apophis");
    State state = new State(StateEnum.NOT_DEPLOYED);
    virtualMachine.setState(state);
    virtualMachine.setVdrpIP("vdrpIP");
    virtualMachine.setVdrpPort(5050);

    VirtualimageHB virtualImageHB = createVirtualImage("image", 4, 256, 2);
    virtualMachine.setVirtualImage(virtualImageHB.toPojo());

    createVirtualImageNode(virtualImageHB, virtualMachine);

    factorytest.endConnection();
  }
Пример #5
0
  /**
   * Persist on database the input PhysicalMachine (also its DataCenter, Rack and So).
   *
   * @throws PersistenceException
   */
  protected PhysicalmachineHB createPhysicalMachine(
      PhysicalmachineHB machine, RackHB rack, HypervisorType htype) throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    PhysicalMachineDAO pmDAO = factorytest.getPhysicalMachineDAO();
    HyperVisorDAO hyperDAO = factorytest.getHyperVisorDAO();

    factorytest.beginConnection();

    HypervisorHB hyper = createHypervisor(htype);

    machine.setRack(rack);
    machine.setDataCenter(rack.getDatacenter());

    machine.setHypervisor(hyper);

    pmDAO.makePersistent(machine);

    log.debug("Added machine [{}]", machine.getName());

    hyper.setPhysicalMachine(machine);
    hyperDAO.makePersistent(hyper);

    factorytest.endConnection();

    return machine;
  }
Пример #6
0
  /** Gets the default user (named user ) */
  protected UserHB getDefaultUser() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    UserDAO daoUser = factorytest.getUserDAO();

    factorytest.beginConnection();

    UserHB userHB = daoUser.findById(2);

    factorytest.endConnection();

    return userHB;
  }
Пример #7
0
  /**
   * Gets the default virtual image category (Others with id=1)
   *
   * @throws PersistenceException
   */
  protected CategoryHB getDefaultCategory() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    CategoryDAO daoCategory = factorytest.getCategoryDAO();

    factorytest.beginConnection();

    CategoryHB catHB = daoCategory.findById(1);

    factorytest.endConnection();

    return catHB;
  }
Пример #8
0
  /**
   * Gets the default repository (main id =1)
   *
   * @throws PersistenceException
   */
  private RepositoryHB getDefaultRepository() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    RepositoryDAO daoRep = factorytest.getRepositoryDAO();

    factorytest.beginConnection();

    RepositoryHB repHB = daoRep.findById(1);

    factorytest.endConnection();

    return repHB;
  }
Пример #9
0
  /** Gets the default enterprise (abiquo with id 1) */
  private EnterpriseHB getDefaultEnterprise() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    EnterpriseDAO daoEnt = factorytest.getEnterpriseDAO();

    factorytest.beginConnection();

    EnterpriseHB entHB = daoEnt.findById(1);

    factorytest.endConnection();

    return entHB;
  }
Пример #10
0
  /**
   * Retrieves the default hypervisor and returns pojo encapsulating this information
   *
   * @return a {@link HypervisorHB} object representing the default Hypervisor stored in the DB
   * @throws PersistenceException
   */
  public HypervisorHB getDefaultHypervisor() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    HyperVisorDAO dao = factorytest.getHyperVisorDAO();

    factorytest.beginConnection();

    HypervisorHB hb = dao.findById(1);

    factorytest.endConnection();

    return hb;
  }
Пример #11
0
  private IconHB createIcon() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    IconDAO daoIcon = factorytest.getIconDAO();

    factorytest.beginConnection();

    IconHB icon = new IconHB();
    icon.setName("test");
    icon.setPath("test");
    daoIcon.makePersistent(icon);

    factorytest.endConnection();

    return icon;
  }
Пример #12
0
  /**
   * Save the virtual machine. XXX it do not use Crudable because the ''session.saveOrUpdate'' fails
   * caused by ''Batch update returned unexpected row count from update [0]; actual row count: 0;
   * expected: 1'' TODO fix
   */
  private VirtualmachineHB createVirtualMachine(VirtualmachineHB vMachine)
      throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    VirtualMachineDAO vmDAO = factorytest.getVirtualMachineDAO();

    factorytest.beginConnection();
    try {
      vmDAO.makePersistent(vMachine);
      factorytest.endConnection();
    } catch (HibernateException e) {
      factorytest.rollbackConnection();
      throw new PersistenceException("Hibernate exception", e);
    }

    return vMachine;
  }
Пример #13
0
  /**
   * Deletes entries in the rasd and rasd-management tables
   *
   * @throws PersistenceException
   */
  private void cleanRasd() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    ResourceManagementDAO resourceManagementHBDao = factorytest.getResourceManagementDAO();
    ResourceAllocationSettingDataDAO rasdDao = factorytest.getResourceAllocationSettingDataDAO();

    factorytest.beginConnection();
    for (ResourceManagementHB rasdManagementHB : resourceManagementHBs) {
      resourceManagementHBDao.makeTransient(rasdManagementHB);
    }

    for (ResourceAllocationSettingData rasd : rasdHBs) {
      rasdDao.makeTransient(rasd);
    }
    factorytest.endConnection();

    log.info("Deleted rasd and rasd-management entries");
  }
Пример #14
0
  private DatacenterHB createDataCenter() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    DataCenterDAO daoDC = factorytest.getDataCenterDAO();

    factorytest.beginConnection();
    DatacenterHB data = new DatacenterHB();

    data.setName(DATACENTER_TEST); // XXX
    data.setSituation("test");

    // XXX data.setRacks(racks);

    daoDC.makePersistent(data);
    factorytest.endConnection();

    return data;
  }
Пример #15
0
  /**
   * Rack Factory construction
   *
   * @throws PersistenceException
   */
  private RackHB createRack(DatacenterHB dc) throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    RackDAO daoRack = factorytest.getRackDAO();

    factorytest.beginConnection();

    RackHB rack = new RackHB();
    rack.setDatacenter(dc);
    rack.setName("test");
    rack.setShortDescription("test");
    rack.setLargeDescription("test");
    daoRack.makePersistent(rack);

    factorytest.endConnection();

    return rack;
  }
Пример #16
0
  /**
   * VirtualDataCenter Factory construction
   *
   * @throws PersistenceException
   */
  private VirtualDataCenterHB createVirtualDataCenter(
      DatacenterHB dc, EnterpriseHB enterprise, HypervisorType htype) throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    VirtualDataCenterDAO daoVdc = factorytest.getVirtualDataCenterDAO();

    factorytest.beginConnection();

    VirtualDataCenterHB vdc = new VirtualDataCenterHB();
    vdc.setEnterpriseHB(enterprise);
    vdc.setIdDataCenter(dc.getIdDataCenter());
    vdc.setName("test");
    vdc.setHypervisorType(htype);
    vdc.setNetwork(createNetwork());
    daoVdc.makePersistent(vdc);

    factorytest.endConnection();

    return vdc;
  }
Пример #17
0
  /**
   * VirtualAppliance Factory construction
   *
   * @throws PersistenceException
   */
  private VirtualappHB createVirtualApp(
      VirtualDataCenterHB vdc, EnterpriseHB enterprise, StateEnum state)
      throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    VirtualApplianceDAO daoApp = factorytest.getVirtualApplianceDAO();

    factorytest.beginConnection();

    VirtualappHB vApp = new VirtualappHB();
    vApp.setEnterpriseHB(enterprise);
    vApp.setState(state);
    vApp.setVirtualDataCenterHB(vdc);
    vApp.setError(0);
    vApp.setHighDisponibility(1);
    vApp.setName("test");
    daoApp.makePersistent(vApp);

    factorytest.endConnection();

    return vApp;
  }
Пример #18
0
  /** Log all PhysicalMachines on the DataBase */
  public void listPhysicalMachines() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    PhysicalMachineDAO daoPM = factorytest.getPhysicalMachineDAO();

    factorytest.beginConnection();

    List<PhysicalmachineHB> machines;

    machines = daoPM.findAll();

    log.debug("########## All PhysicalMachiene ##########");
    for (PhysicalmachineHB pm : machines) {
      log.debug(
          "PhysicalMachine name:"
              + pm.getName()
              + " dc:"
              + pm.getRack().getDatacenter().getName()
              + "\t cpu:"
              + pm.getCpu()
              + "("
              + pm.getCpuUsed()
              + ")"
              + "\t ram:"
              + pm.getRam()
              + "("
              + pm.getRamUsed()
              + ")"
              + "\t hd:"
              + pm.getHd()
              + "("
              + pm.getHdUsed()
              + ")");
    }

    factorytest.endConnection();
  }