예제 #1
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;
  }
예제 #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
  /**
   * Creates a {@link AbicloudNetworkHB} object
   *
   * @return AbicloudNetworkHB object created
   * @throws PersistenceException
   */
  private NetworkHB createNetwork() throws PersistenceException {
    factorytest = HibernateDAOFactory.instance();
    NetworkDAO networkDAO = factorytest.getNetworkDAO();
    VlanNetworkDAO vlanNetworkDAO = factorytest.getVlanNetworkDAO();
    NetworkConfigurationDAO netConfDAO = factorytest.getNetworkConfigurationDAO();
    IpPoolManagementDAO hostDAO = factorytest.getIpPoolManagementDAO();

    factorytest.beginConnection();

    NetworkConfigurationHB netConf = new NetworkConfigurationHB();
    netConf.setMask(24);
    netConf.setNetmask("255.255.255.0");
    netConf.setNetworkAddress("192.168.1.0");
    netConfDAO.makePersistent(netConf);

    VlanNetworkHB vlanHB = new VlanNetworkHB();
    vlanHB.setDefaultNetwork(Boolean.TRUE);
    vlanHB.setNetworkName("Test VLAN");
    vlanHB.setConfiguration(netConf);
    vlanNetworkDAO.makePersistent(vlanHB);

    List<VlanNetworkHB> listOfVlans = new ArrayList<VlanNetworkHB>();
    listOfVlans.add(vlanHB);

    NetworkHB network = new NetworkHB();
    network.setUuid(UUID.randomUUID().toString());
    network.setNetworks(listOfVlans);
    networkDAO.makePersistent(network);

    return network;
  }
예제 #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 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;
  }
예제 #7
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;
  }
예제 #8
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;
  }
예제 #9
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;
  }
예제 #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
  /**
   * 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();
  }
예제 #19
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();
  }