Search in sources :

Example 1 with DefaultJobConfigurationPK

use of io.hops.hopsworks.persistence.entity.jobs.configuration.DefaultJobConfigurationPK in project hopsworks by logicalclocks.

the class DefaultJobConfigurationFacade method createOrUpdate.

public DefaultJobConfiguration createOrUpdate(Project project, JobConfiguration jobConfiguration, JobType jobType, DefaultJobConfiguration currentConfig) throws ProjectException {
    if (jobConfiguration instanceof SparkJobConfiguration) {
        ((SparkJobConfiguration) jobConfiguration).setMainClass(Settings.SPARK_PY_MAINCLASS);
        jobType = JobType.PYSPARK;
    }
    // create
    if (currentConfig == null) {
        currentConfig = new DefaultJobConfiguration();
        DefaultJobConfigurationPK pk = new DefaultJobConfigurationPK();
        pk.setProjectId(project.getId());
        pk.setType(jobType);
        currentConfig.setDefaultJobConfigurationPK(pk);
        currentConfig.setJobConfig(jobConfiguration);
        project.getDefaultJobConfigurationCollection().add(currentConfig);
        em.merge(project);
        return currentConfig;
    // update
    } else {
        for (DefaultJobConfiguration dc : project.getDefaultJobConfigurationCollection()) {
            if (dc.getDefaultJobConfigurationPK().getType().equals(jobType)) {
                dc.setJobConfig(jobConfiguration);
                em.merge(project);
                return dc;
            }
        }
        throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_DEFAULT_JOB_CONFIG_NOT_FOUND, Level.FINEST);
    }
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) SparkJobConfiguration(io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration) DefaultJobConfiguration(io.hops.hopsworks.persistence.entity.project.jobs.DefaultJobConfiguration) DefaultJobConfigurationPK(io.hops.hopsworks.persistence.entity.jobs.configuration.DefaultJobConfigurationPK)

Aggregations

ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 DefaultJobConfigurationPK (io.hops.hopsworks.persistence.entity.jobs.configuration.DefaultJobConfigurationPK)1 SparkJobConfiguration (io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration)1 DefaultJobConfiguration (io.hops.hopsworks.persistence.entity.project.jobs.DefaultJobConfiguration)1