66import javax .ejb .Local ;
77import javax .naming .ConfigurationException ;
88
9+ import com .cloud .agent .AgentManager ;
10+ import com .cloud .agent .Listener ;
11+ import com .cloud .agent .api .AgentControlAnswer ;
12+ import com .cloud .agent .api .AgentControlCommand ;
13+ import com .cloud .agent .api .Answer ;
14+ import com .cloud .agent .api .Command ;
15+ import com .cloud .agent .api .StartupCommand ;
16+ import com .cloud .agent .api .StartupSecondaryStorageCommand ;
917import com .cloud .agent .manager .MockStorageManager ;
18+ import com .cloud .exception .ConnectionException ;
1019import com .cloud .host .HostVO ;
20+ import com .cloud .host .Status ;
21+ import com .cloud .storage .SnapshotVO ;
22+ import com .cloud .storage .dao .SnapshotDao ;
1123import com .cloud .storage .secondary .SecondaryStorageDiscoverer ;
1224import com .cloud .utils .component .Inject ;
25+ import com .cloud .utils .exception .CloudRuntimeException ;
1326@ Local (value =Discoverer .class )
14- public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer {
15- @ Inject
16- MockStorageManager _mockStorageMgr = null ;
27+ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer implements ResourceStateAdapter , Listener {
28+ @ Inject MockStorageManager _mockStorageMgr = null ;
29+ @ Inject AgentManager _agentMgr ;
30+ @ Inject ResourceManager _resourceMgr ;
31+ @ Inject SnapshotDao _snapshotDao ;
1732
1833 @ Override
1934 public boolean configure (String name , Map <String , Object > params ) throws ConfigurationException {
35+ _agentMgr .registerForHostEvents (this , true , false , false );
36+ _resourceMgr .registerResourceStateAdapter (this .getClass ().getSimpleName (), this );
2037 return super .configure (name , params );
2138 }
2239
@@ -27,4 +44,92 @@ public void postDiscovery(List<HostVO> hosts, long msId) {
2744 _mockStorageMgr .preinstallTemplates (host .getStorageUrl (), host .getDataCenterId ());
2845 }
2946 }
47+
48+ @ Override
49+ public HostVO createHostVOForConnectedAgent (HostVO host ,
50+ StartupCommand [] cmd ) {
51+ return null ;
52+ }
53+
54+ @ Override
55+ public HostVO createHostVOForDirectConnectAgent (HostVO host ,
56+ StartupCommand [] startup , ServerResource resource ,
57+ Map <String , String > details , List <String > hostTags ) {
58+ //for detecting SSVM dispatch
59+ StartupCommand firstCmd = startup [0 ];
60+ if (!(firstCmd instanceof StartupSecondaryStorageCommand )) {
61+ return null ;
62+ }
63+
64+ host .setType (com .cloud .host .Host .Type .SecondaryStorageVM );
65+ return host ;
66+ }
67+
68+ @ Override
69+ public DeleteHostAnswer deleteHost (HostVO host , boolean isForced ,
70+ boolean isForceDeleteStorage ) throws UnableDeleteHostException {
71+ long hostId = host .getId ();
72+ List <SnapshotVO > snapshots = _snapshotDao .listByHostId (hostId );
73+ if (snapshots != null && !snapshots .isEmpty ()) {
74+ throw new CloudRuntimeException ("Cannot delete this secondary storage because there are still snapshots on it " );
75+ }
76+ _vmTemplateHostDao .deleteByHost (hostId );
77+ host .setGuid (null );
78+ _hostDao .update (hostId , host );
79+ _hostDao .remove (hostId );
80+ return new DeleteHostAnswer (true );
81+ }
82+
83+ @ Override
84+ public boolean start () {
85+ return true ;
86+ }
87+
88+ @ Override
89+ public boolean stop () {
90+ _resourceMgr .unregisterResourceStateAdapter (this .getClass ().getSimpleName ());
91+ return true ;
92+ }
93+
94+ @ Override
95+ public int getTimeout () {
96+ return 0 ;
97+ }
98+
99+ @ Override
100+ public boolean isRecurring () {
101+ return false ;
102+ }
103+
104+ @ Override
105+ public boolean processAnswers (long agentId , long seq , Answer [] answers ) {
106+ return false ;
107+ }
108+
109+ @ Override
110+ public boolean processCommands (long agentId , long seq , Command [] commands ) {
111+ return false ;
112+ }
113+
114+ @ Override
115+ public void processConnect (HostVO host , StartupCommand cmd ,
116+ boolean forRebalance ) throws ConnectionException {
117+
118+ }
119+
120+ @ Override
121+ public AgentControlAnswer processControlCommand (long agentId ,
122+ AgentControlCommand cmd ) {
123+ return null ;
124+ }
125+
126+ @ Override
127+ public boolean processDisconnect (long agentId , Status state ) {
128+ return false ;
129+ }
130+
131+ @ Override
132+ public boolean processTimeout (long agentId , long seq ) {
133+ return false ;
134+ }
30135}
0 commit comments