Skip to content

Commit 7699485

Browse files
committed
Create DB view for Image Data Store.
1 parent 86a3840 commit 7699485

12 files changed

Lines changed: 729 additions & 21 deletions

File tree

‎api/src/org/apache/cloudstack/api/response/ObjectStoreDetailResponse.java‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public class ObjectStoreDetailResponse extends BaseResponse {
2828
@SerializedName("value") @Param(description="detail property value of the object store")
2929
private String value;
3030

31+
public ObjectStoreDetailResponse(){
32+
super();
33+
}
34+
35+
public ObjectStoreDetailResponse(String name, String val){
36+
super();
37+
this.name = name;
38+
this.value = val;
39+
}
40+
3141
public String getName() {
3242
return name;
3343
}
@@ -44,5 +54,33 @@ public void setValue(String value) {
4454
this.value = value;
4555
}
4656

57+
@Override
58+
public int hashCode() {
59+
final int prime = 31;
60+
int result = 1;
61+
String oid = this.getName();
62+
result = prime * result + ((oid== null) ? 0 : oid.hashCode());
63+
return result;
64+
}
65+
66+
@Override
67+
public boolean equals(Object obj) {
68+
if (this == obj)
69+
return true;
70+
if (obj == null)
71+
return false;
72+
if (getClass() != obj.getClass())
73+
return false;
74+
ObjectStoreDetailResponse other = (ObjectStoreDetailResponse) obj;
75+
String oid = this.getName();
76+
if (oid == null) {
77+
if (other.getName() != null)
78+
return false;
79+
} else if (!oid.equals(other.getName()))
80+
return false;
81+
else if ( this.getValue().equals(other.getValue()))
82+
return false;
83+
return true;
84+
}
4785

4886
}

‎api/src/org/apache/cloudstack/api/response/ObjectStoreResponse.java‎

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19-
import java.util.Date;
20-
21-
import javax.persistence.Column;
19+
import java.util.LinkedHashSet;
20+
import java.util.Set;
2221

2322
import org.apache.cloudstack.api.ApiConstants;
2423
import org.apache.cloudstack.api.BaseResponse;
@@ -27,8 +26,6 @@
2726
import com.cloud.serializer.Param;
2827
import com.cloud.storage.ObjectStore;
2928
import com.cloud.storage.ScopeType;
30-
import com.cloud.storage.StoragePool;
31-
import com.cloud.storage.StoragePoolStatus;
3229
import com.google.gson.annotations.SerializedName;
3330

