mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
Swift : add Swift api
This commit is contained in:
parent
b91dce4f8a
commit
d1141aff7d
@ -149,6 +149,7 @@ public class ApiConstants {
|
||||
public static final String SCHEDULE = "schedule";
|
||||
public static final String SCOPE = "scope";
|
||||
public static final String SECRET_KEY = "usersecretkey";
|
||||
public static final String KEY = "key";
|
||||
public static final String SECURITY_GROUP_IDS = "securitygroupids";
|
||||
public static final String SECURITY_GROUP_NAMES = "securitygroupnames";
|
||||
public static final String SECURITY_GROUP_NAME = "securitygroupname";
|
||||
|
||||
@ -55,6 +55,7 @@ import com.cloud.api.response.ServiceOfferingResponse;
|
||||
import com.cloud.api.response.SnapshotPolicyResponse;
|
||||
import com.cloud.api.response.SnapshotResponse;
|
||||
import com.cloud.api.response.StoragePoolResponse;
|
||||
import com.cloud.api.response.SwiftResponse;
|
||||
import com.cloud.api.response.SystemVmInstanceResponse;
|
||||
import com.cloud.api.response.SystemVmResponse;
|
||||
import com.cloud.api.response.TemplatePermissionsResponse;
|
||||
@ -99,6 +100,7 @@ import com.cloud.projects.ProjectAccount;
|
||||
import com.cloud.projects.ProjectInvitation;
|
||||
import com.cloud.storage.Snapshot;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.Swift;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.snapshot.SnapshotPolicy;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
@ -233,4 +235,6 @@ public interface ResponseGenerator {
|
||||
|
||||
SystemVmInstanceResponse createSystemVmInstanceResponse(VirtualMachine systemVM);
|
||||
|
||||
SwiftResponse createSwiftResponse(Swift swift);
|
||||
|
||||
}
|
||||
|
||||
113
api/src/com/cloud/api/commands/AddSwiftCmd.java
Normal file
113
api/src/com/cloud/api/commands/AddSwiftCmd.java
Normal file
@ -0,0 +1,113 @@
|
||||
/**
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
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.SwiftResponse;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.storage.Swift;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
@Implementation(description = "Adds Swift.", responseObject = HostResponse.class)
|
||||
public class AddSwiftCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AddSwiftCmd.class.getName());
|
||||
private static final String s_name = "addSwiftresponse";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
@Parameter(name = ApiConstants.URL, type = CommandType.STRING, required = true, description = "the URL for swift")
|
||||
private String url;
|
||||
|
||||
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account for swift")
|
||||
private String account;
|
||||
|
||||
@Parameter(name = ApiConstants.USERNAME, type = CommandType.STRING, description = "the username for swift")
|
||||
private String username;
|
||||
|
||||
@Parameter(name = ApiConstants.KEY, type = CommandType.STRING, description = " key for the user for swift")
|
||||
private String key;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEntityOwnerId() {
|
||||
return Account.ACCOUNT_ID_SYSTEM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
try {
|
||||
List<? extends Swift> result = _resourceService.discoverSwift(this);
|
||||
SwiftResponse swiftResponse = null;
|
||||
if (result != null && result.size() > 0) {
|
||||
for (Swift swift : result) {
|
||||
// There should only be one secondary storage host per add
|
||||
swiftResponse = _responseGenerator.createSwiftResponse(swift);
|
||||
swiftResponse.setResponseName(getCommandName());
|
||||
swiftResponse.setObjectName("Swift");
|
||||
this.setResponseObject(swiftResponse);
|
||||
}
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Swift");
|
||||
}
|
||||
} catch (DiscoveryException ex) {
|
||||
String errMsg = "Failed to add Swift due to " + ex.toString();
|
||||
s_logger.warn(errMsg, ex);
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
64
api/src/com/cloud/api/response/SwiftResponse.java
Executable file
64
api/src/com/cloud/api/response/SwiftResponse.java
Executable file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.cloud.api.response;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class SwiftResponse extends BaseResponse {
|
||||
@SerializedName(ApiConstants.ID)
|
||||
@Param(description = "the ID of swift")
|
||||
private Long id;
|
||||
|
||||
@SerializedName(ApiConstants.URL)
|
||||
@Param(description = "url for swift")
|
||||
private String url;
|
||||
|
||||
@SerializedName(ApiConstants.CREATED)
|
||||
@Param(description = "the date and time the host was created")
|
||||
private Date created;
|
||||
|
||||
@Override
|
||||
public Long getObjectId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(Date created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
}
|
||||
@ -22,6 +22,7 @@ import java.util.List;
|
||||
import com.cloud.api.commands.AddClusterCmd;
|
||||
import com.cloud.api.commands.AddHostCmd;
|
||||
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.PrepareForMaintenanceCmd;
|
||||
@ -33,6 +34,7 @@ import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.org.Cluster;
|
||||
import com.cloud.storage.Swift;
|
||||
|
||||
public interface ResourceService {
|
||||
/**
|
||||
@ -86,4 +88,6 @@ public interface ResourceService {
|
||||
Host getHost(long hostId);
|
||||
|
||||
Cluster getCluster(Long clusterId);
|
||||
|
||||
List<? extends Swift> discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException;
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ package com.cloud.storage;
|
||||
import com.cloud.agent.api.to.SwiftTO;
|
||||
|
||||
public interface Swift {
|
||||
public long getId();
|
||||
public String getUrl();
|
||||
public String getAccount();
|
||||
public String getUserName();
|
||||
@ -18,6 +18,8 @@
|
||||
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
@ -26,6 +28,7 @@ import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.agent.api.to.SwiftTO;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
@Entity
|
||||
@Table(name="swift")
|
||||
@ -47,6 +50,9 @@ public class SwiftVO implements Swift {
|
||||
|
||||
@Column(name="key")
|
||||
String key;
|
||||
|
||||
@Column(name = GenericDao.CREATED_COLUMN)
|
||||
private Date created;
|
||||
|
||||
public SwiftVO() { }
|
||||
|
||||
@ -57,6 +63,7 @@ public class SwiftVO implements Swift {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -77,6 +84,10 @@ public class SwiftVO implements Swift {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwiftTO toSwiftTO() {
|
||||
return new SwiftTO(getId(), getUrl(), getAccount(), getUserName(), getKey());
|
||||
|
||||
@ -76,6 +76,7 @@ import com.cloud.api.response.ServiceResponse;
|
||||
import com.cloud.api.response.SnapshotPolicyResponse;
|
||||
import com.cloud.api.response.SnapshotResponse;
|
||||
import com.cloud.api.response.StoragePoolResponse;
|
||||
import com.cloud.api.response.SwiftResponse;
|
||||
import com.cloud.api.response.SystemVmInstanceResponse;
|
||||
import com.cloud.api.response.SystemVmResponse;
|
||||
import com.cloud.api.response.TemplatePermissionsResponse;
|
||||
@ -148,6 +149,7 @@ import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.Swift;
|
||||
import com.cloud.storage.UploadVO;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
@ -597,6 +599,15 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
return hostResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SwiftResponse createSwiftResponse(Swift swift) {
|
||||
SwiftResponse swiftResponse = new SwiftResponse();
|
||||
swiftResponse.setId(swift.getId());
|
||||
swiftResponse.setUrl(swift.getUrl());
|
||||
swiftResponse.setObjectName("Swift");
|
||||
return swiftResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan) {
|
||||
Long podId = ApiDBUtils.getPodIdForVlan(vlan.getId());
|
||||
|
||||
@ -37,6 +37,7 @@ import com.cloud.agent.manager.AgentAttache;
|
||||
import com.cloud.api.commands.AddClusterCmd;
|
||||
import com.cloud.api.commands.AddHostCmd;
|
||||
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.PrepareForMaintenanceCmd;
|
||||
@ -44,6 +45,8 @@ import com.cloud.api.commands.ReconnectHostCmd;
|
||||
import com.cloud.api.commands.UpdateHostCmd;
|
||||
import com.cloud.api.commands.UpdateHostPasswordCmd;
|
||||
import com.cloud.cluster.ManagementServerNode;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.ClusterDetailsDao;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
@ -70,7 +73,10 @@ import com.cloud.org.Grouping;
|
||||
import com.cloud.org.Managed;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.Swift;
|
||||
import com.cloud.storage.SwiftVO;
|
||||
import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||
import com.cloud.storage.dao.SwiftDao;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountManager;
|
||||
@ -110,8 +116,12 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
@Inject
|
||||
protected HostDao _hostDao;
|
||||
@Inject
|
||||
protected SwiftDao _swiftDao;
|
||||
@Inject
|
||||
protected HostDetailsDao _hostDetailsDao;
|
||||
@Inject
|
||||
protected ConfigurationDao _configDao;
|
||||
@Inject
|
||||
protected HostTagsDao _hostTagsDao;
|
||||
@Inject
|
||||
protected GuestOSCategoryDao _guestOSCategoryDao;
|
||||
@ -439,6 +449,19 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
return discoverHostsFull(dcId, null, null, null, url, null, null, "SecondaryStorage", null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Swift> discoverSwift(AddSwiftCmd cmd) throws DiscoveryException {
|
||||
Boolean swiftEnable = Boolean.valueOf(_configDao.getValue(Config.SwiftEnable.key()));
|
||||
if (!swiftEnable) {
|
||||
throw new DiscoveryException("Swift is not enabled");
|
||||
}
|
||||
SwiftVO swift = new SwiftVO(cmd.getUrl(), cmd.getAccount(), cmd.getUsername(), cmd.getKey());
|
||||
swift = _swiftDao.persist(swift);
|
||||
List<SwiftVO> list = new ArrayList<SwiftVO>();
|
||||
list.add(swift);
|
||||
return list;
|
||||
}
|
||||
|
||||
private List<HostVO> discoverHostsFull(Long dcId, Long podId, Long clusterId, String clusterName, String url, String username, String password, String hypervisorType, List<String> hostTags,
|
||||
Map<String, String> params, String allocationState) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
|
||||
URI uri = null;
|
||||
|
||||
@ -1662,6 +1662,7 @@ CREATE TABLE `cloud`.`swift` (
|
||||
`account` varchar(255) NOT NULL COMMENT ' account in swift',
|
||||
`username` varchar(255) NOT NULL COMMENT ' username in swift',
|
||||
`key` varchar(255) NOT NULL COMMENT 'token for this user',
|
||||
`created` datetime COMMENT 'date the swift first signed on',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user