@@ -181,60 +181,44 @@ public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
181181 throw new InvalidParameterValueException ("attachCluster: dataStore should not be null" );
182182 }
183183 if (scope == null ) {
184- throw new InvalidParameterValueException ("attachCluster: clusterScope should not be null" );
184+ throw new InvalidParameterValueException ("attachCluster: scope should not be null" );
185185 }
186186 List <String > hostsIdentifier = new ArrayList <>();
187187 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
188188 if (storagePool == null ) {
189189 s_logger .error ("attachCluster : Storage Pool not found for id: " + dataStore .getId ());
190190 throw new CloudRuntimeException ("attachCluster : Storage Pool not found for id: " + dataStore .getId ());
191191 }
192- PrimaryDataStoreInfo primarystore = (PrimaryDataStoreInfo )dataStore ;
193- List <HostVO > hostsToConnect = _resourceMgr .getEligibleUpAndEnabledHostsInClusterForStorageConnection (primarystore );
192+ PrimaryDataStoreInfo primaryStore = (PrimaryDataStoreInfo )dataStore ;
193+ List <HostVO > hostsToConnect = _resourceMgr .getEligibleUpAndEnabledHostsInClusterForStorageConnection (primaryStore );
194194 // TODO- need to check if no host to connect then throw exception or just continue
195- logger .debug (String . format ( "Attaching the pool to each of the hosts %s in the cluster: %s " , hostsToConnect , primarystore .getClusterId () ));
195+ logger .debug ("attachCluster: Eligible Up and Enabled hosts: {} in cluster {} " , hostsToConnect , primaryStore .getClusterId ());
196196
197- Map <String , String > details = primarystore .getDetails ();
197+ Map <String , String > details = primaryStore .getDetails ();
198198 StorageStrategy strategy = utils .getStrategyByStoragePoolDetails (details );
199199 ProtocolType protocol = ProtocolType .valueOf (details .get (Constants .PROTOCOL ));
200+ //TODO- Check if we have to handle heterogeneous host within the cluster
200201 if (!isProtocolSupportedByAllHosts (hostsToConnect , protocol , hostsIdentifier )) {
201- throw new CloudRuntimeException ("Not all hosts in the cluster support the protocol: " + protocol .toString ());
202+ s_logger .error ("attachCluster: Not all hosts in the cluster support the protocol: " + protocol .name ());
203+ throw new CloudRuntimeException ("attachCluster: Not all hosts in the cluster support the protocol: " + protocol .name ());
202204 }
203205 //TODO - check if no host to connect then also need to create access group without initiators
204206 if (hostsIdentifier != null && hostsIdentifier .size () > 0 ) {
205207 AccessGroup accessGroupRequest = utils .createAccessGroupRequestByProtocol (storagePool , scope .getScopeId (), details , hostsIdentifier );
206208 strategy .createAccessGroup (accessGroupRequest );
207209 }
210+ logger .debug ("attachCluster: Attaching the pool to each of the host in the cluster: %s" , primaryStore .getClusterId ());
208211 for (HostVO host : hostsToConnect ) {
209212 try {
210213 _storageMgr .connectHostToSharedPool (host , dataStore .getId ());
211214 } catch (Exception e ) {
212- logger .warn ("Unable to establish a connection between " + host + " and " + dataStore , e );
215+ logger .warn ("attachCluster: Unable to establish a connection between " + host + " and " + dataStore , e );
213216 }
214217 }
215218 _dataStoreHelper .attachCluster (dataStore );
216219 return true ;
217220 }
218221
219- private boolean isProtocolSupportedByAllHosts (List <HostVO > hosts , ProtocolType protocolType , List <String > hostIdentifiers ) {
220- String protocolPrefix ;
221- switch (protocolType ) {
222- case ISCSI :
223- protocolPrefix = Constants .IQN ;
224- for (HostVO host : hosts ) {
225- if (host == null || host .getStorageUrl () == null || host .getStorageUrl ().trim ().isEmpty ()
226- || !host .getStorageUrl ().startsWith (protocolPrefix )) {
227- return false ;
228- }
229- hostIdentifiers .add (host .getStorageUrl ());
230- }
231- break ;
232- default :
233- throw new CloudRuntimeException ("Unsupported protocol: " + protocolType .toString ());
234- }
235- return true ;
236- }
237-
238222 @ Override
239223 public boolean attachHost (DataStore store , HostScope scope , StoragePoolInfo existingInfo ) {
240224 return false ;
@@ -247,30 +231,31 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper
247231 throw new InvalidParameterValueException ("attachZone: dataStore should not be null" );
248232 }
249233 if (scope == null ) {
250- throw new InvalidParameterValueException ("attachZone: clusterScope should not be null" );
234+ throw new InvalidParameterValueException ("attachZone: scope should not be null" );
251235 }
252236 List <String > hostsIdentifier = new ArrayList <>();
253237 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
254238 if (storagePool == null ) {
255- s_logger .error ("attachCluster : Storage Pool not found for id: " + dataStore .getId ());
239+ s_logger .error ("attachZone : Storage Pool not found for id: " + dataStore .getId ());
256240 throw new CloudRuntimeException ("attachCluster : Storage Pool not found for id: " + dataStore .getId ());
257241 }
258242 List <HostVO > hostsToConnect = _resourceMgr .getEligibleUpAndEnabledHostsInZoneForStorageConnection (dataStore , scope .getScopeId (), Hypervisor .HypervisorType .KVM );
259243 // TODO- need to check if no host to connect then throw exception or just continue
260- logger .debug (String . format ( "In createPool. Attaching the pool to each of the hosts in %s. " , hostsToConnect ) );
244+ logger .debug ("attachZone: Eligible Up and Enabled hosts: {} " , hostsToConnect );
261245
262246 Map <String , String > details = storagePoolDetailsDao .listDetailsKeyPairs (dataStore .getId ());
263247 StorageStrategy strategy = utils .getStrategyByStoragePoolDetails (details );
264248 ProtocolType protocol = ProtocolType .valueOf (details .get (Constants .PROTOCOL ));
249+ //TODO- Check if we have to handle heterogeneous host within the zone
265250 if (!isProtocolSupportedByAllHosts (hostsToConnect , protocol , hostsIdentifier )) {
266- throw new CloudRuntimeException ("Not all hosts in the zone support the protocol: " + protocol .toString ());
251+ s_logger .error ("attachZone: Not all hosts in the cluster support the protocol: " + protocol .name ());
252+ throw new CloudRuntimeException ("attachZone: Not all hosts in the zone support the protocol: " + protocol .name ());
267253 }
268254 if (hostsIdentifier != null && !hostsIdentifier .isEmpty ()) {
269255 AccessGroup accessGroupRequest = utils .createAccessGroupRequestByProtocol (storagePool , scope .getScopeId (), details , hostsIdentifier );
270256 strategy .createAccessGroup (accessGroupRequest );
271257 }
272258 for (HostVO host : hostsToConnect ) {
273- // TODO: Fetch the host IQN and add to the initiator group on ONTAP cluster
274259 try {
275260 _storageMgr .connectHostToSharedPool (host , dataStore .getId ());
276261 } catch (Exception e ) {
@@ -281,6 +266,24 @@ public boolean attachZone(DataStore dataStore, ZoneScope scope, Hypervisor.Hyper
281266 return true ;
282267 }
283268
269+ private boolean isProtocolSupportedByAllHosts (List <HostVO > hosts , ProtocolType protocolType , List <String > hostIdentifiers ) {
270+ switch (protocolType ) {
271+ case ISCSI :
272+ String protocolPrefix = Constants .IQN ;
273+ for (HostVO host : hosts ) {
274+ if (host == null || host .getStorageUrl () == null || host .getStorageUrl ().trim ().isEmpty ()
275+ || !host .getStorageUrl ().startsWith (protocolPrefix )) {
276+ return false ;
277+ }
278+ hostIdentifiers .add (host .getStorageUrl ());
279+ }
280+ break ;
281+ default :
282+ throw new CloudRuntimeException ("isProtocolSupportedByAllHosts : Unsupported protocol: " + protocolType .name ());
283+ }
284+ return true ;
285+ }
286+
284287 @ Override
285288 public boolean maintain (DataStore store ) {
286289 return true ;
0 commit comments