示例#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
  /**
   * Create a ResourceAllocatingSettingData of type 10
   *
   * @param session
   * @throws PersistenceException
   */
  private void createRASD10(Session session) throws PersistenceException {
    session.beginTransaction();

    ResourceAllocationSettingData rasd = new ResourceAllocationSettingData();
    rasd.setInstanceID("3");
    rasd.setAddress("00:1d:09:2c:50:d6");
    rasd.setResourceSubType("PCNet32");
    rasd.setConnection("VM Network");
    rasd.setElementName("Ethernet adapter on 'VM Network'");
    rasd.setResourceType(10);

    session.saveOrUpdate(rasd);

    // add this to the list "rasdHBs"
    rasdHBs.add(rasd);
  }