Search in sources :

Example 1 with JobSuggestedParamValue

use of models.JobSuggestedParamValue in project dr-elephant by linkedin.

the class AutoTuningAPIHelper method createDefaultJobExecution.

/**
 * This method creates a job execution with default parameters. This is required when there is no parameters set
 * remains for suggestion.
 * @param tuningJobDefinition Job definition
 * @return
 */
private TuningJobExecution createDefaultJobExecution(TuningJobDefinition tuningJobDefinition) {
    logger.info("Creating an execution with default parameter values for job: " + tuningJobDefinition.job.jobDefId);
    // Get default execution from DB and clone that to create a new default execution
    TuningJobExecution tuningJobExecutionDefault = TuningJobExecution.find.select("*").where().eq(TuningJobExecution.TABLE.jobExecution + "." + JobExecution.TABLE.job + "." + JobDefinition.TABLE.id, tuningJobDefinition.job.id).eq(TuningJobExecution.TABLE.isDefaultExecution, true).setMaxRows(1).findUnique();
    TuningJobExecution tuningJobExecution = new TuningJobExecution();
    JobExecution jobExecution = new JobExecution();
    jobExecution.id = 0L;
    jobExecution.job = tuningJobExecutionDefault.jobExecution.job;
    jobExecution.executionState = ExecutionState.NOT_STARTED;
    jobExecution.save();
    tuningJobExecution.jobExecution = jobExecution;
    tuningJobExecution.isDefaultExecution = tuningJobExecutionDefault.isDefaultExecution;
    tuningJobExecution.tuningAlgorithm = tuningJobExecutionDefault.tuningAlgorithm;
    tuningJobExecution.paramSetState = ParamSetStatus.CREATED;
    tuningJobExecution.save();
    logger.debug("Execution with default parameter created with execution id: " + tuningJobExecution.jobExecution.id);
    List<JobSuggestedParamValue> jobSuggestedParamValueList = JobSuggestedParamValue.find.where().eq(JobSuggestedParamValue.TABLE.jobExecution + "." + JobExecution.TABLE.id, tuningJobExecutionDefault.jobExecution.id).findList();
    // Save default parameters corresponding to new default execution
    for (JobSuggestedParamValue jobSuggestedParamValue : jobSuggestedParamValueList) {
        JobSuggestedParamValue jobSuggestedParamValue1 = new JobSuggestedParamValue();
        jobSuggestedParamValue1.id = 0;
        jobSuggestedParamValue1.jobExecution = jobExecution;
        jobSuggestedParamValue1.paramValue = jobSuggestedParamValue.paramValue;
        jobSuggestedParamValue1.tuningParameter = jobSuggestedParamValue.tuningParameter;
        jobSuggestedParamValue1.save();
    }
    tuningJobExecution = TuningJobExecution.find.select("*").where().eq(TuningJobExecution.TABLE.jobExecution + "." + JobExecution.TABLE.id, tuningJobExecution.jobExecution.id).setMaxRows(1).findUnique();
    return tuningJobExecution;
}
Also used : TuningJobExecution(models.TuningJobExecution) JobExecution(models.JobExecution) JobSuggestedParamValue(models.JobSuggestedParamValue) TuningJobExecution(models.TuningJobExecution)

Example 2 with JobSuggestedParamValue

use of models.JobSuggestedParamValue in project dr-elephant by linkedin.

the class AutoTuningAPIHelper method getCurrentRunParameters.

/**
 * Handles the api request and returns param suggestions as response
 * @param tuningInput Rest api parameters
 * @return Parameter Suggestion
 */
