-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communication mechanism for js (#289)
* Job Details from Extension for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Commnunication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Commnunication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Commnunication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Commnunication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Commnunication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Commnunication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> * Communication Mechanism for JS Signed-off-by: Varun Jain <varunudr@amazon.com> Signed-off-by: Varun Jain <varunudr@amazon.com>
- Loading branch information
1 parent
b67c000
commit 2c9084b
Showing
15 changed files
with
1,709 additions
and
8 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
185 changes: 185 additions & 0 deletions
185
src/main/java/org/opensearch/jobscheduler/model/JobDetails.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,185 @@ | ||
/* | ||
* 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.Nullable; | ||
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 { | ||
|
||
/** | ||
* 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 jobParameterAction; | ||
|
||
/** | ||
* jobRunner action to trigger the response back to the extension. | ||
*/ | ||
private String jobRunnerAction; | ||
|
||
public static final String JOB_INDEX = "job_index"; | ||
public static final String JOB_TYPE = "job_type"; | ||
public static final String JOB_PARAMETER_ACTION = "job_parser_action"; | ||
public static final String JOB_RUNNER_ACTION = "job_runner_action"; | ||
|
||
public JobDetails() {} | ||
|
||
public JobDetails(String jobIndex, String jobType, String jobParameterAction, String jobRunnerAction) { | ||
this.jobIndex = jobIndex; | ||
this.jobType = jobType; | ||
this.jobParameterAction = jobParameterAction; | ||
this.jobRunnerAction = jobRunnerAction; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException { | ||
XContentBuilder xContentBuilder = builder.startObject(); | ||
if (jobIndex != null) { | ||
xContentBuilder.field(JOB_INDEX, jobIndex); | ||
} | ||
if (jobType != null) { | ||
xContentBuilder.field(JOB_TYPE, jobType); | ||
} | ||
if (jobParameterAction != null) { | ||
xContentBuilder.field(JOB_PARAMETER_ACTION, jobParameterAction); | ||
} | ||
if (jobRunnerAction != null) { | ||
xContentBuilder.field(JOB_RUNNER_ACTION, jobRunnerAction); | ||
} | ||
return xContentBuilder.endObject(); | ||
} | ||
|
||
public static JobDetails parse(XContentParser parser) throws IOException { | ||
String jobIndex = null; | ||
String jobType = null; | ||
String jobParameterAction = 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_PARAMETER_ACTION: | ||
jobParameterAction = parser.text(); | ||
break; | ||
case JOB_RUNNER_ACTION: | ||
jobRunnerAction = parser.text(); | ||
break; | ||
default: | ||
parser.skipChildren(); | ||
break; | ||
} | ||
} | ||
|
||
return new JobDetails(jobIndex, jobType, jobParameterAction, jobRunnerAction); | ||
} | ||
|
||
public JobDetails(final JobDetails copyJobDetails) { | ||
this(copyJobDetails.jobIndex, copyJobDetails.jobType, copyJobDetails.jobParameterAction, copyJobDetails.jobRunnerAction); | ||
} | ||
|
||
@Nullable | ||
public String getJobIndex() { | ||
return jobIndex; | ||
} | ||
|
||
public void setJobIndex(String jobIndex) { | ||
this.jobIndex = jobIndex; | ||
} | ||
|
||
@Nullable | ||
public String getJobType() { | ||
return jobType; | ||
} | ||
|
||
public void setJobType(String jobType) { | ||
this.jobType = jobType; | ||
} | ||
|
||
@Nullable | ||
public String getJobParameterAction() { | ||
return jobParameterAction; | ||
} | ||
|
||
public void setJobParameterAction(String jobParameterAction) { | ||
this.jobParameterAction = jobParameterAction; | ||
} | ||
|
||
@Nullable | ||
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(jobParameterAction, that.jobParameterAction) | ||
&& Objects.equals(jobRunnerAction, that.jobRunnerAction); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(jobIndex, jobType, jobParameterAction, jobRunnerAction); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "JobDetails{" | ||
+ "jobIndex='" | ||
+ jobIndex | ||
+ '\'' | ||
+ ", jobType='" | ||
+ jobType | ||
+ '\'' | ||
+ ", jobParameterAction='" | ||
+ jobParameterAction | ||
+ '\'' | ||
+ ", jobRunnerAction='" | ||
+ jobRunnerAction | ||
+ '\'' | ||
+ '}'; | ||
} | ||
} |
Oops, something went wrong.