3431
@EntityReference(value=ObjectStore.class)
@@ -43,7 +40,7 @@ public class ObjectStoreResponse extends BaseResponse {
4340
private String zoneName;
4441

4542
@SerializedName("regionid") @Param(description="the Region ID of the object store")
46-
private String regionId;
43+
private Long regionId;
4744

4845
@SerializedName("regionname") @Param(description="the Region name of the object store")
4946
private String regionName;
@@ -54,16 +51,22 @@ public class ObjectStoreResponse extends BaseResponse {
5451
@SerializedName("url") @Param(description="the url of the object store")
5552
private String url;
5653

54+
@SerializedName("protocol") @Param(description="the protocol of the object store")
55+
private String protocol;
56+
5757
@SerializedName("providername") @Param(description="the provider name of the object store")
5858
private String providerName;
5959

6060
@SerializedName("scope") @Param(description="the scope of the object store")
61-
private ScopeType type;
61+
private ScopeType scope;
6262

6363
@SerializedName("details") @Param(description="the details of the object store")
64-
private String details;
64+
private Set<ObjectStoreDetailResponse> details;
6565

6666

67+
public ObjectStoreResponse(){
68+
this.details = new LinkedHashSet<ObjectStoreDetailResponse>();
69+
}
6770

6871
@Override
6972
public String getObjectId() {
@@ -95,11 +98,11 @@ public void setZoneName(String zoneName) {
9598
}
9699

97100

98-
public String getRegionId() {
101+
public Long getRegionId() {
99102
return regionId;
100103
}
101104

102-
public void setRegionId(String regionId) {
105+
public void setRegionId(Long regionId) {
103106
this.regionId = regionId;
104107
}
105108

@@ -135,22 +138,35 @@ public void setProviderName(String providerName) {
135138
this.providerName = providerName;
136139
}
137140

138-
public ScopeType getType() {
139-
return type;
141+
public ScopeType getScope() {
142+
return scope;
143+
}
144+
145+
public void setScope(ScopeType type) {
146+
this.scope = type;
140147
}
141148

142-
public void setType(ScopeType type) {
143-
this.type = type;
149+
150+
public String getProtocol() {
151+
return protocol;
152+
}
153+
154+
public void setProtocol(String protocol) {
155+
this.protocol = protocol;
144156
}
145157

146-
public String getDetails() {
158+
public Set<ObjectStoreDetailResponse> getDetails() {
147159
return details;
148160
}
149161

150-
public void setDetails(String details) {
162+
public void setDetails(Set<ObjectStoreDetailResponse> details) {
151163
this.details = details;
152164
}
153165

166+
public void addDetail(ObjectStoreDetailResponse detail){
167+
this.details.add(detail);
168+
}
169+
154170

155171

156172
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 org.apache.cloudstack.storage.datastore.db;
18+
19+
import org.apache.cloudstack.api.InternalIdentity;
20+
21+
import javax.persistence.Column;
22+
import javax.persistence.Entity;
23+
import javax.persistence.GeneratedValue;
24+
import javax.persistence.GenerationType;
25+
import javax.persistence.Id;
26+
import javax.persistence.Table;
27+
28+
@Entity
29+
@Table(name="image_data_store_details")
30+
public class ImageDataStoreDetailVO implements InternalIdentity {
31+
@Id
32+
@GeneratedValue(strategy=GenerationType.IDENTITY)
33+
@Column(name="id")
34+
long id;
35+
36+
@Column(name="store_id")
37+
long storeId;
38+
39+
@Column(name="name")
40+
String name;
41+
42+
@Column(name="value")
43+
String value;
44+
45+
public ImageDataStoreDetailVO(long storeId, String name, String value) {
46+
this.storeId = storeId;
47+
this.name = name;
48+
this.value = value;
49+
}
50+
51+
public long getId() {
52+
return id;
53+
}
54+
55+
public long getStoreId() {
56+
return storeId;
57+
}
58+
59+
public void setStoreId(long storeId) {
60+
this.storeId = storeId;
61+
}
62+
63+
public String getName() {
64+
return name;
65+
}
66+
67+
public void setName(String name) {
68+
this.name = name;
69+
}
70+
71+
public String getValue() {
72+
return value;
73+
}
74+
75+
public void setValue(String value) {
76+
this.value = value;
77+
}
78+
79+
protected ImageDataStoreDetailVO() {
80+
}
81+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 org.apache.cloudstack.storage.datastore.db;
18+
19+
import java.util.Map;
20+
21+
22+
import com.cloud.utils.db.GenericDao;
23+
24+
public interface ImageDataStoreDetailsDao extends GenericDao<ImageDataStoreDetailVO, Long> {
25+
26+
void update(long storeId, Map<String, String> details);
27+
Map<String, String> getDetails(long storeId);
28+
}

‎server/src/com/cloud/api/ApiDBUtils.java‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.apache.cloudstack.api.response.EventResponse;
3535
import org.apache.cloudstack.api.response.HostResponse;
3636
import org.apache.cloudstack.api.response.InstanceGroupResponse;
37+
import org.apache.cloudstack.api.response.ObjectStoreResponse;
3738
import org.apache.cloudstack.api.response.ProjectAccountResponse;
3839
import org.apache.cloudstack.api.response.ProjectInvitationResponse;
3940
import org.apache.cloudstack.api.response.ProjectResponse;
@@ -55,6 +56,7 @@
5556
import com.cloud.api.query.dao.DiskOfferingJoinDao;
5657
import com.cloud.api.query.dao.DomainRouterJoinDao;
5758
import com.cloud.api.query.dao.HostJoinDao;
59+
import com.cloud.api.query.dao.ImageDataStoreJoinDao;
5860
import com.cloud.api.query.dao.InstanceGroupJoinDao;
5961
import com.cloud.api.query.dao.ProjectAccountJoinDao;
6062
import com.cloud.api.query.dao.ProjectInvitationJoinDao;
@@ -73,6 +75,7 @@
7375
import com.cloud.api.query.vo.DomainRouterJoinVO;
7476
import com.cloud.api.query.vo.EventJoinVO;
7577
import com.cloud.api.query.vo.HostJoinVO;
78+
import com.cloud.api.query.vo.ImageDataStoreJoinVO;
7679
import com.cloud.api.query.vo.InstanceGroupJoinVO;
7780
import com.cloud.api.query.vo.ProjectAccountJoinVO;
7881
import com.cloud.api.query.vo.ProjectInvitationJoinVO;
@@ -284,7 +287,7 @@ public class ApiDBUtils {
284287
static NetworkModel _networkModel;
285288
static NetworkManager _networkMgr;
286289
static TemplateManager _templateMgr;
287-
290+
288291
static StatsCollector _statsCollector;
289292

290293
static AccountDao _accountDao;
@@ -362,6 +365,7 @@ public class ApiDBUtils {
362365
static HostJoinDao _hostJoinDao;
363366
static VolumeJoinDao _volJoinDao;
364367
static StoragePoolJoinDao _poolJoinDao;
368+
static ImageDataStoreJoinDao _imageStoreJoinDao;
365369
static AccountJoinDao _accountJoinDao;
366370
static AsyncJobJoinDao _jobJoinDao;
367371

@@ -466,6 +470,7 @@ public class ApiDBUtils {
466470
@Inject private HostJoinDao hostJoinDao;
467471
@Inject private VolumeJoinDao volJoinDao;
468472
@Inject private StoragePoolJoinDao poolJoinDao;
473+
@Inject private ImageDataStoreJoinDao imageStoreJoinDao;
469474
@Inject private AccountJoinDao accountJoinDao;
470475
@Inject private AsyncJobJoinDao jobJoinDao;
471476

@@ -566,6 +571,7 @@ void init() {
566571
_hostJoinDao = hostJoinDao;
567572
_volJoinDao = volJoinDao;
568573
_poolJoinDao = poolJoinDao;
574+
_imageStoreJoinDao = imageStoreJoinDao;
569575
_accountJoinDao = accountJoinDao;
570576
_jobJoinDao = jobJoinDao;
571577

@@ -1535,6 +1541,18 @@ public static List<StoragePoolJoinVO> newStoragePoolView(StoragePool vr){
15351541
return _poolJoinDao.newStoragePoolView(vr);
15361542
}
15371543

1544+
public static ObjectStoreResponse newImageStoreResponse(ImageDataStoreJoinVO vr) {
1545+
return _imageStoreJoinDao.newObjectStoreResponse(vr);
1546+
}
1547+
1548+
public static ObjectStoreResponse fillImageStoreDetails(ObjectStoreResponse vrData, ImageDataStoreJoinVO vr){
1549+
return _imageStoreJoinDao.setObjectStoreResponse(vrData, vr);
1550+
}
1551+
1552+
public static List<ImageDataStoreJoinVO> newImageStoreView(ObjectStore vr){
1553+
return _imageStoreJoinDao.newObjectStoreView(vr);
1554+
}
1555+
15381556

15391557
public static AccountResponse newAccountResponse(AccountJoinVO ve) {
15401558
return _accountJoinDao.newAccountResponse(ve);
@@ -1579,7 +1597,7 @@ public static ZoneResponse newDataCenterResponse(DataCenterJoinVO dc, Boolean sh
15791597
public static DataCenterJoinVO newDataCenterView(DataCenter dc){
15801598
return _dcJoinDao.newDataCenterView(dc);
15811599
}
1582-
1600+
15831601
public static Map<String, String> findHostDetailsById(long hostId){
15841602
return _hostDetailsDao.findDetails(hostId);
15851603
}

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
import com.cloud.api.query.vo.DomainRouterJoinVO;
143143
import com.cloud.api.query.vo.EventJoinVO;
144144
import com.cloud.api.query.vo.HostJoinVO;
145+
import com.cloud.api.query.vo.ImageDataStoreJoinVO;
145146
import com.cloud.api.query.vo.InstanceGroupJoinVO;
146147
import com.cloud.api.query.vo.ProjectAccountJoinVO;
147148
import com.cloud.api.query.vo.ProjectInvitationJoinVO;
@@ -892,8 +893,12 @@ public StoragePoolResponse createStoragePoolResponse(StoragePool pool) {
892893

893894
@Override
894895
public ObjectStoreResponse createObjectStoreResponse(ObjectStore os) {
895-
// TODO Auto-generated method stub
896-
return null;
896+
List<ImageDataStoreJoinVO> viewStores = ApiDBUtils.newImageStoreView(os);
897+
List<ObjectStoreResponse> listStores = ViewResponseHelper.createObjectStoreResponse(viewStores.toArray(new ImageDataStoreJoinVO[viewStores.size()]));
898+
assert listStores != null && listStores.size() == 1 : "There should be one image data store returned";
899+
return listStores.get(0);
900+
901+
897902
}
898903

899904

0 commit comments

Comments
 (0)