public Map<String, Double> getCurrentRunParameters(TuningInput tuningInput) {
    logger.info("Parameter suggestion request for execution: " + tuningInput.getJobExecId());
    setDefaultValue(tuningInput);
    String jobDefId = tuningInput.getJobDefId();
    TuningJobDefinition tuningJobDefinition = TuningJobDefinition.find.select("*").fetch(TuningJobDefinition.TABLE.job, "*").where().eq(TuningJobDefinition.TABLE.job + "." + JobDefinition.TABLE.jobDefId, jobDefId).eq(TuningJobDefinition.TABLE.tuningEnabled, 1).findUnique();
    // If new job for tuning, update db with new job configuration
    if (tuningJobDefinition == null) {
        logger.debug("New job encountered for tuning");
        AutoTuningMetricsController.markNewAutoTuningJob();
        tuningJobDefinition = addNewJobForTuning(tuningInput);
    }
    logger.debug("Finding parameter suggestion for job: " + tuningJobDefinition.job.jobName);
    TuningJobExecution tuningJobExecution = TuningJobExecution.find.select("*").fetch(TuningJobExecution.TABLE.jobExecution, "*").fetch(TuningJobExecution.TABLE.jobExecution + "." + JobExecution.TABLE.job, "*").where().eq(TuningJobExecution.TABLE.jobExecution + "." + JobExecution.TABLE.job + "." + JobDefinition.TABLE.id, tuningJobDefinition.job.id).eq(TuningJobExecution.TABLE.paramSetState, ParamSetStatus.CREATED).order().asc(TuningJobExecution.TABLE.jobExecution + "." + JobExecution.TABLE.createdTs).setMaxRows(1).findUnique();
    // If no new parameter set for suggestion, create a new suggestion with default parameter
    if (tuningJobExecution == null) {
        logger.info("Returning default parameters as no parameter suggestion found for job: " + tuningJobDefinition.job.jobName);
        AutoTuningMetricsController.markParamSetNotFound();
        tuningJobExecution = createDefaultJobExecution(tuningJobDefinition);
    }
    logger.debug("Finding parameters corresponding to execution id: " + tuningJobExecution.jobExecution.id);
    List<JobSuggestedParamValue> jobSuggestedParamValues = JobSuggestedParamValue.find.where().eq(JobSuggestedParamValue.TABLE.jobExecution + "." + JobExecution.TABLE.id, tuningJobExecution.jobExecution.id).findList();
    logger.debug("Number of output parameters : " + jobSuggestedParamValues.size());
    Map<String, Double> paramValues = new HashMap<String, Double>();
    if (jobSuggestedParamValues != null) {
        for (JobSuggestedParamValue jobSuggestedParamValue : jobSuggestedParamValues) {
            logger.debug("Param Name is " + jobSuggestedParamValue.tuningParameter.paramName + " And value is " + jobSuggestedParamValue.paramValue);
            paramValues.put(jobSuggestedParamValue.tuningParameter.paramName, jobSuggestedParamValue.paramValue);
        }
    }
    updateJobExecutionParameter(tuningJobExecution, tuningInput);
    logger.info("Finishing getCurrentRunParameters");
    return paramValues;
}
Also used : HashMap(java.util.HashMap) JobSuggestedParamValue(models.JobSuggestedParamValue) TuningJobDefinition(models.TuningJobDefinition) TuningJobExecution(models.TuningJobExecution)

Example 3 with JobSuggestedParamValue

use of models.JobSuggestedParamValue in project dr-elephant by linkedin.

the class AutoTuningAPIHelper method insertExecutionParameter.

/**
 * Inserts parameter of an execution in database
 * @param jobExecution Job execution
 * @param paramName Parameter name
 * @param paramValue Parameter value
 */
private void insertExecutionParameter(JobExecution jobExecution, String paramName, Double paramValue) {
    logger.debug("Starting insertExecutionParameter");
    JobSuggestedParamValue jobSuggestedParamValue = new JobSuggestedParamValue();
    jobSuggestedParamValue.jobExecution = jobExecution;
    TuningParameter tuningParameter = TuningParameter.find.where().eq(TuningParameter.TABLE.paramName, paramName).findUnique();
    if (tuningParameter != null) {
        jobSuggestedParamValue.tuningParameter = tuningParameter;
        jobSuggestedParamValue.paramValue = paramValue;
        jobSuggestedParamValue.save();
        logger.debug("Finishing insertDefaultJobExecution. Job Execution ID. Param ID " + jobSuggestedParamValue.tuningParameter.id + " Param Name: " + jobSuggestedParamValue.tuningParameter.paramName);
    } else {
        logger.warn("TuningAlgorithm param null " + paramName);
    }
}
Also used : TuningParameter(models.TuningParameter) JobSuggestedParamValue(models.JobSuggestedParamValue)

Aggregations

JobSuggestedParamValue (models.JobSuggestedParamValue)3 TuningJobExecution (models.TuningJobExecution)2 HashMap (java.util.HashMap)1 JobExecution (models.JobExecution)1 TuningJobDefinition (models.TuningJobDefinition)1 TuningParameter (models.TuningParameter)1