Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor (bpdm) - DEBUG Logging Messages and Logging Patterns #637

Merged
merged 1 commit into from
Dec 6, 2023
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
15 changes: 12 additions & 3 deletions bpdm-bridge-dummy/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,18 @@ bpdm:
host: localhost
schema: bpdm-bridge-dummy

# Logging Configuration
logging:
unknown-user: Anonymous
# Logging Configuration
logging:
unknown-user: Anonymous
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %green([%-10.10X{user:-System}]) %magenta([%-10.10X{request:-No Request}]) %yellow([%-15.15t]) %cyan(%-40.40logger{39}) : %m%n%wEx"
level:
root: INFO
com:
catenax:
bpdm:
bridge:
dummy: DEBUG

#Enable actuator endpoints
management:
Expand Down
39 changes: 26 additions & 13 deletions bpdm-cleaning-service-dummy/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,40 @@ bpdm:
# Connection to Orchestrator
client:
orchestrator:
base-url: http://localhost:8085/
base-url: http://localhost:8085/

# Logging Configuration
# Logging Configuration
logging:
unknown-user: Anonymous
unknown-user: Anonymous

# Cleaning Service Configurations
# Cleaning Service Configurations
cleaningService:
pollingCron: '-'
pollingCron: '-'

# Logging Configuration
logging:
unknown-user: Anonymous
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %green([%-10.10X{user:-System}]) %magenta([%-10.10X{request:-No Request}]) %yellow([%-15.15t]) %cyan(%-40.40logger{39}) : %m%n%wEx"
level:
root: INFO
org:
eclipse:
tractusx:
bpdm:
cleaning: DEBUG

# Enable actuator endpoints
management:
endpoint:
health:
probes:
enabled: true
endpoint:
health:
livenessState:
enabled: true
readinessState:
enabled: true
probes:
enabled: true
health:
livenessState:
enabled: true
readinessState:
enabled: true

# Springdoc swagger configuration
springdoc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.eclipse.tractusx.bpdm.gate.service

