/** * 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; }
/** 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(); }