agave-monitors/monitors-core/src/main/java/org/iplantc/service/monitor/managers/MonitorManager.java
/**
	 * Performs a check on connectivity to a storage system.
	 * 
	 * @param monitor the monitor to check
	 * @param createdBy user who kicked off the check
	 * @return a monitor check with the current check results
	 */
Performs a check on connectivity to a storage system.

@param monitor the monitor to check
@param createdBy user who kicked off the check
@return a monitor check with the current check results
Performs a check on connectivity to a storage system . @param monitor the monitor to check @param createdBy user who kicked off the check @return a monitor check with the current check results
@SuppressWarnings("unused")
    private MonitorCheck doStorageCheck(Monitor monitor, String createdBy)
	{
		MonitorCheck currentCheck = new MonitorCheck(monitor, MonitorStatusType.UNKNOWN, null, MonitorCheckType.STORAGE);
		RemoteDataClient monitoredSystemRemoteDataClient = null;
		MonitorCheck lastCheck = null;
		RemoteSystem system = null;
		try 
		{
			system = monitor.getSystem();
			verifyUserHasSystemDataPermissions(system, monitor.getOwner());
			lastCheck = getMonitorCheckDao().getLastMonitorCheck(monitor.getId());
			monitoredSystemRemoteDataClient = system.getRemoteDataClient(monitor.getInternalUsername());
			if (log.isTraceEnabled())
			    log.trace("[" + Thread.currentThread().getName() + "] Checking authentication to " + system.getSystemId() +
					system.getStorageConfig().toString());
			monitoredSystemRemoteDataClient.authenticate();
			if (log.isTraceEnabled())
				log.trace("Data connectivity succeeded to " + system.getSystemId() +
						"(" +  system.getStorageConfig().getProtocol() + ":" + monitoredSystemRemoteDataClient.getHost() + ")");
			if (log.isTraceEnabled())
				log.trace("[" + Thread.currentThread().getName() + "] Checking data connectivity to " + system.getSystemId() +
						system.getStorageConfig().toString());
			monitoredSystemRemoteDataClient.doesExist("/");
			if (log.isTraceEnabled())
				log.trace("Data connectivity succeeded to " + system.getSystemId() +
						"(" +  system.getStorageConfig().getProtocol() + ":" + monitoredSystemRemoteDataClient.getHost() + ")");
			currentCheck.setResult(MonitorStatusType.PASSED);
			currentCheck.setCreated(new Date());
		} catch (SystemRoleException e) {
			String msg = String.format("Unable to verify owner permissions on monitor %s to access system %s. Skipping check.",
					monitor.getUuid(), system.getSystemId());
			log.error(msg);
			currentCheck.setMessage(e.getMessage());
			currentCheck.setResult(MonitorStatusType.UNKNOWN);
		}
		catch (PermissionException e) {
			if (log.isTraceEnabled())
				log.trace(e.getMessage());
			currentCheck.setMessage(e.getMessage());
			currentCheck.setResult(MonitorStatusType.FAILED);
		} catch (RemoteDataException|IOException  e) {
			if (system.getStorageConfig() != null) {
				log.debug("Data connectivity failed to " + system.getSystemId() + 
					"(" +  system.getStorageConfig().getProtocol() + ":" + system.getStorageConfig().getHost() + ")" +
					". " + e.getMessage());
			} else {
				log.debug("Data connectivity failed to " + system.getSystemId() + 
						". " + e.getMessage());
			}
			currentCheck.setMessage(e.getMessage());
			currentCheck.setResult(MonitorStatusType.FAILED);
		}
		catch (RemoteCredentialException e) 
		{
			log.debug("Failed to retrieve an authentication credential for " + system.getSystemId() +
				" when running storage check. " +  e.getMessage());
			currentCheck.setMessage("Authentication failed for " + system.getSystemId() + 
					". " + e.getMessage());
			currentCheck.setResult(MonitorStatusType.FAILED);
		}
		catch (Exception e)
		{
			if (system != null && system.getStorageConfig() != null) {
				log.debug("Data connectivity failed to " + system.getSystemId() + " " +
								system.getStorageConfig().toString() + ". " + e.getMessage());
			} else if (system != null) {
				log.debug("Data connectivity failed to " + system.getSystemId() + 
						". " + e.getMessage());
			} else {
				log.debug("Data connectivity failed for monitor " + monitor.getId());
			}
			currentCheck.setMessage("Failed to perform storage monitoring check on " + 
					monitor.getSystem().getSystemId() + "\n" + e.getMessage());
			currentCheck.setResult(MonitorStatusType.FAILED);
		}
		finally {
			try { if (monitoredSystemRemoteDataClient != null) monitoredSystemRemoteDataClient.disconnect(); } catch (Exception ignored) {}
		}
		try {
			currentCheck.setMonitor(monitor);
			getMonitorCheckDao().persist(currentCheck);
			eventProcessor.processCheckEvent(monitor, lastCheck, currentCheck, createdBy);
		} 
		catch (Exception e)  {
			log.error("Failed to persist storage monitor check " + currentCheck.getUuid() + " for monitor " + monitor.getUuid(), e);
		} finally {
			try {
				monitor.setLastUpdated(new Date());
				getMonitorDao().persist(monitor);
			} catch (StaleStateException e) {
				log.error("Failed to update stale reference to monitor " + monitor.getUuid() +
						" after check " + currentCheck.getUuid());
			} catch (Throwable t){
				log.error("Failed to update monitor " + monitor.getUuid() + " after check " +
						currentCheck.getUuid(), t);
			}
		}
		return currentCheck;
	}
