Skip to content

Commit

Permalink
Merge pull request #517 from catenax-ng/feat/orchestrator_service_logic
Browse files Browse the repository at this point in the history
Orchestrator: Service logic
  • Loading branch information
nicoprow authored Oct 17, 2023
2 parents 17f68ee + 85c6800 commit 14c50a4
Show file tree
Hide file tree
Showing 19 changed files with 1,088 additions and 413 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ interface GoldenRecordTaskApi {

@Operation(
summary = "Search for the state of golden record tasks by task identifiers",
description = "Returns the state of golden record tasks based on the provided task identifiers."
description = "Returns the state of golden record tasks based on the provided task identifiers. Unknown task identifiers are ignored."
)
@ApiResponses(
value = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ package org.eclipse.tractusx.orchestrator.api.model

enum class StepState {
Queued,
Reserved
}
Reserved,
Success,
Error
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@ data class TaskProcessingStateDto(
val createdAt: Instant,

@get:Schema(description = "When the task has last been modified", required = true)
val modifiedAt: Instant
val modifiedAt: Instant,

@get:Schema(description = "The timestamp until the task is removed from the Orchestrator")
val timeout: Instant
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties

@ConfigurationProperties(prefix = "bpdm.api")
data class ApiConfigProperties(
val upsertLimit: Int = 100,
val upsertLimit: Int = 100
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.config

import org.springframework.boot.context.properties.ConfigurationProperties
import java.time.Duration

@ConfigurationProperties(prefix = "bpdm.task")
data class TaskConfigProperties(
// Duration after which a task is removed from the Orchestrator after creation
val taskTimeout: Duration = Duration.ofHours(3 * 24),
// Duration for which a reservation is valid and results are accepted
val taskReservationTimeout: Duration = Duration.ofHours(24)
)
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,43 @@ package org.eclipse.tractusx.bpdm.orchestrator.controller

import org.eclipse.tractusx.bpdm.common.exception.BpdmUpsertLimitException
import org.eclipse.tractusx.bpdm.orchestrator.config.ApiConfigProperties
import org.eclipse.tractusx.bpdm.orchestrator.exception.BpdmEmptyResultException
import org.eclipse.tractusx.bpdm.orchestrator.util.DummyValues
import org.eclipse.tractusx.bpdm.orchestrator.service.GoldenRecordTaskService
import org.eclipse.tractusx.orchestrator.api.GoldenRecordTaskApi
import org.eclipse.tractusx.orchestrator.api.model.*
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController

@RestController
class GoldenRecordTaskController(
val apiConfigProperties: ApiConfigProperties
val apiConfigProperties: ApiConfigProperties,
val goldenRecordTaskService: GoldenRecordTaskService
) : GoldenRecordTaskApi {

override fun createTasks(createRequest: TaskCreateRequest): TaskCreateResponse {
if (createRequest.businessPartners.size > apiConfigProperties.upsertLimit)
throw BpdmUpsertLimitException(createRequest.businessPartners.size, apiConfigProperties.upsertLimit)

//ToDo: Replace with service logic
return DummyValues.dummyResponseCreateTask
return goldenRecordTaskService.createTasks(createRequest)
}

override fun reserveTasksForStep(reservationRequest: TaskStepReservationRequest): TaskStepReservationResponse {
if (reservationRequest.amount > apiConfigProperties.upsertLimit) {
if (reservationRequest.amount > apiConfigProperties.upsertLimit)
throw BpdmUpsertLimitException(reservationRequest.amount, apiConfigProperties.upsertLimit)
}

//ToDo: Replace with service logic
return when (reservationRequest.step) {
TaskStep.CleanAndSync -> DummyValues.dummyStepReservationResponse
TaskStep.PoolSync -> DummyValues.dummyPoolSyncResponse
TaskStep.Clean -> DummyValues.dummyStepReservationResponse
}
return goldenRecordTaskService.reserveTasksForStep(reservationRequest)
}

@ResponseStatus(HttpStatus.NO_CONTENT)
override fun resolveStepResults(resultRequest: TaskStepResultRequest) {
if (resultRequest.results.size > apiConfigProperties.upsertLimit)
throw BpdmUpsertLimitException(resultRequest.results.size, apiConfigProperties.upsertLimit)

resultRequest.results.forEach { resultEntry ->
if (resultEntry.businessPartner == null && resultEntry.errors.isEmpty())
throw BpdmEmptyResultException(resultEntry.taskId)
}
goldenRecordTaskService.resolveStepResults(resultRequest)
}


override fun searchTaskStates(stateRequest: TaskStateRequest): TaskStateResponse {
// ToDo: Replace with service logic
return DummyValues.dummyResponseTaskState
return goldenRecordTaskService.searchTaskStates(stateRequest)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.exception

import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus


@ResponseStatus(HttpStatus.BAD_REQUEST)
class BpdmDuplicateTaskIdException(
taskId: String
) : RuntimeException("Duplicate task ID '$taskId'.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.exception

import org.eclipse.tractusx.bpdm.orchestrator.model.TaskProcessingState
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus


@ResponseStatus(HttpStatus.BAD_REQUEST)
class BpdmIllegalStateException(
taskId: String,
state: TaskProcessingState
) : RuntimeException("Task with ID '$taskId' is in illegal state for transition: resultState=${state.resultState}, step=${state.step}, stepState=${state.stepState}")
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.exception

import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ResponseStatus


@ResponseStatus(HttpStatus.BAD_REQUEST)
class BpdmTaskNotFoundException(
taskId: String
) : RuntimeException("Task with ID '$taskId' not found.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.model

import org.eclipse.tractusx.orchestrator.api.model.BusinessPartnerFullDto

data class GoldenRecordTask(
val taskId: String,
var businessPartner: BusinessPartnerFullDto,
val processingState: TaskProcessingState
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2021,2023 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License 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.
*
* SPDX-License-Identifier: Apache-2.0
******************************************************************************/

package org.eclipse.tractusx.bpdm.orchestrator.model

import org.eclipse.tractusx.orchestrator.api.model.*
import java.time.Instant

data class TaskProcessingState(
val mode: TaskMode,
var resultState: ResultState,
var errors: List<TaskErrorDto> = emptyList(),

var step: TaskStep,
var stepState: StepState,
var reservationTimeout: Instant?,

val taskCreatedAt: Instant,
var taskModifiedAt: Instant,
val taskTimeout: Instant,
)
Loading

0 comments on commit 14c50a4

Please sign in to comment.