Skip to content

Commit 6bd4c6f

Browse files
committed
sending core changes for review
Signed-off-by: Dennis Toepker <[email protected]>
1 parent 42c0878 commit 6bd4c6f

20 files changed

+1632
-60
lines changed

core/build.gradle

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ apply plugin: 'opensearch.java-rest-test'
88
apply plugin: 'org.jetbrains.kotlin.jvm'
99
apply plugin: 'jacoco'
1010

11-
configurations{
11+
configurations {
12+
zipArchive
1213
all {
1314
resolutionStrategy {
1415
// force commons-beanutils to a non-vulnerable version
@@ -17,6 +18,18 @@ configurations{
1718
}
1819
}
1920

21+
def sqlJarDirectory = "$buildDir/dependencies/opensearch-sql-plugin"
22+
23+
task addJarsToClasspath(type: Copy) {
24+
from(fileTree(dir: sqlJarDirectory)) {
25+
include "opensearch-sql-${opensearch_build}.jar"
26+
include "ppl-${opensearch_build}.jar"
27+
include "protocol-${opensearch_build}.jar"
28+
include "core-${opensearch_build}.jar"
29+
}
30+
into("$buildDir/classes")
31+
}
32+
2033
dependencies {
2134
compileOnly "org.opensearch:opensearch:${opensearch_version}"
2235
implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
@@ -26,8 +39,44 @@ dependencies {
2639
api "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
2740
api "org.opensearch:common-utils:${common_utils_version}@jar"
2841
implementation 'commons-validator:commons-validator:1.7'
42+
implementation 'org.json:json:20240303'
43+
44+
api fileTree(dir: sqlJarDirectory, include: ["opensearch-sql-thin-${opensearch_build}.jar", "ppl-${opensearch_build}.jar", "protocol-${opensearch_build}.jar", "core-${opensearch_build}.jar"])
45+
46+
zipArchive group: 'org.opensearch.plugin', name:'opensearch-sql-plugin', version: "${opensearch_build}"
2947

3048
testImplementation "org.opensearch.test:framework:${opensearch_version}"
3149
testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
3250
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${kotlin_version}"
3351
}
52+
53+
task extractSqlJar(type: Copy) {
54+
mustRunAfter()
55+
from(zipTree(configurations.zipArchive.find { it.name.startsWith("opensearch-sql-plugin") }))
56+
into sqlJarDirectory
57+
}
58+
59+
task extractSqlClass(type: Copy, dependsOn: [extractSqlJar]) {
60+
from zipTree("${sqlJarDirectory}/opensearch-sql-${opensearch_build}.jar")
61+
into("$buildDir/opensearch-sql")
62+
include 'org/opensearch/sql/**'
63+
}
64+
65+
task replaceSqlJar(type: Jar, dependsOn: [extractSqlClass]) {
66+
from("$buildDir/opensearch-sql")
67+
archiveFileName = "opensearch-sql-thin-${opensearch_build}.jar"
68+
destinationDirectory = file(sqlJarDirectory)
69+
doLast {
70+
file("${sqlJarDirectory}/opensearch-sql-${opensearch_build}.jar").delete()
71+
}
72+
}
73+
74+
tasks.addJarsToClasspath.dependsOn(replaceSqlJar)
75+
76+
compileJava {
77+
dependsOn addJarsToClasspath
78+
}
79+
80+
compileKotlin {
81+
dependsOn addJarsToClasspath
82+
}

core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobStats.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ package org.opensearch.alerting.core.action.node
77

88
import org.opensearch.action.support.nodes.BaseNodeResponse
99
import org.opensearch.alerting.core.JobSweeperMetrics
10-
import org.opensearch.alerting.core.resthandler.RestScheduledJobStatsHandler
10+
import org.opensearch.alerting.core.resthandler.StatsRequestUtils.JOBS_INFO
11+
import org.opensearch.alerting.core.resthandler.StatsRequestUtils.JOB_SCHEDULING_METRICS
1112
import org.opensearch.alerting.core.schedule.JobSchedulerMetrics
1213
import org.opensearch.cluster.node.DiscoveryNode
1314
import org.opensearch.core.common.io.stream.StreamInput
@@ -69,13 +70,13 @@ class ScheduledJobStats : BaseNodeResponse, ToXContentFragment {
6970
builder.field("schedule_status", status)
7071
builder.field("roles", node.roles.map { it.roleName().uppercase(Locale.getDefault()) })
7172
if (jobSweeperMetrics != null) {
72-
builder.startObject(RestScheduledJobStatsHandler.JOB_SCHEDULING_METRICS)
73+
builder.startObject(JOB_SCHEDULING_METRICS)
7374
jobSweeperMetrics!!.toXContent(builder, params)
7475
builder.endObject()
7576
}
7677

7778
if (jobInfos != null) {
78-
builder.startObject(RestScheduledJobStatsHandler.JOBS_INFO)
79+
builder.startObject(JOBS_INFO)
7980
for (job in jobInfos!!) {
8081
builder.startObject(job.scheduledJobId)
8182
job.toXContent(builder, params)

core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsRequest.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ import java.io.IOException
1717
class ScheduledJobsStatsRequest : BaseNodesRequest<ScheduledJobsStatsRequest> {
1818
var jobSchedulingMetrics: Boolean = true
1919
var jobsInfo: Boolean = true
20+
var showAlertingV2ScheduledJobs: Boolean = false // show Alerting V2 scheduled jobs if true, Alerting V1 scheduled jobs if false
2021

2122
constructor(si: StreamInput) : super(si) {
2223
jobSchedulingMetrics = si.readBoolean()
2324
jobsInfo = si.readBoolean()
25+
showAlertingV2ScheduledJobs = si.readBoolean()
26+
}
27+
28+
constructor(nodeIds: Array<String>, showAlertingV2ScheduledJobs: Boolean) : super(*nodeIds) {
29+
this.showAlertingV2ScheduledJobs = showAlertingV2ScheduledJobs
2430
}
25-
constructor(nodeIds: Array<String>) : super(*nodeIds)
2631

2732
@Throws(IOException::class)
2833
override fun writeTo(out: StreamOutput) {
2934
super.writeTo(out)
3035
out.writeBoolean(jobSchedulingMetrics)
3136
out.writeBoolean(jobsInfo)
37+
out.writeBoolean(showAlertingV2ScheduledJobs)
3238
}
3339

3440
fun all(): ScheduledJobsStatsRequest {

core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsTransportAction.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ class ScheduledJobsStatsTransportAction : TransportNodesAction<ScheduledJobsStat
9393
scheduledJobsStatusRequest: ScheduledJobsStatsRequest
9494
): ScheduledJobStats {
9595
val jobSweeperMetrics = jobSweeper.getJobSweeperMetrics()
96-
val jobSchedulerMetrics = jobScheduler.getJobSchedulerMetric()
96+
97+
val jobSchedulerMetrics = if (scheduledJobsStatusRequest.showAlertingV2ScheduledJobs) { // show V2 scheduled jobs
98+
jobScheduler.getJobSchedulerV2Metric()
99+
} else { // show V1 scheduled jobs
100+
jobScheduler.getJobSchedulerMetric()
101+
}
97102

98103
val status: ScheduledJobStats.ScheduleStatus = evaluateStatus(jobSchedulerMetrics, jobSweeperMetrics)
99104
return ScheduledJobStats(

0 commit comments

Comments
 (0)