@ SuppressWarnings ( "unused" ) private MonitorCheck doStorageCheck ( Monitor monitor , String createdBy ) { MonitorCheck currentCheck = new MonitorCheck ( monitor , MonitorStatusType . UNKNOWN , null , MonitorCheckType . STORAGE ) ; RemoteDataClient monitoredSystemRemoteDataClient = null ; MonitorCheck lastCheck = null ; RemoteSystem system = null ; try { system = monitor . getSystem ( ) ; verifyUserHasSystemDataPermissions ( system , monitor . getOwner ( ) ) ; lastCheck = getMonitorCheckDao ( ) . getLastMonitorCheck ( monitor . getId ( ) ) ; monitoredSystemRemoteDataClient = system . getRemoteDataClient ( monitor . getInternalUsername ( ) ) ; if ( log . isTraceEnabled ( ) ) log . trace ( "[" + Thread . currentThread ( ) . getName ( ) + "] Checking authentication to " + system . getSystemId ( ) + system . getStorageConfig ( ) . toString ( ) ) ; monitoredSystemRemoteDataClient . authenticate ( ) ; if ( log . isTraceEnabled ( ) ) log . trace ( "Data connectivity succeeded to " + system . getSystemId ( ) + "(" + system . getStorageConfig ( ) . getProtocol ( ) + ":" + monitoredSystemRemoteDataClient . getHost ( ) + ")" ) ; if ( log . isTraceEnabled ( ) ) log . trace ( "[" + Thread . currentThread ( ) . getName ( ) + "] Checking data connectivity to " + system . getSystemId ( ) + system . getStorageConfig ( ) . toString ( ) ) ; monitoredSystemRemoteDataClient . doesExist ( "/" ) ; if ( log . isTraceEnabled ( ) ) log . trace ( "Data connectivity succeeded to " + system . getSystemId ( ) + "(" + system . getStorageConfig ( ) . getProtocol ( ) + ":" + monitoredSystemRemoteDataClient . getHost ( ) + ")" ) ; currentCheck . setResult ( MonitorStatusType . PASSED ) ; currentCheck . setCreated ( new Date ( ) ) ; } catch ( SystemRoleException e ) { String msg = String . format ( "Unable to verify owner permissions on monitor %s to access system %s. Skipping check." , monitor . getUuid ( ) , system . getSystemId ( ) ) ; log . error ( msg ) ; currentCheck . setMessage ( e . getMessage ( ) ) ; currentCheck . setResult ( MonitorStatusType . UNKNOWN ) ; } catch ( PermissionException e ) { if ( log . isTraceEnabled ( ) ) log . trace ( e . getMessage ( ) ) ; currentCheck . setMessage ( e . getMessage ( ) ) ; currentCheck . setResult ( MonitorStatusType . FAILED ) ; } catch ( RemoteDataException | IOException e ) { if ( system . getStorageConfig ( ) != null ) { log . debug ( "Data connectivity failed to " + system . getSystemId ( ) + "(" + system . getStorageConfig ( ) . getProtocol ( ) + ":" + system . getStorageConfig ( ) . getHost ( ) + ")" + ". " + e . getMessage ( ) ) ; } else { log . debug ( "Data connectivity failed to " + system . getSystemId ( ) + ". " + e . getMessage ( ) ) ; } currentCheck . setMessage ( e . getMessage ( ) ) ; currentCheck . setResult ( MonitorStatusType . FAILED ) ; } catch ( RemoteCredentialException e ) { log . debug ( "Failed to retrieve an authentication credential for " + system . getSystemId ( ) + " when running storage check. " + e . getMessage ( ) ) ; currentCheck . setMessage ( "Authentication failed for " + system . getSystemId ( ) + ". " + e . getMessage ( ) ) ; currentCheck . setResult ( MonitorStatusType . FAILED ) ; } catch ( Exception e ) { if ( system != null && system . getStorageConfig ( ) != null ) { log . debug ( "Data connectivity failed to " + system . getSystemId ( ) + " " + system . getStorageConfig ( ) . toString ( ) + ". " + e . getMessage ( ) ) ; } else if ( system != null ) { log . debug ( "Data connectivity failed to " + system . getSystemId ( ) + ". " + e . getMessage ( ) ) ; } else { log . debug ( "Data connectivity failed for monitor " + monitor . getId ( ) ) ; } currentCheck . setMessage ( "Failed to perform storage monitoring check on " + monitor . getSystem ( ) . getSystemId ( ) + "\n" + e . getMessage ( ) ) ; currentCheck . setResult ( MonitorStatusType . FAILED ) ; } finally { try { if ( monitoredSystemRemoteDataClient != null ) monitoredSystemRemoteDataClient . disconnect ( ) ; } catch ( Exception ignored ) { } } try { currentCheck . setMonitor ( monitor ) ; getMonitorCheckDao ( ) . persist ( currentCheck ) ; eventProcessor . processCheckEvent ( monitor , lastCheck , currentCheck , createdBy ) ; } catch ( Exception e ) { log . error ( "Failed to persist storage monitor check " + currentCheck . getUuid ( ) + " for monitor " + monitor . getUuid ( ) , e ) ; } finally { try { monitor . setLastUpdated ( new Date ( ) ) ; getMonitorDao ( ) . persist ( monitor ) ; } catch ( StaleStateException e ) { log . error ( "Failed to update stale reference to monitor " + monitor . getUuid ( ) + " after check " + currentCheck . getUuid ( ) ) ; } catch ( Throwable t ) { log . error ( "Failed to update monitor " + monitor . getUuid ( ) + " after check " + currentCheck . getUuid ( ) , t ) ; } } return currentCheck ; }
Performs a check on connectivity to a storage system.
Performs a check on connectivity to a storage system .
// system was verified when the monitoring task was selected, so we use the interal getter here // check user still has permission to run the data check on the target system. The permission exception // will be handled with failure logic, but will not disable the monitor. This allows for situations where // a check might run while a system is being published, updated, or a user is revoked access for a short // period of time. // remote storage auth check // file system check // we perform an existence check on / because if that does not exist, data operations on the remote system // won't be useful anyway. // if both succeeded, this check passes // fail the check // something went wrong. The system storage is not accessible. // something went wrong. The system storage is not accessible.