Skip to content

Commit fea9ca5

Browse files
committed
SWIFT : add listSwift api
1 parent 8c85d8f commit fea9ca5

7 files changed

Lines changed: 122 additions & 1 deletion

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.api.commands;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
24+
import org.apache.log4j.Logger;
25+
26+
import com.cloud.api.ApiConstants;
27+
import com.cloud.api.BaseCmd;
28+
import com.cloud.api.Implementation;
29+
import com.cloud.api.Parameter;
30+
import com.cloud.api.ServerApiException;
31+
import com.cloud.api.response.HostResponse;
32+
import com.cloud.api.response.ListResponse;
33+
import com.cloud.api.response.SwiftResponse;
34+
import com.cloud.storage.Swift;
35+
import com.cloud.user.Account;
36+
37+
@Implementation(description = "List Swift.", responseObject = HostResponse.class)
38+
public class ListSwiftCmd extends BaseCmd {
39+
public static final Logger s_logger = Logger.getLogger(ListSwiftCmd.class.getName());
40+
private static final String s_name = "ListSwiftresponse";
41+
42+
/////////////////////////////////////////////////////
43+
//////////////// API parameters /////////////////////
44+
/////////////////////////////////////////////////////
45+
46+
@Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "the id of the swift")
47+
private Long id;
48+
49+
/////////////////////////////////////////////////////
50+
/////////////// API Implementation///////////////////
51+
/////////////////////////////////////////////////////
52+
53+
public Long getId() {
54+
return id;
55+
}
56+
57+
58+
@Override
59+
public String getCommandName() {
60+
return s_name;
61+
}
62+
63+
@Override
64+
public long getEntityOwnerId() {
65+
return Account.ACCOUNT_ID_SYSTEM;
66+
}
67+
68+
@Override
69+
public void execute(){
70+
List<? extends Swift> result = _resourceService.listSwift(this);
71+
ListResponse<SwiftResponse> response = new ListResponse<SwiftResponse>();
72+
List<SwiftResponse> swiftResponses = new ArrayList<SwiftResponse>();
73+
74+
if (result != null) {
75+
SwiftResponse swiftResponse = null;
76+
for (Swift swift : result) {
77+
swiftResponse = _responseGenerator.createSwiftResponse(swift);
78+
swiftResponse.setResponseName(getCommandName());
79+
swiftResponse.setObjectName("swift");
80+
swiftResponses.add(swiftResponse);
81+
}
82+
response.setResponses(swiftResponses);
83+
response.setResponseName(getCommandName());
84+
this.setResponseObject(response);
85+
86+
} else {
87+
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Swift");
88+
}
89+
}
90+
}

api/src/com/cloud/resource/ResourceService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.cloud.api.commands.AddSwiftCmd;
2626
import com.cloud.api.commands.CancelMaintenanceCmd;
2727
import com.cloud.api.commands.DeleteClusterCmd;
28+
import com.cloud.api.commands.ListSwiftCmd;
2829
import com.cloud.api.commands.PrepareForMaintenanceCmd;
2930
import com.cloud.api.commands.ReconnectHostCmd;
3031
import com.cloud.api.commands.UpdateHostCmd;
@@ -92,4 +93,6 @@ public interface ResourceService {
9293
Swift discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException;
9394

9495
List<HypervisorType> getSupportedHypervisorTypes(long zoneId);
96+
97+
List<? extends Swift> listSwift(ListSwiftCmd cmd);
9598
}

client/tomcatconf/commands.properties.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ listCapacity=com.cloud.api.commands.ListCapacityCmd;3
181181

182182
#### swift commands^M
183183
addSwift=com.cloud.api.commands.AddSwiftCmd;1
184+
listSwift=com.cloud.api.commands.ListSwiftCmd;1
184185

185186

186187
#### host commands

