Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Added model for all REST request/response #167

Merged
merged 1 commit into from
Nov 3, 2020
Merged
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
7 changes: 3 additions & 4 deletions reports-scheduler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ ext {
isSnapshot = "true" == System.getProperty("build.snapshot", "true")
}

group = "com.amazon.opendistroforelasticsearch"
version = "${opendistroVersion}.0"

if (isSnapshot) {
version += "-SNAPSHOT"
}
Expand All @@ -115,6 +112,7 @@ plugins.withId('org.jetbrains.kotlin.jvm') {
}

allprojects {
group = "com.amazon.opendistroforelasticsearch"
version = "${opendistroVersion}.0"

plugins.withId('java') {
Expand All @@ -127,7 +125,8 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
compileOnly "${group}:opendistro-job-scheduler-spi:1.10.1.0"
compile "${group}:common-utils:${version}"
compileOnly "${group}:opendistro-job-scheduler-spi:${version}"
compile group: 'com.google.guava', name: 'guava', version: '15.0'
testImplementation(
'org.assertj:assertj-core:3.16.1',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*
*/

package com.amazon.opendistroforelasticsearch.reportsscheduler.action

import com.amazon.opendistroforelasticsearch.reportsscheduler.ReportsSchedulerPlugin.Companion.LOG_PREFIX
import com.amazon.opendistroforelasticsearch.reportsscheduler.index.IndexManager
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.CreateReportDefinitionRequest
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.CreateReportDefinitionResponse
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.DeleteReportDefinitionRequest
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.DeleteReportDefinitionResponse
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.GetAllReportDefinitionsRequest
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.GetAllReportDefinitionsResponse
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.GetReportDefinitionRequest
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.GetReportDefinitionsResponse
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.ReportDefinitionDetails
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.UpdateReportDefinitionRequest
import com.amazon.opendistroforelasticsearch.reportsscheduler.model.UpdateReportDefinitionResponse
import com.amazon.opendistroforelasticsearch.reportsscheduler.util.logger
import org.elasticsearch.rest.RestStatus
import java.time.Instant

/**
* Report definitions index operation actions.
*/
internal object ReportDefinitionActions {
private val log by logger(ReportDefinitionActions::class.java)
private const val TEMP_ROLE_ID = "roleId" // TODO get this from request

/**
* Create new ReportDefinition
* @param request [CreateReportDefinitionRequest] object
* @return [CreateReportDefinitionResponse]
*/
fun create(request: CreateReportDefinitionRequest): CreateReportDefinitionResponse {
log.info("$LOG_PREFIX:ReportDefinition-create")
val currentTime = Instant.now()
val reportDefinitionDetails = ReportDefinitionDetails("ignore",
currentTime,
currentTime,
listOf(TEMP_ROLE_ID), // TODO update with actual requester ID
request.reportDefinition
)
val docId = IndexManager.createReportDefinition(reportDefinitionDetails)
return if (docId == null) {
CreateReportDefinitionResponse(RestStatus.INTERNAL_SERVER_ERROR,
"Report Definition Creation failed",
null)
} else {
CreateReportDefinitionResponse(RestStatus.OK,
null,
docId)
}
}

/**
* Update ReportDefinition
* @param request [UpdateReportDefinitionRequest] object
* @return [UpdateReportDefinitionResponse]
*/
fun update(request: UpdateReportDefinitionRequest): UpdateReportDefinitionResponse {
log.info("$LOG_PREFIX:ReportDefinition-update ${request.reportDefinitionId}")
val currentReportDefinitionDetails = IndexManager.getReportDefinition(request.reportDefinitionId)
return if (currentReportDefinitionDetails == null) { // TODO verify actual requester ID
UpdateReportDefinitionResponse(RestStatus.NOT_FOUND,
"Report Definition ${request.reportDefinitionId} not found",
null)
} else {
val currentTime = Instant.now()
val reportDefinitionDetails = ReportDefinitionDetails(request.reportDefinitionId,
currentTime,
currentReportDefinitionDetails.createdTime,
currentReportDefinitionDetails.roles,
request.reportDefinition
)
val isUpdated = IndexManager.updateReportDefinition(request.reportDefinitionId, reportDefinitionDetails)
if (isUpdated) {
UpdateReportDefinitionResponse(RestStatus.OK,
null,
request.reportDefinitionId)
} else {
UpdateReportDefinitionResponse(RestStatus.INTERNAL_SERVER_ERROR,
"Report Definition Update failed",
null)
}
}
}

/**
* Get ReportDefinition info
* @param request [GetReportDefinitionRequest] object
* @return [GetReportDefinitionsResponse]
*/
fun info(request: GetReportDefinitionRequest): GetReportDefinitionsResponse {
log.info("$LOG_PREFIX:ReportDefinition-info ${request.reportDefinitionId}")
val reportDefinitionDetails = IndexManager.getReportDefinition(request.reportDefinitionId)
return if (reportDefinitionDetails == null) { // TODO verify actual requester ID
GetReportDefinitionsResponse(RestStatus.NOT_FOUND,
"Report Definition ${request.reportDefinitionId} not found",
null)
} else {
GetReportDefinitionsResponse(RestStatus.OK,
null,
reportDefinitionDetails)
}
}

/**
* Delete ReportDefinition
* @param request [DeleteReportDefinitionRequest] object
* @return [DeleteReportDefinitionResponse]
*/
fun delete(request: DeleteReportDefinitionRequest): DeleteReportDefinitionResponse {
log.info("$LOG_PREFIX:ReportDefinition-delete ${request.reportDefinitionId}")
val reportDefinitionDetails = IndexManager.getReportDefinition(request.reportDefinitionId)
return if (reportDefinitionDetails == null) { // TODO verify actual requester ID
DeleteReportDefinitionResponse(RestStatus.NOT_FOUND,
"Report Definition ${request.reportDefinitionId} not found",
null)
} else {
val isDeleted = IndexManager.deleteReportDefinition(request.reportDefinitionId)
if (!isDeleted) {
DeleteReportDefinitionResponse(RestStatus.REQUEST_TIMEOUT,
"Report Definition ${request.reportDefinitionId} delete failed",
null)
} else {
DeleteReportDefinitionResponse(RestStatus.OK,
null,
request.reportDefinitionId)
}
}
}

/**
* Get all ReportDefinitions
* @param request [GetAllReportDefinitionsRequest] object
* @return [GetAllReportDefinitionsResponse]
*/
fun getAll(request: GetAllReportDefinitionsRequest): GetAllReportDefinitionsResponse {
log.info("$LOG_PREFIX:ReportDefinition-getAll ${request.fromIndex}")
// TODO verify actual requester ID
val reportDefinitionsList = IndexManager.getAllReportDefinitions(listOf(TEMP_ROLE_ID), request.fromIndex)
return if (reportDefinitionsList.isEmpty()) {
GetAllReportDefinitionsResponse(RestStatus.NOT_FOUND,
"No Report Definitions found",
null)
} else {
GetAllReportDefinitionsResponse(RestStatus.OK, null, reportDefinitionsList)
}
}
}
Loading