agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/managers/launchers/WrapperTemplateMacroResolver.java
/**
     * Resolves a template variable with optional runtime arguments supplied which will then
     * be passed as a json object in a postback to the trigger service. Syntax is of the form
     * as <pre>${AGAVE_JOB_CALLBACK_NOTIFICATION::FOO,BAR,BAM}</pre>
     *
     * @param eventName the name of the event
     * @param callbackVariableNames the callback variable names to honor
     * @return a bash snippet containing callback functions to run on the remote host within the wrapper script during the life of the job.
     */
Resolves a template variable with optional runtime arguments supplied which will then
be passed as a json object in a postback to the trigger service. Syntax is of the form
as ${AGAVE_JOB_CALLBACK_NOTIFICATION::FOO,BAR,BAM}

@param eventName the name of the event
@param callbackVariableNames the callback variable names to honor
@return a bash snippet containing callback functions to run on the remote host within the wrapper script during the life of the job.
Resolves a template variable with optional runtime arguments supplied which will then be passed as a json object in a postback to the trigger service . Syntax is of the form as $ { AGAVE_JOB_CALLBACK_NOTIFICATION :: FOO BAR BAM } @param eventName the name of the event @param callbackVariableNames the callback variable names to honor @return a bash snippet containing callback functions to run on the remote host within the wrapper script during the life of the job .
public String resolveNotificationEventMacro(String eventName, String[] callbackVariableNames) {
        if (callbackVariableNames == null) {
            callbackVariableNames = new String[]{};
        }
        eventName = StringUtils.trimToNull(eventName);
        StringBuilder sb = new StringBuilder();
        sb.append("# Building job callback document to send to any notifications\n");
        sb.append("AGAVE_CALLBACK_FILE=\".callback-$(date +%Y-%m-%dT%H:%M:%S%z)\"\n");
        sb.append("echo -e \"{\" > \"$AGAVE_CALLBACK_FILE\"\n");
        if (!ArrayUtils.isEmpty(callbackVariableNames)) {
            for (String varName : new HashSet<String>(Arrays.asList(callbackVariableNames))) {
                varName = StringUtils.trimToNull(varName);
                if (varName != null) {
                    String key = varName;
                    String value = varName;
                    if (varName.contains(":")) {
                        String[] kv = StringUtils.split(varName, ":");
                        if (kv.length >= 2) {
                            key = kv[0];
                            value = kv[1];
                        }
                    }
                    sb.append(String.format("echo '  \"%s\": \"'$(printf %%q \"$%s\")'\",' >> \"$AGAVE_CALLBACK_FILE\"\n", key, value));
                }
            }
        }
        if (StringUtils.isEmpty(eventName)) {
            eventName = "JOB_RUNTIME_CALLBACK_EVENT";
        }
        sb.append("echo '  \"CUSTOM_USER_JOB_EVENT_NAME\": \"" + eventName + "\"' >> \"$AGAVE_CALLBACK_FILE\"\n");
        sb.append("echo -e \"}\" >> \"$AGAVE_CALLBACK_FILE\"\n\n");
        String callbackUrl = resolveTenantJobUrl(getJob().getTenantId());
        sb.append(String.format("agave_log_response $(cat \"$AGAVE_CALLBACK_FILE\" | sed  -e \"s#: \\\"''\\\"#: \\\"\\\"#g\" | curl --connect-timeout 10 -sS%s -H \"Content-Type: application/json\" -X POST --data-binary @- \"%strigger/job/%s/token/%s/status/HEARTBEAT?pretty=true\" 2>&1) \n\n\n",
                callbackUrl.startsWith("https") ? "k" : "",
                callbackUrl,
                getJob().getUuid(),
                getJob().getUpdateToken()));
        return sb.toString();
    }
public String resolveNotificationEventMacro ( String eventName , String [ ] callbackVariableNames ) { if ( callbackVariableNames == null ) { callbackVariableNames = new String [ ] { } ; } eventName = StringUtils . trimToNull ( eventName ) ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( "# Building job callback document to send to any notifications\n" ) ; sb . append ( "AGAVE_CALLBACK_FILE=\".callback-$(date +%Y-%m-%dT%H:%M:%S%z)\"\n" ) ; sb . append ( "echo -e \"{\" > \"$AGAVE_CALLBACK_FILE\"\n" ) ; if ( ! ArrayUtils . isEmpty ( callbackVariableNames ) ) { for ( String varName : new HashSet < String > ( Arrays . asList ( callbackVariableNames ) ) ) { varName = StringUtils . trimToNull ( varName ) ; if ( varName != null ) { String key = varName ; String value = varName ; if ( varName . contains ( ":" ) ) { String [ ] kv = StringUtils . split ( varName , ":" ) ; if ( kv . length >= 2 ) { key = kv [ 0 ] ; value = kv [ 1 ] ; } } sb . append ( String . format ( "echo '  \"%s\": \"'$(printf %%q \"$%s\")'\",' >> \"$AGAVE_CALLBACK_FILE\"\n" , key , value ) ) ; } } } if ( StringUtils . isEmpty ( eventName ) ) { eventName = "JOB_RUNTIME_CALLBACK_EVENT" ; } sb . append ( "echo '  \"CUSTOM_USER_JOB_EVENT_NAME\": \"" + eventName + "\"' >> \"$AGAVE_CALLBACK_FILE\"\n" ) ; sb . append ( "echo -e \"}\" >> \"$AGAVE_CALLBACK_FILE\"\n\n" ) ; String callbackUrl = resolveTenantJobUrl ( getJob ( ) . getTenantId ( ) ) ; sb . append ( String . format ( "agave_log_response $(cat \"$AGAVE_CALLBACK_FILE\" | sed  -e \"s#: \\\"''\\\"#: \\\"\\\"#g\" | curl --connect-timeout 10 -sS%s -H \"Content-Type: application/json\" -X POST --data-binary @- \"%strigger/job/%s/token/%s/status/HEARTBEAT?pretty=true\" 2>&1) \n\n\n" , callbackUrl . startsWith ( "https" ) ? "k" : "" , callbackUrl , getJob ( ) . getUuid ( ) , getJob ( ) . getUpdateToken ( ) ) ) ; return sb . toString ( ) ; }
Resolves a template variable with optional runtime arguments supplied which will then
 be passed as a json object in a postback to the trigger service.
Resolves a template variable with optional runtime arguments supplied which will then be passed as a json object in a postback to the trigger service .
// if there is a colon in the value, it's a custom name for the variable // such as name:JOB_NAME // add the user-defined event if provided