agave-jobs/jobs-core/src/main/java/org/iplantc/service/jobs/managers/launchers/WrapperTemplateMacroResolver.java
/**
     * Returns the {@link WrapperTemplateAttributeVariableType} value for the given job.
     *
     * @param executionSystem the job execution.
     * @param jobAttributeMacro the job attribute macro to resolve
     * @return resolved value of the variable.
     * @throws JobMacroResolutionException when the macro cannot be resolved. Generally this is due to an unavailable execution system
     */
Returns the  WrapperTemplateAttributeVariableType value for the given job.
@param executionSystem the job execution.
@param jobAttributeMacro the job attribute macro to resolve
@return resolved value of the variable.
@throws JobMacroResolutionException when the macro cannot be resolved. Generally this is due to an unavailable execution system
Returns the WrapperTemplateAttributeVariableType value for the given job . @param executionSystem the job execution . @param jobAttributeMacro the job attribute macro to resolve @return resolved value of the variable . @throws JobMacroResolutionException when the macro cannot be resolved . Generally this is due to an unavailable execution system
protected String resolveJobAttributeMacro(ExecutionSystem executionSystem, WrapperTemplateAttributeVariableType jobAttributeMacro) throws JobMacroResolutionException {
        switch (jobAttributeMacro) {
            case IPLANT_JOB_NAME:
            case AGAVE_JOB_NAME:
                return Slug.toSlug(getJob().getName());
            case AGAVE_JOB_NAME_RAW:
                return getJob().getName();
            case AGAVE_JOB_ID:
                return StringUtils.isNotEmpty(getJob().getUuid()) ? getJob().getUuid() : "";
            case AGAVE_JOB_APP_ID:
                return getJob().getSoftwareName();
            case AGAVE_JOB_EXECUTION_SYSTEM:
                return StringUtils.isNotEmpty(getJob().getSystem()) ? getJob().getSystem() : "";
            case AGAVE_JOB_BATCH_QUEUE:
                return getJob().getBatchQueue();
            case AGAVE_JOB_BATCH_QUEUE_EFFECTIVE_NAME:
                BatchQueue queue = executionSystem.getQueue(getJob().getBatchQueue());
                if (queue != null) {
                    return queue.getEffectiveMappedName();
                } else {
                    throw new JobMacroResolutionException("Batch queue " + getJob().getBatchQueue() +
                            " is no longer available on system " + getJob().getSystem() +
                            " to resolve effective batch queue name for job " + getJob().getUuid());
                }
            case AGAVE_JOB_SUBMIT_TIME:
                return getJob().getSubmitTime() == null ? "" : new DateTime(getJob().getSubmitTime()).toString();
            case AGAVE_JOB_ARCHIVE_SYSTEM:
                return (getJob().getArchiveSystem() == null ? "" : getJob().getArchiveSystem().getSystemId());
            case AGAVE_JOB_ARCHIVE_PATH:
                return (StringUtils.isNotEmpty(getJob().getArchivePath()) ? getJob().getArchivePath() : "");
            case AGAVE_JOB_NODE_COUNT:
                return String.valueOf(getJob().getNodeCount());
            case IPLANT_CORES_REQUESTED:
                return String.valueOf(getJob().getProcessorsPerNode() * getJob().getNodeCount());
            case AGAVE_JOB_PROCESSORS_PER_NODE:
                return String.valueOf(getJob().getProcessorsPerNode());
            case AGAVE_JOB_MEMORY_PER_NODE:
                return String.valueOf(getJob().getMemoryPerNode());
            case AGAVE_JOB_MAX_RUNTIME:
                return String.valueOf(getJob().getMaxRunTime());
            case AGAVE_JOB_MAX_RUNTIME_MILLISECONDS:
                try {
                    return String.valueOf(TimeUtils.getMillisecondsForMaxTimeValue(getJob().getMaxRunTime()));
                } catch (Exception e) {
                    return "0";
                }
            case AGAVE_JOB_MAX_RUNTIME_SECONDS:
                try {
                    return String.valueOf(Math.floor(TimeUtils.getMillisecondsForMaxTimeValue(getJob().getMaxRunTime()) / 1000));
                } catch (Exception e) {
                    return "0";
                }
            case AGAVE_BASE_URL:
                return TenancyHelper.resolveURLToCurrentTenant("https://example.com/", getJob().getTenantId());
            case AGAVE_JOB_OWNER:
                return getJob().getOwner();
            case AGAVE_JOB_TENANT:
                return getJob().getTenantId();
            case AGAVE_JOB_ARCHIVE:
                return getJob().isArchiveOutput() ? "1" : "";
            case AGAVE_JOB_WORK_PATH:
                return getJob().getWorkPath();
            case AGAVE_JOB_ARCHIVE_URL:
                if (getJob().isArchiveOutput()) {
                    return String.format("%smedia/system/%s/%s",
                            TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_IO_SERVICE, getJob().getTenantId()),
                            getJob().getArchiveSystem().getSystemId(),
                            getJob().getArchivePath());
                } else {
                    return "";
                }
            default:
                throw new JobMacroResolutionException("The template variable " + jobAttributeMacro.name() + " is not yet supported.");
        }
    }
