Search in sources :

Example 1 with SparkJobConfiguration

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

the class JupyterSettingsFacade method findByProjectUser.

public JupyterSettings findByProjectUser(Project project, String email) {
    JupyterSettingsPK pk = new JupyterSettingsPK(project.getId(), email);
    JupyterSettings js;
    js = em.find(JupyterSettings.class, pk);
    if (js == null) {
        String secret = DigestUtils.sha256Hex(Integer.toString(ThreadLocalRandom.current().nextInt()));
        js = new JupyterSettings(pk);
        js.setSecret(secret);
        js.setJobConfig(new SparkJobConfiguration(ExperimentType.EXPERIMENT));
        js.setBaseDir(Utils.getProjectPath(project.getName()) + Settings.ServiceDataset.JUPYTER.getName());
        persist(js);
    }
    if (js.getJobConfig() == null) {
        js.setJobConfig(new SparkJobConfiguration(ExperimentType.EXPERIMENT));
    }
    return js;
}
Also used : JupyterSettingsPK(io.hops.hopsworks.persistence.entity.jupyter.JupyterSettingsPK) JupyterSettings(io.hops.hopsworks.persistence.entity.jupyter.JupyterSettings) SparkJobConfiguration(io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration)

Example 2 with SparkJobConfiguration

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

the class SparkJob method setupJob.

@Override
protected boolean setupJob() {
    SparkJobConfiguration jobconfig = (SparkJobConfiguration) jobs.getJobConfig();
    // Then: actually get to running.
    if (jobconfig.getAppName() == null || jobconfig.getAppName().isEmpty()) {
        jobconfig.setAppName("Untitled Spark Job");
    }
    // If runnerbuilder is not null, it has been instantiated by child class,
    if (runnerbuilder == null) {
        runnerbuilder = new SparkYarnRunnerBuilder(jobs);
        runnerbuilder.setJobName(jobconfig.getAppName());
    }
    if (jobconfig.getLocalResources() != null) {
        runnerbuilder.addExtraFiles(Arrays.asList(jobconfig.getLocalResources()));
    }
    // Set project specific resources, i.e. Kafka certificates
    runnerbuilder.addExtraFiles(projectLocalResources);
    if (jobSystemProperties != null && !jobSystemProperties.isEmpty()) {
        for (Entry<String, String> jobSystemProperty : jobSystemProperties.entrySet()) {
            runnerbuilder.addSystemProperty(jobSystemProperty.getKey(), jobSystemProperty.getValue());
        }
    }
    String stdFinalDestination = Utils.getProjectPath(jobs.getProject().getName()) + Settings.BaseDataset.LOGS.getName() + "/" + JobType.SPARK.getName();
    setStdOutFinalDestination(stdFinalDestination);
    setStdErrFinalDestination(stdFinalDestination);
    try {
        runner = runnerbuilder.getYarnRunner(jobs.getProject(), jobUser, user, services, services.getFileOperations(hdfsUser.getUserName()), yarnClient, settings, kafkaBrokersString, hopsworksRestEndpoint, servingConfig, serviceDiscoveryController);
    } catch (Exception e) {
        LOG.log(Level.WARNING, "Failed to create YarnRunner.", e);
        try {
            writeToLogs(e.getLocalizedMessage());
        } catch (IOException ex) {
            LOG.log(Level.SEVERE, "Failed to write logs for failed application.", ex);
        }
        return false;
    }
    return true;
}
Also used : SparkJobConfiguration(io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration) IOException(java.io.IOException) IOException(java.io.IOException)

Example 3 with SparkJobConfiguration

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

the class SparkController method sanityCheck.

