示例#1
0
  private <T extends ResourceManagementHB> void createRasdManagement(
      Session session, int[] resourceTypes, Class<T> cl) throws PersistenceException {

    VirtualappHB virtualAppHB =
        (VirtualappHB) session.get("VirtualappExtendedHB", vApp.getIdVirtualApp());

    VirtualDataCenterHB virtualDataCenterHB = virtualAppHB.getVirtualDataCenterHB();

    Disjunction virtualAppDisjuction = Restrictions.disjunction();
    virtualAppDisjuction.add(Restrictions.eq("idVirtualApp", virtualAppHB.getIdVirtualApp()));
    ArrayList<NodeHB> nodes =
        (ArrayList<NodeHB>) session.createCriteria(NodeHB.class).add(virtualAppDisjuction).list();

    VirtualmachineHB virtualMachineHB;

    ArrayList<ResourceAllocationSettingData> rasds;

    ResourceManagementHB resourceManagement = null;
    Timestamp timestamp = new Timestamp(new GregorianCalendar().getTimeInMillis());
    for (NodeHB node : nodes) {
      if (node.getType() == NodeTypeEnum.VIRTUAL_IMAGE) {
        NodeVirtualImageHB nodeVirtualImage = (NodeVirtualImageHB) node;
        virtualMachineHB = nodeVirtualImage.getVirtualMachineHB();

        if (virtualMachineHB != null) {
          for (int resourceType : resourceTypes) {
            rasds = getRasds(session, resourceType);

            for (ResourceAllocationSettingData rasd : rasds) {
              try {
                resourceManagement = cl.newInstance();
              } catch (Exception e) {
                throw new PersistenceException(
                    "Unable to create a new instance of " + cl.getName());
              }

              resourceManagement.setIdResourceType(rasd.getResourceType() + "");
              resourceManagement.setRasd(rasd);
              resourceManagement.setVirtualApp(virtualAppHB);
              resourceManagement.setVirtualMachine(virtualMachineHB);
              resourceManagement.setVirtualDataCenter(virtualDataCenterHB);

              session.saveOrUpdate(resourceManagement);

              resourceManagementHBs.add(resourceManagement);
            }
          }
        }
      }
    }
  }
示例#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
  @Override
  public NodeVirtualImageHB toPojoHB() {
    NodeHB nodeHB = super.toPojoHB();
    NodeVirtualImageHB nodeVirtualImageHB = new NodeVirtualImageHB(nodeHB);

    // Adding NodeVirtualImage's fields
    nodeVirtualImageHB.setVirtualImageHB(virtualImage.toPojoHB());
    if (virtualMachine != null) {
      nodeVirtualImageHB.setVirtualMachineHB(virtualMachine.toPojoHB());
    } else {
      nodeVirtualImageHB.setVirtualMachineHB(null);
    }

    return nodeVirtualImageHB;
  }