Skip to content

Commit 1fc7d70

Browse files
authored
Add idempotent primary keys on tables missing them (apache#5785)
* In progress primary keys * Refactor in progress to idempotent way * Finish SQL changes * Add java code to match new columns * Fix imports * Fix tests * Remove comments * Fix index name on vmsnapshot * Fix parse from correct column on usage storage * Fix parser columns * Fix NPE * Fix NPE for the rest of the occurrences * Further fix for similar issue
1 parent 0e15095 commit 1fc7d70

28 files changed

Lines changed: 342 additions & 80 deletions

engine/schema/src/main/java/com/cloud/usage/UsageIPAddressVO.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import javax.persistence.Column;
2222
import javax.persistence.Entity;
23+
import javax.persistence.GeneratedValue;
24+
import javax.persistence.GenerationType;
25+
import javax.persistence.Id;
2326
import javax.persistence.Table;
2427
import javax.persistence.Temporal;
2528
import javax.persistence.TemporalType;
@@ -29,6 +32,12 @@
2932
@Entity
3033
@Table(name = "usage_ip_address")
3134
public class UsageIPAddressVO implements InternalIdentity {
35+
36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
@Column(name = "id")
39+
private Long id;
40+
3241
@Column(name = "account_id")
3342
private long accountId;
3443

@@ -38,8 +47,8 @@ public class UsageIPAddressVO implements InternalIdentity {
3847
@Column(name = "zone_id")
3948
private long zoneId;
4049

41-
@Column(name = "id")
42-
private long id;
50+
@Column(name = "ip_id")
51+
private long ipId;
4352

4453
@Column(name = "public_ip_address")
4554
private String address = null;
@@ -65,7 +74,7 @@ protected UsageIPAddressVO() {
6574
}
6675

6776
public UsageIPAddressVO(long id, long accountId, long domainId, long zoneId, String address, boolean isSourceNat, boolean isSystem, Date assigned, Date released, boolean isHidden) {
68-
this.id = id;
77+
this.ipId = id;
6978
this.accountId = accountId;
7079
this.domainId = domainId;
7180
this.zoneId = zoneId;
@@ -128,4 +137,8 @@ public void setReleased(Date released) {
128137
public boolean isHidden() {
129138
return isHidden;
130139
}
140+
141+
public long getIpId() {
142+
return ipId;
143+
}
131144
}

engine/schema/src/main/java/com/cloud/usage/UsageLoadBalancerPolicyVO.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import javax.persistence.Column;
2222
import javax.persistence.Entity;
23+
import javax.persistence.GeneratedValue;
24+
import javax.persistence.GenerationType;
25+
import javax.persistence.Id;
2326
import javax.persistence.Table;
2427
import javax.persistence.Temporal;
2528
import javax.persistence.TemporalType;
@@ -30,6 +33,11 @@
3033
@Table(name = "usage_load_balancer_policy")
3134
public class UsageLoadBalancerPolicyVO implements InternalIdentity {
3235

36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
@Column(name = "id")
39+
private Long id;
40+
3341
@Column(name = "zone_id")
3442
private long zoneId;
3543

@@ -39,8 +47,8 @@ public class UsageLoadBalancerPolicyVO implements InternalIdentity {
3947
@Column(name = "domain_id")
4048
private long domainId;
4149

42-
@Column(name = "id")
43-
private long id;
50+
@Column(name = "lb_id")
51+
private long lbId;
4452

4553
@Column(name = "created")
4654
@Temporal(value = TemporalType.TIMESTAMP)
@@ -57,7 +65,7 @@ public UsageLoadBalancerPolicyVO(long id, long zoneId, long accountId, long doma
5765
this.zoneId = zoneId;
5866
this.accountId = accountId;
5967
this.domainId = domainId;
60-
this.id = id;
68+
this.lbId = id;
6169
this.created = created;
6270
this.deleted = deleted;
6371
}
@@ -90,4 +98,8 @@ public Date getDeleted() {
9098
public void setDeleted(Date deleted) {
9199
this.deleted = deleted;
92100
}
101+
102+
public long getLbId() {
103+
return lbId;
104+
}
93105
}

engine/schema/src/main/java/com/cloud/usage/UsageNetworkOfferingVO.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,27 @@
1616
// under the License.
1717
package com.cloud.usage;
1818

19+
import org.apache.cloudstack.api.InternalIdentity;
20+
1921
import java.util.Date;
2022

2123
import javax.persistence.Column;
2224
import javax.persistence.Entity;
25+
import javax.persistence.GeneratedValue;
26+
import javax.persistence.GenerationType;
27+
import javax.persistence.Id;
2328
import javax.persistence.Table;
2429
import javax.persistence.Temporal;
2530
import javax.persistence.TemporalType;
2631

2732
@Entity
2833
@Table(name = "usage_network_offering")
29-
public class UsageNetworkOfferingVO {
34+
public class UsageNetworkOfferingVO implements InternalIdentity {
35+
36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
@Column(name = "id")
39+
private Long id;
3040

3141
@Column(name = "zone_id")
3242
private long zoneId;
@@ -116,4 +126,9 @@ public Long getNicId() {
116126
public void setNicId(Long nicId) {
117127
this.nicId = nicId;
118128
}
129+
130+
@Override
131+
public long getId() {
132+
return this.id;
133+
}
119134
}

engine/schema/src/main/java/com/cloud/usage/UsagePortForwardingRuleVO.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import javax.persistence.Column;
2222
import javax.persistence.Entity;
23+
import javax.persistence.GeneratedValue;
24+
import javax.persistence.GenerationType;
25+
import javax.persistence.Id;
2326
import javax.persistence.Table;
2427
import javax.persistence.Temporal;
2528
import javax.persistence.TemporalType;
@@ -30,6 +33,11 @@
3033
@Table(name = "usage_port_forwarding")
3134
public class UsagePortForwardingRuleVO implements InternalIdentity {
3235

36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
@Column(name = "id")
39+
private Long id;
40+
3341
@Column(name = "zone_id")
3442
private long zoneId;
3543

@@ -39,8 +47,8 @@ public class UsagePortForwardingRuleVO implements InternalIdentity {
3947
@Column(name = "domain_id")
4048
private long domainId;
4149

42-
@Column(name = "id")
43-
private long id;
50+
@Column(name = "pf_id")
51+
private long pfId;
4452

4553
@Column(name = "created")
4654
@Temporal(value = TemporalType.TIMESTAMP)
@@ -57,7 +65,7 @@ public UsagePortForwardingRuleVO(long id, long zoneId, long accountId, long doma
5765
this.zoneId = zoneId;
5866
this.accountId = accountId;
5967
this.domainId = domainId;
60-
this.id = id;
68+
this.pfId = id;
6169
this.created = created;
6270
this.deleted = deleted;
6371
}
@@ -90,4 +98,8 @@ public Date getDeleted() {
9098
public void setDeleted(Date deleted) {
9199
this.deleted = deleted;
92100
}
101+
102+
public long getPfId() {
103+
return pfId;
104+
}
93105
}

engine/schema/src/main/java/com/cloud/usage/UsageSecurityGroupVO.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,27 @@
1616
// under the License.
1717
package com.cloud.usage;
1818

19+
import org.apache.cloudstack.api.InternalIdentity;
20+
1921
import java.util.Date;
2022

2123
import javax.persistence.Column;
2224
import javax.persistence.Entity;
25+
import javax.persistence.GeneratedValue;
26+
import javax.persistence.GenerationType;
27+
import javax.persistence.Id;
2328
import javax.persistence.Table;
2429
import javax.persistence.Temporal;
2530
import javax.persistence.TemporalType;
2631

2732
@Entity
2833
@Table(name = "usage_security_group")
29-
public class UsageSecurityGroupVO {
34+
public class UsageSecurityGroupVO implements InternalIdentity {
35+
36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
@Column(name = "id")
39+
private Long id;
3040

3141
@Column(name = "zone_id")
3242
private long zoneId;
@@ -95,4 +105,9 @@ public Date getDeleted() {
95105
public void setDeleted(Date deleted) {
96106
this.deleted = deleted;
97107
}
108+
109+
@Override
110+
public long getId() {
111+
return this.id;
112+
}
98113
}

engine/schema/src/main/java/com/cloud/usage/UsageSnapshotOnPrimaryVO.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import javax.persistence.Column;
2222
import javax.persistence.Entity;
23+
import javax.persistence.GeneratedValue;
24+
import javax.persistence.GenerationType;
25+
import javax.persistence.Id;
2326
import javax.persistence.Table;
2427
import javax.persistence.Temporal;
2528
import javax.persistence.TemporalType;
@@ -30,9 +33,13 @@
3033
@Table(name = "usage_snapshot_on_primary")
3134
public class UsageSnapshotOnPrimaryVO implements InternalIdentity {
3235

36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
3338
@Column(name = "id")
34-
// volumeId
35-
private long id;
39+
private Long id;
40+
41+
@Column(name = "volume_id")
42+
private long volumeId;
3643

3744
@Column(name = "zone_id")
3845
private long zoneId;
@@ -73,7 +80,7 @@ protected UsageSnapshotOnPrimaryVO() {
7380
}
7481

7582
public UsageSnapshotOnPrimaryVO(long id, long zoneId, long accountId, long domainId, long vmId, String name, int type, long virtualSize, long physicalSize, Date created, Date deleted) {
76-
this.id = id;
83+
this.volumeId = id;
7784
this.zoneId = zoneId;
7885
this.accountId = accountId;
7986
this.domainId = domainId;
@@ -153,4 +160,7 @@ public String toString() {
153160
+ ", snapshotType=" + snapshotType + ", physicalSize=" + physicalSize + ", created=" + created + ", deleted=" + deleted + ", virtualSize=" + virtualSize + ", vmSnapshotId=" + vmSnapshotId + "]";
154161
}
155162

163+
public long getVolumeId() {
164+
return volumeId;
165+
}
156166
}

engine/schema/src/main/java/com/cloud/usage/UsageStorageVO.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
import javax.persistence.Column;
2222
import javax.persistence.Entity;
23+
import javax.persistence.GeneratedValue;
24+
import javax.persistence.GenerationType;
25+
import javax.persistence.Id;
2326
import javax.persistence.Table;
2427
import javax.persistence.Temporal;
2528
import javax.persistence.TemporalType;
@@ -30,6 +33,11 @@
3033
@Table(name = "usage_storage")
3134
public class UsageStorageVO implements InternalIdentity {
3235

36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
@Column(name = "id")
39+
private Long id;
40+
3341
@Column(name = "zone_id")
3442
private long zoneId;
3543

@@ -39,8 +47,8 @@ public class UsageStorageVO implements InternalIdentity {
3947
@Column(name = "domain_id")
4048
private long domainId;
4149

42-
@Column(name = "id")
43-
private long id;
50+
@Column(name = "entity_id")
51+
private long entityId;
4452

4553
@Column(name = "storage_type")
4654
private int storageType;
@@ -69,7 +77,7 @@ public UsageStorageVO(long id, long zoneId, long accountId, long domainId, int s
6977
this.zoneId = zoneId;
7078
this.accountId = accountId;
7179
this.domainId = domainId;
72-
this.id = id;
80+
this.entityId = id;
7381
this.storageType = storageType;
7482
this.sourceId = sourceId;
7583
this.size = size;
@@ -81,7 +89,7 @@ public UsageStorageVO(long id, long zoneId, long accountId, long domainId, int s
8189
this.zoneId = zoneId;
8290
this.accountId = accountId;
8391
this.domainId = domainId;
84-
this.id = id;
92+
this.entityId = id;
8593
this.storageType = storageType;
8694
this.sourceId = sourceId;
8795
this.size = size;
@@ -134,4 +142,8 @@ public Date getDeleted() {
134142
public void setDeleted(Date deleted) {
135143
this.deleted = deleted;
136144
}
145+
146+
public long getEntityId() {
147+
return entityId;
148+
}
137149
}

engine/schema/src/main/java/com/cloud/usage/UsageVMInstanceVO.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,27 @@
1616
// under the License.
1717
package com.cloud.usage;
1818

19+
import org.apache.cloudstack.api.InternalIdentity;
20+
1921
import java.util.Date;
2022

2123
import javax.persistence.Column;
2224
import javax.persistence.Entity;
25+
import javax.persistence.GeneratedValue;
26+
import javax.persistence.GenerationType;
27+
import javax.persistence.Id;
2328
import javax.persistence.Table;
2429
import javax.persistence.Temporal;
2530
import javax.persistence.TemporalType;
2631

2732
@Entity
2833
@Table(name = "usage_vm_instance")
29-
public class UsageVMInstanceVO {
34+
public class UsageVMInstanceVO implements InternalIdentity {
35+
36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
@Column(name = "id")
39+
private Long id;
3040

3141
@Column(name = "usage_type")
3242
private int usageType;
@@ -178,4 +188,9 @@ public Long getCpuSpeed() {
178188
public void setCpuSpeed(Long cpuSpeed) {
179189
this.cpuSpeed = cpuSpeed;
180190
}
191+
192+
@Override
193+
public long getId() {
194+
return this.id;
195+
}
181196
}

0 commit comments

Comments
 (0)