server/src/com/cloud/configuration/Config.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public enum Config {
7878
CopyVolumeWait("Storage", StorageManager.class, Integer.class, "copy.volume.wait", "10800", "In second, timeout for copy volume command", null),
7979
CreatePrivateTemplateFromVolumeWait("Storage", UserVmManager.class, Integer.class, "create.private.template.from.volume.wait", "10800", "In second, timeout for CreatePrivateTemplateFromVolumeCommand", null),
8080
CreatePrivateTemplateFromSnapshotWait("Storage", UserVmManager.class, Integer.class, "create.private.template.from.snapshot.wait", "10800", "In second, timeout for CreatePrivateTemplateFromSnapshotCommand", null),
81-
BackupSnapshotWait("Storage", StorageManager.class, Integer.class, "backup.snapshot.wait", "10800", "In second, timeout for BackupSnapshotCommand", null),
81+
BackupSnapshotWait(
82+
"Storage", StorageManager.class, Integer.class, "backup.snapshot.wait", "21600", "In second, timeout for BackupSnapshotCommand", null),
8283

8384
// Network
8485
NetworkLBHaproxyStatsVisbility("Network", ManagementServer.class, String.class, "network.loadbalancer.haproxy.stats.visibility", "global", "Load Balancer(haproxy) stats visibilty, the value can be one of the following six parameters : global,guest-network,link-local,disabled,all,default", null),

server/src/com/cloud/resource/ResourceManagerImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.cloud.api.commands.AddSwiftCmd;
5555
import com.cloud.api.commands.CancelMaintenanceCmd;
5656
import com.cloud.api.commands.DeleteClusterCmd;
57+
import com.cloud.api.commands.ListSwiftCmd;
5758
import com.cloud.api.commands.PrepareForMaintenanceCmd;
5859
import com.cloud.api.commands.ReconnectHostCmd;
5960
import com.cloud.api.commands.UpdateHostCmd;
@@ -107,6 +108,7 @@
107108
import com.cloud.storage.StoragePoolVO;
108109
import com.cloud.storage.StorageService;
109110
import com.cloud.storage.Swift;
111+
import com.cloud.storage.SwiftVO;
110112
import com.cloud.storage.dao.GuestOSCategoryDao;
111113
import com.cloud.storage.dao.StoragePoolDao;
112114
import com.cloud.storage.dao.StoragePoolHostDao;
@@ -515,6 +517,11 @@ public Swift discoverSwift(AddSwiftCmd cmd) throws DiscoveryException {
515517
return _swiftMgr.addSwift(cmd);
516518
}
517519

520+
@Override
521+
public List<SwiftVO> listSwift(ListSwiftCmd cmd) {
522+
return _swiftMgr.listSwift(cmd);
523+
}
524+
518525
private List<HostVO> discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List<String> hostTags,
519526
Map<String, String> params) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
520527
URI uri = null;

server/src/com/cloud/storage/swift/SwiftManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424

2525
package com.cloud.storage.swift;
2626

27+
import java.util.List;
28+
2729
import com.cloud.agent.api.to.SwiftTO;
2830
import com.cloud.api.commands.AddSwiftCmd;
2931
import com.cloud.api.commands.DeleteIsoCmd;
3032
import com.cloud.api.commands.DeleteTemplateCmd;
33+
import com.cloud.api.commands.ListSwiftCmd;
3134
import com.cloud.exception.DiscoveryException;
3235
import com.cloud.storage.Swift;
36+
import com.cloud.storage.SwiftVO;
3337
import com.cloud.utils.component.Manager;
3438
public interface SwiftManager extends Manager {
3539

@@ -52,4 +56,6 @@ public interface SwiftManager extends Manager {
5256
void propagateSwiftTmplteOnZone(Long zoneId);
5357

5458
Long chooseZoneForTmpltExtract(Long tmpltId);
59+
60+
List<SwiftVO> listSwift(ListSwiftCmd cmd);
5561
}

server/src/com/cloud/storage/swift/SwiftManagerImpl.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.cloud.api.commands.AddSwiftCmd;
4343
import com.cloud.api.commands.DeleteIsoCmd;
4444
import com.cloud.api.commands.DeleteTemplateCmd;
45+
import com.cloud.api.commands.ListSwiftCmd;
4546
import com.cloud.configuration.Config;
4647
import com.cloud.configuration.dao.ConfigurationDao;
4748
import com.cloud.dc.DataCenterVO;
@@ -264,6 +265,18 @@ public Long chooseZoneForTmpltExtract(Long tmpltId) {
264265
return dcs.get(0).getId();
265266
}
266267

268+
@Override
269+
public List<SwiftVO> listSwift(ListSwiftCmd cmd) {
270+
if (cmd.getId() == null) {
271+
return _swiftDao.listAll();
272+
} else {
273+
List<SwiftVO> list = new ArrayList<SwiftVO>();
274+
SwiftVO swift = _swiftDao.findById(cmd.getId());
275+
list.add(swift);
276+
return list;
277+
}
278+
}
279+
267280

268281
@Override
269282
public boolean stop() {

0 commit comments

Comments
 (0)