Skip to content

Commit af434ad

Browse files
committed
including SQL jar dependencies and various cleanups
1 parent 4ee1f6f commit af434ad

File tree

3 files changed

+40
-24
lines changed

3 files changed

+40
-24
lines changed

build.gradle

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ dependencies {
112112
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
113113
testImplementation "com.cronutils:cron-utils:9.1.6"
114114
testImplementation "commons-validator:commons-validator:1.7"
115+
implementation 'org.json:json:20240303'
115116

116-
implementation fileTree(dir: sqlJarDirectory, include: ["opensearch-sql-${opensearch_build}.jar", "ppl-${opensearch_build}.jar", "protocol-${opensearch_build}.jar", "core-${opensearch_build}.jar"])
117+
implementation fileTree(dir: sqlJarDirectory, include: ["opensearch-sql-thin-${opensearch_build}.jar", "ppl-${opensearch_build}.jar", "protocol-${opensearch_build}.jar", "core-${opensearch_build}.jar"])
117118

118119
zipArchive group: 'org.opensearch.plugin', name:'opensearch-sql-plugin', version: "${opensearch_build}"
119120

@@ -126,7 +127,22 @@ task extractSqlJar(type: Copy) {
126127
into sqlJarDirectory
127128
}
128129

129-
tasks.addJarsToClasspath.dependsOn(extractSqlJar)
130+
task extractSqlClass(type: Copy, dependsOn: [extractSqlJar]) {
131+
from zipTree("${sqlJarDirectory}/opensearch-sql-${opensearch_build}.jar")
132+
into("$buildDir/opensearch-sql")
133+
include 'org/opensearch/sql/**'
134+
}
135+
136+
task replaceSqlJar(type: Jar, dependsOn: [extractSqlClass]) {
137+
from("$buildDir/opensearch-sql")
138+
archiveFileName = "opensearch-sql-thin-${opensearch_build}.jar"
139+
destinationDirectory = file(sqlJarDirectory)
140+
doLast {
141+
file("${sqlJarDirectory}/opensearch-sql-${opensearch_build}.jar").delete()
142+
}
143+
}
144+
145+
tasks.addJarsToClasspath.dependsOn(replaceSqlJar)
130146

131147
test {
132148
useJUnitPlatform()
@@ -175,11 +191,11 @@ tasks.register('ktlintFormat', JavaExec) {
175191
}
176192

177193
compileJava {
178-
dependsOn extractSqlJar
194+
dependsOn addJarsToClasspath
179195
}
180196

181197
compileKotlin {
182-
dependsOn extractSqlJar
198+
dependsOn addJarsToClasspath
183199
kotlinOptions {
184200
freeCompilerArgs = ['-Xjsr305=strict']
185201
jvmTarget = "21"

src/main/kotlin/org/opensearch/commons/alerting/model/PPLMonitor.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ data class PPLMonitor(
4242
override val name: String,
4343
override val enabled: Boolean,
4444
override val schedule: Schedule,
45+
override val lookBackWindow: TimeValue? = null,
4546
override val lastUpdateTime: Instant,
4647
override val enabledTime: Instant?,
47-
override val triggers: List<TriggerV2>,
48+
override val triggers: List<TriggerV2>, // TODO: change this to list of PPLTriggers
4849
override val schemaVersion: Int = NO_SCHEMA_VERSION,
49-
override val lookBackWindow: TimeValue? = null,
5050
val queryLanguage: QueryLanguage = QueryLanguage.PPL, // default to PPL, SQL not currently supported
5151
val query: String
5252
) : MonitorV2 {
@@ -88,11 +88,11 @@ data class PPLMonitor(
8888
name = sin.readString(),
8989
enabled = sin.readBoolean(),
9090
schedule = Schedule.readFrom(sin),
91+
lookBackWindow = TimeValue.parseTimeValue(sin.readString(), PLACEHOLDER_LOOK_BACK_WINDOW_SETTING_NAME),
9192
lastUpdateTime = sin.readInstant(),
9293
enabledTime = sin.readOptionalInstant(),
9394
triggers = sin.readList(TriggerV2::readFrom),
9495
schemaVersion = sin.readInt(),
95-
lookBackWindow = TimeValue.parseTimeValue(sin.readString(), PLACEHOLDER_LOOK_BACK_WINDOW_SETTING_NAME),
9696
queryLanguage = sin.readEnum(QueryLanguage::class.java),
9797
query = sin.readString()
9898
)
@@ -113,12 +113,12 @@ data class PPLMonitor(
113113

114114
builder.field(NAME_FIELD, name)
115115
builder.field(SCHEDULE_FIELD, schedule)
116+
builder.field(LOOK_BACK_WINDOW_FIELD, lookBackWindow?.toHumanReadableString(0))
116117
builder.field(ENABLED_FIELD, enabled)
117118
builder.nonOptionalTimeField(LAST_UPDATE_TIME_FIELD, lastUpdateTime)
118119
builder.optionalTimeField(ENABLED_TIME_FIELD, enabledTime)
119120
builder.field(TRIGGERS_FIELD, triggers.toTypedArray())
120121
builder.field(SCHEMA_VERSION_FIELD, schemaVersion)
121-
builder.field(LOOK_BACK_WINDOW_FIELD, lookBackWindow?.toHumanReadableString(0))
122122
builder.field(QUERY_LANGUAGE_FIELD, queryLanguage.value)
123123
builder.field(QUERY_FIELD, query)
124124

@@ -145,6 +145,10 @@ data class PPLMonitor(
145145
} else {
146146
out.writeEnum(Schedule.TYPE.INTERVAL)
147147
}
148+
149+
out.writeBoolean(lookBackWindow != null)
150+
lookBackWindow?.let { out.writeString(lookBackWindow.toHumanReadableString(0)) }
151+
148152
out.writeInstant(lastUpdateTime)
149153
out.writeOptionalInstant(enabledTime)
150154
out.writeVInt(triggers.size)
@@ -153,10 +157,6 @@ data class PPLMonitor(
153157
it.writeTo(out)
154158
}
155159
out.writeInt(schemaVersion)
156-
157-
out.writeBoolean(lookBackWindow != null)
158-
lookBackWindow?.let { out.writeString(lookBackWindow.toHumanReadableString(0)) }
159-
160160
out.writeEnum(queryLanguage)
161161
out.writeString(query)
162162
}
@@ -168,10 +168,10 @@ data class PPLMonitor(
168168
NAME_FIELD to name,
169169
ENABLED_FIELD to enabled,
170170
SCHEDULE_FIELD to schedule,
171+
LOOK_BACK_WINDOW_FIELD to lookBackWindow?.toHumanReadableString(0),
171172
LAST_UPDATE_TIME_FIELD to lastUpdateTime.toEpochMilli(),
172173
ENABLED_TIME_FIELD to enabledTime?.toEpochMilli(),
173174
TRIGGERS_FIELD to triggers,
174-
LOOK_BACK_WINDOW_FIELD to lookBackWindow?.toHumanReadableString(0),
175175
QUERY_LANGUAGE_FIELD to queryLanguage.value,
176176
QUERY_FIELD to query
177177
)
@@ -211,11 +211,11 @@ data class PPLMonitor(
211211
var monitorType: String = PPL_MONITOR_TYPE
212212
var enabled = true
213213
var schedule: Schedule? = null
214+
var lookBackWindow: TimeValue? = null
214215
var lastUpdateTime: Instant? = null
215216
var enabledTime: Instant? = null
216217
val triggers: MutableList<TriggerV2> = mutableListOf()
217218
var schemaVersion = NO_SCHEMA_VERSION
218-
var lookBackWindow: TimeValue? = null
219219
var queryLanguage: QueryLanguage = QueryLanguage.PPL // default to PPL
220220
var query: String? = null
221221

@@ -230,6 +230,14 @@ data class PPLMonitor(
230230
MONITOR_TYPE_FIELD -> monitorType = xcp.text()
231231
ENABLED_FIELD -> enabled = xcp.booleanValue()
232232
SCHEDULE_FIELD -> schedule = Schedule.parse(xcp)
233+
LOOK_BACK_WINDOW_FIELD -> {
234+
lookBackWindow = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
235+
null
236+
} else {
237+
val input = xcp.text()
238+
TimeValue.parseTimeValue(input, PLACEHOLDER_LOOK_BACK_WINDOW_SETTING_NAME) // throws IllegalArgumentException if there's parsing error
239+
}
240+
}
233241
LAST_UPDATE_TIME_FIELD -> lastUpdateTime = xcp.instant()
234242
ENABLED_TIME_FIELD -> enabledTime = xcp.instant()
235243
TRIGGERS_FIELD -> {
@@ -243,14 +251,6 @@ data class PPLMonitor(
243251
}
244252
}
245253
SCHEMA_VERSION_FIELD -> schemaVersion = xcp.intValue()
246-
LOOK_BACK_WINDOW_FIELD -> {
247-
lookBackWindow = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
248-
null
249-
} else {
250-
val input = xcp.text()
251-
TimeValue.parseTimeValue(input, PLACEHOLDER_LOOK_BACK_WINDOW_SETTING_NAME) // throws IllegalArgumentException if there's parsing error
252-
}
253-
}
254254
QUERY_LANGUAGE_FIELD -> {
255255
val input = xcp.text()
256256
val enumMatchResult = QueryLanguage.enumFromString(input)
@@ -308,11 +308,11 @@ data class PPLMonitor(
308308
name,
309309
enabled,
310310
schedule,
311+
lookBackWindow,
311312
lastUpdateTime,
312313
enabledTime,
313314
triggers,
314315
schemaVersion,
315-
lookBackWindow,
316316
queryLanguage,
317317
query
318318
)

src/main/kotlin/org/opensearch/commons/alerting/model/PPLTriggerRunResult.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import java.time.Instant
1313

1414
data class PPLTriggerRunResult(
1515
override var triggerName: String,
16-
override var triggered: Boolean, // TODO: may need to change this based on whether trigger mode is result set or per result
16+
override var triggered: Boolean,
1717
override var error: Exception?,
1818
var actionResults: MutableMap<String, ActionRunResult> = mutableMapOf()
1919
) : TriggerV2RunResult {

0 commit comments

Comments
 (0)