forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
147 additions
and
96 deletions.
There are no files selected for viewing
File renamed without changes.
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
13 changes: 13 additions & 0 deletions
13
spark/src/main/java/org/opensearch/sql/spark/asyncquery/AsyncQueryScheduler.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,13 @@ | ||
package org.opensearch.sql.spark.asyncquery; | ||
|
||
import org.opensearch.sql.spark.dispatcher.model.DispatchQueryContext; | ||
import org.opensearch.sql.spark.dispatcher.model.DispatchQueryRequest; | ||
import org.opensearch.sql.spark.flint.FlintIndexMetadataService; | ||
|
||
public interface AsyncQueryScheduler { | ||
public void scheduleQuery(); | ||
|
||
public void disableScheduledQuery(); | ||
|
||
public void cancelScheduledQuery(); | ||
} |
103 changes: 103 additions & 0 deletions
103
...n/java/org/opensearch/sql/spark/asyncquery/OpenSearchAsyncQuerySchedulingServiceImpl.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,103 @@ | ||
package org.opensearch.sql.spark.asyncquery; | ||
|
||
import java.io.IOException; | ||
import java.time.Instant; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.core.xcontent.XContentParser; | ||
import org.opensearch.core.xcontent.XContentParserUtils; | ||
import org.opensearch.jobscheduler.spi.ScheduledJobParser; | ||
import org.opensearch.jobscheduler.spi.ScheduledJobRunner; | ||
import org.opensearch.jobscheduler.spi.schedule.ScheduleParser; | ||
import org.opensearch.sql.spark.client.EMRServerlessClientFactory; | ||
import org.opensearch.sql.spark.dispatcher.AsyncQueryHandler; | ||
import org.opensearch.sql.spark.dispatcher.model.DispatchQueryContext; | ||
import org.opensearch.sql.spark.dispatcher.model.DispatchQueryRequest; | ||
import org.opensearch.sql.spark.flint.FlintIndexMetadataService; | ||
import org.opensearch.threadpool.ThreadPool; | ||
|
||
@RequiredArgsConstructor | ||
public class OpenSearchAsyncQuerySchedulingServiceImpl implements AsyncQueryScheduler { | ||
static final String JOB_INDEX_NAME = ".scheduler_sample_extension"; | ||
private final Client client; | ||
private final ClusterService clusterService; | ||
private final ThreadPool threadPool; | ||
AsyncQueryJobMetadataStorageService asyncQueryJobMetadataStorageService; | ||
|
||
public ScheduledJobRunner getJobRunner() { | ||
SampleJobRunner sampleJobRunner = SampleJobRunner.getJobRunnerInstance(); | ||
sampleJobRunner.setClusterService(clusterService); | ||
sampleJobRunner.setThreadPool(threadPool); | ||
sampleJobRunner.setClient(client); | ||
return sampleJobRunner; | ||
} | ||
|
||
public ScheduledJobParser getJobParser() { | ||
return (parser, id, jobDocVersion) -> { | ||
SampleJobParameter jobParameter = new SampleJobParameter(); | ||
XContentParserUtils.ensureExpectedToken( | ||
XContentParser.Token.START_OBJECT, parser.nextToken(), parser); | ||
|
||
while (!parser.nextToken().equals(XContentParser.Token.END_OBJECT)) { | ||
String fieldName = parser.currentName(); | ||
parser.nextToken(); | ||
switch (fieldName) { | ||
case SampleJobParameter.NAME_FIELD: | ||
jobParameter.setJobName(parser.text()); | ||
break; | ||
case SampleJobParameter.ENABLED_FILED: | ||
jobParameter.setEnabled(parser.booleanValue()); | ||
break; | ||
case SampleJobParameter.ENABLED_TIME_FILED: | ||
jobParameter.setEnabledTime(parseInstantValue(parser)); | ||
break; | ||
case SampleJobParameter.LAST_UPDATE_TIME_FIELD: | ||
jobParameter.setLastUpdateTime(parseInstantValue(parser)); | ||
break; | ||
case SampleJobParameter.SCHEDULE_FIELD: | ||
jobParameter.setSchedule(ScheduleParser.parse(parser)); | ||
break; | ||
case SampleJobParameter.INDEX_NAME_FIELD: | ||
jobParameter.setIndexToWatch(parser.text()); | ||
break; | ||
case SampleJobParameter.LOCK_DURATION_SECONDS: | ||
jobParameter.setLockDurationSeconds(parser.longValue()); | ||
break; | ||
case SampleJobParameter.JITTER: | ||
jobParameter.setJitter(parser.doubleValue()); | ||
break; | ||
default: | ||
XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation()); | ||
} | ||
} | ||
return jobParameter; | ||
}; | ||
} | ||
|
||
private Instant parseInstantValue(XContentParser parser) throws IOException { | ||
if (XContentParser.Token.VALUE_NULL.equals(parser.currentToken())) { | ||
return null; | ||
} | ||
if (parser.currentToken().isValue()) { | ||
return Instant.ofEpochMilli(parser.longValue()); | ||
} | ||
XContentParserUtils.throwUnknownToken(parser.currentToken(), parser.getTokenLocation()); | ||
return null; | ||
} | ||
|
||
@Override | ||
public void scheduleQuery() { | ||
asyncQueryJobMetadataStorageService.storeJobMetadata(); | ||
} | ||
|
||
@Override | ||
public void disableScheduledQuery() { | ||
|
||
} | ||
|
||
@Override | ||
public void cancelScheduledQuery() { | ||
|
||
} | ||
} |
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