Skip to content

Commit 7a897d3

Browse files
author
Sina Kashipazha
committed
Change variable names with regards to DaanHoogland comments.
1 parent 6a6e18b commit 7a897d3

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
199199
+
200200
"from op_host_capacity capacity where cluster_id = ? and capacity_type = ?;";
201201

202-
private static final String LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE_PART1 = "SELECT v.data_center_id, SUM(cpu) AS cpucore, " +
202+
private static final String LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE = "SELECT v.data_center_id, SUM(cpu) AS cpucore, " +
203203
"SUM(cpu * speed) AS cpu, SUM(ram_size * 1024 * 1024) AS memory " +
204204
"FROM (SELECT vi.data_center_id, (CASE WHEN ISNULL(service_offering.cpu) THEN custom_cpu.value ELSE service_offering.cpu end) AS cpu, " +
205205
"(CASE WHEN ISNULL(service_offering.speed) THEN custom_speed.value ELSE service_offering.speed end) AS speed, " +
@@ -209,9 +209,11 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
209209
"LEFT JOIN user_vm_details custom_speed ON(((custom_speed.vm_id = vi.id) AND (custom_speed.name = 'CpuSpeed'))) " +
210210
"LEFT JOIN user_vm_details custom_ram_size ON(((custom_ram_size.vm_id = vi.id) AND (custom_ram_size.name = 'memory'))) ";
211211

212-
private static final String LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE_PART2 =
212+
private static final String WHERE_STATE_IS_NOT_DESTRUCTIVE =
213213
"WHERE ISNULL(vi.removed) AND vi.state NOT IN ('Destroyed', 'Error', 'Expunging')";
214214

215+
private static final String LEFT_JOIN_VM_TEMPLATE = "LEFT JOIN vm_template ON vm_template.id = vi.vm_template_id ";
216+
215217
public CapacityDaoImpl() {
216218
_hostIdTypeSearch = createSearchBuilder();
217219
_hostIdTypeSearch.and("hostId", _hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
@@ -428,14 +430,13 @@ public List<SummedCapacity> listCapacitiesGroupedByLevelAndType(Integer capacity
428430
@Override
429431
public Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId, String hostTag) {
430432
TransactionLegacy txn = TransactionLegacy.currentTxn();
431-
PreparedStatement pstmt = null;
432-
List<SummedCapacity> results = new ArrayList<SummedCapacity>();
433+
PreparedStatement pstmt;
433434

434-
StringBuilder allocatedSql = new StringBuilder(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE_PART1);
435+
StringBuilder allocatedSql = new StringBuilder(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE);
435436
if (hostTag != null && ! hostTag.isEmpty()) {
436-
allocatedSql.append("LEFT JOIN vm_template ON vm_template.id = vi.vm_template_id ");
437+
allocatedSql.append(LEFT_JOIN_VM_TEMPLATE);
437438
}
438-
allocatedSql.append(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE_PART2);
439+
allocatedSql.append(WHERE_STATE_IS_NOT_DESTRUCTIVE);
439440
if (zoneId != null){
440441
allocatedSql.append(" AND vi.data_center_id = ?");
441442
}
@@ -444,6 +445,7 @@ public Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId, Strin
444445
allocatedSql.append(" OR service_offering.host_tag = '").append(hostTag).append("')");
445446
}
446447
allocatedSql.append(" ) AS v GROUP BY v.data_center_id");
448+
447449
try {
448450
// add allocated capacity of zone in result
449451
pstmt = txn.prepareAutoCloseStatement(allocatedSql.toString());
@@ -452,9 +454,9 @@ public Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId, Strin
452454
}
453455
ResultSet rs = pstmt.executeQuery();
454456
if (rs.next()) {
455-
return new Ternary(rs.getLong(2), rs.getLong(3), rs.getLong(4)); // cpu cores, cpu, memory
457+
return new Ternary<>(rs.getLong(2), rs.getLong(3), rs.getLong(4)); // cpu cores, cpu, memory
456458
}
457-
return new Ternary(0L, 0L, 0L);
459+
return new Ternary<>(0L, 0L, 0L);
458460
} catch (SQLException e) {
459461
throw new CloudRuntimeException("DB Exception on: " + allocatedSql, e);
460462
}
@@ -467,8 +469,8 @@ public List<SummedCapacity> findCapacityBy(Integer capacityType, Long zoneId, Lo
467469
PreparedStatement pstmt = null;
468470
List<SummedCapacity> results = new ArrayList<SummedCapacity>();
469471

470-
StringBuilder allocatedSql = new StringBuilder(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE_PART1);
471-
allocatedSql.append(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE_PART2);
472+
StringBuilder allocatedSql = new StringBuilder(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE);
473+
allocatedSql.append(WHERE_STATE_IS_NOT_DESTRUCTIVE);
472474

473475
HashMap<Long, Long> sumCpuCore = new HashMap<Long, Long>();
474476
HashMap<Long, Long> sumCpu = new HashMap<Long, Long>();

0 commit comments

Comments
 (0)