Search in sources :

Example 1 with HOCONInputStreamJobTemplate

use of org.apache.gobblin.runtime.template.HOCONInputStreamJobTemplate in project incubator-gobblin by apache.

the class FSFlowTemplateCatalog method getJobTemplatesForFlow.

/**
 * @param flowTemplateDirURI Relative URI of the flow template directory
 * @return a list of {@link JobTemplate}s for a given flow identified by its {@link URI}.
 * @throws IOException
 * @throws SpecNotFoundException
 * @throws JobTemplate.TemplateException
 */
public List<JobTemplate> getJobTemplatesForFlow(URI flowTemplateDirURI) throws IOException, SpecNotFoundException, JobTemplate.TemplateException, URISyntaxException {
    PathFilter extensionFilter = file -> {
        for (String extension : JOB_FILE_EXTENSIONS) {
            if (file.getName().endsWith(extension)) {
                return true;
            }
        }
        return false;
    };
    if (!validateTemplateURI(flowTemplateDirURI)) {
        throw new JobTemplate.TemplateException(String.format("The FlowTemplate %s is not valid", flowTemplateDirURI));
    }
    List<JobTemplate> jobTemplates = new ArrayList<>();
    String templateCatalogDir = this.sysConfig.getString(ServiceConfigKeys.TEMPLATE_CATALOGS_FULLY_QUALIFIED_PATH_KEY);
    // Flow templates are located under templateCatalogDir/flowEdgeTemplates
    Path flowTemplateDirPath = PathUtils.mergePaths(new Path(templateCatalogDir), new Path(flowTemplateDirURI));
    // Job files (with extension .job) are located under templateCatalogDir/flowEdgeTemplates/jobs directory.
    Path jobFilePath = new Path(flowTemplateDirPath, JOBS_DIR_NAME);
    FileSystem fs = FileSystem.get(jobFilePath.toUri(), new Configuration());
    for (FileStatus fileStatus : fs.listStatus(jobFilePath, extensionFilter)) {
        Config jobConfig = loadHoconFileAtPath(fileStatus.getPath());
        // Check if the .job file has an underlying job template
        if (jobConfig.hasPath(GOBBLIN_JOB_TEMPLATE_KEY)) {
            URI jobTemplateRelativeUri = new URI(jobConfig.getString(GOBBLIN_JOB_TEMPLATE_KEY));
            if (!jobTemplateRelativeUri.getScheme().equals(FS_SCHEME)) {
                throw new RuntimeException("Expected scheme " + FS_SCHEME + " got unsupported scheme " + flowTemplateDirURI.getScheme());
            }
            Path fullJobTemplatePath = PathUtils.mergePaths(new Path(templateCatalogDir), new Path(jobTemplateRelativeUri));
            jobConfig = jobConfig.withFallback(loadHoconFileAtPath(fullJobTemplatePath));
        }
        jobTemplates.add(new HOCONInputStreamJobTemplate(jobConfig, fileStatus.getPath().toUri(), this));
    }
    return jobTemplates;
}
Also used : Arrays(java.util.Arrays) FileSystem(org.apache.hadoop.fs.FileSystem) FlowTemplate(org.apache.gobblin.service.modules.template.FlowTemplate) URISyntaxException(java.net.URISyntaxException) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) Configuration(org.apache.hadoop.conf.Configuration) Path(org.apache.hadoop.fs.Path) ConfigFactory(com.typesafe.config.ConfigFactory) JobTemplate(org.apache.gobblin.runtime.api.JobTemplate) PathUtils(org.apache.gobblin.util.PathUtils) URI(java.net.URI) ServiceConfigKeys(org.apache.gobblin.service.ServiceConfigKeys) HOCONInputStreamJobTemplate(org.apache.gobblin.runtime.template.HOCONInputStreamJobTemplate) Charsets(com.google.common.base.Charsets) FSJobCatalog(org.apache.gobblin.runtime.job_catalog.FSJobCatalog) Config(com.typesafe.config.Config) IOException(java.io.IOException) ConfigurationKeys(org.apache.gobblin.configuration.ConfigurationKeys) InputStreamReader(java.io.InputStreamReader) Alpha(org.apache.gobblin.annotation.Alpha) SpecNotFoundException(org.apache.gobblin.runtime.api.SpecNotFoundException) HOCONInputStreamFlowTemplate(org.apache.gobblin.service.modules.template.HOCONInputStreamFlowTemplate) List(java.util.List) GOBBLIN_JOB_TEMPLATE_KEY(org.apache.gobblin.runtime.AbstractJobLauncher.GOBBLIN_JOB_TEMPLATE_KEY) InputStream(java.io.InputStream) Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) Configuration(org.apache.hadoop.conf.Configuration) Config(com.typesafe.config.Config) ArrayList(java.util.ArrayList) HOCONInputStreamJobTemplate(org.apache.gobblin.runtime.template.HOCONInputStreamJobTemplate) JobTemplate(org.apache.gobblin.runtime.api.JobTemplate) HOCONInputStreamJobTemplate(org.apache.gobblin.runtime.template.HOCONInputStreamJobTemplate) URI(java.net.URI) FileSystem(org.apache.hadoop.fs.FileSystem)

Aggregations

Charsets (com.google.common.base.Charsets)1 Config (com.typesafe.config.Config)1 ConfigFactory (com.typesafe.config.ConfigFactory)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Alpha (org.apache.gobblin.annotation.Alpha)1 ConfigurationKeys (org.apache.gobblin.configuration.ConfigurationKeys)1 GOBBLIN_JOB_TEMPLATE_KEY (org.apache.gobblin.runtime.AbstractJobLauncher.GOBBLIN_JOB_TEMPLATE_KEY)1 JobTemplate (org.apache.gobblin.runtime.api.JobTemplate)1 SpecNotFoundException (org.apache.gobblin.runtime.api.SpecNotFoundException)1 FSJobCatalog (org.apache.gobblin.runtime.job_catalog.FSJobCatalog)1 HOCONInputStreamJobTemplate (org.apache.gobblin.runtime.template.HOCONInputStreamJobTemplate)1 ServiceConfigKeys (org.apache.gobblin.service.ServiceConfigKeys)1 FlowTemplate (org.apache.gobblin.service.modules.template.FlowTemplate)1