Skip to content

Commit b0ce8fd

Browse files
minchen07yadvr
authored andcommitted
api: Optimize and improve api, db call perfomance
This is part 1 of list API refactoring. Commands covered: listVmsCmd, listRoutersCmd Response covered: UserVmResponse, DomainRouterResponse. DB views created: user_vm_view, domain_router_view. Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
1 parent c59de6c commit b0ce8fd

35 files changed

Lines changed: 4394 additions & 751 deletions

api/src/com/cloud/api/response/BaseResponse.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,26 @@ public void setObjectName(String objectName) {
4646
this.objectName = objectName;
4747
}
4848

49+
//TODO: TO be replaced by getObjectUuid() after all response refactoring
4950
public Long getObjectId() {
5051
return null;
5152
}
5253

54+
public String getObjectUuid(){
55+
return null;
56+
}
57+
5358
// For use by list commands with pending async jobs
54-
@SerializedName(ApiConstants.JOB_ID) @Param(description="the ID of the latest async job acting on this object")
59+
//TODO: To be replaced by jobUuid after all response refactoring
5560
protected IdentityProxy jobId = new IdentityProxy("async_job");
5661

62+
@SerializedName(ApiConstants.JOB_ID) @Param(description="the UUID of the latest async job acting on this object")
63+
protected String jobUuid;
64+
5765
@SerializedName(ApiConstants.JOB_STATUS) @Param(description="the current status of the latest async job acting on this object")
5866
private Integer jobStatus;
5967

68+
//TODO: TO be replaced by getter and setters for jobUuid.
6069
public Long getJobId() {
6170
return jobId.getValue();
6271
}
@@ -65,6 +74,14 @@ public void setJobId(Long jobId) {
6574
this.jobId.setValue(jobId);
6675
}
6776

