Skip to content

Commit

Permalink
SpotlessApply
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Palis <jpalis@amazon.com>
  • Loading branch information
joshpalis committed Dec 29, 2022
1 parent 522e08f commit 80310b0
Show file tree
Hide file tree
Showing 54 changed files with 1,494 additions and 1,116 deletions.
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ coverage:
project:
default:
target: 75% # the required coverage value
threshold: 1% # the leniency in hitting the target
threshold: 1% # the leniency in hitting the target
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ contact_links:
about: Please ask and answer questions here.
- name: AWS/Amazon Security
url: https://aws.amazon.com/security/vulnerability-reporting/
about: Please report security vulnerabilities here.
about: Please report security vulnerabilities here.
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ jobs:
- name: Publish to Maven Local
run: |
./gradlew publishToMavenLocal
- name: Upload Coverage Report
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

2 changes: 1 addition & 1 deletion .github/workflows/dco.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- name: DCO Check
uses: tim-actions/dco@v1.1.0
with:
commits: ${{ steps.get-pr-commits.outputs.commits }}
commits: ${{ steps.get-pr-commits.outputs.commits }}
2 changes: 1 addition & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Fail if there were link errors
run: exit ${{ steps.lychee.outputs.exit_code }}
run: exit ${{ steps.lychee.outputs.exit_code }}
2 changes: 1 addition & 1 deletion ADMINS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
| --------------- | --------------------------------------- | ----------- |
| Henri Yandell | [hyandell](https://github.com/hyandell) | Amazon |

[This document](https://github.com/opensearch-project/.github/blob/main/ADMINS.md) explains what admins do in this repo. and how they should be doing it. If you're interested in becoming a maintainer, see [MAINTAINERS](MAINTAINERS.md). If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
[This document](https://github.com/opensearch-project/.github/blob/main/ADMINS.md) explains what admins do in this repo. and how they should be doing it. If you're interested in becoming a maintainer, see [MAINTAINERS](MAINTAINERS.md). If you're interested in contributing, see [CONTRIBUTING](CONTRIBUTING.md).
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contributing to this project

OpenSearch is a community project that is built and maintained by people just like **you**.
[This document](https://github.com/opensearch-project/.github/blob/main/CONTRIBUTING.md) explains how you can contribute to this and related projects.
[This document](https://github.com/opensearch-project/.github/blob/main/CONTRIBUTING.md) explains how you can contribute to this and related projects.
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ See [CONTRIBUTING](CONTRIBUTING.md).

### Backport

- [Link to backport documentation](https://github.com/opensearch-project/opensearch-plugins/blob/main/BACKPORT.md)
- [Link to backport documentation](https://github.com/opensearch-project/opensearch-plugins/blob/main/BACKPORT.md)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ monitoring the shard allocation by calling OpenSearch API and post the output to

## Getting Started
Add the following to your plugin to integrate with JobScheduler
1. Gradle
1. Gradle
* [Extend plugin from `opensearch-job-scheduler`](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/build.gradle#L36)
* Add [this workaround](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/build.gradle#L36) to make sure that job-schedular plugin is correctly installed during integration tests.

2. Implement the following classes
* Implement these two interfaces [ScheduledJobParameter](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/src/main/java/org/opensearch/jobscheduler/sampleextension/SampleJobParameter.java#L37) and [ScheduledJobRunner](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/src/main/java/org/opensearch/jobscheduler/sampleextension/SampleJobRunner.java#L43)
* Implement these two interfaces [ScheduledJobParameter](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/src/main/java/org/opensearch/jobscheduler/sampleextension/SampleJobParameter.java#L37) and [ScheduledJobRunner](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/src/main/java/org/opensearch/jobscheduler/sampleextension/SampleJobRunner.java#L43)
* Extend class [JobSchedulerExtension](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/src/main/java/org/opensearch/jobscheduler/sampleextension/SampleExtensionPlugin.java#L12)

3. Add the resource file
* Create `org.opensearch.jobscheduler.spi.JobSchedulerExtension` [file](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/src/main/resources/META-INF/services/org.opensearch.jobscheduler.spi.JobSchedulerExtension#L1).
* Create `org.opensearch.jobscheduler.spi.JobSchedulerExtension` [file](https://github.com/opensearch-project/job-scheduler/blob/main/sample-extension-plugin/src/main/resources/META-INF/services/org.opensearch.jobscheduler.spi.JobSchedulerExtension#L1).

## Contributing

Expand All @@ -61,4 +61,4 @@ This project is licensed under the [Apache v2.0 License](./LICENSE.txt)

## Copyright

Copyright OpenSearch Contributors. See [NOTICE](NOTICE) for details.
Copyright OpenSearch Contributors. See [NOTICE](NOTICE) for details.
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
This project follows the [OpenSearch release process](https://github.com/opensearch-project/.github/blob/main/RELEASING.md).
This project follows the [OpenSearch release process](https://github.com/opensearch-project/.github/blob/main/RELEASING.md).
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Reporting a Vulnerability

If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. Please do **not** create a public GitHub issue.
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/) or directly via email to aws-security@amazon.com. Please do **not** create a public GitHub issue.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ afterEvaluate {
maintainer 'OpenSearch Team <opensearch@amazon.com>'
url 'https://opensearch.org/downloads.html'
summary '''
JobScheduler plugin for OpenSearch.
JobScheduler plugin for OpenSearch.
Reference documentation can be found at https://docs-beta.opensearch.org/.
'''.stripIndent().replace('\n', ' ').trim()
}
Expand Down
2 changes: 1 addition & 1 deletion sample-extension-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ String bwcDownloadUrl = "https://ci.opensearch.org/ci/dbc/distribution-build-ope
if (!f.exists()) {
new URL(bwcDownloadUrl).withInputStream{ ins -> f.withOutputStream{ it << ins }}
}
return f
return f
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.jobscheduler.sampleextension;

import org.opensearch.jobscheduler.spi.JobSchedulerExtension;
Expand Down Expand Up @@ -54,12 +57,19 @@ public class SampleExtensionPlugin extends Plugin implements ActionPlugin, JobSc
static final String JOB_INDEX_NAME = ".scheduler_sample_extension";

@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
NamedXContentRegistry xContentRegistry, Environment environment,
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<RepositoriesService> repositoriesServiceSupplier) {
public Collection<Object> createComponents(
Client client,
ClusterService clusterService,
ThreadPool threadPool,
ResourceWatcherService resourceWatcherService,
ScriptService scriptService,
NamedXContentRegistry xContentRegistry,
Environment environment,
NodeEnvironment nodeEnvironment,
NamedWriteableRegistry namedWriteableRegistry,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<RepositoriesService> repositoriesServiceSupplier
) {
SampleJobRunner jobRunner = SampleJobRunner.getJobRunnerInstance();
jobRunner.setClusterService(clusterService);
jobRunner.setThreadPool(threadPool);
Expand Down Expand Up @@ -117,28 +127,35 @@ public ScheduledJobParser getJobParser() {
case SampleJobParameter.JITTER:
jobParameter.setJitter(parser.doubleValue());
break;
default: XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation());
default:
XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation());
}
}
return jobParameter;
};
}

private Instant parseInstantValue(XContentParser parser) throws IOException {
if(XContentParser.Token.VALUE_NULL.equals(parser.currentToken())) {
if (XContentParser.Token.VALUE_NULL.equals(parser.currentToken())) {
return null;
}
if(parser.currentToken().isValue()) {
if (parser.currentToken().isValue()) {
return Instant.ofEpochMilli(parser.longValue());
}
XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation());
return null;
}

@Override
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
public List<RestHandler> getRestHandlers(
Settings settings,
RestController restController,
ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings,
SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster
) {
return Collections.singletonList(new SampleExtensionRestHandler());
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.jobscheduler.sampleextension;

import org.opensearch.action.support.WriteRequest;
Expand Down Expand Up @@ -32,11 +35,11 @@
*
* Users need to provide "id", "index", "job_name", and "interval" parameter to schedule
* a job. e.g.
* {@code
* {@code
* POST /_plugins/scheduler_sample/watch?id=dashboards-job-id&job_name=watch dashboards index&index=.opensearch_dashboards_1&interval=1
* }
*
* creates a job with id "dashboards-job-id" and job name "watch dashboards index",
* creates a job with id "dashboards-job-id" and job name "watch dashboards index",
* which logs ".opensearch_dashboards_1" index's shards info every 1 minute
*
* Users can remove that job by calling
Expand All @@ -52,10 +55,9 @@ public String getName() {

@Override
public List<Route> routes() {
return Collections.unmodifiableList(Arrays.asList(
new Route(RestRequest.Method.POST, WATCH_INDEX_URI),
new Route(RestRequest.Method.DELETE, WATCH_INDEX_URI)
));
return Collections.unmodifiableList(
Arrays.asList(new Route(RestRequest.Method.POST, WATCH_INDEX_URI), new Route(RestRequest.Method.DELETE, WATCH_INDEX_URI))
);
}

@Override
Expand All @@ -71,27 +73,34 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
String jitterString = request.param("jitter");
Double jitter = jitterString != null ? Double.parseDouble(jitterString) : null;

if(id == null || indexName ==null) {
if (id == null || indexName == null) {
throw new IllegalArgumentException("Must specify id and index parameter");
}
SampleJobParameter jobParameter = new SampleJobParameter(id, jobName, indexName,
new IntervalSchedule(Instant.now(), Integer.parseInt(interval), ChronoUnit.MINUTES), lockDurationSeconds, jitter);
IndexRequest indexRequest = new IndexRequest()
.index(SampleExtensionPlugin.JOB_INDEX_NAME)
.id(id)
.source(jobParameter.toXContent(JsonXContent.contentBuilder(), null))
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
SampleJobParameter jobParameter = new SampleJobParameter(
id,
jobName,
indexName,
new IntervalSchedule(Instant.now(), Integer.parseInt(interval), ChronoUnit.MINUTES),
lockDurationSeconds,
jitter
);
IndexRequest indexRequest = new IndexRequest().index(SampleExtensionPlugin.JOB_INDEX_NAME)
.id(id)
.source(jobParameter.toXContent(JsonXContent.contentBuilder(), null))
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);

return restChannel -> {
// index the job parameter
client.index(indexRequest, new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse indexResponse) {
try {
RestResponse restResponse = new BytesRestResponse(RestStatus.OK,
indexResponse.toXContent(JsonXContent.contentBuilder(), null));
RestResponse restResponse = new BytesRestResponse(
RestStatus.OK,
indexResponse.toXContent(JsonXContent.contentBuilder(), null)
);
restChannel.sendResponse(restResponse);
} catch(IOException e) {
} catch (IOException e) {
restChannel.sendResponse(new BytesRestResponse(RestStatus.INTERNAL_SERVER_ERROR, e.getMessage()));
}
}
Expand All @@ -105,9 +114,7 @@ public void onFailure(Exception e) {
} else if (request.method().equals(RestRequest.Method.DELETE)) {
// delete job parameter doc from index
String id = request.param("id");
DeleteRequest deleteRequest = new DeleteRequest()
.index(SampleExtensionPlugin.JOB_INDEX_NAME)
.id(id);
DeleteRequest deleteRequest = new DeleteRequest().index(SampleExtensionPlugin.JOB_INDEX_NAME).id(id);

return restChannel -> {
client.delete(deleteRequest, new ActionListener<DeleteResponse>() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.jobscheduler.sampleextension;

import org.opensearch.jobscheduler.spi.ScheduledJobParameter;
Expand Down Expand Up @@ -39,8 +42,7 @@ public class SampleJobParameter implements ScheduledJobParameter {
private Long lockDurationSeconds;
private Double jitter;

public SampleJobParameter() {
}
public SampleJobParameter() {}

public SampleJobParameter(String id, String name, String indexToWatch, Schedule schedule, Long lockDurationSeconds, Double jitter) {
this.jobName = name;
Expand Down Expand Up @@ -85,7 +87,8 @@ public Long getLockDurationSeconds() {
return this.lockDurationSeconds;
}

@Override public Double getJitter() {
@Override
public Double getJitter() {
return jitter;
}

Expand Down
Loading

0 comments on commit 80310b0

Please sign in to comment.