2323import javax .naming .ConfigurationException ;
2424
2525import org .apache .log4j .Logger ;
26- import org .springframework .stereotype .Component ;
2726
2827import com .cloud .agent .AgentManager ;
29- import com .cloud .agent .api .AgentControlAnswer ;
30- import com .cloud .agent .api .ConsoleAccessAuthenticationAnswer ;
31- import com .cloud .agent .api .ConsoleAccessAuthenticationCommand ;
32- import com .cloud .agent .api .ConsoleProxyLoadReportCommand ;
3328import com .cloud .agent .api .GetVncPortAnswer ;
3429import com .cloud .agent .api .GetVncPortCommand ;
35- import com .cloud .agent .api .StartupCommand ;
3630import com .cloud .agent .api .StartupProxyCommand ;
37- import com .cloud .agent .api .StopAnswer ;
38- import com .cloud .agent .api .to .NicTO ;
39- import com .cloud .agent .api .to .VirtualMachineTO ;
40- import com .cloud .agent .manager .Commands ;
4131import com .cloud .configuration .dao .ConfigurationDao ;
42- import com .cloud .deploy .DeployDestination ;
43- import com .cloud .exception .ConcurrentOperationException ;
44- import com .cloud .exception .InsufficientCapacityException ;
45- import com .cloud .exception .ResourceUnavailableException ;
4632import com .cloud .host .HostVO ;
47- import com .cloud .host .Status ;
4833import com .cloud .host .dao .HostDao ;
4934import com .cloud .info .ConsoleProxyInfo ;
50- import com .cloud .network . Network ;
35+ import com .cloud .keystore . KeystoreManager ;
5136import com .cloud .utils .NumbersUtil ;
5237import com .cloud .utils .component .ManagerBase ;
5338import com .cloud .vm .ConsoleProxyVO ;
54- import com .cloud .vm .ReservationContext ;
5539import com .cloud .vm .UserVmVO ;
5640import com .cloud .vm .VMInstanceVO ;
57- import com .cloud .vm .VirtualMachine ;
58- import com .cloud .vm .VirtualMachineGuru ;
5941import com .cloud .vm .VirtualMachineManager ;
60- import com .cloud .vm .VirtualMachineName ;
61- import com .cloud .vm .VirtualMachineProfile ;
6242import com .cloud .vm .dao .ConsoleProxyDao ;
6343import com .cloud .vm .dao .UserVmDao ;
6444import com .cloud .vm .dao .VMInstanceDao ;
6545
6646@ Local (value = { ConsoleProxyManager .class })
67- public class AgentBasedConsoleProxyManager extends ManagerBase implements ConsoleProxyManager , VirtualMachineGuru < ConsoleProxyVO >, AgentHook {
47+ public class AgentBasedConsoleProxyManager extends ManagerBase implements ConsoleProxyManager {
6848 private static final Logger s_logger = Logger .getLogger (AgentBasedConsoleProxyManager .class );
6949
7050 @ Inject
@@ -85,9 +65,25 @@ public class AgentBasedConsoleProxyManager extends ManagerBase implements Consol
8565 VirtualMachineManager _itMgr ;
8666 @ Inject
8767 protected ConsoleProxyDao _cpDao ;
68+ @ Inject
69+ protected KeystoreManager _ksMgr ;
8870
8971 @ Inject ConfigurationDao _configDao ;
9072
73+ public class AgentBasedAgentHook extends AgentHookBase {
74+
75+ public AgentBasedAgentHook (VMInstanceDao instanceDao , HostDao hostDao , ConfigurationDao cfgDao ,
76+ KeystoreManager ksMgr , AgentManager agentMgr ) {
77+ super (instanceDao , hostDao , cfgDao , ksMgr , agentMgr );
78+ }
79+
80+ @ Override
81+ protected HostVO findConsoleProxyHost (StartupProxyCommand cmd ) {
82+ return _hostDao .findByGuid (cmd .getGuid ());
83+ }
84+
85+ }
86+
9187 public int getVncPort (VMInstanceVO vm ) {
9288 if (vm .getHostId () == null ) {
9389 return -1 ;
@@ -123,11 +119,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
123119
124120 _consoleProxyUrlDomain = configs .get ("consoleproxy.url.domain" );
125121
126- _listener = new ConsoleProxyListener (this );
122+ _listener =
123+ new ConsoleProxyListener (new AgentBasedAgentHook (_instanceDao , _hostDao , _configDao , _ksMgr , _agentMgr ));
127124 _agentMgr .registerForHostEvents (_listener , true , true , false );
128125
129- _itMgr .registerGuru (VirtualMachine .Type .ConsoleProxy , this );
130-
131126 if (s_logger .isInfoEnabled ()) {
132127 s_logger .info ("AgentBasedConsoleProxyManager has been configured. SSL enabled: " + _sslEnabled );
133128 }
@@ -177,64 +172,8 @@ public ConsoleProxyInfo assignProxy(long dataCenterId, long userVmId) {
177172 return null ;
178173 }
179174
180- @ Override
181- public void onLoadReport (ConsoleProxyLoadReportCommand cmd ) {
182- }
183-
184- @ Override
185- public AgentControlAnswer onConsoleAccessAuthentication (ConsoleAccessAuthenticationCommand cmd ) {
186- long vmId = 0 ;
187-
188- if (cmd .getVmId () != null && cmd .getVmId ().isEmpty ()) {
189- if (s_logger .isTraceEnabled ()) {
190- s_logger .trace ("Invalid vm id sent from proxy(happens when proxy session has terminated)" );
191- }
192- return new ConsoleAccessAuthenticationAnswer (cmd , false );
193- }
194-
195- try {
196- vmId = Long .parseLong (cmd .getVmId ());
197- } catch (NumberFormatException e ) {
198- s_logger .error ("Invalid vm id " + cmd .getVmId () + " sent from console access authentication" , e );
199- return new ConsoleAccessAuthenticationAnswer (cmd , false );
200- }
201-
202- // TODO authentication channel between console proxy VM and management
203- // server needs to be secured,
204- // the data is now being sent through private network, but this is
205- // apparently not enough
206- VMInstanceVO vm = _instanceDao .findById (vmId );
207- if (vm == null ) {
208- return new ConsoleAccessAuthenticationAnswer (cmd , false );
209- }
210-
211- if (vm .getHostId () == null ) {
212- s_logger .warn ("VM " + vmId + " lost host info, failed authentication request" );
213- return new ConsoleAccessAuthenticationAnswer (cmd , false );
214- }
215-
216- HostVO host = _hostDao .findById (vm .getHostId ());
217- if (host == null ) {
218- s_logger .warn ("VM " + vmId + "'s host does not exist, fail authentication request" );
219- return new ConsoleAccessAuthenticationAnswer (cmd , false );
220- }
221175
222- String sid = cmd .getSid ();
223- if (sid == null || !sid .equals (vm .getVncPassword ())) {
224- s_logger .warn ("sid " + sid + " in url does not match stored sid " + vm .getVncPassword ());
225- return new ConsoleAccessAuthenticationAnswer (cmd , false );
226- }
227176
228- return new ConsoleAccessAuthenticationAnswer (cmd , true );
229- }
230-
231- @ Override
232- public void onAgentConnect (HostVO host , StartupCommand cmd ) {
233- }
234-
235- @ Override
236- public void onAgentDisconnect (long agentId , Status state ) {
237- }
238177
239178 @ Override
240179 public ConsoleProxyVO startProxy (long proxyVmId ) {
@@ -269,91 +208,8 @@ public ConsoleProxyManagementState getManagementState() {
269208 public void resumeLastManagementState () {
270209 }
271210
272- @ Override
273- public void startAgentHttpHandlerInVM (StartupProxyCommand startupCmd ) {
274- }
275-
276211 @ Override
277212 public String getName () {
278213 return _name ;
279214 }
280-
281- @ Override
282- public Long convertToId (String vmName ) {
283- if (!VirtualMachineName .isValidConsoleProxyName (vmName , _instance )) {
284- return null ;
285- }
286- return VirtualMachineName .getConsoleProxyId (vmName );
287- }
288-
289- @ Override
290- public ConsoleProxyVO findByName (String name ) {
291- // TODO Auto-generated method stub
292- return null ;
293- }
294-
295- @ Override
296- public ConsoleProxyVO findById (long id ) {
297- // TODO Auto-generated method stub
298- return null ;
299- }
300-
301- @ Override
302- public ConsoleProxyVO persist (ConsoleProxyVO vm ) {
303- // TODO Auto-generated method stub
304- return null ;
305- }
306-
307- @ Override
308- public boolean finalizeVirtualMachineProfile (VirtualMachineProfile <ConsoleProxyVO > profile , DeployDestination dest , ReservationContext context ) {
309- // TODO Auto-generated method stub
310- return false ;
311- }
312-
313- @ Override
314- public boolean finalizeDeployment (Commands cmds , VirtualMachineProfile <ConsoleProxyVO > profile , DeployDestination dest , ReservationContext context ) {
315- // TODO Auto-generated method stub
316- return false ;
317- }
318-
319- @ Override
320- public boolean finalizeCommandsOnStart (Commands cmds , VirtualMachineProfile <ConsoleProxyVO > profile ) {
321- // TODO Auto-generated method stub
322- return false ;
323- }
324-
325- @ Override
326- public boolean finalizeStart (VirtualMachineProfile <ConsoleProxyVO > profile , long hostId , Commands cmds , ReservationContext context ) {
327- // TODO Auto-generated method stub
328- return false ;
329- }
330-
331- @ Override
332- public void finalizeStop (VirtualMachineProfile <ConsoleProxyVO > profile , StopAnswer answer ) {
333- // TODO Auto-generated method stub
334- }
335-
336- @ Override
337- public void finalizeExpunge (ConsoleProxyVO proxy ) {
338- }
339-
340- @ Override
341- public boolean plugNic (Network network , NicTO nic , VirtualMachineTO vm ,
342- ReservationContext context , DeployDestination dest ) throws ConcurrentOperationException , ResourceUnavailableException ,
343- InsufficientCapacityException {
344- //not supported
345- throw new UnsupportedOperationException ("Plug nic is not supported for vm of type " + vm .getType ());
346- }
347-
348-
349- @ Override
350- public boolean unplugNic (Network network , NicTO nic , VirtualMachineTO vm ,
351- ReservationContext context , DeployDestination dest ) throws ConcurrentOperationException , ResourceUnavailableException {
352- //not supported
353- throw new UnsupportedOperationException ("Unplug nic is not supported for vm of type " + vm .getType ());
354- }
355-
356- @ Override
357- public void prepareStop (VirtualMachineProfile <ConsoleProxyVO > profile ) {
358- }
359215}
0 commit comments