3030import org .apache .cloudstack .storage .datastore .db .StoragePoolDetailsDao ;
3131import org .apache .commons .collections .MapUtils ;
3232import org .apache .commons .lang3 .StringUtils ;
33- import org .apache .log4j .Logger ;
33+ import org .apache .logging .log4j .LogManager ;
34+ import org .apache .logging .log4j .Logger ;
3435import org .springframework .stereotype .Component ;
3536
3637import com .cloud .agent .AgentManager ;
5152
5253@ Component
5354public class ScaleIOSDCManagerImpl implements ScaleIOSDCManager {
54- private static final Logger LOGGER = Logger .getLogger (ScaleIOSDCManagerImpl .class );
55+ private static final Logger logger = LogManager .getLogger (ScaleIOSDCManagerImpl .class );
5556
5657 @ Inject
5758 AgentManager agentManager ;
@@ -79,14 +80,14 @@ public boolean areSDCConnectionsWithinLimit(Long storagePoolId) {
7980
8081 int connectedSdcsCount = getScaleIOClient (storagePoolId ).getConnectedSdcsCount ();
8182 if (connectedSdcsCount < connectedClientsLimit ) {
82- LOGGER .debug (String .format ("Current connected SDCs count: %d - SDC connections are within the limit (%d) on PowerFlex Storage with pool id: %d" , connectedSdcsCount , connectedClientsLimit , storagePoolId ));
83+ logger .debug (String .format ("Current connected SDCs count: %d - SDC connections are within the limit (%d) on PowerFlex Storage with pool id: %d" , connectedSdcsCount , connectedClientsLimit , storagePoolId ));
8384 return true ;
8485 }
85- LOGGER .debug (String .format ("Current connected SDCs count: %d - SDC connections limit (%d) reached on PowerFlex Storage with pool id: %d" , connectedSdcsCount , connectedClientsLimit , storagePoolId ));
86+ logger .debug (String .format ("Current connected SDCs count: %d - SDC connections limit (%d) reached on PowerFlex Storage with pool id: %d" , connectedSdcsCount , connectedClientsLimit , storagePoolId ));
8687 return false ;
8788 } catch (Exception e ) {
8889 String errMsg = "Unable to check SDC connections for the PowerFlex storage pool with id: " + storagePoolId + " due to " + e .getMessage ();
89- LOGGER .warn (errMsg , e );
90+ logger .warn (errMsg , e );
9091 return false ;
9192 }
9293 }
@@ -109,33 +110,33 @@ public String prepareSDC(Host host, DataStore dataStore) {
109110
110111 int storagePoolMaxWaitSeconds = NumbersUtil .parseInt (configDao .getValue (Config .StoragePoolMaxWaitSeconds .key ()), 3600 );
111112 if (!hostIdStorageSystemIdLock .lock (storagePoolMaxWaitSeconds )) {
112- LOGGER .debug ("Unable to prepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString );
113+ logger .debug ("Unable to prepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString );
113114 throw new CloudRuntimeException ("Unable to prepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString );
114115 }
115116
116117 long poolId = dataStore .getId ();
117118 long hostId = host .getId ();
118119 String sdcId = getConnectedSdc (poolId , hostId );
119120 if (StringUtils .isNotBlank (sdcId )) {
120- LOGGER .debug (String .format ("SDC %s already connected for the pool: %d on host: %d, no need to prepare/start it" , sdcId , poolId , hostId ));
121+ logger .debug (String .format ("SDC %s already connected for the pool: %d on host: %d, no need to prepare/start it" , sdcId , poolId , hostId ));
121122 return sdcId ;
122123 }
123124
124125 String storageSystemIdLockString = String .format (POWERFLEX_SDC_SYSTEMID_LOCK_FORMAT , systemId );
125126 storageSystemIdLock = GlobalLock .getInternLock (storageSystemIdLockString );
126127 if (storageSystemIdLock == null ) {
127- LOGGER .error ("Unable to prepare SDC, couldn't get global lock on: " + storageSystemIdLockString );
128+ logger .error ("Unable to prepare SDC, couldn't get global lock on: " + storageSystemIdLockString );
128129 throw new CloudRuntimeException ("Unable to prepare SDC, couldn't get global lock on " + storageSystemIdLockString );
129130 }
130131
131132 if (!storageSystemIdLock .lock (storagePoolMaxWaitSeconds )) {
132- LOGGER .error ("Unable to prepare SDC, couldn't lock on " + storageSystemIdLockString );
133+ logger .error ("Unable to prepare SDC, couldn't lock on " + storageSystemIdLockString );
133134 throw new CloudRuntimeException ("Unable to prepare SDC, couldn't lock on " + storageSystemIdLockString );
134135 }
135136
136137 if (!areSDCConnectionsWithinLimit (poolId )) {
137138 String errorMsg = String .format ("Unable to check SDC connections or the connections limit reached for Powerflex storage (System ID: %s)" , systemId );
138- LOGGER .error (errorMsg );
139+ logger .error (errorMsg );
139140 throw new CloudRuntimeException (errorMsg );
140141 }
141142
@@ -174,7 +175,7 @@ public String prepareSDC(Host host, DataStore dataStore) {
174175 }
175176
176177 private String prepareSDCOnHost (Host host , DataStore dataStore , String systemId ) {
177- LOGGER .debug (String .format ("Preparing SDC on the host %s (%s)" , host .getId (), host .getName ()));
178+ logger .debug (String .format ("Preparing SDC on the host %s (%s)" , host .getId (), host .getName ()));
178179 Map <String ,String > details = new HashMap <>();
179180 details .put (ScaleIOGatewayClient .STORAGE_POOL_SYSTEM_ID , systemId );
180181 PrepareStorageClientCommand cmd = new PrepareStorageClientCommand (((PrimaryDataStore ) dataStore ).getPoolType (), dataStore .getUuid (), details );
@@ -186,25 +187,25 @@ private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId)
186187 prepareStorageClientAnswer = (PrepareStorageClientAnswer ) agentManager .send (host .getId (), cmd );
187188 } catch (AgentUnavailableException | OperationTimedoutException e ) {
188189 String err = String .format ("Failed to prepare SDC on the host %s, due to: %s" , host .getName (), e .getMessage ());
189- LOGGER .error (err );
190+ logger .error (err );
190191 throw new CloudRuntimeException (err );
191192 }
192193
193194 if (prepareStorageClientAnswer == null ) {
194195 String err = String .format ("Unable to prepare SDC on the host %s" , host .getName ());
195- LOGGER .error (err );
196+ logger .error (err );
196197 throw new CloudRuntimeException (err );
197198 }
198199
199200 if (!prepareStorageClientAnswer .getResult ()) {
200201 String err = String .format ("Unable to prepare SDC on the host %s, due to: %s" , host .getName (), prepareStorageClientAnswer .getDetails ());
201- LOGGER .error (err );
202+ logger .error (err );
202203 throw new CloudRuntimeException (err );
203204 }
204205
205206 Map <String ,String > poolDetails = prepareStorageClientAnswer .getDetailsMap ();
206207 if (MapUtils .isEmpty (poolDetails )) {
207- LOGGER .warn (String .format ("PowerFlex storage SDC details not found on the host: %s, try (re)install SDC and restart agent" , host .getId ()));
208+ logger .warn (String .format ("PowerFlex storage SDC details not found on the host: %s, try (re)install SDC and restart agent" , host .getId ()));
208209 return null ;
209210 }
210211
@@ -217,7 +218,7 @@ private String prepareSDCOnHost(Host host, DataStore dataStore, String systemId)
217218 }
218219
219220 if (StringUtils .isBlank (sdcId )) {
220- LOGGER .warn (String .format ("Couldn't retrieve PowerFlex storage SDC details from the host: %s, try (re)install SDC and restart agent" , host .getId ()));
221+ logger .warn (String .format ("Couldn't retrieve PowerFlex storage SDC details from the host: %s, try (re)install SDC and restart agent" , host .getId ()));
221222 return null ;
222223 }
223224
@@ -241,15 +242,15 @@ public boolean stopSDC(Host host, DataStore dataStore) {
241242
242243 int storagePoolMaxWaitSeconds = NumbersUtil .parseInt (configDao .getValue (Config .StoragePoolMaxWaitSeconds .key ()), 3600 );
243244 if (!lock .lock (storagePoolMaxWaitSeconds )) {
244- LOGGER .debug ("Unable to unprepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString );
245+ logger .debug ("Unable to unprepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString );
245246 throw new CloudRuntimeException ("Unable to unprepare SDC, couldn't lock on " + hostIdStorageSystemIdLockString );
246247 }
247248
248249 long poolId = dataStore .getId ();
249250 long hostId = host .getId ();
250251 String sdcId = getConnectedSdc (poolId , hostId );
251252 if (StringUtils .isBlank (sdcId )) {
252- LOGGER .debug ("SDC not connected, no need to unprepare it" );
253+ logger .debug ("SDC not connected, no need to unprepare it" );
253254 return true ;
254255 }
255256
@@ -263,7 +264,7 @@ public boolean stopSDC(Host host, DataStore dataStore) {
263264 }
264265
265266 private boolean unprepareSDCOnHost (Host host , DataStore dataStore ) {
266- LOGGER .debug (String .format ("Unpreparing SDC on the host %s (%s)" , host .getId (), host .getName ()));
267+ logger .debug (String .format ("Unpreparing SDC on the host %s (%s)" , host .getId (), host .getName ()));
267268 UnprepareStorageClientCommand cmd = new UnprepareStorageClientCommand (((PrimaryDataStore ) dataStore ).getPoolType (), dataStore .getUuid ());
268269 int timeoutSeconds = 60 ;
269270 cmd .setWait (timeoutSeconds );
@@ -273,25 +274,25 @@ private boolean unprepareSDCOnHost(Host host, DataStore dataStore) {
273274 unprepareStorageClientAnswer = agentManager .send (host .getId (), cmd );
274275 } catch (AgentUnavailableException | OperationTimedoutException e ) {
275276 String err = String .format ("Failed to unprepare SDC on the host %s due to: %s" , host .getName (), e .getMessage ());
276- LOGGER .error (err );
277+ logger .error (err );
277278 return false ;
278279 }
279280
280281 if (!unprepareStorageClientAnswer .getResult ()) {
281282 String err = String .format ("Unable to unprepare SDC on the the host %s due to: %s" , host .getName (), unprepareStorageClientAnswer .getDetails ());
282- LOGGER .error (err );
283+ logger .error (err );
283284 return false ;
284285 }
285286 return true ;
286287 }
287288
288289 private String getHostSdcId (String sdcGuid , long poolId ) {
289290 try {
290- LOGGER .debug (String .format ("Try to get host SDC Id for pool: %s, with SDC guid %s" , poolId , sdcGuid ));
291+ logger .debug (String .format ("Try to get host SDC Id for pool: %s, with SDC guid %s" , poolId , sdcGuid ));
291292 ScaleIOGatewayClient client = getScaleIOClient (poolId );
292293 return client .getSdcIdByGuid (sdcGuid );
293294 } catch (Exception e ) {
294- LOGGER .error (String .format ("Failed to get host SDC Id for pool: %s" , poolId ), e );
295+ logger .error (String .format ("Failed to get host SDC Id for pool: %s" , poolId ), e );
295296 throw new CloudRuntimeException (String .format ("Failed to establish connection with PowerFlex Gateway to get host SDC Id for pool: %s" , poolId ));
296297 }
297298 }
@@ -308,14 +309,14 @@ private String getConnectedSdc(long poolId, long hostId) {
308309 return poolHostVO .getLocalPath ();
309310 }
310311 } catch (Exception e ) {
311- LOGGER .warn ("Unable to get connected SDC for the host: " + hostId + " and storage pool: " + poolId + " due to " + e .getMessage (), e );
312+ logger .warn ("Unable to get connected SDC for the host: " + hostId + " and storage pool: " + poolId + " due to " + e .getMessage (), e );
312313 }
313314
314315 return null ;
315316 }
316317
317318 private boolean hostSdcConnected (String sdcId , long poolId , int waitTimeInSecs ) {
318- LOGGER .debug (String .format ("Waiting (for %d secs) for the SDC %s of the pool id: %d to connect" , waitTimeInSecs , sdcId , poolId ));
319+ logger .debug (String .format ("Waiting (for %d secs) for the SDC %s of the pool id: %d to connect" , waitTimeInSecs , sdcId , poolId ));
319320 int timeBetweenTries = 1000 ; // Try more frequently (every sec) and return early if connected
320321 while (waitTimeInSecs > 0 ) {
321322 if (isHostSdcConnected (sdcId , poolId )) {
@@ -335,7 +336,7 @@ private boolean isHostSdcConnected(String sdcId, long poolId) {
335336 final ScaleIOGatewayClient client = getScaleIOClient (poolId );
336337 return client .isSdcConnected (sdcId );
337338 } catch (Exception e ) {
338- LOGGER .error ("Failed to check host SDC connection" , e );
339+ logger .error ("Failed to check host SDC connection" , e );
339340 throw new CloudRuntimeException ("Failed to establish connection with PowerFlex Gateway to check host SDC connection" );
340341 }
341342 }
0 commit comments