Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,26 @@ dependencies {
compileOnly "commons-validator:commons-validator:1.7"
testImplementation "org.opensearch.test:framework:${opensearch_version}"
testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
testImplementation "org.mockito:mockito-core:3.10.0"
testImplementation "org.mockito:mockito-core:5.20.0"
testImplementation('junit:junit:4.13.2') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testRuntimeOnly('org.junit.vintage:junit-vintage-engine:5.11.4') {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.4'
testImplementation 'org.mockito:mockito-junit-jupiter:3.10.0'
testImplementation 'org.mockito:mockito-junit-jupiter:5.20.0'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation "com.cronutils:cron-utils:9.2.1"
testImplementation "commons-validator:commons-validator:1.7"
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.4'

ktlint "com.pinterest:ktlint:0.47.1"
ktlint "com.pinterest.ktlint:ktlint-cli:1.8.0"
}

test {
useJUnitPlatform()
systemProperty "jdk.attach.allowAttachSelf", true
testLogging {
exceptionFormat = "full"
events "skipped", "passed", "failed" // "started"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import org.opensearch.transport.client.node.NodeClient
* All the transport action plugin interfaces for the Alerting plugin
*/
object AlertingPluginInterface {

/**
* Index monitor interface.
* @param client Node client for making transport action
Expand All @@ -54,36 +53,36 @@ object AlertingPluginInterface {
client: NodeClient,
request: IndexMonitorRequest,
namedWriteableRegistry: NamedWriteableRegistry,
listener: ActionListener<IndexMonitorResponse>
listener: ActionListener<IndexMonitorResponse>,
) {
client.execute(
AlertingActions.INDEX_MONITOR_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response, namedWriteableRegistry) {
IndexMonitorResponse(
it
it,
)
}
}
},
)
}

fun deleteMonitor(
client: NodeClient,
request: DeleteMonitorRequest,
listener: ActionListener<DeleteMonitorResponse>
listener: ActionListener<DeleteMonitorResponse>,
) {
client.execute(
AlertingActions.DELETE_MONITOR_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
DeleteMonitorResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -97,36 +96,36 @@ object AlertingPluginInterface {
fun indexWorkflow(
client: NodeClient,
request: IndexWorkflowRequest,
listener: ActionListener<IndexWorkflowResponse>
listener: ActionListener<IndexWorkflowResponse>,
) {
client.execute(
AlertingActions.INDEX_WORKFLOW_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
IndexWorkflowResponse(
it
it,
)
}
}
},
)
}

fun deleteWorkflow(
client: NodeClient,
request: DeleteWorkflowRequest,
listener: ActionListener<DeleteWorkflowResponse>
listener: ActionListener<DeleteWorkflowResponse>,
) {
client.execute(
AlertingActions.DELETE_WORKFLOW_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
DeleteWorkflowResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -139,18 +138,18 @@ object AlertingPluginInterface {
fun getAlerts(
client: NodeClient,
request: GetAlertsRequest,
listener: ActionListener<GetAlertsResponse>
listener: ActionListener<GetAlertsResponse>,
) {
client.execute(
AlertingActions.GET_ALERTS_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
GetAlertsResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -163,18 +162,18 @@ object AlertingPluginInterface {
fun getWorkflowAlerts(
client: NodeClient,
request: GetWorkflowAlertsRequest,
listener: ActionListener<GetWorkflowAlertsResponse>
listener: ActionListener<GetWorkflowAlertsResponse>,
) {
client.execute(
AlertingActions.GET_WORKFLOW_ALERTS_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
GetWorkflowAlertsResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -187,18 +186,18 @@ object AlertingPluginInterface {
fun getWorkflow(
client: NodeClient,
request: GetWorkflowRequest,
listener: ActionListener<GetWorkflowResponse>
listener: ActionListener<GetWorkflowResponse>,
) {
client.execute(
AlertingActions.GET_WORKFLOW_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
GetWorkflowResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -211,18 +210,18 @@ object AlertingPluginInterface {
fun getFindings(
client: NodeClient,
request: GetFindingsRequest,
listener: ActionListener<GetFindingsResponse>
listener: ActionListener<GetFindingsResponse>,
) {
client.execute(
AlertingActions.GET_FINDINGS_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
GetFindingsResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -235,36 +234,36 @@ object AlertingPluginInterface {
fun acknowledgeAlerts(
client: NodeClient,
request: AcknowledgeAlertRequest,
listener: ActionListener<AcknowledgeAlertResponse>
listener: ActionListener<AcknowledgeAlertResponse>,
) {
client.execute(
AlertingActions.ACKNOWLEDGE_ALERTS_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
AcknowledgeAlertResponse(
it
it,
)
}
}
},
)
}

fun publishFinding(
client: NodeClient,
request: PublishFindingsRequest,
listener: ActionListener<SubscribeFindingsResponse>
listener: ActionListener<SubscribeFindingsResponse>,
) {
client.execute(
AlertingActions.SUBSCRIBE_FINDINGS_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
SubscribeFindingsResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -277,18 +276,18 @@ object AlertingPluginInterface {
fun acknowledgeChainedAlerts(
client: NodeClient,
request: AcknowledgeChainedAlertRequest,
listener: ActionListener<AcknowledgeAlertResponse>
listener: ActionListener<AcknowledgeAlertResponse>,
) {
client.execute(
AlertingActions.ACKNOWLEDGE_CHAINED_ALERTS_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
AcknowledgeAlertResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -301,18 +300,18 @@ object AlertingPluginInterface {
fun getMonitor(
client: NodeClient,
request: GetMonitorRequest,
listener: ActionListener<GetMonitorResponse>
listener: ActionListener<GetMonitorResponse>,
) {
client.execute(
AlertingActions.GET_MONITOR_ACTION_TYPE,
request,
wrapActionListener(listener) { response ->
recreateObject(response) {
GetMonitorResponse(
it
it,
)
}
}
},
)
}

Expand All @@ -325,24 +324,24 @@ object AlertingPluginInterface {
fun searchMonitors(
client: NodeClient,
request: SearchMonitorRequest,
listener: ActionListener<SearchResponse>
listener: ActionListener<SearchResponse>,
) {
client.execute(
AlertingActions.SEARCH_MONITORS_ACTION_TYPE,
request,
// we do not use the wrapActionListener in this case since there is no need
// to recreate any object or specially handle onResponse / onFailure. It is
// simply returning a SearchResponse.
listener
listener,
)
}

@Suppress("UNCHECKED_CAST")
private fun <Response : BaseResponse> wrapActionListener(
listener: ActionListener<Response>,
recreate: (Writeable) -> Response
): ActionListener<Response> {
return object : ActionListener<ActionResponse> {
recreate: (Writeable) -> Response,
): ActionListener<Response> =
object : ActionListener<ActionResponse> {
override fun onResponse(response: ActionResponse) {
val recreated = response as? Response ?: recreate(response)
listener.onResponse(recreated)
Expand All @@ -352,5 +351,4 @@ object AlertingPluginInterface {
listener.onFailure(exception)
}
} as ActionListener<Response>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AcknowledgeAlertRequest : ActionRequest {
constructor(
monitorId: String,
alertIds: List<String>,
refreshPolicy: WriteRequest.RefreshPolicy
refreshPolicy: WriteRequest.RefreshPolicy,
) : super() {
this.monitorId = monitorId
this.alertIds = alertIds
Expand All @@ -32,12 +32,10 @@ class AcknowledgeAlertRequest : ActionRequest {
constructor(sin: StreamInput) : this(
sin.readString(), // monitorId
Collections.unmodifiableList(sin.readStringList()), // alertIds
WriteRequest.RefreshPolicy.readFrom(sin) // refreshPolicy
WriteRequest.RefreshPolicy.readFrom(sin), // refreshPolicy
)

override fun validate(): ActionRequestValidationException? {
return null
}
override fun validate(): ActionRequestValidationException? = null

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
Expand Down
Loading
Loading