mirror of https://github.com/apache/cloudstack.git
Refactored the reconnectHost command
This commit is contained in:
parent
49482e947b
commit
be75946b1f
|
|
@ -26,6 +26,7 @@ import com.cloud.agent.api.Command;
|
|||
import com.cloud.api.commands.AddHostCmd;
|
||||
import com.cloud.api.commands.AddHostOrStorageCmd;
|
||||
import com.cloud.api.commands.DeleteHostCmd;
|
||||
import com.cloud.api.commands.ReconnectHostCmd;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.PodCluster;
|
||||
|
|
@ -220,6 +221,7 @@ public interface AgentManager extends Manager {
|
|||
|
||||
public boolean executeUserRequest(long hostId, Event event) throws AgentUnavailableException;
|
||||
public boolean reconnect(final long hostId) throws AgentUnavailableException;
|
||||
public boolean reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException;
|
||||
|
||||
public List<HostVO> discoverHosts(AddHostOrStorageCmd cmd) throws DiscoveryException, InvalidParameterValueException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,9 +70,11 @@ import com.cloud.agent.transport.Request;
|
|||
import com.cloud.agent.transport.Response;
|
||||
import com.cloud.agent.transport.UpgradeResponse;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.commands.AddHostCmd;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.commands.AddHostOrStorageCmd;
|
||||
import com.cloud.api.commands.DeleteHostCmd;
|
||||
import com.cloud.api.commands.ReconnectHostCmd;
|
||||
import com.cloud.capacity.CapacityVO;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
|
|
@ -96,10 +98,10 @@ import com.cloud.exception.UnsupportedVersionException;
|
|||
import com.cloud.ha.HighAvailabilityManager;
|
||||
import com.cloud.host.DetailVO;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.HostStats;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Host.Type;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.DetailsDao;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
|
|
@ -1254,6 +1256,20 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory {
|
|||
return send(hostId, cmds, stopOnError, _wait);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException
|
||||
{
|
||||
Long hostId = cmd.getId();
|
||||
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
if (host == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Host with id " + hostId.toString() + " doesn't exist");
|
||||
}
|
||||
|
||||
return reconnect(hostId);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reconnect(final long hostId) throws AgentUnavailableException {
|
||||
HostVO host;
|
||||
|
|
|
|||
|
|
@ -18,27 +18,18 @@
|
|||
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseAsyncCmd;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
public class ReconnectHostCmd extends BaseCmd {
|
||||
import com.cloud.api.BaseCmd.Manager;
|
||||
|
||||
@Implementation(method="reconnectHost", manager=Manager.AgentManager)
|
||||
public class ReconnectHostCmd extends BaseAsyncCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName());
|
||||
|
||||
private static final String s_name = "reconnecthostresponse";
|
||||
private static final List<Pair<Enum, Boolean>> s_properties = new ArrayList<Pair<Enum, Boolean>>();
|
||||
|
||||
static {
|
||||
s_properties.add(new Pair<Enum, Boolean>(BaseCmd.Properties.ID, Boolean.TRUE));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
|
|
@ -66,30 +57,33 @@ public class ReconnectHostCmd extends BaseCmd {
|
|||
public static String getResultObjectName() {
|
||||
return "host";
|
||||
}
|
||||
public List<Pair<Enum, Boolean>> getProperties() {
|
||||
return s_properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
Long hostId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
|
||||
//verify input parameters
|
||||
HostVO host = getManagementServer().getHostBy(hostId);
|
||||
if (host == null) {
|
||||
throw new ServerApiException(BaseCmd.PARAM_ERROR, "Host with id " + hostId.toString() + " doesn't exist");
|
||||
}
|
||||
|
||||
long jobId = getManagementServer().reconnectAsync(hostId);
|
||||
if(jobId == 0) {
|
||||
s_logger.warn("Unable to schedule async-job for ReconnectHost comamnd");
|
||||
} else {
|
||||
if(s_logger.isDebugEnabled())
|
||||
s_logger.debug("ReconnectHost command has been accepted, job id: " + jobId);
|
||||
}
|
||||
|
||||
List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
|
||||
return returnValues;
|
||||
}
|
||||
// @Override
|
||||
// public List<Pair<String, Object>> execute(Map<String, Object> params) {
|
||||
// Long hostId = (Long)params.get(BaseCmd.Properties.ID.getName());
|
||||
//
|
||||
// //verify input parameters
|
||||
// HostVO host = getManagementServer().getHostBy(hostId);
|
||||
// if (host == null) {
|
||||
// throw new ServerApiException(BaseCmd.PARAM_ERROR, "Host with id " + hostId.toString() + " doesn't exist");
|
||||
// }
|
||||
//
|
||||
// long jobId = getManagementServer().reconnectAsync(hostId);
|
||||
// if(jobId == 0) {
|
||||
// s_logger.warn("Unable to schedule async-job for ReconnectHost comamnd");
|
||||
// } else {
|
||||
// if(s_logger.isDebugEnabled())
|
||||
// s_logger.debug("ReconnectHost command has been accepted, job id: " + jobId);
|
||||
// }
|
||||
//
|
||||
// List<Pair<String, Object>> returnValues = new ArrayList<Pair<String, Object>>();
|
||||
// returnValues.add(new Pair<String, Object>(BaseCmd.Properties.JOB_ID.getName(), Long.valueOf(jobId)));
|
||||
// return returnValues;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public String getResponse() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,8 +134,8 @@ public interface ManagementServer {
|
|||
* @return a user object
|
||||
*/
|
||||
User createUser(String username, String password, String firstName, String lastName, Long domain, String accountName, short userType, String email, String timezone);
|
||||
boolean reconnect(long hostId);
|
||||
long reconnectAsync(long hostId);
|
||||
// boolean reconnect(long hostId);
|
||||
// long reconnectAsync(long hostId);
|
||||
|
||||
ClusterVO findClusterById(long clusterId);
|
||||
List<ClusterVO> listClusterByPodId(long podId);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ import com.cloud.api.commands.EnableUserCmd;
|
|||
import com.cloud.api.commands.GetCloudIdentifierCmd;
|
||||
import com.cloud.api.commands.PrepareForMaintenanceCmd;
|
||||
import com.cloud.api.commands.PreparePrimaryStorageForMaintenanceCmd;
|
||||
import com.cloud.api.commands.ReconnectHostCmd;
|
||||
import com.cloud.api.commands.RegisterCmd;
|
||||
import com.cloud.api.commands.RemovePortForwardingServiceCmd;
|
||||
import com.cloud.api.commands.StartRouterCmd;
|
||||
|
|
@ -2220,29 +2219,29 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean reconnect(long hostId) {
|
||||
try {
|
||||
return _agentMgr.reconnect(hostId);
|
||||
} catch (AgentUnavailableException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// @Override
|
||||
// public boolean reconnect(long hostId) {
|
||||
// try {
|
||||
// return _agentMgr.reconnect(hostId);
|
||||
// } catch (AgentUnavailableException e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public long reconnectAsync(long hostId) {
|
||||
Long param = new Long(hostId);
|
||||
Gson gson = GsonHelper.getBuilder().create();
|
||||
|
||||
AsyncJobVO job = new AsyncJobVO();
|
||||
job.setUserId(UserContext.current().getUserId());
|
||||
job.setAccountId(Account.ACCOUNT_ID_SYSTEM);
|
||||
job.setCmd("Reconnect");
|
||||
job.setCmdInfo(gson.toJson(param));
|
||||
job.setCmdOriginator(ReconnectHostCmd.getResultObjectName());
|
||||
|
||||
return _asyncMgr.submitAsyncJob(job);
|
||||
}
|
||||
// @Override
|
||||
// public long reconnectAsync(long hostId) {
|
||||
// Long param = new Long(hostId);
|
||||
// Gson gson = GsonHelper.getBuilder().create();
|
||||
//
|
||||
// AsyncJobVO job = new AsyncJobVO();
|
||||
// job.setUserId(UserContext.current().getUserId());
|
||||
// job.setAccountId(Account.ACCOUNT_ID_SYSTEM);
|
||||
// job.setCmd("Reconnect");
|
||||
// job.setCmdInfo(gson.toJson(param));
|
||||
// job.setCmdOriginator(ReconnectHostCmd.getResultObjectName());
|
||||
//
|
||||
// return _asyncMgr.submitAsyncJob(job);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public UserVm deployVirtualMachine(long userId, long accountId, long dataCenterId, long serviceOfferingId, long templateId, Long diskOfferingId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue