test_class.declarator: rackGenerator
test_class.modifier: private
test_class.original_string: private RackGenerator rackGenerator;
test_class.type: RackGenerator
test_class.var_name: rackGenerator
test_class.declarator: enterpriseGenerator
test_class.modifier: private
test_class.original_string: private EnterpriseGenerator enterpriseGenerator;
test_class.type: EnterpriseGenerator
test_class.var_name: enterpriseGenerator
test_class.file: model/src/test/java/com/abiquo/server/core/infrastructure/DatacenterDAOTest.java
test_class.identifier: DatacenterDAOTest
test_class.superclass: extends DefaultDAOTestBase<DatacenterDAO, Datacenter>
test_case.body: @Test(enabled = false)
      public void test_getUsedResources()
      {
          Enterprise enterprise = this.enterpriseGenerator.createInstance("Enterprise Name");
          Datacenter datacenter = createUniqueEntity();
  
          datacenter.setName("Datacenter name");
          ds().persistAll(datacenter, enterprise);
  
          DatacenterDAO dao = createDaoWithNoTransaction();
  
          DefaultEntityCurrentUsed expectedUsed = new DefaultEntityCurrentUsed(0, 0, 0);
          DefaultEntityCurrentUsed currentUsed =
              dao.getCurrentResourcesAllocated(datacenter.getId(), enterprise.getId());
          Assert.assertEquals(currentUsed.getCpu(), expectedUsed.getCpu());
          Assert.assertEquals(currentUsed.getRamInMb(), expectedUsed.getRamInMb());
          Assert.assertEquals(currentUsed.getHdInMb(), expectedUsed.getHdInMb());
          Assert.assertEquals(currentUsed.getPublicIp(), expectedUsed.getPublicIp());
          Assert.assertEquals(currentUsed.getVlanCount(), expectedUsed.getVlanCount());
  
      }
test_case.class_method_signature: DatacenterDAOTest.test_getUsedResources()
test_case.full_signature: @Test(enabled = false) public void test_getUsedResources()
test_case.identifier: test_getUsedResources
test_case.invocations: createInstance createUniqueEntity setName persistAll ds createDaoWithNoTransaction getCurrentResourcesAllocated getId getId assertEquals getCpu getCpu assertEquals getRamInMb getRamInMb assertEquals getHdInMb getHdInMb assertEquals getPublicIp getPublicIp assertEquals getVlanCount getVlanCount
test_case.modifiers: @Test(enabled = false) public
test_case.parameters: ()
test_case.return: void
test_case.signature: void test_getUsedResources()
focal_class.declarator: BY_ENT_WITH_NETWORK =
          " select distinct ent from  VirtualDatacenter vdc, " + " VLANNetwork vn, "
              + " DatacenterLimits dcl join dcl.enterprise ent join dcl.datacenter dc"
              + " WHERE vn.network.id = vdc.network.id" + " and vdc.enterprise.id = ent.id"
              + " and vdc.datacenter.id = dc.id " + " and dc.id = :datacenter_id "
focal_class.modifier: public static final
focal_class.original_string: public static final String BY_ENT_WITH_NETWORK =
          " select distinct ent from  VirtualDatacenter vdc, " + " VLANNetwork vn, "
              + " DatacenterLimits dcl join dcl.enterprise ent join dcl.datacenter dc"
              + " WHERE vn.network.id = vdc.network.id" + " and vdc.enterprise.id = ent.id"
              + " and vdc.datacenter.id = dc.id " + " and dc.id = :datacenter_id ";
focal_class.type: String
focal_class.var_name: BY_ENT_WITH_NETWORK
focal_class.declarator: BY_ENT =
          " select distinct ent from DatacenterLimits dcl join dcl.enterprise ent join dcl.datacenter dc"
              + " WHERE dc.id = :datacenter_id "
focal_class.modifier: public static final
focal_class.original_string: public static final String BY_ENT =
          " select distinct ent from DatacenterLimits dcl join dcl.enterprise ent join dcl.datacenter dc"
              + " WHERE dc.id = :datacenter_id ";
