GutoVeronezi commented on a change in pull request #4438:
URL: https://github.com/apache/cloudstack/pull/4438#discussion_r714716487
##########
File path:
engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
##########
@@ -411,6 +416,41 @@ public static void setValues(PreparedStatement
preparedStatement, Object... valu
}
+ @Override
+ public Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId,
String hostTag) {
+ TransactionLegacy txn = TransactionLegacy.currentTxn();
+ PreparedStatement pstmt;
+
+ StringBuilder allocatedSql = new
StringBuilder(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE);
+ if (hostTag != null && ! hostTag.isEmpty()) {
Review comment:
We could use `StringUtils#isNotEmpty`.
##########
File path:
engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
##########
@@ -411,6 +416,41 @@ public static void setValues(PreparedStatement
preparedStatement, Object... valu
}
+ @Override
+ public Ternary<Long, Long, Long> findCapacityByZoneAndHostTag(Long zoneId,
String hostTag) {
+ TransactionLegacy txn = TransactionLegacy.currentTxn();
+ PreparedStatement pstmt;
+
+ StringBuilder allocatedSql = new
StringBuilder(LIST_ALLOCATED_CAPACITY_GROUP_BY_CAPACITY_AND_ZONE);
+ if (hostTag != null && ! hostTag.isEmpty()) {
+ allocatedSql.append(LEFT_JOIN_VM_TEMPLATE);
+ }
+ allocatedSql.append(WHERE_STATE_IS_NOT_DESTRUCTIVE);
+ if (zoneId != null) {
+ allocatedSql.append(" AND vi.data_center_id = ?");
+ }
+ if (hostTag != null && ! hostTag.isEmpty()) {
Review comment:
We could use `StringUtils#isNotEmpty`.
##########
File path: engine/schema/src/main/java/com/cloud/vm/dao/UserVmDaoImpl.java
##########
@@ -692,4 +703,35 @@ public boolean remove(Long id) {
return vmsDetailByNames;
}
+
+ @Override
+ public List<Ternary<Integer, Integer, Integer>> countVmsBySize(long dcId,
int limit) {
+ TransactionLegacy txn = TransactionLegacy.currentTxn();
+ String sql = "SELECT cpu,ram_size,count(1) AS count FROM (SELECT *
FROM user_vm_view WHERE data_center_id = ? AND state NOT IN ('Destroyed',
'Error', 'Expunging') GROUP BY id) AS uvv GROUP BY cpu,ram_size ORDER BY count
DESC ";
+ if (limit >= 0)
+ sql = sql + "limit " + limit;
+ PreparedStatement pstmt = null;
+ List<Ternary<Integer, Integer, Integer>> result = new ArrayList<>();
+ try {
+ pstmt = txn.prepareAutoCloseStatement(sql);
+ pstmt.setLong(1, dcId);
+ ResultSet rs = pstmt.executeQuery();
+ while (rs.next()) {
+ result.add(new Ternary<Integer, Integer,
Integer>(rs.getInt(1), rs.getInt(2), rs.getInt(3)));
+ }
+ } catch (Exception e) {
+ s_logger.warn("Error counting vms by size", e);
Review comment:
We could add some context to this log, like `dcId`.
##########
File path:
plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
##########
@@ -524,14 +647,20 @@ public ItemHostMemory(final String zn, final String zu,
final String hn, final S
filter = fl;
miBytes = membytes / (1024.0 * 1024.0);
isDedicated = dedicated;
+ hosttags = tags;
}
@Override
public String toMetricsString() {
- if (Strings.isNullOrEmpty(hostName) && Strings.isNullOrEmpty(ip)) {
- return String.format("%s{zone=\"%s\",filter=\"%s\"} %.2f",
name, zoneName, filter, miBytes);
+ if (StringUtils.isEmpty(hostName) && StringUtils.isEmpty(ip)) {
Review comment:
We could use `StringUtils#isAllEmpty`.
##########
File path:
plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterImpl.java
##########
@@ -460,14 +567,20 @@ public ItemVMCore(final String zn, final String zu, final
String hn, final Strin
core = cr;
}
isDedicated = dedicated;
+ hosttags = tags;
}
@Override
public String toMetricsString() {
- if (Strings.isNullOrEmpty(hostName) && Strings.isNullOrEmpty(ip)) {
- return String.format("%s{zone=\"%s\",filter=\"%s\"} %d", name,
zoneName, filter, core);
+ if (StringUtils.isEmpty(hostName) && StringUtils.isEmpty(ip)) {
Review comment:
We could use StringUtils#isAllEmpty.
##########
File path: engine/schema/src/main/java/com/cloud/vm/dao/VMInstanceDaoImpl.java
##########
@@ -802,6 +802,27 @@ public Long countByZoneAndState(long zoneId, State state) {
return customSearch(sc, null).get(0);
}
+ @Override
+ public Long countByZoneAndStateAndHostTag(long dcId, State state, String
hostTag) {
+ TransactionLegacy txn = TransactionLegacy.currentTxn();
+ String sql = "SELECT COUNT(1) FROM vm_instance vi "
+ + "JOIN service_offering so ON vi.service_offering_id=so.id "
+ + "JOIN vm_template vt ON vi.vm_template_id = vt.id "
+ + "WHERE vi.data_center_id= " + dcId + " AND vi.state = '" +
state + "' AND vi.removed IS NULL "
+ + "AND (so.host_tag='" + hostTag + "' OR vt.template_tag='" +
hostTag + "')";
+ PreparedStatement pstmt = null;
+ try {
+ pstmt = txn.prepareAutoCloseStatement(sql);
+ ResultSet rs = pstmt.executeQuery();
+ if (rs.next()) {
+ return rs.getLong(1);
+ }
+ } catch (Exception e) {
+ s_logger.warn("Error counting vms by host tag", e);
Review comment:
We could add some context to this log, like `dcId` and `hostTag`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]