private void sanityCheck(Jobs job, Users user) throws GenericException, ProjectException {
    if (job == null) {
        throw new IllegalArgumentException("Trying to start job but job is not provided");
    } else if (user == null) {
        throw new IllegalArgumentException("Trying to start job but user is not provided");
    } else if (job.getJobType() != JobType.SPARK && job.getJobType() != JobType.PYSPARK) {
        throw new IllegalArgumentException("Job configuration is not a Spark job configuration. Type: " + job.getJobType());
    }
    SparkJobConfiguration jobConf = (SparkJobConfiguration) job.getJobConfig();
    if (jobConf == null) {
        throw new IllegalArgumentException("Trying to start job but JobConfiguration is null");
    }
    String path = jobConf.getAppPath();
    if (Strings.isNullOrEmpty(path) || !(path.endsWith(".jar") || path.endsWith(".py") || path.endsWith(".ipynb"))) {
        throw new IllegalArgumentException("Path does not point to a .jar, .py or .ipynb file.");
    }
    inspectDependencies(job.getProject(), user, (SparkJobConfiguration) job.getJobConfig());
}
Also used : SparkJobConfiguration(io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration)

Example 4 with SparkJobConfiguration

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

the class SparkController method inspectProgram.

public SparkJobConfiguration inspectProgram(SparkJobConfiguration existingConfig, String path, DistributedFileSystemOps udfso) throws JobException {
    SparkJobConfiguration sparkConfig = null;
    if (existingConfig == null) {
        sparkConfig = new SparkJobConfiguration();
    } else {
        sparkConfig = existingConfig;
    }
    // If the main program is in a jar, try to set main class from it
    if (path.endsWith(".jar")) {
        try (JarInputStream jis = new JarInputStream(udfso.open(path))) {
            Manifest mf = jis.getManifest();
            if (mf != null) {
                Attributes atts = mf.getMainAttributes();
                if (atts.containsKey(Attributes.Name.MAIN_CLASS)) {
                    sparkConfig.setMainClass(atts.getValue(Attributes.Name.MAIN_CLASS));
                } else {
                    sparkConfig.setMainClass(null);
                }
            }
        } catch (IOException ex) {
            throw new JobException(RESTCodes.JobErrorCode.JAR_INSPECTION_ERROR, Level.SEVERE, "Failed to inspect jar at:" + path, ex.getMessage(), ex);
        }
    } else {
        // In that case we should not override it and set the experimentType, only set it if no default exists
        if (existingConfig == null) {
            sparkConfig.setExperimentType(ExperimentType.EXPERIMENT);
        }
        sparkConfig.setMainClass(Settings.SPARK_PY_MAINCLASS);
    }
    sparkConfig.setAppPath(path);
    return sparkConfig;
}
Also used : JobException(io.hops.hopsworks.exceptions.JobException) JarInputStream(java.util.jar.JarInputStream) SparkJobConfiguration(io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration) Attributes(java.util.jar.Attributes) IOException(java.io.IOException) Manifest(java.util.jar.Manifest)

Example 5 with SparkJobConfiguration

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

the class AbstractExecutionController method start.