focal_class.type: String
focal_class.var_name: BY_ENT
focal_class.declarator: SUM_VM_RESOURCES =
          "select sum(vm.cpu), sum(vm.ram), sum(vm.hd) from virtualmachine vm, hypervisor hy, physicalmachine pm "
              + " where hy.id = vm.idHypervisor and pm.idPhysicalMachine = hy.idPhysicalMachine "//
              // and pm.idState != 7" // not HA_DISABLED
              + " and pm.idDatacenter = :datacenterId and vm.idEnterprise = :enterpriseId and vm.state != 'NOT_ALLOCATED' and vm.idHypervisor is not null"
focal_class.modifier: private static final
focal_class.original_string: private static final String SUM_VM_RESOURCES =
          "select sum(vm.cpu), sum(vm.ram), sum(vm.hd) from virtualmachine vm, hypervisor hy, physicalmachine pm "
              + " where hy.id = vm.idHypervisor and pm.idPhysicalMachine = hy.idPhysicalMachine "//
              // and pm.idState != 7" // not HA_DISABLED
              + " and pm.idDatacenter = :datacenterId and vm.idEnterprise = :enterpriseId and vm.state != 'NOT_ALLOCATED' and vm.idHypervisor is not null";
focal_class.type: String
focal_class.var_name: SUM_VM_RESOURCES
focal_class.declarator: SUM_EXTRA_HD_RESOURCES =
          "select sum(r.limitResource) from rasd r, rasd_management rm, virtualdatacenter vdc, virtualmachine vm where r.instanceID = rm.idResource "
              + "and rm.idResourceType = '17' and rm.idVirtualDatacenter = vdc.idVirtualDatacenter and vdc.idDatacenter=:datacenterId "
              + "and  rm.idVM = vm.idVM and vm.state != 'NOT_ALLOCATED' and vm.idHypervisor is not null"
focal_class.modifier: private static final
focal_class.original_string: private static final String SUM_EXTRA_HD_RESOURCES =
          "select sum(r.limitResource) from rasd r, rasd_management rm, virtualdatacenter vdc, virtualmachine vm where r.instanceID = rm.idResource "
              + "and rm.idResourceType = '17' and rm.idVirtualDatacenter = vdc.idVirtualDatacenter and vdc.idDatacenter=:datacenterId "
              + "and  rm.idVM = vm.idVM and vm.state != 'NOT_ALLOCATED' and vm.idHypervisor is not null";
focal_class.type: String
focal_class.var_name: SUM_EXTRA_HD_RESOURCES
focal_class.declarator: SUM_STORAGE_RESOURCES =
          "select sum(r.limitResource) "
              + "from volume_management vm, storage_pool sp, storage_device sd, rasd_management rm, virtualdatacenter vdc, rasd r "
              + "where " + "vm.idManagement = rm.idManagement " + "and rm.idResource = r.instanceID "
              + "and vm.idStorage = sp.idStorage " + "and sp.idStorageDevice = sd.id "
              + "and sd.idDataCenter = :datacenterId "
              + "and rm.idVirtualDataCenter = vdc.idVirtualDataCenter "
              + "and vdc.idEnterprise = :enterpriseId"
focal_class.modifier: private static final
focal_class.original_string: private static final String SUM_STORAGE_RESOURCES =
          "select sum(r.limitResource) "
              + "from volume_management vm, storage_pool sp, storage_device sd, rasd_management rm, virtualdatacenter vdc, rasd r "
              + "where " + "vm.idManagement = rm.idManagement " + "and rm.idResource = r.instanceID "
              + "and vm.idStorage = sp.idStorage " + "and sp.idStorageDevice = sd.id "
              + "and sd.idDataCenter = :datacenterId "
              + "and rm.idVirtualDataCenter = vdc.idVirtualDataCenter "
              + "and vdc.idEnterprise = :enterpriseId";
focal_class.type: String
focal_class.var_name: SUM_STORAGE_RESOURCES
focal_class.declarator: COUNT_IP_RESOURCES =
          "select count(*) from ip_pool_management ipm, rasd_management rm, vlan_network vn, datacenter dc, virtualdatacenter vdc, enterprise_limits_by_datacenter el "
              + " where ipm.vlan_network_id = vn.vlan_network_id "
              + " and vn.network_id = dc.network_id "
              + " and rm.idManagement = ipm.idManagement "
              + " and rm.idVirtualDataCenter = vdc.idVirtualDataCenter "
              + " and dc.idDataCenter = :datacenterId and vdc.idEnterprise = :enterpriseId "
              + " and el.idEnterprise = vdc.idEnterprise "
              + " and el.idDataCenter = dc.idDataCenter " + " and vn.networktype = 'PUBLIC' "
