-
Notifications
You must be signed in to change notification settings - Fork 73
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
Communication mechanism for js #289
Changes from 7 commits
7b23218
ecb3462
692d659
97e783b
b97d08a
92e5a15
da64ca7
5eb8dc5
21dfd75
15e9e2e
c9933e6
ff9e493
7933c4e
37c8d0d
7879155
1367c02
a27c263
f4e36f0
0b62209
fac7c69
1494680
dbc9382
6796447
eb1ccb6
3ef8a3c
b726e5c
a123089
d6bea89
3613ec8
9a881dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* 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.constant; | ||
|
||
public class CommonValue { | ||
|
||
public static String EXTERNAL_ACTION_PREFIX = "cluster:admin/opendistro/js/"; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/* | ||
* 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.model; | ||
|
||
import org.opensearch.common.xcontent.ToXContent; | ||
import org.opensearch.common.xcontent.ToXContentObject; | ||
import org.opensearch.common.xcontent.XContentBuilder; | ||
import org.opensearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
/** | ||
* This model class stores the job details of the extension. | ||
*/ | ||
public class JobDetails implements ToXContentObject { | ||
joshpalis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* jobIndex from the extension. | ||
*/ | ||
private String jobIndex; | ||
|
||
/** | ||
* jobType from the extension. | ||
*/ | ||
private String jobType; | ||
|
||
/** | ||
* jobParser action to trigger the response back to the extension. | ||
*/ | ||
private String jobParserAction; | ||
|
||
/** | ||
* jobRunner action to trigger the response back to the extension. | ||
*/ | ||
private String jobRunnerAction; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need jobRunner action and jobParser action? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There will be 2 callback methods. One to retrieve ScheduleJobParser and other would be ScheduleJobRunner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm why though, could you help me understand the flow? May be im missing the pieces to pull the puzzle together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In JobSweeper. java sweep method
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saratvemulapalli We'll need to transfer the bytesReference (jobDocVersion) to AD to parse the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With extensions, the parser is not really passed to JS to run, probably lets name it get job param as an API as we discussed offline. |
||
|
||
public static final String JOB_INDEX = "job_index"; | ||
public static final String JOB_TYPE = "job_type"; | ||
public static final String JOB_PARSER_ACTION = "job_parser_action"; | ||
public static final String JOB_RUNNER_ACTION = "job_runner_action"; | ||
|
||
public JobDetails() {} | ||
|
||
public JobDetails(String jobIndex, String jobType, String jobParserAction, String jobRunnerAction) { | ||
this.jobIndex = jobIndex; | ||
this.jobType = jobType; | ||
this.jobParserAction = jobParserAction; | ||
this.jobRunnerAction = jobRunnerAction; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
XContentBuilder xContentBuilder = builder.startObject(); | ||
if (jobIndex != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to understand, a. do we need to check if they are null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we do have to check if they are null or not as while testing if we provide no value then it should handle that test case gracefully. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the api call will be made then the job index will never be null. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK |
||
xContentBuilder.field(JOB_INDEX, jobIndex); | ||
} | ||
if (jobType != null) { | ||
xContentBuilder.field(JOB_TYPE, jobType); | ||
} | ||
if (jobParserAction != null) { | ||
xContentBuilder.field(JOB_PARSER_ACTION, jobParserAction); | ||
} | ||
if (jobRunnerAction != null) { | ||
xContentBuilder.field(JOB_RUNNER_ACTION, jobRunnerAction); | ||
} | ||
return xContentBuilder.endObject(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nulls are dangerous and usually best avoided. Personal preference is to try to use Looking at all the classes in this PR, it seems that we always require
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
|
||
public static JobDetails parse(XContentParser parser) throws IOException { | ||
String jobIndex = null; | ||
String jobType = null; | ||
String jobParserAction = null; | ||
String jobRunnerAction = null; | ||
|
||
ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.currentToken(), parser); | ||
|
||
while (parser.nextToken() != XContentParser.Token.END_OBJECT) { | ||
String fieldName = parser.currentName(); | ||
parser.nextToken(); | ||
switch (fieldName) { | ||
case JOB_INDEX: | ||
jobIndex = parser.text(); | ||
break; | ||
case JOB_TYPE: | ||
jobType = parser.text(); | ||
break; | ||
case JOB_PARSER_ACTION: | ||
jobParserAction = parser.text(); | ||
break; | ||
case JOB_RUNNER_ACTION: | ||
jobRunnerAction = parser.text(); | ||
break; | ||
default: | ||
parser.skipChildren(); | ||
break; | ||
} | ||
} | ||
|
||
return new JobDetails(jobIndex, jobType, jobParserAction, jobRunnerAction); | ||
} | ||
|
||
public String getJobIndex() { | ||
return jobIndex; | ||
} | ||
|
||
public void setJobIndex(String jobIndex) { | ||
this.jobIndex = jobIndex; | ||
} | ||
|
||
public String getJobType() { | ||
return jobType; | ||
} | ||
|
||
public void setJobType(String jobType) { | ||
this.jobType = jobType; | ||
} | ||
|
||
public String getJobParserAction() { | ||
return jobParserAction; | ||
} | ||
|
||
public void setJobParserAction(String jobParserAction) { | ||
this.jobParserAction = jobParserAction; | ||
} | ||
|
||
public String getJobRunnerAction() { | ||
return jobRunnerAction; | ||
} | ||
|
||
public void setJobRunnerAction(String jobRunnerAction) { | ||
this.jobRunnerAction = jobRunnerAction; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
JobDetails that = (JobDetails) o; | ||
return Objects.equals(jobIndex, that.jobIndex) | ||
&& Objects.equals(jobType, that.jobType) | ||
&& Objects.equals(jobParserAction, that.jobParserAction) | ||
&& Objects.equals(jobRunnerAction, that.jobRunnerAction); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobIndex, jobType, jobParserAction, jobRunnerAction); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JobDetails{" | ||
+ "jobIndex='" | ||
+ jobIndex | ||
+ '\'' | ||
+ ", jobType='" | ||
+ jobType | ||
+ '\'' | ||
+ ", jobParserAction='" | ||
+ jobParserAction | ||
+ '\'' | ||
+ ", jobRunnerAction='" | ||
+ jobRunnerAction | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
opendistro
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I am changing it to plugins. The reason to change as suggested by @saratvemulapalli is
opendistro is part of ODFE: https://opendistro.github.io/for-elasticsearch/ which end of life.
AD security features were built in ODFE which is why it has legacy code