Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #816 from jsanda/hwkmetrics-648
[HWKMETRICS-648] add support for modifying and persisting job params
- Loading branch information
Showing
15 changed files
with
577 additions
and
171 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
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
67 changes: 67 additions & 0 deletions
67
job-scheduler/src/main/java/org/hawkular/metrics/scheduler/api/JobParameters.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,67 @@ | ||
/* | ||
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.scheduler.api; | ||
|
||
import java.util.Map; | ||
|
||
import rx.Completable; | ||
|
||
/** | ||
* Provides a map-like key/value API for job parameters. The parameters are mutable. Changes will be persisted after | ||
* job execution completes (for repeating jobs). Changes can also be persisted during execution using the | ||
* {@link #save() save} method. | ||
* | ||
* @author jsanda | ||
*/ | ||
public interface JobParameters { | ||
|
||
/** | ||
* Return the value associated with the key or null if there is no such parameter | ||
*/ | ||
String get(String key); | ||
|
||
/** | ||
* Associates the value with the key and returns the old value if there previously was a mapping for the key | ||
*/ | ||
String put(String key, String value); | ||
|
||
/** | ||
* Removes the value associated with the key or null if there is no such parameter | ||
*/ | ||
String remove(String key); | ||
|
||
/** | ||
* Return true if the parameters contain a value for the key | ||
*/ | ||
boolean containsKey(String key); | ||
|
||
/** | ||
* Return an immutable map of the parameters. Note that this map is a copy. Any changes made to the parameters | ||
* through methods like {@link #get(String) get} or {@link #put(String, String) put} will not be reflected in | ||
* this map. | ||
*/ | ||
Map<String, String> getMap(); | ||
|
||
/** | ||
* Asynchronously save the parameters back to Cassandra. For reoccurring jobs any changes to parameters will | ||
* automatically be persisted when the job finishes and is rescheduled for its next run. This method can be useful | ||
* for long running jobs that perform a lot of work. It can be used to create checkpoints so that if a job is | ||
* abruptly stopped and restarted it can resume its work from that checkpoint rather than starting all over. | ||
*/ | ||
Completable save(); | ||
|
||
} |
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
142 changes: 142 additions & 0 deletions
142
job-scheduler/src/main/java/org/hawkular/metrics/scheduler/impl/JobDetailsImpl.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,142 @@ | ||
/* | ||
* Copyright 2014-2017 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hawkular.metrics.scheduler.impl; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
|
||
import org.hawkular.metrics.scheduler.api.JobDetails; | ||
import org.hawkular.metrics.scheduler.api.JobParameters; | ||
import org.hawkular.metrics.scheduler.api.JobStatus; | ||
import org.hawkular.metrics.scheduler.api.Trigger; | ||
|
||
import com.google.common.base.MoreObjects; | ||
|
||
import rx.Completable; | ||
|
||
/** | ||
* @author jsanda | ||
*/ | ||
public class JobDetailsImpl implements JobDetails { | ||
|
||
private UUID jobId; | ||
|
||
private String jobType; | ||
|
||
private String jobName; | ||
|
||
private JobParametersImpl parameters; | ||
|
||
private Trigger trigger; | ||
|
||
private JobStatus status; | ||
|
||
public JobDetailsImpl(UUID jobId, String jobType, String jobName, JobParametersImpl parameters, Trigger trigger) { | ||
this.jobId = jobId; | ||
this.jobType = jobType; | ||
this.jobName = jobName; | ||
this.parameters = parameters; | ||
this.trigger = trigger; | ||
status = JobStatus.NONE; | ||
} | ||
|
||
public JobDetailsImpl(UUID jobId, String jobType, String jobName, JobParametersImpl parameters, Trigger trigger, | ||
JobStatus status) { | ||
this.jobId = jobId; | ||
this.jobType = jobType; | ||
this.jobName = jobName; | ||
this.parameters = parameters; | ||
this.trigger = trigger; | ||
this.status = status; | ||
} | ||
|
||
public JobDetailsImpl(JobDetailsImpl details, Trigger newTrigger) { | ||
jobId = details.jobId; | ||
jobType = details.jobType; | ||
jobName = details.jobName; | ||
parameters = details.parameters; | ||
status = details.status; | ||
trigger = newTrigger; | ||
} | ||
|
||
@Override | ||
public UUID getJobId() { | ||
return jobId; | ||
} | ||
|
||
@Override | ||
public String getJobType() { | ||
return jobType; | ||
} | ||
|
||
@Override | ||
public String getJobName() { | ||
return jobName; | ||
} | ||
|
||
@Override | ||
public JobParameters getParameters() { | ||
return parameters; | ||
} | ||
|
||
public void setSaveParameters(Function<Map<String, String>, Completable> saveParameters) { | ||
parameters.setSaveParameters(saveParameters); | ||
} | ||
|
||
@Override | ||
public Trigger getTrigger() { | ||
return trigger; | ||
} | ||
|
||
@Override | ||
public JobStatus getStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
JobDetailsImpl details = (JobDetailsImpl) o; | ||
return Objects.equals(jobId, details.jobId) && | ||
Objects.equals(jobType, details.jobType) && | ||
Objects.equals(jobName, details.jobName) && | ||
Objects.equals(parameters, details.parameters) && | ||
Objects.equals(trigger, details.trigger) && | ||
Objects.equals(status, details.status); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobId, jobType, jobName, parameters, trigger, status); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return MoreObjects.toStringHelper(this) | ||
.add("jobId", jobId) | ||
.add("jobType", jobType) | ||
.add("jobName", jobName) | ||
.add("parameters", parameters) | ||
.add("trigger", trigger) | ||
.add("status", status) | ||
.omitNullValues() | ||
.toString(); | ||
} | ||
} |
Oops, something went wrong.