protected String resolveJobAttributeMacro ( ExecutionSystem executionSystem , WrapperTemplateAttributeVariableType jobAttributeMacro ) throws JobMacroResolutionException { switch ( jobAttributeMacro ) { case IPLANT_JOB_NAME : case AGAVE_JOB_NAME : return Slug . toSlug ( getJob ( ) . getName ( ) ) ; case AGAVE_JOB_NAME_RAW : return getJob ( ) . getName ( ) ; case AGAVE_JOB_ID : return StringUtils . isNotEmpty ( getJob ( ) . getUuid ( ) ) ? getJob ( ) . getUuid ( ) : "" ; case AGAVE_JOB_APP_ID : return getJob ( ) . getSoftwareName ( ) ; case AGAVE_JOB_EXECUTION_SYSTEM : return StringUtils . isNotEmpty ( getJob ( ) . getSystem ( ) ) ? getJob ( ) . getSystem ( ) : "" ; case AGAVE_JOB_BATCH_QUEUE : return getJob ( ) . getBatchQueue ( ) ; case AGAVE_JOB_BATCH_QUEUE_EFFECTIVE_NAME : BatchQueue queue = executionSystem . getQueue ( getJob ( ) . getBatchQueue ( ) ) ; if ( queue != null ) { return queue . getEffectiveMappedName ( ) ; } else { throw new JobMacroResolutionException ( "Batch queue " + getJob ( ) . getBatchQueue ( ) + " is no longer available on system " + getJob ( ) . getSystem ( ) + " to resolve effective batch queue name for job " + getJob ( ) . getUuid ( ) ) ; } case AGAVE_JOB_SUBMIT_TIME : return getJob ( ) . getSubmitTime ( ) == null ? "" : new DateTime ( getJob ( ) . getSubmitTime ( ) ) . toString ( ) ; case AGAVE_JOB_ARCHIVE_SYSTEM : return ( getJob ( ) . getArchiveSystem ( ) == null ? "" : getJob ( ) . getArchiveSystem ( ) . getSystemId ( ) ) ; case AGAVE_JOB_ARCHIVE_PATH : return ( StringUtils . isNotEmpty ( getJob ( ) . getArchivePath ( ) ) ? getJob ( ) . getArchivePath ( ) : "" ) ; case AGAVE_JOB_NODE_COUNT : return String . valueOf ( getJob ( ) . getNodeCount ( ) ) ; case IPLANT_CORES_REQUESTED : return String . valueOf ( getJob ( ) . getProcessorsPerNode ( ) * getJob ( ) . getNodeCount ( ) ) ; case AGAVE_JOB_PROCESSORS_PER_NODE : return String . valueOf ( getJob ( ) . getProcessorsPerNode ( ) ) ; case AGAVE_JOB_MEMORY_PER_NODE : return String . valueOf ( getJob ( ) . getMemoryPerNode ( ) ) ; case AGAVE_JOB_MAX_RUNTIME : return String . valueOf ( getJob ( ) . getMaxRunTime ( ) ) ; case AGAVE_JOB_MAX_RUNTIME_MILLISECONDS : try { return String . valueOf ( TimeUtils . getMillisecondsForMaxTimeValue ( getJob ( ) . getMaxRunTime ( ) ) ) ; } catch ( Exception e ) { return "0" ; } case AGAVE_JOB_MAX_RUNTIME_SECONDS : try { return String . valueOf ( Math . floor ( TimeUtils . getMillisecondsForMaxTimeValue ( getJob ( ) . getMaxRunTime ( ) ) / 1000 ) ) ; } catch ( Exception e ) { return "0" ; } case AGAVE_BASE_URL : return TenancyHelper . resolveURLToCurrentTenant ( "https://example.com/" , getJob ( ) . getTenantId ( ) ) ; case AGAVE_JOB_OWNER : return getJob ( ) . getOwner ( ) ; case AGAVE_JOB_TENANT : return getJob ( ) . getTenantId ( ) ; case AGAVE_JOB_ARCHIVE : return getJob ( ) . isArchiveOutput ( ) ? "1" : "" ; case AGAVE_JOB_WORK_PATH : return getJob ( ) . getWorkPath ( ) ; case AGAVE_JOB_ARCHIVE_URL : if ( getJob ( ) . isArchiveOutput ( ) ) { return String . format ( "%smedia/system/%s/%s" , TenancyHelper . resolveURLToCurrentTenant ( Settings . IPLANT_IO_SERVICE , getJob ( ) . getTenantId ( ) ) , getJob ( ) . getArchiveSystem ( ) . getSystemId ( ) , getJob ( ) . getArchivePath ( ) ) ; } else { return "" ; } default : throw new JobMacroResolutionException ( "The template variable " + jobAttributeMacro . name ( ) + " is not yet supported." ) ; } }
Returns the {@link WrapperTemplateAttributeVariableType} value for the given job.
Returns the { @link WrapperTemplateAttributeVariableType } value for the given job .