Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes backfill creation #146

Merged
merged 5 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions core/src/main/javascript/app/pages/Backfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ class BackfillDetail extends React.Component {
const { classes } = this.props;

const created = b => `by ${b.created_by} on ${b.created}`;
const jobIdFromName = (n: String) =>
this.props.workflow.jobs.find(j => j.name == n).id;

const jobLinks =
backfill &&
backfill.jobs.split(",").map(jobName => {
const jobId = jobIdFromName(jobName);
backfill.jobs.split(",").map(jobId => {
const job = this.props.workflow.getJob(jobId);
const jobName = job && job.name || job.id;
return (
<Link className="job-badge" href={`/workflow/${jobId}`}>
<span>{jobName}</span>
Expand Down
39 changes: 32 additions & 7 deletions core/src/main/javascript/app/pages/BackfillCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const formatDate = value => {
return date.isValid() ? date.format(DATE_FORMAT) : value;
};

const Label = ({ name }: any) => <dt key={`_${name}`}>{name}</dt>;
const Label = ({ name, style=null }: any) => <dt key={`_${name}`} style={style}>{name}</dt>;

const InputField = ({
name,
Expand Down Expand Up @@ -137,11 +137,19 @@ class BackfillCreate extends React.Component<any, Props, void> {
throw new SubmissionError({ _error: "No jobs selected" });

return fetch(
`/api/timeseries/backfill?` +
`name=${name}&description=${description || ""}&` +
`jobs=${jobs.join(",")}&priority=${priority}&` +
`startDate=${start.toISOString()}&endDate=${end.toISOString()}`,
{ method: "POST", credentials: "include" }
`/api/timeseries/backfill`,
{
method: "POST",
credentials: "include",
body: JSON.stringify({
name: name,
description: description || "",
jobs: jobs.join(","),
priority: priority,
startDate: start.toISOString(),
endDate: end.toISOString()
})
}
)
.then((response: Response) => {
if (!response.ok) return response.text();
Expand Down Expand Up @@ -244,7 +252,7 @@ class BackfillCreate extends React.Component<any, Props, void> {
style={{ display: "flex", width: "100%" }}
className={env.critical ? "confirm confirm-critical" : "confirm"}
>
<Label name="Confirm" />
<Label name="Confirm" style={{color : 'white'}} />
<dd name="confirm">
<Field
name="confirm"
Expand Down Expand Up @@ -334,6 +342,23 @@ const styles = {
},
"& .input-warning": {
marginLeft: "5px"
},
"& input::-webkit-input-placeholder, textarea::-webkit-input-placeholder" : {
color: "#aaa"
},
"& input:-moz-placeholder, textarea:-moz-placeholder": { /* Mozilla Firefox 4 to 18 */
color: "#aaa",
opacity: 1
},
"& input::-moz-placeholder, textarea::-moz-placeholder": { /* Mozilla Firefox 19+ */
color: "#aaa",
opacity: 1
},
"& input:-ms-input-placeholder, textarea:-ms-input-placeholder": { /* Internet Explorer 10-11 */
color: "#aaa"
},
"& input::-ms-input-placeholder, textarea::-ms-input-placeholder": { /* Microsoft Edge */
color: "#aaa"
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object HelloWorld {
val start: Instant = LocalDate.now.minusDays(7).atStartOfDay.toInstant(UTC)

val hello1 =
Job("hello1", hourly(start)) { implicit e =>
Job("hello1", hourly(start), "Hello 1") { implicit e =>
sh"""
echo "Hello 1"
echo check my project page https://github.com/criteo/cuttle
Expand All @@ -23,7 +23,7 @@ object HelloWorld {
}

val hello2 =
Job("hello2", hourly(start)) { implicit e =>
Job("hello2", hourly(start), "Hello 2") { implicit e =>
sh"""
echo "Looping for 20 seconds..."
for i in {1..20}; do
Expand All @@ -35,7 +35,7 @@ object HelloWorld {
}

val hello3 =
Job("hello3", hourly(start), tags = Set(Tag("unsafe job"))) { implicit e =>
Job("hello3", hourly(start), "Hello 3", tags = Set(Tag("unsafe job"))) { implicit e =>
sh"""
echo "Hello 3"
sleep 3
Expand All @@ -50,7 +50,7 @@ object HelloWorld {
}
}

val world = Job("world", daily(start, UTC)) { implicit e =>
val world = Job("world", daily(start, UTC), "World") { implicit e =>
sh"""
echo "World"
sleep 6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package com.criteo.cuttle.timeseries
import com.criteo.cuttle._

import io.circe._
import io.circe.generic.semiauto._

import cats.syntax.either._

import java.time.Instant

import io.circe.generic.semiauto.deriveDecoder

private[timeseries] object Internal {

implicit def jobEncoder[A <: Scheduling]: Encoder[Job[A]] =
Expand All @@ -21,5 +24,19 @@ private[timeseries] object Internal {
Decoder.decodeString.emap { s =>
Either.catchNonFatal(Instant.parse(s)).leftMap(s => "Instant")
}
}

private[timeseries] object BackfillCreate {
import Internal._

implicit val decodeBackfillCreate : Decoder[BackfillCreate] = deriveDecoder[BackfillCreate]
}

private[timeseries] case class BackfillCreate(
name : String,
description : String,
jobs : String,
startDate : Instant,
endDate : Instant,
priority : Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import intervals._
import Bound.{Bottom, Finite, Top}
import ExecutionStatus._
import com.criteo.cuttle.authentication.AuthenticatedService
import scala.concurrent.ExecutionContext.Implicits.global

private[timeseries] trait TimeSeriesApp { self: TimeSeriesScheduler =>

Expand Down Expand Up @@ -426,15 +427,31 @@ private[timeseries] trait TimeSeriesApp { self: TimeSeriesScheduler =>
private[cuttle] override def privateRoutes(workflow: Workflow[TimeSeries],
executor: Executor[TimeSeries],
xa: XA): AuthenticatedService = {
case POST at url"/api/timeseries/backfill?name=$name&description=$description&jobs=$jobsString&startDate=$start&endDate=$end&priority=$priority" =>
implicit user_ =>
val jobIds = jobsString.split(",")
val jobs = workflow.vertices.filter((job: TimeSeriesJob) => jobIds.contains(job.id))
val startDate = Instant.parse(start)
val endDate = Instant.parse(end)
if (backfillJob(name, description, jobs, startDate, endDate, priority.toInt, xa))
Ok("ok".asJson)
else
BadRequest("invalid backfill")

case req @ POST at url"/api/timeseries/backfill" => implicit user =>
req.readAs[Json].map(
_.as[BackfillCreate]
.fold(
_ => BadRequest("cannot parse request body"),
backfill => {
val jobIds = backfill.jobs.split(",")
val jobs = workflow.vertices
.filter((job: TimeSeriesJob) => jobIds.contains(job.id))

if (backfillJob(
backfill.name,
backfill.description,
jobs,
backfill.startDate,
backfill.endDate,
backfill.priority,
xa)) {
Ok("ok".asJson)
}
else {
BadRequest("invalid backfill")
}
})
)
}
}