mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Make AddCluster Command return standard json object format
This commit is contained in:
parent
f89fb73571
commit
9e2cbbe0dd
@ -10,12 +10,14 @@ 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.ClusterResponse;
|
||||
import com.cloud.api.response.HostResponse;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.org.Cluster;
|
||||
|
||||
@Implementation(description="Adds a new cluster", responseObject=HostResponse.class)
|
||||
@Implementation(description="Adds a new cluster", responseObject=ClusterResponse.class)
|
||||
public class AddClusterCmd extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(AddClusterCmd.class.getName());
|
||||
|
||||
@ -90,19 +92,19 @@ public class AddClusterCmd extends BaseCmd {
|
||||
@Override
|
||||
public void execute(){
|
||||
try {
|
||||
List<? extends Host> result = _resourceService.discoverCluster(this);
|
||||
ListResponse<HostResponse> response = new ListResponse<HostResponse>();
|
||||
List<HostResponse> hostResponses = new ArrayList<HostResponse>();
|
||||
List<? extends Cluster> result = _resourceService.discoverCluster(this);
|
||||
ListResponse<ClusterResponse> response = new ListResponse<ClusterResponse>();
|
||||
List<ClusterResponse> clusterResponses = new ArrayList<ClusterResponse>();
|
||||
if (result != null) {
|
||||
for (Host host : result) {
|
||||
HostResponse hostResponse = _responseGenerator.createHostResponse(host);
|
||||
hostResponses.add(hostResponse);
|
||||
for (Cluster cluster : result) {
|
||||
ClusterResponse clusterResponse = _responseGenerator.createClusterResponse(cluster);
|
||||
clusterResponses.add(clusterResponse);
|
||||
}
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add host cluster");
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add cluster");
|
||||
}
|
||||
|
||||
response.setResponses(hostResponses);
|
||||
response.setResponses(clusterResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
|
||||
this.setResponseObject(response);
|
||||
|
||||
@ -32,6 +32,7 @@ import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.org.Cluster;
|
||||
|
||||
public interface ResourceService {
|
||||
/**
|
||||
@ -56,7 +57,7 @@ public interface ResourceService {
|
||||
* @throws DiscoveryException
|
||||
* @throws InvalidParameterValueException
|
||||
*/
|
||||
List<? extends Host> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
|
||||
List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
|
||||
boolean deleteCluster(DeleteClusterCmd cmd) throws InvalidParameterValueException;
|
||||
|
||||
List<? extends Host> discoverHosts(AddHostCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException;
|
||||
|
||||
@ -531,7 +531,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Host> discoverCluster(AddClusterCmd cmd)
|
||||
public List<? extends Cluster> discoverCluster(AddClusterCmd cmd)
|
||||
throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
|
||||
Long dcId = cmd.getZoneId();
|
||||
Long podId = cmd.getPodId();
|
||||
@ -586,25 +586,26 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
||||
throw new InvalidParameterValueException("Please specify a valid hypervisor");
|
||||
}
|
||||
|
||||
List<ClusterVO> result = new ArrayList<ClusterVO>();
|
||||
|
||||
long clusterId = 0;
|
||||
if (clusterName != null) {
|
||||
ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
|
||||
cluster.setHypervisorType(cmd.getHypervisor());
|
||||
|
||||
cluster.setClusterType(clusterType);
|
||||
try {
|
||||
cluster = _clusterDao.persist(cluster);
|
||||
} catch (Exception e) {
|
||||
cluster = _clusterDao.findBy(clusterName, podId);
|
||||
if (cluster == null) {
|
||||
throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + podId + " and data center " + dcId, e);
|
||||
}
|
||||
ClusterVO cluster = new ClusterVO(dcId, podId, clusterName);
|
||||
cluster.setHypervisorType(cmd.getHypervisor());
|
||||
|
||||
cluster.setClusterType(clusterType);
|
||||
try {
|
||||
cluster = _clusterDao.persist(cluster);
|
||||
} catch (Exception e) {
|
||||
cluster = _clusterDao.findBy(clusterName, podId);
|
||||
if (cluster == null) {
|
||||
throw new CloudRuntimeException("Unable to create cluster " + clusterName + " in pod " + podId + " and data center " + dcId, e);
|
||||
}
|
||||
clusterId = cluster.getId();
|
||||
}
|
||||
clusterId = cluster.getId();
|
||||
result.add(cluster);
|
||||
|
||||
if(clusterType == Cluster.ClusterType.CloudManaged) {
|
||||
return _hostDao.listByCluster(clusterId);
|
||||
return result;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
@ -641,7 +642,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
|
||||
}
|
||||
s_logger.info("External cluster has been successfully discovered by " + discoverer.getName());
|
||||
success = true;
|
||||
return hosts;
|
||||
return result;
|
||||
}
|
||||
|
||||
s_logger.warn("Unable to find the server resources at " + url);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user