77+
public String getJobUuid() {
78+
return jobUuid;
79+
}
80+
81+
public void setJobUuid(String jobUuid) {
82+
this.jobUuid = jobUuid;
83+
}
84+
6885
public Integer getJobStatus() {
6986
return jobStatus;
7087
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.api.response;
18+
19+
public interface ControlledViewEntityResponse {
20+
21+
public void setAccountName(String accountName);
22+
23+
public void setProjectId(String projectId);
24+
25+
public void setProjectName(String projectName);
26+
27+
public void setDomainId(String domainId);
28+
29+
public void setDomainName(String domainName);
30+
}
31+

api/src/com/cloud/api/response/DomainRouterResponse.java

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
import java.util.Date;
2020
import java.util.List;
21+
import java.util.HashSet;
22+
import java.util.Set;
23+
2124

2225
import org.apache.cloudstack.api.ApiConstants;
2326
import com.cloud.serializer.Param;
@@ -26,12 +29,12 @@
2629
import com.google.gson.annotations.SerializedName;
2730

2831
@SuppressWarnings("unused")
29-
public class DomainRouterResponse extends BaseResponse implements ControlledEntityResponse{
32+
public class DomainRouterResponse extends BaseResponse implements ControlledViewEntityResponse{
3033
@SerializedName(ApiConstants.ID) @Param(description="the id of the router")
31-
private IdentityProxy id = new IdentityProxy("vm_instance");
34+
private String id;
3235

3336
@SerializedName(ApiConstants.ZONE_ID) @Param(description="the Zone ID for the router")
34-
private IdentityProxy zoneId = new IdentityProxy("data_center");
37+
private String zoneId;
3538

3639
@SerializedName(ApiConstants.ZONE_NAME) @Param(description="the Zone name for the router")
3740
private String zoneName;
@@ -52,10 +55,10 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti
5255
private String name;
5356

5457
@SerializedName(ApiConstants.POD_ID) @Param(description="the Pod ID for the router")
55-
private IdentityProxy podId = new IdentityProxy("host_pod_ref");
58+
private String podId;
5659

5760
@SerializedName(ApiConstants.HOST_ID) @Param(description="the host ID for the router")
58-
private IdentityProxy hostId = new IdentityProxy("host");
61+
private String hostId;
5962

6063
@SerializedName("hostname") @Param(description="the hostname for the router")
6164
private String hostName;
@@ -70,7 +73,7 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti
7073
private String linkLocalNetmask;
7174

7275
@SerializedName(ApiConstants.LINK_LOCAL_NETWORK_ID) @Param(description="the ID of the corresponding link local network")
73-
private IdentityProxy linkLocalNetworkId = new IdentityProxy("networks");
76+
private String linkLocalNetworkId;
7477

7578
@SerializedName(ApiConstants.PUBLIC_IP) @Param(description="the public IP address for the router")
7679
private String publicIp;
@@ -82,7 +85,7 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti
8285
private String publicNetmask;
8386

8487
@SerializedName("publicnetworkid") @Param(description="the ID of the corresponding public network")
85-
private IdentityProxy publicNetworkId = new IdentityProxy("networks");
88+
private String publicNetworkId;
8689

8790
@SerializedName("guestipaddress") @Param(description="the guest IP address for the router")
8891
private String guestIpAddress;
@@ -94,10 +97,10 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti
9497
private String guestNetmask;
9598

9699
@SerializedName("guestnetworkid") @Param(description="the ID of the corresponding guest network")
97-
private IdentityProxy guestNetworkId = new IdentityProxy("networks");
100+
private String guestNetworkId;
98101

99102
@SerializedName(ApiConstants.TEMPLATE_ID) @Param(description="the template ID for the router")
100-
private IdentityProxy templateId = new IdentityProxy("vm_template");
103+
private String templateId;
101104

102105
@SerializedName(ApiConstants.CREATED) @Param(description="the date and time the router was created")
103106
private Date created;
@@ -109,19 +112,19 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti
109112
private String accountName;
110113

111114
@SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the ipaddress")
112-
private IdentityProxy projectId = new IdentityProxy("projects");
115+
private String projectId;
113116

114117
@SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the address")
115118
private String projectName;
116119

117120
@SerializedName(ApiConstants.DOMAIN_ID) @Param(description="the domain ID associated with the router")
118-
private IdentityProxy domainId = new IdentityProxy("domain");
121+
private String domainId;
119122

120123
@SerializedName(ApiConstants.DOMAIN) @Param(description="the domain associated with the router")
121124
private String domainName;
122125

123126
@SerializedName(ApiConstants.SERVICE_OFFERING_ID) @Param(description="the ID of the service offering of the virtual machine")
124-
private IdentityProxy serviceOfferingId = new IdentityProxy("disk_offering");
127+
private String serviceOfferingId;
125128

126129
@SerializedName("serviceofferingname") @Param(description="the name of the service offering of the virtual machine")
127130
private String serviceOfferingName;
@@ -139,27 +142,31 @@ public class DomainRouterResponse extends BaseResponse implements ControlledEnti
139142
private String scriptsVersion;
140143

141144
@SerializedName(ApiConstants.VPC_ID) @Param(description="VPC the network belongs to")
142-
private IdentityProxy vpcId = new IdentityProxy("vpc");
145+
private String vpcId;
143146

144147
@SerializedName("nic") @Param(description="the list of nics associated with the router",
145148
responseObject = NicResponse.class, since="4.0")
146-
private List<NicResponse> nics;
149+
private Set<NicResponse> nics;
150+
151+
public DomainRouterResponse(){
152+
nics = new HashSet<NicResponse>();
153+
}
147154

148155
@Override
149-
public Long getObjectId() {
150-
return getId();
156+
public String getObjectUuid() {
157+
return this.getId();
151158
}
152159

153-
public Long getId() {
154-
return id.getValue();
160+
public String getId() {
161+
return id;
155162
}
156163

157-
public void setId(Long id) {
158-
this.id.setValue(id);
164+
public void setId(String id) {
165+
this.id = id;
159166
}
160167

161-
public void setZoneId(Long zoneId) {
162-
this.zoneId.setValue(zoneId);
168+
public void setZoneId(String zoneId) {
169+
this.zoneId = zoneId;
163170
}
164171

165172
public void setZoneName(String zoneName) {
@@ -186,12 +193,12 @@ public void setName(String name) {
186193
this.name = name;
187194
}
188195

189-
public void setPodId(Long podId) {
190-
this.podId.setValue(podId);
196+
public void setPodId(String podId) {
197+
this.podId = podId;
191198
}
192199

193-
public void setHostId(Long hostId) {
194-
this.hostId.setValue(hostId);
200+
public void setHostId(String hostId) {
201+
this.hostId = hostId;
195202
}
196203

197204
public void setHostName(String hostName) {
@@ -222,8 +229,8 @@ public void setGuestNetmask(String guestNetmask) {
222229
this.guestNetmask = guestNetmask;
223230
}
224231

225-
public void setTemplateId(Long templateId) {
226-
this.templateId.setValue(templateId);
232+
public void setTemplateId(String templateId) {
233+
this.templateId = templateId;
227234
}
228235

229236
public void setCreated(Date created) {
@@ -240,21 +247,21 @@ public void setAccountName(String accountName) {
240247
}
241248

242249
@Override
243-
public void setDomainId(Long domainId) {
244-
this.domainId.setValue(domainId);
250+
public void setDomainId(String domainId) {
251+
this.domainId = domainId;
245252
}
246253

247254
@Override
248255
public void setDomainName(String domainName) {
249256
this.domainName = domainName;
250257
}
251258

252-
public void setPublicNetworkId(Long publicNetworkId) {
253-
this.publicNetworkId.setValue(publicNetworkId);
259+
public void setPublicNetworkId(String publicNetworkId) {
260+
this.publicNetworkId = publicNetworkId;
254261
}
255262

256-
public void setGuestNetworkId(Long guestNetworkId) {
257-
this.guestNetworkId.setValue(guestNetworkId);
263+
public void setGuestNetworkId(String guestNetworkId) {
264+
this.guestNetworkId = guestNetworkId;
258265
}
259266

260267
public void setLinkLocalIp(String linkLocalIp) {
@@ -269,12 +276,12 @@ public void setLinkLocalNetmask(String linkLocalNetmask) {
269276
this.linkLocalNetmask = linkLocalNetmask;
270277
}
271278

272-
public void setLinkLocalNetworkId(Long linkLocalNetworkId) {
273-
this.linkLocalNetworkId.setValue(linkLocalNetworkId);
279+
public void setLinkLocalNetworkId(String linkLocalNetworkId) {
280+
this.linkLocalNetworkId = linkLocalNetworkId;
274281
}
275282

276-
public void setServiceOfferingId(Long serviceOfferingId) {
277-
this.serviceOfferingId.setValue(serviceOfferingId);
283+
public void setServiceOfferingId(String serviceOfferingId) {
284+
this.serviceOfferingId = serviceOfferingId;
278285
}
279286

280287
public void setServiceOfferingName(String serviceOfferingName) {
@@ -305,20 +312,24 @@ public void setScriptsVersion(String scriptsVersion) {
305312
this.scriptsVersion = scriptsVersion;
306313
}
307314
@Override
308-
public void setProjectId(Long projectId) {
309-
this.projectId.setValue(projectId);
315+
public void setProjectId(String projectId) {
316+
this.projectId = projectId;
310317
}
311318

312319
@Override
313320
public void setProjectName(String projectName) {
314321
this.projectName = projectName;
315322
}
316323

317-
public void setVpcId(Long vpcId) {
318-
this.vpcId.setValue(vpcId);
324+
public void setVpcId(String vpcId) {
325+
this.vpcId = vpcId;
319326
}
320327

321-
public void setNics(List<NicResponse> nics) {
328+
public void setNics(Set<NicResponse> nics) {
322329
this.nics = nics;
323330
}
331+
332+
public void addNic(NicResponse nic) {
333+
this.nics.add(nic);
334+
}
324335
}

api/src/com/cloud/api/response/NicResponse.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717
package com.cloud.api.response;
1818

1919
import org.apache.cloudstack.api.ApiConstants;
20-
import com.cloud.utils.IdentityProxy;
2120
import com.cloud.serializer.Param;
2221
import com.google.gson.annotations.SerializedName;
2322

2423
@SuppressWarnings("unused")
2524
public class NicResponse extends BaseResponse {
2625

2726
@SerializedName("id") @Param(description="the ID of the nic")
28-
private final IdentityProxy id = new IdentityProxy("nics");
27+
private String id;
2928

3029
@SerializedName("networkid") @Param(description="the ID of the corresponding network")
31-
private final IdentityProxy networkId = new IdentityProxy("networks");
30+
private String networkId;
3231

3332
@SerializedName("networkname") @Param(description="the name of the corresponding network")
3433
private String networkName ;
@@ -60,16 +59,21 @@ public class NicResponse extends BaseResponse {
6059
@SerializedName("macaddress") @Param(description="true if nic is default, false otherwise")
6160
private String macAddress;
6261

63-
public Long getId() {
64-
return id.getValue();
62+
public String getId() {
63+
return id;
6564
}
6665

67-
public void setId(Long id) {
68-
this.id.setValue(id);
66+
public void setId(String id) {
67+
this.id = id;
6968
}
7069

71-
public void setNetworkid(Long networkid) {
72-
this.networkId.setValue(networkid);
70+
@Override
71+
public String getObjectUuid() {
72+
return this.getId();
73+
}
74+
75+
public void setNetworkid(String networkid) {
76+
this.networkId = networkid;
7377
}
7478

7579
public void setNetworkName(String networkname) {
@@ -116,7 +120,8 @@ public void setMacAddress(String macAddress) {
116120
public int hashCode() {
117121
final int prime = 31;
118122
int result = 1;
119-
result = prime * result + ((id == null) ? 0 : id.hashCode());
123+
String oid = this.getId();
124+
result = prime * result + ((oid== null) ? 0 : oid.hashCode());
120125
return result;
121126
}
122127

@@ -129,10 +134,11 @@ public boolean equals(Object obj) {
129134
if (getClass() != obj.getClass())
130135
return false;
131136
NicResponse other = (NicResponse) obj;
132-
if (id == null) {
133-
if (other.id != null)
137+
String oid = this.getId();
138+
if (oid == null) {
139+
if (other.getId() != null)
134140
return false;
135-
} else if (!id.equals(other.id))
141+
} else if (!oid.equals(other.getId()))
136142
return false;
137143
return true;
138144
}

0 commit comments

Comments
 (0)