diff --git a/api/src/com/cloud/api/commands/ListSwiftCmd.java b/api/src/com/cloud/api/commands/ListSwiftCmd.java new file mode 100644 index 00000000000..9e8e6b3e141 --- /dev/null +++ b/api/src/com/cloud/api/commands/ListSwiftCmd.java @@ -0,0 +1,90 @@ +/** + * Copyright (C) 2010 Cloud.com, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +import com.cloud.api.Implementation; +import com.cloud.api.Parameter; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.HostResponse; +import com.cloud.api.response.ListResponse; +import com.cloud.api.response.SwiftResponse; +import com.cloud.storage.Swift; +import com.cloud.user.Account; + +@Implementation(description = "List Swift.", responseObject = HostResponse.class) +public class ListSwiftCmd extends BaseCmd { + public static final Logger s_logger = Logger.getLogger(ListSwiftCmd.class.getName()); + private static final String s_name = "ListSwiftresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.LONG, description = "the id of the swift") + private Long id; + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute(){ + List result = _resourceService.listSwift(this); + ListResponse response = new ListResponse(); + List swiftResponses = new ArrayList(); + + if (result != null) { + SwiftResponse swiftResponse = null; + for (Swift swift : result) { + swiftResponse = _responseGenerator.createSwiftResponse(swift); + swiftResponse.setResponseName(getCommandName()); + swiftResponse.setObjectName("swift"); + swiftResponses.add(swiftResponse); + } + response.setResponses(swiftResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Swift"); + } + } +} diff --git a/api/src/com/cloud/resource/ResourceService.java b/api/src/com/cloud/resource/ResourceService.java index ea8111d4b38..2235ebe5e3c 100755 --- a/api/src/com/cloud/resource/ResourceService.java +++ b/api/src/com/cloud/resource/ResourceService.java @@ -25,6 +25,7 @@ import com.cloud.api.commands.AddSecondaryStorageCmd; import com.cloud.api.commands.AddSwiftCmd; import com.cloud.api.commands.CancelMaintenanceCmd; import com.cloud.api.commands.DeleteClusterCmd; +import com.cloud.api.commands.ListSwiftCmd; import com.cloud.api.commands.PrepareForMaintenanceCmd; import com.cloud.api.commands.ReconnectHostCmd; import com.cloud.api.commands.UpdateHostCmd; @@ -92,4 +93,6 @@ public interface ResourceService { Swift discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException; List getSupportedHypervisorTypes(long zoneId); + + List listSwift(ListSwiftCmd cmd); } diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index 5f7a90b8fd5..bdf24a65f8b 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -181,6 +181,7 @@ listCapacity=com.cloud.api.commands.ListCapacityCmd;3 #### swift commands^M addSwift=com.cloud.api.commands.AddSwiftCmd;1 +listSwift=com.cloud.api.commands.ListSwiftCmd;1 #### host commands diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index 6d7fb2abf75..326a5faf664 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -78,7 +78,8 @@ public enum Config { CopyVolumeWait("Storage", StorageManager.class, Integer.class, "copy.volume.wait", "10800", "In second, timeout for copy volume command", null), CreatePrivateTemplateFromVolumeWait("Storage", UserVmManager.class, Integer.class, "create.private.template.from.volume.wait", "10800", "In second, timeout for CreatePrivateTemplateFromVolumeCommand", null), CreatePrivateTemplateFromSnapshotWait("Storage", UserVmManager.class, Integer.class, "create.private.template.from.snapshot.wait", "10800", "In second, timeout for CreatePrivateTemplateFromSnapshotCommand", null), - BackupSnapshotWait("Storage", StorageManager.class, Integer.class, "backup.snapshot.wait", "10800", "In second, timeout for BackupSnapshotCommand", null), + BackupSnapshotWait( + "Storage", StorageManager.class, Integer.class, "backup.snapshot.wait", "21600", "In second, timeout for BackupSnapshotCommand", null), // Network 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), diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java index 37f983b7f74..4db664e4b58 100755 --- a/server/src/com/cloud/resource/ResourceManagerImpl.java +++ b/server/src/com/cloud/resource/ResourceManagerImpl.java @@ -54,6 +54,7 @@ import com.cloud.api.commands.AddSecondaryStorageCmd; import com.cloud.api.commands.AddSwiftCmd; import com.cloud.api.commands.CancelMaintenanceCmd; import com.cloud.api.commands.DeleteClusterCmd; +import com.cloud.api.commands.ListSwiftCmd; import com.cloud.api.commands.PrepareForMaintenanceCmd; import com.cloud.api.commands.ReconnectHostCmd; import com.cloud.api.commands.UpdateHostCmd; @@ -107,6 +108,7 @@ import com.cloud.storage.StoragePoolStatus; import com.cloud.storage.StoragePoolVO; import com.cloud.storage.StorageService; import com.cloud.storage.Swift; +import com.cloud.storage.SwiftVO; import com.cloud.storage.dao.GuestOSCategoryDao; import com.cloud.storage.dao.StoragePoolDao; import com.cloud.storage.dao.StoragePoolHostDao; @@ -515,6 +517,11 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma return _swiftMgr.addSwift(cmd); } + @Override + public List listSwift(ListSwiftCmd cmd) { + return _swiftMgr.listSwift(cmd); + } + private List discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List hostTags, Map params) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException { URI uri = null; diff --git a/server/src/com/cloud/storage/swift/SwiftManager.java b/server/src/com/cloud/storage/swift/SwiftManager.java index 9240353440e..8875f7469e9 100644 --- a/server/src/com/cloud/storage/swift/SwiftManager.java +++ b/server/src/com/cloud/storage/swift/SwiftManager.java @@ -24,12 +24,16 @@ package com.cloud.storage.swift; +import java.util.List; + import com.cloud.agent.api.to.SwiftTO; import com.cloud.api.commands.AddSwiftCmd; import com.cloud.api.commands.DeleteIsoCmd; import com.cloud.api.commands.DeleteTemplateCmd; +import com.cloud.api.commands.ListSwiftCmd; import com.cloud.exception.DiscoveryException; import com.cloud.storage.Swift; +import com.cloud.storage.SwiftVO; import com.cloud.utils.component.Manager; public interface SwiftManager extends Manager { @@ -52,4 +56,6 @@ public interface SwiftManager extends Manager { void propagateSwiftTmplteOnZone(Long zoneId); Long chooseZoneForTmpltExtract(Long tmpltId); + + List listSwift(ListSwiftCmd cmd); } \ No newline at end of file diff --git a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java index eac79191cc5..125e262bf6d 100644 --- a/server/src/com/cloud/storage/swift/SwiftManagerImpl.java +++ b/server/src/com/cloud/storage/swift/SwiftManagerImpl.java @@ -42,6 +42,7 @@ import com.cloud.agent.api.to.SwiftTO; import com.cloud.api.commands.AddSwiftCmd; import com.cloud.api.commands.DeleteIsoCmd; import com.cloud.api.commands.DeleteTemplateCmd; +import com.cloud.api.commands.ListSwiftCmd; import com.cloud.configuration.Config; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.DataCenterVO; @@ -264,6 +265,18 @@ public class SwiftManagerImpl implements SwiftManager { return dcs.get(0).getId(); } + @Override + public List listSwift(ListSwiftCmd cmd) { + if (cmd.getId() == null) { + return _swiftDao.listAll(); + } else { + List list = new ArrayList(); + SwiftVO swift = _swiftDao.findById(cmd.getId()); + list.add(swift); + return list; + } + } + @Override public boolean stop() {