-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JobTemplates and Flink demo (#74)
* Add JobTemplates and Flink demo * PR fixes h/t @jogrogan
- Loading branch information
1 parent
159a0e9
commit 11c53f8
Showing
47 changed files
with
1,023 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## This template adds Flink support. | ||
|
||
apiVersion: hoptimator.linkedin.com/v1alpha1 | ||
kind: JobTemplate | ||
metadata: | ||
name: flink-template | ||
spec: | ||
yaml: | | ||
apiVersion: flink.apache.org/v1beta1 | ||
kind: FlinkDeployment | ||
metadata: | ||
name: {{name}} | ||
spec: | ||
image: docker.io/library/hoptimator-flink-runner | ||
imagePullPolicy: Never | ||
flinkVersion: v1_16 | ||
flinkConfiguration: | ||
taskmanager.numberOfTaskSlots: "1" | ||
serviceAccount: flink | ||
jobManager: | ||
resource: | ||
memory: "2048m" | ||
cpu: 0.1 | ||
taskManager: | ||
resource: | ||
memory: "2048m" | ||
cpu: 0.1 | ||
job: | ||
entryClass: com.linkedin.hoptimator.flink.runner.FlinkRunner | ||
args: | ||
- {{sql}} | ||
jarURI: local:///opt/hoptimator-flink-runner.jar | ||
parallelism: 1 | ||
upgradeMode: stateless | ||
state: running | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
hoptimator-k8s/src/main/java/com/linkedin/hoptimator/k8s/K8sJobDeployer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.linkedin.hoptimator.k8s; | ||
|
||
import com.linkedin.hoptimator.util.Job; | ||
import com.linkedin.hoptimator.util.Template; | ||
import com.linkedin.hoptimator.k8s.models.V1alpha1JobTemplate; | ||
import com.linkedin.hoptimator.k8s.models.V1alpha1JobTemplateList; | ||
|
||
import org.apache.calcite.sql.SqlDialect; | ||
import org.apache.calcite.sql.dialect.AnsiSqlDialect; | ||
import org.apache.calcite.sql.dialect.MysqlSqlDialect; | ||
import org.apache.calcite.sql.dialect.CalciteSqlDialect; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.sql.SQLException; | ||
|
||
/** Specifies an abstract Job with concrete YAML by applying JobTemplates. */ | ||
class K8sJobDeployer extends K8sYamlDeployer<Job> { | ||
|
||
private final K8sApi<V1alpha1JobTemplate, V1alpha1JobTemplateList> jobTemplateApi; | ||
|
||
K8sJobDeployer(K8sContext context) { | ||
super(context); | ||
this.jobTemplateApi = new K8sApi<>(context, K8sApiEndpoints.JOB_TEMPLATES); | ||
} | ||
|
||
@Override | ||
public List<String> specify(Job job) throws SQLException { | ||
Function<SqlDialect, String> sql = job.sql(); | ||
Template.Environment env = Template.Environment.EMPTY | ||
.with("name", job.sink().database() + "-" + job.sink().table().toLowerCase(Locale.ROOT)) | ||
.with("database", job.sink().database()) | ||
.with("schema", job.sink().schema()) | ||
.with("table", job.sink().table()) | ||
.with("sql", sql.apply(MysqlSqlDialect.DEFAULT)) | ||
.with("ansisql", sql.apply(AnsiSqlDialect.DEFAULT)) | ||
.with("calcitesql", sql.apply(CalciteSqlDialect.DEFAULT)) | ||
.with(job.sink().options()); | ||
return jobTemplateApi.list().stream() | ||
.map(x -> x.getSpec()) | ||
.filter(x -> x.getDatabases() == null || x.getDatabases().contains(job.sink().database())) | ||
.filter(x -> x.getYaml() != null) | ||
.map(x -> x.getYaml()) | ||
.map(x -> new Template.SimpleTemplate(x).render(env)) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.