4444import com .cloud .storage .VMTemplateVO ;
4545import com .cloud .storage .VMTemplateZoneVO ;
4646import com .cloud .storage .dao .VMTemplateDao ;
47- import com .cloud .storage .dao .VMTemplateHostDao ;
4847import com .cloud .storage .dao .VMTemplateZoneDao ;
4948import com .cloud .storage .resource .DummySecondaryStorageResource ;
5049import com .cloud .storage .resource .LocalSecondaryStorageResource ;
6160@ Local (value =Discoverer .class )
6261public class SecondaryStorageDiscoverer extends DiscovererBase implements Discoverer {
6362 private static final Logger s_logger = Logger .getLogger (SecondaryStorageDiscoverer .class );
64-
63+
6564 long _timeout = 2 * 60 * 1000 ; // 2 minutes
6665 String _mountParent ;
6766 boolean _useServiceVM = false ;
68-
67+
6968 Random _random = new Random (System .currentTimeMillis ());
7069 @ Inject
7170 protected HostDao _hostDao = null ;
7271 @ Inject
7372 protected VMTemplateDao _tmpltDao = null ;
7473 @ Inject
75- protected VMTemplateHostDao _vmTemplateHostDao = null ;
76- @ Inject
7774 protected VMTemplateZoneDao _vmTemplateZoneDao = null ;
7875 @ Inject
7976 protected VMTemplateDao _vmTemplateDao = null ;
8077 @ Inject
8178 protected ConfigurationDao _configDao = null ;
8279 @ Inject
8380 protected AgentManager _agentMgr = null ;
84-
81+
8582 protected SecondaryStorageDiscoverer () {
8683 }
87-
84+
8885 @ Override
8986 public Map <? extends ServerResource , Map <String , String >> find (long dcId , Long podId , Long clusterId , URI uri , String username , String password , List <String > hostTags ) {
9087 if (!uri .getScheme ().equalsIgnoreCase ("nfs" ) && !uri .getScheme ().equalsIgnoreCase ("file" )
@@ -103,43 +100,43 @@ public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long p
103100 return null ;
104101 }
105102 }
106-
103+
107104 protected Map <? extends ServerResource , Map <String , String >> createNfsSecondaryStorageResource (long dcId , Long podId , URI uri ) {
108-
105+
109106 if (_useServiceVM ) {
110107 return createDummySecondaryStorageResource (dcId , podId , uri );
111108 }
112109 String mountStr = NfsUtils .uri2Mount (uri );
113-
110+
114111 Script script = new Script (true , "mount" , _timeout , s_logger );
115112 String mntPoint = null ;
116113 File file = null ;
117114 do {
118115 mntPoint = _mountParent + File .separator + Integer .toHexString (_random .nextInt (Integer .MAX_VALUE ));
119116 file = new File (mntPoint );
120117 } while (file .exists ());
121-
118+
122119 if (!file .mkdirs ()) {
123120 s_logger .warn ("Unable to make directory: " + mntPoint );
124121 return null ;
125122 }
126-
123+
127124 script .add (mountStr , mntPoint );
128125 String result = script .execute ();
129126 if (result != null && !result .contains ("already mounted" )) {
130127 s_logger .warn ("Unable to mount " + uri .toString () + " due to " + result );
131128 file .delete ();
132129 return null ;
133130 }
134-
131+
135132 script = new Script (true , "umount" , 0 , s_logger );
136133 script .add (mntPoint );
137134 script .execute ();
138-
135+
139136 file .delete ();
140-
137+
141138 Map <NfsSecondaryStorageResource , Map <String , String >> srs = new HashMap <NfsSecondaryStorageResource , Map <String , String >>();
142-
139+
143140 NfsSecondaryStorageResource storage ;
144141 if (_configDao .isPremium ()) {
145142 Class <?> impl ;
@@ -174,12 +171,12 @@ protected Map<? extends ServerResource, Map<String, String>> createNfsSecondaryS
174171 } else {
175172 storage = new NfsSecondaryStorageResource ();
176173 }
177-
174+
178175 Map <String , String > details = new HashMap <String , String >();
179176 details .put ("mount.path" , mountStr );
180177 details .put ("orig.url" , uri .toString ());
181178 details .put ("mount.parent" , _mountParent );
182-
179+
183180 Map <String , Object > params = new HashMap <String , Object >();
184181 params .putAll (details );
185182 params .put ("zone" , Long .toString (dcId ));
@@ -189,95 +186,95 @@ protected Map<? extends ServerResource, Map<String, String>> createNfsSecondaryS
189186 params .put ("guid" , uri .toString ());
190187 params .put ("secondary.storage.vm" , "false" );
191188 params .put ("max.template.iso.size" , _configDao .getValue ("max.template.iso.size" ));
192-
189+
193190 try {
194191 storage .configure ("Storage" , params );
195192 } catch (ConfigurationException e ) {
196193 s_logger .warn ("Unable to configure the storage " , e );
197194 return null ;
198195 }
199196 srs .put (storage , details );
200-
197+
201198 return srs ;
202199 }
203-
200+
204201 protected Map <? extends ServerResource , Map <String , String >> createLocalSecondaryStorageResource (long dcId , Long podId , URI uri ) {
205202 Map <LocalSecondaryStorageResource , Map <String , String >> srs = new HashMap <LocalSecondaryStorageResource , Map <String , String >>();
206-
203+
207204 LocalSecondaryStorageResource storage = new LocalSecondaryStorageResource ();
208205 storage = ComponentContext .inject (storage );
209-
206+
210207 Map <String , String > details = new HashMap <String , String >();
211-
208+
212209 File file = new File (uri );
213210 details .put ("mount.path" , file .getAbsolutePath ());
214211 details .put ("orig.url" , uri .toString ());
215-
212+
216213 Map <String , Object > params = new HashMap <String , Object >();
217214 params .putAll (details );
218215 params .put ("zone" , Long .toString (dcId ));
219216 if (podId != null ) {
220217 params .put ("pod" , podId .toString ());
221218 }
222219 params .put ("guid" , uri .toString ());
223-
220+
224221 try {
225222 storage .configure ("Storage" , params );
226223 } catch (ConfigurationException e ) {
227224 s_logger .warn ("Unable to configure the storage " , e );
228225 return null ;
229226 }
230227 srs .put (storage , details );
231-
228+
232229 return srs ;
233230 }
234-
231+
235232 protected Map <ServerResource , Map <String , String >> createDummySecondaryStorageResource (long dcId , Long podId , URI uri ) {
236233 Map <ServerResource , Map <String , String >> srs = new HashMap <ServerResource , Map <String , String >>();
237-
234+
238235 DummySecondaryStorageResource storage = new DummySecondaryStorageResource (_useServiceVM );
239236 storage = ComponentContext .inject (storage );
240-
237+
241238 Map <String , String > details = new HashMap <String , String >();
242-
239+
243240 details .put ("mount.path" , uri .toString ());
244241 details .put ("orig.url" , uri .toString ());
245-
242+
246243 Map <String , Object > params = new HashMap <String , Object >();
247244 params .putAll (details );
248245 params .put ("zone" , Long .toString (dcId ));
249246 if (podId != null ) {
250247 params .put ("pod" , podId .toString ());
251248 }
252249 params .put ("guid" , uri .toString ());
253-
250+
254251 try {
255252 storage .configure ("Storage" , params );
256253 } catch (ConfigurationException e ) {
257254 s_logger .warn ("Unable to configure the storage " , e );
258255 return null ;
259256 }
260257 srs .put (storage , details );
261-
258+
262259 return srs ;
263260 }
264-
261+
265262 @ Override
266263 public boolean configure (String name , Map <String , Object > params ) throws ConfigurationException {
267264 super .configure (name , params );
268-
265+
269266 _mountParent = _params .get ("mount.parent" );
270267 if (_mountParent == null ) {
271268 _mountParent = "/mnt" ;
272269 }
273-
270+
274271 String useServiceVM = _params .get ("secondary.storage.vm" );
275272 if ("true" .equalsIgnoreCase (useServiceVM )){
276273 _useServiceVM = true ;
277274 }
278275 return true ;
279276 }
280-
277+
281278 @ Override
282279 public boolean matchHypervisor (String hypervisor ) {
283280 if ( hypervisor .equals ("SecondaryStorage" )) {
@@ -291,7 +288,7 @@ public boolean matchHypervisor(String hypervisor) {
291288 public Hypervisor .HypervisorType getHypervisorType () {
292289 return Hypervisor .HypervisorType .None ;
293290 }
294-
291+
295292 @ Override
296293 public void postDiscovery (List <HostVO > hosts , long msId ) {
297294 if (_useServiceVM ) {
@@ -302,9 +299,9 @@ public void postDiscovery(List<HostVO> hosts, long msId) {
302299 for (HostVO h : hosts ) {
303300 associateTemplatesToZone (h .getId (), h .getDataCenterId ());
304301 }
305-
302+
306303 }
307-
304+
308305 private void associateTemplatesToZone (long hostId , long dcId ){
309306 VMTemplateZoneVO tmpltZone ;
310307
0 commit comments