mirror of https://github.com/apache/cloudstack.git
SWIFT: api refine
This commit is contained in:
parent
ec9bbd4993
commit
235c5aa6eb
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.ApiConstants;
|
||||
|
|
@ -91,16 +89,13 @@ public class AddSwiftCmd extends BaseCmd {
|
|||
@Override
|
||||
public void execute(){
|
||||
try {
|
||||
List<? extends Swift> result = _resourceService.discoverSwift(this);
|
||||
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);
|
||||
}
|
||||
if (result != null) {
|
||||
swiftResponse = _responseGenerator.createSwiftResponse(result);
|
||||
swiftResponse.setResponseName(getCommandName());
|
||||
swiftResponse.setObjectName("Swift");
|
||||
this.setResponseObject(swiftResponse);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add Swift");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,15 @@ public class SwiftResponse extends BaseResponse {
|
|||
@Param(description = "the date and time the host was created")
|
||||
private Date created;
|
||||
|
||||
@SerializedName(ApiConstants.ACCOUNT)
|
||||
@Param(description = "the account for swift")
|
||||
private String account;
|
||||
|
||||
@SerializedName(ApiConstants.ACCOUNT)
|
||||
@Param(description = "the username for swift")
|
||||
private String username;
|
||||
|
||||
|
||||
@Override
|
||||
public Long getObjectId() {
|
||||
return id.getValue();
|
||||
|
|
@ -62,4 +71,20 @@ public class SwiftResponse extends BaseResponse {
|
|||
this.created = created;
|
||||
}
|
||||
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public interface ResourceService {
|
|||
|
||||
Cluster getCluster(Long clusterId);
|
||||
|
||||
List<? extends Swift> discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException;
|
||||
Swift discoverSwift(AddSwiftCmd addSwiftCmd) throws DiscoveryException;
|
||||
|
||||
List<HypervisorType> getSupportedHypervisorTypes(long zoneId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -652,6 +652,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
SwiftResponse swiftResponse = new SwiftResponse();
|
||||
swiftResponse.setId(swift.getId());
|
||||
swiftResponse.setUrl(swift.getUrl());
|
||||
swiftResponse.setAccount(swift.getAccount());
|
||||
swiftResponse.setUsername(swift.getUserName());
|
||||
swiftResponse.setObjectName("Swift");
|
||||
return swiftResponse;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,10 +83,10 @@ import com.cloud.ha.HighAvailabilityManager.WorkType;
|
|||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.HostStats;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.host.dao.HostTagsDao;
|
||||
|
|
@ -513,7 +513,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Swift> discoverSwift(AddSwiftCmd cmd) throws DiscoveryException {
|
||||
public Swift discoverSwift(AddSwiftCmd cmd) throws DiscoveryException {
|
||||
return _swiftMgr.addSwift(cmd);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
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;
|
||||
|
|
@ -39,7 +37,7 @@ public interface SwiftManager extends Manager {
|
|||
|
||||
SwiftTO getSwiftTO();
|
||||
|
||||
List<? extends Swift> addSwift(AddSwiftCmd cmd) throws DiscoveryException;
|
||||
Swift addSwift(AddSwiftCmd cmd) throws DiscoveryException;
|
||||
|
||||
boolean isSwiftEnabled();
|
||||
|
||||
|
|
|
|||
|
|
@ -24,8 +24,6 @@
|
|||
|
||||
package com.cloud.storage.swift;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
|
@ -43,7 +41,6 @@ import com.cloud.api.commands.DeleteTemplateCmd;
|
|||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.storage.Swift;
|
||||
import com.cloud.storage.SwiftVO;
|
||||
import com.cloud.storage.VMTemplateSwiftVO;
|
||||
import com.cloud.storage.dao.SwiftDao;
|
||||
|
|
@ -100,15 +97,13 @@ public class SwiftManagerImpl implements SwiftManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Swift> addSwift(AddSwiftCmd cmd) throws DiscoveryException {
|
||||
public SwiftVO addSwift(AddSwiftCmd cmd) throws DiscoveryException {
|
||||
if (!isSwiftEnabled()) {
|
||||
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;
|
||||
return swift;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue