agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/managers/JobRequestProcessor.java
/**
	 * Takes a JsonNode representing a job request and parses it into a job object.
	 *
	 * @param json a JsonNode containing the job request
	 * @return validated job object ready for submission
	 * @throws JobProcessingException of the job request cannot be validated
	 */
Takes a JsonNode representing a job request and parses it into a job object.
@param json a JsonNode containing the job request
@return validated job object ready for submission
@throws JobProcessingException of the job request cannot be validated
Takes a JsonNode representing a job request and parses it into a job object . @param json a JsonNode containing the job request @return validated job object ready for submission @throws JobProcessingException of the job request cannot be validated
public Job processJob(JsonNode json)
	throws JobProcessingException
	{
	    HashMap<String, Object> jobRequestMap = new HashMap<String, Object>();
		String currentKey = null;
		try
		{
		    try {
				Iterator<String> fields = json.fieldNames();
				while(fields.hasNext()) {
		            String key = fields.next();
				    if (StringUtils.isEmpty(key)) continue;
				    currentKey = key;
				    if (key.equals("notifications")) {
					    continue;
				    }
				    if (key.equals("callbackUrl")) {
					    continue;
				    }
				    if (key.equals("dependencies"))
				    {
				        String msg = "Job dependencies are not yet supported.";
				        log.error(msg);
					    throw new JobProcessingException(400, msg);
				    }
				    JsonNode child = json.get(key);
				    if (child.isNull()) {
				        jobRequestMap.put(key, null);
				    }
				    else if (child.isNumber())
				    {
				        jobRequestMap.put(key, child.asText());
				    }
				    else if (child.isObject())
				    {
					    Iterator<String> childFields = child.fieldNames();
					    while(childFields.hasNext())
					    {
						    String childKey = childFields.next();
						    JsonNode childchild = child.path(childKey);
						    if (StringUtils.isEmpty(childKey) || childchild.isNull() || childchild.isMissingNode()) {
							    continue;
						    }
						    else if (childchild.isDouble()) {
						        jobRequestMap.put(childKey, childchild.decimalValue().toPlainString());
						    }
						    else if (childchild.isNumber())
						    {
						        jobRequestMap.put(childKey, childchild.longValue());
						    }
						    else if (childchild.isArray()) {
						        List<String> arrayValues = new ArrayList<String>();
								for (JsonNode argValue : childchild) {
									if (argValue.isNull() || argValue.isMissingNode()) {
										continue;
									} else {
										arrayValues.add(argValue.asText());
									}
								}
							    jobRequestMap.put(childKey, StringUtils.join(arrayValues, Settings.AGAVE_SERIALIZED_LIST_DELIMITER));
						    }
						    else if (childchild.isTextual()) {
						        jobRequestMap.put(childKey, childchild.textValue());
						    }
						    else if (childchild.isBoolean()) {
						        jobRequestMap.put(childKey, childchild.asBoolean() ? "true" : "false");
						    }
					    }
				    }
				    else
				    {
				        jobRequestMap.put(key, json.get(key).asText());
				    }
		        }
		    }
		    catch (Exception e) {
                String msg = "Assignment for json key " + currentKey + " failed: " +
                             e.getMessage();
                log.error(msg);
                throw e;
		    }
   			Job job = null;
   			try {
   				job = processJob(jobRequestMap);
   			} catch (Exception e) {
				String msg = "Job processing failed: " + e.getMessage();
				log.error(msg);
				throw e;
			}
   			setNotificationProcessor(new JobRequestNotificationProcessor(getUsername(), job));
			if (json.has("notifications")) {
				try {
					getNotificationProcessor().process(json.get("notifications"));
				} catch (Exception e) {
					String input = "";
					try { input = json.get("notifications").toString(); } catch (Exception ignored) {}
					String msg = "General notification processing failed with input [" +
								 input + "]\n" + e.getMessage();
					log.error(msg);
					throw e;
				}
			}
			else if (json.has("callbackUrl")) {
				try {
					getNotificationProcessor().process(json.get("callbackUrl"));
				} catch (Exception e) {
					String input = "";
					try {input = json.get("callbackUrl").toString();} catch (Exception ignored) {}
					String msg = "Callback notification processing failed with input [" +
								 input + "]\n" + e.getMessage();
					log.error(msg);
					throw e;
				}
			}
			for (Notification notification: getNotificationProcessor().getNotifications()) {
				try {
					job.addNotification(notification);
				} catch (Exception e) {
					String msg = "Add notification to job failure: " + e.getMessage();
					log.error(msg);
					throw e;
				}
			}
			for (JobEvent jobEvent: job.getEvents()) {
			    try {
			        JobEventProcessor eventProcessor = new JobEventProcessor(jobEvent);
			        eventProcessor.process();
			    } catch (Exception e) {
					String msg = "Failure to process job event " + jobEvent.getUuid() +
								 " for tenant " + jobEvent.getTenantId() + ": " + e.getMessage();
					log.error(msg);
					throw e;
				}
			}
			return job;
		}
		catch (NotificationException e) {
			throw new JobProcessingException(500, e);
		}
		catch (JobProcessingException e) {
			throw e;
		}
		catch (SoftwareException e) {
			throw new JobProcessingException(400, e);
		}
		catch (Throwable e) {
			throw new JobProcessingException(400,
					"Job processing failed with exception type " +
					e.getClass().getSimpleName() + ": " + e.getMessage(), e);
		}
	}
public Job processJob ( JsonNode json ) throws JobProcessingException { HashMap < String , Object > jobRequestMap = new HashMap < String , Object > ( ) ; String currentKey = null ; try { try { Iterator < String > fields = json . fieldNames ( ) ; while ( fields . hasNext ( ) ) { String key = fields . next ( ) ; if ( StringUtils . isEmpty ( key ) ) continue ; currentKey = key ; if ( key . equals ( "notifications" ) ) { continue ; } if ( key . equals ( "callbackUrl" ) ) { continue ; } if ( key . equals ( "dependencies" ) ) { String msg = "Job dependencies are not yet supported." ; log . error ( msg ) ; throw new JobProcessingException ( 400 , msg ) ; } JsonNode child = json . get ( key ) ; if ( child . isNull ( ) ) { jobRequestMap . put ( key , null ) ; } else if ( child . isNumber ( ) ) { jobRequestMap . put ( key , child . asText ( ) ) ; } else if ( child . isObject ( ) ) { Iterator < String > childFields = child . fieldNames ( ) ; while ( childFields . hasNext ( ) ) { String childKey = childFields . next ( ) ; JsonNode childchild = child . path ( childKey ) ; if ( StringUtils . isEmpty ( childKey ) || childchild . isNull ( ) || childchild . isMissingNode ( ) ) { continue ; } else if ( childchild . isDouble ( ) ) { jobRequestMap . put ( childKey , childchild . decimalValue ( ) . toPlainString ( ) ) ; } else if ( childchild . isNumber ( ) ) { jobRequestMap . put ( childKey , childchild . longValue ( ) ) ; } else if ( childchild . isArray ( ) ) { List < String > arrayValues = new ArrayList < String > ( ) ; for ( JsonNode argValue : childchild ) { if ( argValue . isNull ( ) || argValue . isMissingNode ( ) ) { continue ; } else { arrayValues . add ( argValue . asText ( ) ) ; } } jobRequestMap . put ( childKey , StringUtils . join ( arrayValues , Settings . AGAVE_SERIALIZED_LIST_DELIMITER ) ) ; } else if ( childchild . isTextual ( ) ) { jobRequestMap . put ( childKey , childchild . textValue ( ) ) ; } else if ( childchild . isBoolean ( ) ) { jobRequestMap . put ( childKey , childchild . asBoolean ( ) ? "true" : "false" ) ; } } } else { jobRequestMap . put ( key , json . get ( key ) . asText ( ) ) ; } } } catch ( Exception e ) { String msg = "Assignment for json key " + currentKey + " failed: " + e . getMessage ( ) ; log . error ( msg ) ; throw e ; } Job job = null ; try { job = processJob ( jobRequestMap ) ; } catch ( Exception e ) { String msg = "Job processing failed: " + e . getMessage ( ) ; log . error ( msg ) ; throw e ; } setNotificationProcessor ( new JobRequestNotificationProcessor ( getUsername ( ) , job ) ) ; if ( json . has ( "notifications" ) ) { try { getNotificationProcessor ( ) . process ( json . get ( "notifications" ) ) ; } catch ( Exception e ) { String input = "" ; try { input = json . get ( "notifications" ) . toString ( ) ; } catch ( Exception ignored ) { } String msg = "General notification processing failed with input [" + input + "]\n" + e . getMessage ( ) ; log . error ( msg ) ; throw e ; } } else if ( json . has ( "callbackUrl" ) ) { try { getNotificationProcessor ( ) . process ( json . get ( "callbackUrl" ) ) ; } catch ( Exception e ) { String input = "" ; try { input = json . get ( "callbackUrl" ) . toString ( ) ; } catch ( Exception ignored ) { } String msg = "Callback notification processing failed with input [" + input + "]\n" + e . getMessage ( ) ; log . error ( msg ) ; throw e ; } } for ( Notification notification : getNotificationProcessor ( ) . getNotifications ( ) ) { try { job . addNotification ( notification ) ; } catch ( Exception e ) { String msg = "Add notification to job failure: " + e . getMessage ( ) ; log . error ( msg ) ; throw e ; } } for ( JobEvent jobEvent : job . getEvents ( ) ) { try { JobEventProcessor eventProcessor = new JobEventProcessor ( jobEvent ) ; eventProcessor . process ( ) ; } catch ( Exception e ) { String msg = "Failure to process job event " + jobEvent . getUuid ( ) + " for tenant " + jobEvent . getTenantId ( ) + ": " + e . getMessage ( ) ; log . error ( msg ) ; throw e ; } } return job ; } catch ( NotificationException e ) { throw new JobProcessingException ( 500 , e ) ; } catch ( JobProcessingException e ) { throw e ; } catch ( SoftwareException e ) { throw new JobProcessingException ( 400 , e ) ; } catch ( Throwable e ) { throw new JobProcessingException ( 400 , "Job processing failed with exception type " + e . getClass ( ) . getSimpleName ( ) + ": " + e . getMessage ( ) , e ) ; } }
Takes a JsonNode representing a job request and parses it into a job object.
Takes a JsonNode representing a job request and parses it into a job object .
// If the job request had notification configured for job creation // they could not have fired yet. Here we explicitly add them. //		    log.error(e.getClass().getSimpleName() + ": " + e.getMessage(), e); //		    log.error(e.getClass().getSimpleName() + ": " + e.getMessage(), e); //		    log.error(e.getClass().getSimpleName() + ": " + e.getMessage(), e); //		    log.error(e.getClass().getSimpleName() + ": " + e.getMessage(), e);