agave-monitors/monitors-core/src/main/java/org/iplantc/service/monitor/managers/MonitorManager.java
/**
	 * Performs a check on connectivity to a login 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 login 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 login 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 doLoginCheck(Monitor monitor, String createdBy)
	{
		MonitorCheck currentCheck = new MonitorCheck(monitor, MonitorStatusType.FAILED, null, MonitorCheckType.LOGIN);
		MonitorCheck lastCheck = null;
		ExecutionSystem system = null;
		try 
		{	
			lastCheck = getMonitorCheckDao().getLastMonitorCheck(monitor.getId());
			system = (ExecutionSystem)monitor.getSystem();
			if (log.isTraceEnabled())
				log.trace(String.format("Checking login connectivity to %s -> %s",
					system.getSystemId(), system.getLoginConfig().toString()));
			try (RemoteSubmissionClient submissionClient = ((ExecutionSystem)monitor.getSystem()).getRemoteSubmissionClient(monitor.getInternalUsername())) {
				if (submissionClient.canAuthentication()) {
					currentCheck.setResult(MonitorStatusType.PASSED);
					if (log.isTraceEnabled())
						log.trace("Login authentication succeeded to " + system.getSystemId() +
							" -> " + system.getLoginConfig().toString());
				} else {
					currentCheck.setMessage("Failed to authenticate to system " + system.getSystemId() + " at " +
							system.getLoginConfig().getProtocol() + ":" + system.getLoginConfig().getHost());
					log.debug("Login authentication failed to " + system.getSystemId() +
							" -> " + system.getLoginConfig().toString());
				}
			} catch (AuthenticationException e) {
				log.debug("Failed to retrieve an authentication credential to " + system.getSystemId() +
						" -> " + system.getLoginConfig().toString() + " when running login check. " +  e.getMessage());
				currentCheck.setMessage("Authentication failed for " + system.getSystemId() +
						". " + e.getMessage());
			}
		} 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());
		} catch (MonitorException e) {
			log.error("Failed to fetch previous check for monitor " + monitor.getUuid() +
					" from the database when processing check " + currentCheck.getUuid() + ". " + e.getMessage());
		}
		catch (Exception e)
		{
			String msg = String.format("Failed to perform login check %s for monitor %s on system %s. %s",
					currentCheck.getUuid(), monitor.getUuid(), system.getSystemId(), e.getMessage());
			log.error(msg);
			currentCheck.setResult(MonitorStatusType.UNKNOWN);
			currentCheck.setMessage(String.format("Failed to perform login check on %s. Caused by: %s",
					system.getSystemId(), e.getMessage()));
		}
		try {
			currentCheck.setMonitor(monitor);
			currentCheck.setCreated(new Date());
			getMonitorCheckDao().persist(currentCheck);
			eventProcessor.processCheckEvent(monitor, lastCheck, currentCheck, createdBy);
		} catch (Exception e) {
			log.error("Failed to persist login monitor check " + currentCheck.getUuid() + " for monitor " + monitor.getUuid(), e);
		} finally {
			try {
				monitor.setLastUpdated(new Date());
				getMonitorDao().persist(monitor);
			} catch (Exception ignored){}
		}
		return currentCheck;
	}
@ SuppressWarnings ( "unused" ) private MonitorCheck doLoginCheck ( Monitor monitor , String createdBy ) { MonitorCheck currentCheck = new MonitorCheck ( monitor , MonitorStatusType . FAILED , null , MonitorCheckType . LOGIN ) ; MonitorCheck lastCheck = null ; ExecutionSystem system = null ; try { lastCheck = getMonitorCheckDao ( ) . getLastMonitorCheck ( monitor . getId ( ) ) ; system = ( ExecutionSystem ) monitor . getSystem ( ) ; if ( log . isTraceEnabled ( ) ) log . trace ( String . format ( "Checking login connectivity to %s -> %s" , system . getSystemId ( ) , system . getLoginConfig ( ) . toString ( ) ) ) ; try ( RemoteSubmissionClient submissionClient = ( ( ExecutionSystem ) monitor . getSystem ( ) ) . getRemoteSubmissionClient ( monitor . getInternalUsername ( ) ) ) { if ( submissionClient . canAuthentication ( ) ) { currentCheck . setResult ( MonitorStatusType . PASSED ) ; if ( log . isTraceEnabled ( ) ) log . trace ( "Login authentication succeeded to " + system . getSystemId ( ) + " -> " + system . getLoginConfig ( ) . toString ( ) ) ; } else { currentCheck . setMessage ( "Failed to authenticate to system " + system . getSystemId ( ) + " at " + system . getLoginConfig ( ) . getProtocol ( ) + ":" + system . getLoginConfig ( ) . getHost ( ) ) ; log . debug ( "Login authentication failed to " + system . getSystemId ( ) + " -> " + system . getLoginConfig ( ) . toString ( ) ) ; } } catch ( AuthenticationException e ) { log . debug ( "Failed to retrieve an authentication credential to " + system . getSystemId ( ) + " -> " + system . getLoginConfig ( ) . toString ( ) + " when running login check. " + e . getMessage ( ) ) ; currentCheck . setMessage ( "Authentication failed for " + system . getSystemId ( ) + ". " + e . getMessage ( ) ) ; } } 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 ( ) ) ; } catch ( MonitorException e ) { log . error ( "Failed to fetch previous check for monitor " + monitor . getUuid ( ) + " from the database when processing check " + currentCheck . getUuid ( ) + ". " + e . getMessage ( ) ) ; } catch ( Exception e ) { String msg = String . format ( "Failed to perform login check %s for monitor %s on system %s. %s" , currentCheck . getUuid ( ) , monitor . getUuid ( ) , system . getSystemId ( ) , e . getMessage ( ) ) ; log . error ( msg ) ; currentCheck . setResult ( MonitorStatusType . UNKNOWN ) ; currentCheck . setMessage ( String . format ( "Failed to perform login check on %s. Caused by: %s" , system . getSystemId ( ) , e . getMessage ( ) ) ) ; } try { currentCheck . setMonitor ( monitor ) ; currentCheck . setCreated ( new Date ( ) ) ; getMonitorCheckDao ( ) . persist ( currentCheck ) ; eventProcessor . processCheckEvent ( monitor , lastCheck , currentCheck , createdBy ) ; } catch ( Exception e ) { log . error ( "Failed to persist login monitor check " + currentCheck . getUuid ( ) + " for monitor " + monitor . getUuid ( ) , e ) ; } finally { try { monitor . setLastUpdated ( new Date ( ) ) ; getMonitorDao ( ) . persist ( monitor ) ; } catch ( Exception ignored ) { } } return currentCheck ; }
Performs a check on connectivity to a login system.
Performs a check on connectivity to a login system .
// something went wrong. The system storage is not accessible. // fail the check // set the status to unknown as we do not know the actual remote status since we were unable to // run the check. // pass on the message to the end user.