focal_class.modifier: private static final
focal_class.original_string: private static final String COUNT_IP_RESOURCES =
          "select count(*) from ip_pool_management ipm, rasd_management rm, vlan_network vn, datacenter dc, virtualdatacenter vdc, enterprise_limits_by_datacenter el "
              + " where ipm.vlan_network_id = vn.vlan_network_id "
              + " and vn.network_id = dc.network_id "
              + " and rm.idManagement = ipm.idManagement "
              + " and rm.idVirtualDataCenter = vdc.idVirtualDataCenter "
              + " and dc.idDataCenter = :datacenterId and vdc.idEnterprise = :enterpriseId "
              + " and el.idEnterprise = vdc.idEnterprise "
              + " and el.idDataCenter = dc.idDataCenter " + " and vn.networktype = 'PUBLIC' ";
focal_class.type: String
focal_class.var_name: COUNT_IP_RESOURCES
focal_class.declarator: COUNT_VLAN_RESOURCES =
          "select count(*) from vlan_network vn, virtualdatacenter vdc, enterprise_limits_by_datacenter el "
              + "where vn.network_id = vdc.networktypeId and el.idDatacenter = :datacenterId and el.idEnterprise = :enterpriseId "
              + "and vdc.idEnterprise = el.idEnterprise"
focal_class.modifier: private static final
focal_class.original_string: private static final String COUNT_VLAN_RESOURCES =
          "select count(*) from vlan_network vn, virtualdatacenter vdc, enterprise_limits_by_datacenter el "
              + "where vn.network_id = vdc.networktypeId and el.idDatacenter = :datacenterId and el.idEnterprise = :enterpriseId "
              + "and vdc.idEnterprise = el.idEnterprise";
focal_class.type: String
focal_class.var_name: COUNT_VLAN_RESOURCES
focal_class.file: model/src/main/java/com/abiquo/server/core/infrastructure/DatacenterDAO.java
focal_class.identifier: DatacenterDAO
focal_class.class_method_signature: DatacenterDAO.DatacenterDAO()
focal_class.full_signature: public  DatacenterDAO()
focal_class.identifier: DatacenterDAO
focal_class.modifiers: public
focal_class.parameters: ()
focal_class.signature:  DatacenterDAO()
focal_class.class_method_signature: DatacenterDAO.DatacenterDAO(final EntityManager entityManager)
focal_class.full_signature: public  DatacenterDAO(final EntityManager entityManager)
focal_class.identifier: DatacenterDAO
focal_class.modifiers: public
focal_class.parameters: (final EntityManager entityManager)
focal_class.signature:  DatacenterDAO(final EntityManager entityManager)
focal_class.class_method_signature: DatacenterDAO.equalName(final String name)
focal_class.full_signature: private static Criterion equalName(final String name)
focal_class.identifier: equalName
focal_class.modifiers: private static
focal_class.parameters: (final String name)
focal_class.return: Criterion
focal_class.signature: Criterion equalName(final String name)
focal_class.class_method_signature: DatacenterDAO.existsAnyWithName(final String name)
focal_class.full_signature: public boolean existsAnyWithName(final String name)
focal_class.identifier: existsAnyWithName
focal_class.modifiers: public
focal_class.parameters: (final String name)
focal_class.return: boolean
focal_class.signature: boolean existsAnyWithName(final String name)
focal_class.class_method_signature: DatacenterDAO.existsAnyOtherWithName(final Datacenter datacenter, final String name)
focal_class.full_signature: public boolean existsAnyOtherWithName(final Datacenter datacenter, final String name)
focal_class.identifier: existsAnyOtherWithName
focal_class.modifiers: public
focal_class.parameters: (final Datacenter datacenter, final String name)
focal_class.return: boolean
focal_class.signature: boolean existsAnyOtherWithName(final Datacenter datacenter, final String name)
focal_class.class_method_signature: DatacenterDAO.getCurrentResourcesAllocated(final int datacenterId,
          final int enterpriseId)