@Override
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public Execution start(Jobs job, String args, Users user) throws JobException, GenericException, ServiceException, ProjectException {
    // If the limit for the number of executions for this job has been reached, return an error
    checkExecutionLimit(job);
    // A user should not be able to start a job if the project is prepaid and it doesn't have quota.
    if (job.getProject().getPaymentType().equals(PaymentType.PREPAID)) {
        YarnProjectsQuota projectQuota = yarnProjectsQuotaFacade.findByProjectName(job.getProject().getName());
        if (projectQuota == null || projectQuota.getQuotaRemaining() <= 0) {
            throw new ProjectException(RESTCodes.ProjectErrorCode.PROJECT_QUOTA_ERROR, Level.FINE);
        }
    }
    // If enabled and nodemanagers are all offline throw an JobException exception
    if (settings.isCheckingForNodemanagerStatusEnabled() && job.getJobType() != JobType.PYTHON) {
        hostServicesFacade.findServices("nodemanager").stream().filter(s -> s.getStatus() == ServiceStatus.Started).findFirst().orElseThrow(() -> new JobException(RESTCodes.JobErrorCode.NODEMANAGERS_OFFLINE, Level.SEVERE));
    }
    Execution exec;
    switch(job.getJobType()) {
        case FLINK:
            // Materialize certs
            return flinkController.startJob(job, user);
        case SPARK:
            exec = sparkController.startJob(job, args, user);
            if (exec == null) {
                throw new IllegalArgumentException("Problem getting execution object for: " + job.getJobType());
            }
            SparkJobConfiguration config = (SparkJobConfiguration) job.getJobConfig();
            String path = config.getAppPath();
            String pathOfInode;
            try {
                pathOfInode = Utils.prepPath(path);
            } catch (UnsupportedEncodingException ex) {
                throw new JobException(RESTCodes.JobErrorCode.JOB_START_FAILED, Level.FINE, "Job name: " + job.getName(), ex.getMessage(), ex);
            }
            Inode inode = inodeController.getInodeAtPath(pathOfInode);
            String inodeName = inode.getInodePK().getName();
            activityFacade.persistActivity(ActivityFacade.EXECUTED_JOB + inodeName, job.getProject(), user, ActivityFlag.JOB);
            break;
        case PYSPARK:
            if (job.getProject().getPythonEnvironment() == null) {
                throw new ProjectException(RESTCodes.ProjectErrorCode.ANACONDA_NOT_ENABLED, Level.FINEST);
            }
            exec = sparkController.startJob(job, args, user);
            if (exec == null) {
                throw new IllegalArgumentException("Error while getting execution object for: " + job.getJobType());
            }
            break;
        default:
            throw new GenericException(RESTCodes.GenericErrorCode.UNKNOWN_ACTION, Level.FINE, "Unsupported job type: " + job.getJobType());
    }
    return exec;
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) JobException(io.hops.hopsworks.exceptions.JobException) Execution(io.hops.hopsworks.persistence.entity.jobs.history.Execution) Inode(io.hops.hopsworks.persistence.entity.hdfs.inode.Inode) SparkJobConfiguration(io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration) UnsupportedEncodingException(java.io.UnsupportedEncodingException) GenericException(io.hops.hopsworks.exceptions.GenericException) YarnProjectsQuota(io.hops.hopsworks.persistence.entity.jobs.quota.YarnProjectsQuota) TransactionAttribute(javax.ejb.TransactionAttribute)

Aggregations

SparkJobConfiguration (io.hops.hopsworks.persistence.entity.jobs.configuration.spark.SparkJobConfiguration)18 JobException (io.hops.hopsworks.exceptions.JobException)4 IOException (java.io.IOException)4 ProjectException (io.hops.hopsworks.exceptions.ProjectException)3 Jobs (io.hops.hopsworks.persistence.entity.jobs.description.Jobs)3 DefaultJobConfiguration (io.hops.hopsworks.persistence.entity.project.jobs.DefaultJobConfiguration)3 HashMap (java.util.HashMap)3 TransactionAttribute (javax.ejb.TransactionAttribute)3 Path (org.apache.hadoop.fs.Path)3 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)2 SparkConfigurationUtil (io.hops.hopsworks.common.util.SparkConfigurationUtil)2 ConfigProperty (io.hops.hopsworks.common.util.templates.ConfigProperty)2 Inode (io.hops.hopsworks.persistence.entity.hdfs.inode.Inode)2 FlinkJobConfiguration (io.hops.hopsworks.persistence.entity.jobs.configuration.flink.FlinkJobConfiguration)2 Execution (io.hops.hopsworks.persistence.entity.jobs.history.Execution)2 JAXBException (javax.xml.bind.JAXBException)2 ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)1 Service (com.logicalclocks.servicediscoverclient.service.Service)1 TemplateException (freemarker.template.TemplateException)1 DistributedFileSystemOps (io.hops.hopsworks.common.hdfs.DistributedFileSystemOps)1