Skip to content

Commit dce4258

Browse files
author
Prachi Damle
committed
CLOUDSTACK-2568: ACS41 regression in storage subsystem (seen with local storage and 2 or more hosts)
Changes: - In VolumeReservationVO, the getter method of a column had a typo, causing us to create a wrong searchbuilder. It was searching over the 'id' column instead of 'vm_reservation_id' causing - This bug was causing the vm deployment to choose a wrong pool during deployment since the search was choosing incorrectly - This bug in the GenericSearchBuilder is also fixed - if the getter method does not use the standard 'get' or 'is' prefix, one should annotate that method using @column(name = "<column_name>") and indicate which column this method refers to. This will cause the GenericSearchBuilder to identify the field correctly.
1 parent 0a44369 commit dce4258

3 files changed

Lines changed: 15 additions & 27 deletions

File tree

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/VolumeReservationVO.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,14 @@
1616
// under the License.
1717
package org.apache.cloudstack.engine.cloud.entity.api.db;
1818

19-
import java.util.Date;
20-
import java.util.Map;
21-
2219
import javax.persistence.Column;
2320
import javax.persistence.Entity;
2421
import javax.persistence.GeneratedValue;
2522
import javax.persistence.GenerationType;
2623
import javax.persistence.Id;
2724
import javax.persistence.Table;
28-
import javax.persistence.Transient;
29-
30-
import org.apache.cloudstack.api.Identity;
3125
import org.apache.cloudstack.api.InternalIdentity;
3226

33-
import com.cloud.utils.db.GenericDao;
34-
3527
@Entity
3628
@Table(name = "volume_reservation")
3729
public class VolumeReservationVO implements InternalIdentity{
@@ -42,7 +34,7 @@ public class VolumeReservationVO implements InternalIdentity{
4234
private long id;
4335

4436
@Column(name = "vm_reservation_id")
45-
private Long vmReservationId;
37+
private long vmReservationId;
4638

4739
@Column(name = "vm_id")
4840
private long vmId;
@@ -53,18 +45,14 @@ public class VolumeReservationVO implements InternalIdentity{
5345
@Column(name="pool_id")
5446
private long poolId;
5547

56-
// VolumeId -> poolId
57-
@Transient
58-
Map<String, String> volumeReservationMap;
59-
6048
/**
6149
* There should never be a public constructor for this class. Since it's
6250
* only here to define the table for the DAO class.
6351
*/
6452
protected VolumeReservationVO() {
6553
}
6654

67-
public VolumeReservationVO(long vmId, long volumeId, long poolId, Long vmReservationId) {
55+
public VolumeReservationVO(long vmId, long volumeId, long poolId, long vmReservationId) {
6856
this.vmId = vmId;
6957
this.volumeId = volumeId;
7058
this.poolId = poolId;
@@ -80,7 +68,7 @@ public long getVmId() {
8068
return vmId;
8169
}
8270

83-
public Long geVmReservationId() {
71+
public long getVmReservationId() {
8472
return vmReservationId;
8573
}
8674

@@ -93,8 +81,4 @@ public Long getPoolId() {
9381
}
9482

9583

96-
public Map<String,String> getVolumeReservation(){
97-
return volumeReservationMap;
98-
}
99-
10084
}

engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/db/dao/VolumeReservationDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void init() {
4949
VmIdSearch.done();
5050

5151
VmReservationIdSearch = createSearchBuilder();
52-
VmReservationIdSearch.and("vmReservationId", VmReservationIdSearch.entity().geVmReservationId(), SearchCriteria.Op.EQ);
52+
VmReservationIdSearch.and("vmReservationId", VmReservationIdSearch.entity().getVmReservationId(), SearchCriteria.Op.EQ);
5353
VmReservationIdSearch.done();
5454
}
5555

utils/src/com/cloud/utils/db/GenericSearchBuilder.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.List;
2424
import java.util.Map;
2525

26+
import javax.persistence.Column;
2627
import javax.persistence.Transient;
2728

2829
import net.sf.cglib.proxy.Factory;
@@ -163,13 +164,16 @@ public Object intercept(Object object, Method method, Object[] args, MethodProxy
163164
set(fieldName);
164165
return null;
165166
} else {
166-
name = name.toLowerCase();
167-
for (String fieldName : _attrs.keySet()) {
168-
if (name.endsWith(fieldName.toLowerCase())) {
169-
set(fieldName);
170-
return null;
171-
}
172-
}
167+
Column ann = method.getAnnotation(Column.class);
168+
if (ann != null) {
169+
String colName = ann.name();
170+
for (Map.Entry<String, Attribute> attr : _attrs.entrySet()) {
171+
if (colName.equals(attr.getValue().columnName)) {
172+
set(attr.getKey());
173+
return null;
174+
}
175+
}
176+
}
173177
assert false : "Perhaps you need to make the method start with get or is?";
174178
}
175179
}

0 commit comments

Comments
 (0)