focal_class.full_signature: public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId,
          final int enterpriseId)
focal_class.identifier: getCurrentResourcesAllocated
focal_class.modifiers: public
focal_class.parameters: (final int datacenterId,
          final int enterpriseId)
focal_class.return: DefaultEntityCurrentUsed
focal_class.signature: DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId,
          final int enterpriseId)
focal_class.class_method_signature: DatacenterDAO.findEnterprisesByDatacenters(final Datacenter datacenter,
          final Integer firstElem, final Integer numElem, final Boolean network)
focal_class.full_signature: public List<Enterprise> findEnterprisesByDatacenters(final Datacenter datacenter,
          final Integer firstElem, final Integer numElem, final Boolean network)
focal_class.identifier: findEnterprisesByDatacenters
focal_class.modifiers: public
focal_class.parameters: (final Datacenter datacenter,
          final Integer firstElem, final Integer numElem, final Boolean network)
focal_class.return: List<Enterprise>
focal_class.signature: List<Enterprise> findEnterprisesByDatacenters(final Datacenter datacenter,
          final Integer firstElem, final Integer numElem, final Boolean network)
focal_class.superclass: extends DefaultDAOBase<Integer, Datacenter>
focal_method.body: public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId,
          final int enterpriseId)
      {
          Object[] vmResources =
              (Object[]) getSession().createSQLQuery(SUM_VM_RESOURCES).setParameter("datacenterId",
                  datacenterId).setParameter("enterpriseId", enterpriseId).uniqueResult();
  
          Long cpu = vmResources[0] == null ? 0 : ((BigDecimal) vmResources[0]).longValue();
          Long ram = vmResources[1] == null ? 0 : ((BigDecimal) vmResources[1]).longValue();
          Long hd = vmResources[2] == null ? 0 : ((BigDecimal) vmResources[2]).longValue();
  
          BigDecimal extraHd =
              (BigDecimal) getSession().createSQLQuery(SUM_EXTRA_HD_RESOURCES).setParameter(
                  "datacenterId", datacenterId).uniqueResult();
          Long hdTot = extraHd == null ? hd : hd + extraHd.longValue() * 1024 * 1024;
  
          BigDecimal storage =
              (BigDecimal) getSession().createSQLQuery(SUM_STORAGE_RESOURCES).setParameter(
                  "datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId)
                  .uniqueResult();
  
          BigInteger publicIps =
              (BigInteger) getSession().createSQLQuery(COUNT_IP_RESOURCES).setParameter(
                  "datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId)
                  .uniqueResult();
  
          BigInteger vlan =
              (BigInteger) getSession().createSQLQuery(COUNT_VLAN_RESOURCES).setParameter(
                  "datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId)
                  .uniqueResult();
  
          DefaultEntityCurrentUsed used = new DefaultEntityCurrentUsed(cpu.intValue(), ram, hdTot);
  
          // Storage usage is stored in MB
          used.setStorage(storage == null ? 0 : storage.longValue() * 1024 * 1024);
          used.setPublicIp(publicIps == null ? 0 : publicIps.longValue());
          used.setVlanCount(vlan == null ? 0 : vlan.longValue());
          return used;
      }
focal_method.class_method_signature: DatacenterDAO.getCurrentResourcesAllocated(final int datacenterId,
          final int enterpriseId)
focal_method.full_signature: public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId,
          final int enterpriseId)
focal_method.identifier: getCurrentResourcesAllocated
focal_method.invocations: uniqueResult setParameter setParameter createSQLQuery getSession longValue longValue longValue uniqueResult setParameter createSQLQuery getSession longValue uniqueResult setParameter setParameter createSQLQuery getSession uniqueResult setParameter setParameter createSQLQuery getSession uniqueResult setParameter setParameter createSQLQuery getSession intValue setStorage longValue setPublicIp longValue setVlanCount longValue
focal_method.modifiers: public
focal_method.parameters: (final int datacenterId,
          final int enterpriseId)
focal_method.return: DefaultEntityCurrentUsed
focal_method.signature: DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId,
          final int enterpriseId)