import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
import org.eclipse.tractusx.bpdm.common.model.StageType
Expand Down Expand Up @@ -56,9 +57,11 @@ class BusinessPartnerService(
private val orchestratorMappings: OrchestratorMappings,
private val sharingStateRepository: SharingStateRepository
) {
private val logger = KotlinLogging.logger { }

@Transactional
fun upsertBusinessPartnersInput(dtos: List<BusinessPartnerInputRequest>): List<BusinessPartnerInputDto> {
logger.debug { "Executing upsertBusinessPartnersInput() with parameters $dtos" }
val entities = dtos.map { dto -> businessPartnerMappings.toBusinessPartnerInput(dto) }
//Validation method
val validatedEntities = filterUpdateCandidates(entities, StageType.Input)
Expand All @@ -67,17 +70,20 @@ class BusinessPartnerService(

@Transactional
fun upsertBusinessPartnersOutput(dtos: Collection<BusinessPartnerOutputRequest>): Collection<BusinessPartnerOutputDto> {
logger.debug { "Executing upsertBusinessPartnersOutput() with parameters $dtos" }
val entities = dtos.map { dto -> businessPartnerMappings.toBusinessPartnerOutput(dto) }
return upsertBusinessPartnersOutputFromCandidates(entities).map(businessPartnerMappings::toBusinessPartnerOutputDto)
}

fun getBusinessPartnersInput(pageRequest: PageRequest, externalIds: Collection<String>?): PageDto<BusinessPartnerInputDto> {
logger.debug { "Executing getBusinessPartnersInput() with parameters $pageRequest and $externalIds" }
val stage = StageType.Input
return getBusinessPartners(pageRequest, externalIds, stage)
.toPageDto(businessPartnerMappings::toBusinessPartnerInputDto)
}

fun getBusinessPartnersOutput(pageRequest: PageRequest, externalIds: Collection<String>?): PageDto<BusinessPartnerOutputDto> {
logger.debug { "Executing getBusinessPartnersOutput() with parameters $pageRequest and $externalIds" }
val stage = StageType.Output
return getBusinessPartners(pageRequest, externalIds, stage)
.toPageDto(businessPartnerMappings::toBusinessPartnerOutputDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.eclipse.tractusx.bpdm.gate.service

import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.model.StageType
import org.eclipse.tractusx.bpdm.gate.api.exception.ChangeLogOutputError
Expand All @@ -38,6 +39,8 @@ import java.time.Instant
@Service
class ChangelogService(private val changelogRepository: ChangelogRepository) {

private val logger = KotlinLogging.logger { }

fun getChangeLogEntries(
externalIds: Set<String>?,
businessPartnerTypes: Set<BusinessPartnerType>?,
Expand All @@ -47,6 +50,8 @@ class ChangelogService(private val changelogRepository: ChangelogRepository) {
pageSize: Int
): PageChangeLogDto<ChangelogGateDto> {

logger.debug { "Executing getChangeLogEntries() with parameters $externalIds // $businessPartnerTypes // $stage // $createdAt" }

val nonNullExternalIds = externalIds ?: emptySet()

val spec = Specification.allOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.eclipse.tractusx.bpdm.gate.service

import jakarta.persistence.EntityManager
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.util.JpaMermaidCreator
import org.eclipse.tractusx.bpdm.common.util.JpaMetaModelReader
import org.springframework.stereotype.Service
Expand All @@ -32,8 +33,10 @@ class DocumentationService(
val entityManager: EntityManager
) {

fun getMermaidGatePersistence(): String {
private val logger = KotlinLogging.logger { }

fun getMermaidGatePersistence(): String {
logger.info { "Executing getMermaidGatePersistence()" }
val allClassInfos = JpaMetaModelReader().createJpaClassInfos(this.entityManager.metamodel)
return JpaMermaidCreator().getMermaid(allClassInfos, "Gate persistence")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.eclipse.tractusx.bpdm.gate.service

import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.BusinessPartnerType
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.PageDto
Expand All @@ -43,10 +44,13 @@ const val ERROR_MISSING_TASK = "Request for Pending state but no task-id specifi
@Service
class SharingStateService(private val stateRepository: SharingStateRepository) {

private val logger = KotlinLogging.logger { }

/**
* Upsert fixed sharing state based on given DTO
*/
fun upsertSharingState(request: SharingStateDto) {
logger.info { "Executing upsertSharingState() with parameters $request" }
val sharingState = getOrCreate(request.externalId, request.businessPartnerType)

when (request.sharingStateType) {
Expand Down Expand Up @@ -79,6 +83,8 @@ class SharingStateService(private val stateRepository: SharingStateRepository) {
externalIds: Collection<String>?
): PageDto<SharingStateDto> {

logger.info { "findSharingStates() called with $paginationRequest // $businessPartnerType and $externalIds" }

val pageRequest = PageRequest.of(paginationRequest.page, paginationRequest.size)
val spec = Specification.allOf(byExternalIdsIn(externalIds), byBusinessPartnerType(businessPartnerType))
val sharingStatePage = stateRepository.findAll(spec, pageRequest)
Expand Down
1 change: 1 addition & 0 deletions bpdm-gate/src/main/resources/application-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ bpdm:
refresh-url: ${bpdm.security.token-url}
token-url: ${bpdm.security.auth-server-url}/realms/${bpdm.security.realm}/protocol/openid-connect/token


#Spring OAuth configuration
spring:
security:
Expand Down
17 changes: 13 additions & 4 deletions bpdm-gate/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ bpdm:
api:
upsert-limit: 100

# Logging Configuration
logging:
unknown-user: Anonymous

# Cleaning Task Job Configurations
goldenRecordTask:
pollingCron: '-'
Expand All @@ -60,6 +56,19 @@ bpdm:
datasource:
host: localhost

# Logging Configuration
logging:
unknown-user: Anonymous
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %green([%-10.10X{user:-System}]) %magenta([%-10.10X{request:-No Request}]) %yellow([%-15.15t]) %cyan(%-40.40logger{39}) : %m%n%wEx"
level:
root: INFO
org:
eclipse:
tractusx:
bpdm:
gate: DEBUG

# Enable actuator endpoints
management:
endpoint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class GoldenRecordTaskService(

@Synchronized
fun createTasks(createRequest: TaskCreateRequest): TaskCreateResponse {
logger.debug { "Creation of new golden record tasks: executing createTasks() with parameters $createRequest" }
return createRequest.businessPartners
.map { businessPartnerGeneric -> taskStorage.addTask(initTask(createRequest, businessPartnerGeneric)) }
.map(::toTaskClientStateDto)
Expand All @@ -50,6 +51,7 @@ class GoldenRecordTaskService(

@Synchronized
fun searchTaskStates(stateRequest: TaskStateRequest): TaskStateResponse {
logger.debug { "Search for the state of golden record task: executing searchTaskStates() with parameters $stateRequest" }
return stateRequest.taskIds
.mapNotNull { taskId -> taskStorage.getTask(taskId) } // skip missing tasks
.map(::toTaskClientStateDto)
Expand All @@ -58,6 +60,7 @@ class GoldenRecordTaskService(

@Synchronized
fun reserveTasksForStep(reservationRequest: TaskStepReservationRequest): TaskStepReservationResponse {
logger.debug { "Reservation of next golden record tasks: executing reserveTasksForStep() with parameters $reservationRequest" }
val now = Instant.now()

val tasks = taskStorage.getQueuedTasksByStep(reservationRequest.step, reservationRequest.amount)
Expand All @@ -81,6 +84,7 @@ class GoldenRecordTaskService(

@Synchronized
fun resolveStepResults(resultRequest: TaskStepResultRequest) {
logger.debug { "Step results for reserved golden record tasks: executing resolveStepResults() with parameters $resultRequest" }
resultRequest.results
.forEach { resultEntry ->
val task = taskStorage.getTask(resultEntry.taskId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.eclipse.tractusx.bpdm.orchestrator.service

import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.orchestrator.config.TaskConfigProperties
import org.eclipse.tractusx.bpdm.orchestrator.exception.BpdmIllegalStateException
import org.eclipse.tractusx.bpdm.orchestrator.model.GoldenRecordTask
Expand All @@ -32,7 +33,10 @@ class GoldenRecordTaskStateMachine(
val taskConfigProperties: TaskConfigProperties
) {

private val logger = KotlinLogging.logger { }

fun initProcessingState(mode: TaskMode): TaskProcessingState {
logger.debug { "Executing initProcessingState() with parameters $mode" }
val now = Instant.now()

val initialStep = getInitialStep(mode)
Expand All @@ -53,6 +57,7 @@ class GoldenRecordTaskStateMachine(
}

fun doReserve(task: GoldenRecordTask) {
logger.debug { "Executing doReserve() with parameters $task" }
val state = task.processingState
val now = Instant.now()

Expand All @@ -66,6 +71,7 @@ class GoldenRecordTaskStateMachine(
}

fun doResolveTaskToSuccess(task: GoldenRecordTask, step: TaskStep, resultBusinessPartner: BusinessPartnerFullDto) {
logger.debug { "Executing doResolveTaskToSuccess() with parameters $task // $step and $resultBusinessPartner" }
val state = task.processingState
val now = Instant.now()

Expand All @@ -89,6 +95,7 @@ class GoldenRecordTaskStateMachine(
}

fun doResolveTaskToError(task: GoldenRecordTask, step: TaskStep, errors: List<TaskErrorDto>) {
logger.debug { "Executing doResolveTaskToError() with parameters $task // $step and $errors" }
val state = task.processingState

if (state.resultState != ResultState.Pending || state.stepState != StepState.Reserved || state.step != step) {
Expand Down
1 change: 1 addition & 0 deletions bpdm-orchestrator/src/main/resources/application-auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bpdm:
createTask: create_task
processTaskPrefix: process_task_step
viewTask: view_task

# OAuth configuration
security:
cors-origins: '*'
Expand Down
13 changes: 13 additions & 0 deletions bpdm-orchestrator/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ bpdm:
taskPendingTimeout: 3d
taskRetentionTimeout: 30d

# Logging Configuration
logging:
unknown-user: Anonymous
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss.SSS} %highlight(%-5level) %green([%-10.10X{user:-System}]) %magenta([%-10.10X{request:-No Request}]) %yellow([%-15.15t]) %cyan(%-40.40logger{39}) : %m%n%wEx"
level:
root: INFO
org:
eclipse:
tractusx:
bpdm:
orchestrator: DEBUG

# Enable actuator endpoints
management:
endpoint:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.eclipse.tractusx.bpdm.pool.service

import jakarta.transaction.Transactional
import mu.KotlinLogging
import org.eclipse.tractusx.bpdm.common.dto.request.AddressPartnerBpnSearchRequest
import org.eclipse.tractusx.bpdm.common.dto.request.PaginationRequest
import org.eclipse.tractusx.bpdm.common.dto.response.LogisticAddressVerboseDto
Expand All @@ -40,7 +41,10 @@ class AddressService(
private val legalEntityRepository: LegalEntityRepository,
private val siteRepository: SiteRepository,
) {
private val logger = KotlinLogging.logger { }

fun findByPartnerBpn(bpn: String, pageIndex: Int, pageSize: Int): PageDto<LogisticAddressVerboseDto> {
logger.debug { "Executing findByPartnerBpn() with parameters $bpn // $pageIndex // $pageSize" }
if (!legalEntityRepository.existsByBpn(bpn)) {
throw BpdmNotFoundException("Business Partner", bpn)
}
Expand All @@ -51,6 +55,7 @@ class AddressService(
}

fun findByBpn(bpn: String): LogisticAddressVerboseDto {
logger.debug { "Executing findByBpn() with parameters $bpn" }
val address = logisticAddressRepository.findByBpn(bpn) ?: throw BpdmNotFoundException("Address", bpn)
return address.toDto()
}
Expand All @@ -60,6 +65,8 @@ class AddressService(
searchRequest: AddressPartnerBpnSearchRequest,
paginationRequest: PaginationRequest
): PageDto<LogisticAddressVerboseDto> {
logger.debug { "Executing findByPartnerAndSiteBpns() with parameters $searchRequest and $paginationRequest" }

val partners = if (searchRequest.legalEntities.isNotEmpty()) legalEntityRepository.findDistinctByBpnIn(searchRequest.legalEntities) else emptyList()
val sites = if (searchRequest.sites.isNotEmpty()) siteRepository.findDistinctByBpnIn(searchRequest.sites) else emptyList()

Expand All @@ -74,6 +81,7 @@ class AddressService(
}

fun findLegalAddresses(bpnLs: Collection<String>): Collection<LegalAddressVerboseDto> {
logger.debug { "Executing findLegalAddresses() with parameters $bpnLs" }
val legalEntities = legalEntityRepository.findDistinctByBpnIn(bpnLs)
legalEntityRepository.joinLegalAddresses(legalEntities)
val addresses = legalEntities.map { it.legalAddress }
Expand All @@ -82,6 +90,7 @@ class AddressService(
}

fun findMainAddresses(bpnS: Collection<String>): Collection<MainAddressVerboseDto> {
logger.debug { "Executing findMainAddresses() with parameters $bpnS" }
val sites = siteRepository.findDistinctByBpnIn(bpnS)
siteRepository.joinAddresses(sites)
val addresses = sites.map { it.mainAddress }
Expand Down
Loading
Loading