mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Refactored the destroy console proxy command
This commit is contained in:
		
							parent
							
								
									14fde77792
								
							
						
					
					
						commit
						f73d14e267
					
				| @ -18,20 +18,12 @@ | ||||
| 
 | ||||
| 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.BaseAsyncCmd; | ||||
| import com.cloud.api.BaseCmd; | ||||
| import com.cloud.api.Implementation; | ||||
| import com.cloud.api.Parameter; | ||||
| import com.cloud.api.ServerApiException; | ||||
| import com.cloud.api.BaseCmd.Manager; | ||||
| import com.cloud.utils.Pair; | ||||
| import com.cloud.vm.ConsoleProxyVO; | ||||
| 
 | ||||
| @Implementation(method="destroyConsoleProxy", manager=Manager.ConsoleProxyManager) | ||||
| public class DestroyConsoleProxyCmd extends BaseAsyncCmd { | ||||
| @ -64,27 +56,27 @@ public class DestroyConsoleProxyCmd extends BaseAsyncCmd { | ||||
|         return s_name; | ||||
|     } | ||||
|      | ||||
|     public List<Pair<String, Object>> execute(Map<String, Object> params) { | ||||
| 	    Long proxyId = (Long)params.get(BaseCmd.Properties.ID.getName()); | ||||
| 	     | ||||
| 	    // verify parameters | ||||
|         ConsoleProxyVO proxy = getManagementServer().findConsoleProxyById(proxyId); | ||||
|         if (proxy == null) { | ||||
|         	throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a console proxy with id " + proxyId); | ||||
|         } | ||||
|          | ||||
| 	    long jobId = getManagementServer().destroyConsoleProxyAsync(proxyId.longValue()); | ||||
|         if(jobId == 0) { | ||||
|         	s_logger.warn("Unable to schedule async-job for DestroyConsoleProxy comamnd"); | ||||
|         } else { | ||||
| 	        if(s_logger.isDebugEnabled()) | ||||
| 	        	s_logger.debug("DestroyConsoleProxy 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; | ||||
|     } | ||||
| //    public List<Pair<String, Object>> execute(Map<String, Object> params) { | ||||
| //	    Long proxyId = (Long)params.get(BaseCmd.Properties.ID.getName()); | ||||
| //	     | ||||
| //	    // verify parameters | ||||
| //        ConsoleProxyVO proxy = getManagementServer().findConsoleProxyById(proxyId); | ||||
| //        if (proxy == null) { | ||||
| //        	throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a console proxy with id " + proxyId); | ||||
| //        } | ||||
| //         | ||||
| //	    long jobId = getManagementServer().destroyConsoleProxyAsync(proxyId.longValue()); | ||||
| //        if(jobId == 0) { | ||||
| //        	s_logger.warn("Unable to schedule async-job for DestroyConsoleProxy comamnd"); | ||||
| //        } else { | ||||
| //	        if(s_logger.isDebugEnabled()) | ||||
| //	        	s_logger.debug("DestroyConsoleProxy 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 | ||||
|  | ||||
| @ -22,6 +22,7 @@ import com.cloud.agent.api.AgentControlAnswer; | ||||
| import com.cloud.agent.api.ConsoleAccessAuthenticationCommand; | ||||
| import com.cloud.agent.api.ConsoleProxyLoadReportCommand; | ||||
| import com.cloud.agent.api.StartupCommand; | ||||
| import com.cloud.api.ServerApiException; | ||||
| import com.cloud.api.commands.DestroyConsoleProxyCmd; | ||||
| import com.cloud.host.HostVO; | ||||
| import com.cloud.host.Status; | ||||
| @ -52,5 +53,5 @@ public interface ConsoleProxyManager extends Manager { | ||||
| 	 | ||||
|     public void onAgentConnect(HostVO host, StartupCommand cmd); | ||||
| 	public void onAgentDisconnect(long agentId, Status state); | ||||
| 	public boolean destroyConsoleProxy(DestroyConsoleProxyCmd cmd); | ||||
| 	public boolean destroyConsoleProxy(DestroyConsoleProxyCmd cmd) throws ServerApiException; | ||||
| } | ||||
|  | ||||
| @ -57,6 +57,9 @@ import com.cloud.agent.api.StopAnswer; | ||||
| import com.cloud.agent.api.StopCommand; | ||||
| import com.cloud.agent.api.proxy.ConsoleProxyLoadAnswer; | ||||
| import com.cloud.agent.manager.AgentManager; | ||||
| import com.cloud.api.BaseCmd; | ||||
| import com.cloud.api.ServerApiException; | ||||
| import com.cloud.api.commands.DestroyConsoleProxyCmd; | ||||
| import com.cloud.async.AsyncJobExecutor; | ||||
| import com.cloud.async.AsyncJobManager; | ||||
| import com.cloud.async.AsyncJobVO; | ||||
| @ -76,6 +79,7 @@ import com.cloud.dc.dao.VlanDao; | ||||
| import com.cloud.domain.DomainVO; | ||||
| import com.cloud.event.EventState; | ||||
| import com.cloud.event.EventTypes; | ||||
| import com.cloud.event.EventUtils; | ||||
| import com.cloud.event.EventVO; | ||||
| import com.cloud.event.dao.EventDao; | ||||
| import com.cloud.exception.AgentUnavailableException; | ||||
| @ -2360,4 +2364,20 @@ public class ConsoleProxyManagerImpl implements ConsoleProxyManager, | ||||
| 			return event.getId(); | ||||
| 		return null; | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public boolean destroyConsoleProxy(DestroyConsoleProxyCmd cmd) throws ServerApiException{ | ||||
| 	    Long proxyId = cmd.getId(); | ||||
| 	     | ||||
| 	    // verify parameters | ||||
|         ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyId); | ||||
|         if (proxy == null) { | ||||
|         	throw new ServerApiException (BaseCmd.PARAM_ERROR, "unable to find a console proxy with id " + proxyId); | ||||
|         } | ||||
|          | ||||
|         long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_DESTROY, "destroying console proxy with Id: "+proxyId); | ||||
|          | ||||
|         return destroyProxy(proxyId, eventId); | ||||
|          | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -1322,8 +1322,8 @@ public interface ManagementServer { | ||||
| 	long stopConsoleProxyAsync(long instanceId); | ||||
| 	boolean rebootConsoleProxy(long instanceId, long startEventId); | ||||
| 	long rebootConsoleProxyAsync(long instanceId); | ||||
| 	boolean destroyConsoleProxy(long instanceId, long startEventId); | ||||
| 	long destroyConsoleProxyAsync(long instanceId); | ||||
| //	boolean destroyConsoleProxy(long instanceId, long startEventId); | ||||
| //	long destroyConsoleProxyAsync(long instanceId); | ||||
| 	String getConsoleAccessUrlRoot(long vmId); | ||||
| 	ConsoleProxyVO findConsoleProxyById(long instanceId); | ||||
| 	VMInstanceVO findSystemVMById(long instanceId); | ||||
|  | ||||
| @ -5966,9 +5966,9 @@ public class ManagementServerImpl implements ManagementServer { | ||||
|         return _consoleProxyMgr.rebootProxy(instanceId, startEventId); | ||||
|     } | ||||
| 
 | ||||
|     public boolean destroyConsoleProxy(long instanceId, long startEventId) { | ||||
|         return _consoleProxyMgr.destroyProxy(instanceId, startEventId); | ||||
|     } | ||||
| //    public boolean destroyConsoleProxy(long instanceId, long startEventId) { | ||||
| //        return _consoleProxyMgr.destroyProxy(instanceId, startEventId); | ||||
| //    } | ||||
| 
 | ||||
|     public long startConsoleProxyAsync(long instanceId) { | ||||
|         long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_START, "starting console proxy with Id: "+instanceId); | ||||
| @ -6016,19 +6016,19 @@ public class ManagementServerImpl implements ManagementServer { | ||||
|         return _asyncMgr.submitAsyncJob(job, true); | ||||
|     } | ||||
| 
 | ||||
|     public long destroyConsoleProxyAsync(long instanceId) { | ||||
|         long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_DESTROY, "destroying console proxy with Id: "+instanceId); | ||||
|         VMOperationParam param = new VMOperationParam(0, instanceId, null, eventId); | ||||
|         Gson gson = GsonHelper.getBuilder().create(); | ||||
| 
 | ||||
|         AsyncJobVO job = new AsyncJobVO(); | ||||
|         job.setUserId(UserContext.current().getUserId()); | ||||
|         job.setAccountId(Account.ACCOUNT_ID_SYSTEM); | ||||
|         job.setCmd("DestroyConsoleProxy"); | ||||
|         job.setCmdInfo(gson.toJson(param)); | ||||
|          | ||||
|         return _asyncMgr.submitAsyncJob(job); | ||||
|     } | ||||
| //    public long destroyConsoleProxyAsync(long instanceId) { | ||||
| //        long eventId = EventUtils.saveScheduledEvent(User.UID_SYSTEM, Account.ACCOUNT_ID_SYSTEM, EventTypes.EVENT_PROXY_DESTROY, "destroying console proxy with Id: "+instanceId); | ||||
| //        VMOperationParam param = new VMOperationParam(0, instanceId, null, eventId); | ||||
| //        Gson gson = GsonHelper.getBuilder().create(); | ||||
| // | ||||
| //        AsyncJobVO job = new AsyncJobVO(); | ||||
| //        job.setUserId(UserContext.current().getUserId()); | ||||
| //        job.setAccountId(Account.ACCOUNT_ID_SYSTEM); | ||||
| //        job.setCmd("DestroyConsoleProxy"); | ||||
| //        job.setCmdInfo(gson.toJson(param)); | ||||
| //         | ||||
| //        return _asyncMgr.submitAsyncJob(job); | ||||
| //    } | ||||
| 
 | ||||
|     public String getConsoleAccessUrlRoot(long vmId) { | ||||
|         VMInstanceVO vm = this.findVMInstanceById(vmId); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user