Example #1
0
 public List<ResourceAllocationSettingData> getRasds() {
   // Cleaning the list
   rasds.clear();
   Set<ResourceManagementHB> resMans = getResman();
   for (ResourceManagementHB resMan : resMans) {
     if (resMan.checkResourceCoherency()) {
       rasds.add(resMan.getRasd());
     } else {
       logger.error("concurrency is false");
     }
   }
   return rasds;
 }
Example #2
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);
            }
          }
        }
      }
    }
  }