Skip to content

Commit 2ff0abf

Browse files
committed
code refactor
1 parent 8e6a3bd commit 2ff0abf

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

engine/schema/src/main/java/com/cloud/dc/ClusterDetailsDaoImpl.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
3535
protected final SearchBuilder<ClusterDetailsVO> ClusterSearch;
3636
protected final SearchBuilder<ClusterDetailsVO> DetailSearch;
3737

38+
private final String CPU_OVERPROVISIONING_FACTOR = "cpu.overprovisioning.factor";
39+
private final String MEMORY_OVERPROVISIONING_FACTOR = "mem.overprovisioning.factor";
40+
private final String CPU_OVERCOMMIT_RATIO = "cpuOvercommitRatio";
41+
private final String MEMORY_OVERCOMMIT_RATIO = "memoryOvercommitRatio";
42+
3843
protected ClusterDetailsDaoImpl() {
3944
ClusterSearch = createSearchBuilder();
4045
ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
@@ -50,12 +55,7 @@ protected ClusterDetailsDaoImpl() {
5055
public ClusterDetailsVO findDetail(long clusterId, String name) {
5156
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
5257
// This is temporary fix to support list/update configuration api for cpu and memory overprovisioning ratios
53-
if (name.equalsIgnoreCase("cpu.overprovisioning.factor")) {
54-
name = "cpuOvercommitRatio";
55-
}
56-
if (name.equalsIgnoreCase("mem.overprovisioning.factor")) {
57-
name = "memoryOvercommitRatio";
58-
}
58+
name = getCpuMemoryOvercommitRatio(name);
5959
sc.setParameters("clusterId", clusterId);
6060
sc.setParameters("name", name);
6161

@@ -104,12 +104,7 @@ public void persist(long clusterId, Map<String, String> details) {
104104

105105
for (Map.Entry<String, String> detail : details.entrySet()) {
106106
String name = detail.getKey();
107-
if (name.equalsIgnoreCase("cpu.overprovisioning.factor")) {
108-
name = "cpuOvercommitRatio";
109-
}
110-
if (name.equalsIgnoreCase("mem.overprovisioning.factor")) {
111-
name = "memoryOvercommitRatio";
112-
}
107+
name = getCpuMemoryOvercommitRatio(name);
113108
String value = detail.getValue();
114109
if ("password".equals(detail.getKey())) {
115110
value = DBEncryptionUtil.encrypt(value);
@@ -122,12 +117,7 @@ public void persist(long clusterId, Map<String, String> details) {
122117

123118
@Override
124119
public void persist(long clusterId, String name, String value) {
125-
if (name.equalsIgnoreCase("cpu.overprovisioning.factor")) {
126-
name = "cpuOvercommitRatio";
127-
}
128-
if (name.equalsIgnoreCase("mem.overprovisioning.factor")) {
129-
name = "memoryOvercommitRatio";
130-
}
120+
name = getCpuMemoryOvercommitRatio(name);
131121
TransactionLegacy txn = TransactionLegacy.currentTxn();
132122
txn.start();
133123
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
@@ -160,4 +150,15 @@ public String getVmwareDcName(Long clusterId) {
160150
dcName = tokens[3];
161151
return dcName;
162152
}
153+
154+
private String getCpuMemoryOvercommitRatio(String name) {
155+
if (name.equalsIgnoreCase(CPU_OVERPROVISIONING_FACTOR)) {
156+
name = CPU_OVERCOMMIT_RATIO;
157+
}
158+
if (name.equalsIgnoreCase(MEMORY_OVERPROVISIONING_FACTOR)) {
159+
name = MEMORY_OVERCOMMIT_RATIO;
160+
}
161+
162+
return name;
163+
}
163164
}

0 commit comments

Comments
 (0)