forked from eclipse-tractusx/bpdm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eclipse-tractusx#204 from catenax-ng/feat/bridge_s…
…ync_record Bridge: Sync record for tracking sync processes
- Loading branch information
Showing
16 changed files
with
417 additions
and
138 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/entity/SyncRecord.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/******************************************************************************* | ||
* 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 com.catenax.bpdm.bridge.dummy.entity | ||
|
||
import jakarta.persistence.* | ||
import org.eclipse.tractusx.bpdm.common.model.BaseEntity | ||
import org.eclipse.tractusx.bpdm.common.model.BaseSyncRecord | ||
import org.eclipse.tractusx.bpdm.common.model.SyncStatus | ||
import java.time.Instant | ||
|
||
@Entity | ||
@Table(name = "sync_records") | ||
class SyncRecord( | ||
@Enumerated(EnumType.STRING) | ||
@Column(name = "type", nullable = false, unique = true) | ||
override var type: SyncType, | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(name = "status", nullable = false) | ||
override var status: SyncStatus, | ||
|
||
@Column(name = "from_time", nullable = false) | ||
override var fromTime: Instant, | ||
|
||
@Column(name = "progress", nullable = false) | ||
override var progress: Float = 0f, | ||
|
||
@Column(name = "count", nullable = false) | ||
override var count: Int = 0, | ||
|
||
@Column(name = "status_details") | ||
override var errorDetails: String? = null, | ||
|
||
@Column(name = "save_state") | ||
override var errorSave: String? = null, | ||
|
||
@Column(name = "started_at") | ||
override var startedAt: Instant? = null, | ||
|
||
@Column(name = "finished_at") | ||
override var finishedAt: Instant? = null | ||
|
||
) : BaseEntity(), BaseSyncRecord<SyncType> |
24 changes: 24 additions & 0 deletions
24
bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/entity/SyncType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* 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 com.catenax.bpdm.bridge.dummy.entity | ||
|
||
enum class SyncType { | ||
GATE_TO_POOL | ||
} |
29 changes: 29 additions & 0 deletions
29
...ge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/repository/SyncRecordRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 com.catenax.bpdm.bridge.dummy.repository | ||
|
||
import com.catenax.bpdm.bridge.dummy.entity.SyncRecord | ||
import com.catenax.bpdm.bridge.dummy.entity.SyncType | ||
import org.springframework.data.repository.CrudRepository | ||
|
||
interface SyncRecordRepository : CrudRepository<SyncRecord, Long> { | ||
|
||
fun findByType(type: SyncType): SyncRecord? | ||
} |
46 changes: 46 additions & 0 deletions
46
bpdm-bridge-dummy/src/main/kotlin/com/catenax/bpdm/bridge/dummy/service/SyncRecordService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************* | ||
* 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 com.catenax.bpdm.bridge.dummy.service | ||
|
||
import com.catenax.bpdm.bridge.dummy.entity.SyncRecord | ||
import com.catenax.bpdm.bridge.dummy.entity.SyncType | ||
import com.catenax.bpdm.bridge.dummy.repository.SyncRecordRepository | ||
import mu.KotlinLogging | ||
import org.eclipse.tractusx.bpdm.common.model.SyncStatus | ||
import org.eclipse.tractusx.bpdm.common.service.BaseSyncRecordService | ||
import org.springframework.stereotype.Service | ||
import java.time.Instant | ||
|
||
@Service | ||
class SyncRecordService( | ||
private val syncRecordRepository: SyncRecordRepository | ||
) : BaseSyncRecordService<SyncType, SyncRecord>() { | ||
|
||
override val logger = KotlinLogging.logger { } | ||
|
||
override fun newSyncRecord(type: SyncType, syncStartTime: Instant) = | ||
SyncRecord(type, SyncStatus.NOT_SYNCED, syncStartTime) | ||
|
||
override fun save(record: SyncRecord) = | ||
syncRecordRepository.save(record) | ||
|
||
override fun findByType(type: SyncType) = | ||
syncRecordRepository.findByType(type) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
bpdm-bridge-dummy/src/main/resources/db/migration/V4_0_0_0__create_sequence.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE SEQUENCE IF NOT EXISTS bpdm_sequence START WITH 1 INCREMENT BY 1; |
23 changes: 23 additions & 0 deletions
23
bpdm-bridge-dummy/src/main/resources/db/migration/V4_0_0_1__create_sync_records.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE TABLE sync_records | ||
( | ||
id BIGINT NOT NULL, | ||
uuid UUID NOT NULL, | ||
created_at TIMESTAMP with time zone NOT NULL, | ||
updated_at TIMESTAMP with time zone NOT NULL, | ||
type VARCHAR(255) NOT NULL, | ||
status VARCHAR(255) NOT NULL, | ||
progress FLOAT NOT NULL, | ||
count INTEGER NOT NULL, | ||
status_details VARCHAR(255), | ||
save_state VARCHAR(255), | ||
started_at TIMESTAMP with time zone, | ||
finished_at TIMESTAMP with time zone, | ||
from_time TIMESTAMP with time zone, | ||
CONSTRAINT pk_sync_records PRIMARY KEY (id) | ||
); | ||
|
||
ALTER TABLE sync_records | ||
ADD CONSTRAINT uc_sync_records_type UNIQUE (type); | ||
|
||
ALTER TABLE sync_records | ||
ADD CONSTRAINT uc_sync_records_uuid UNIQUE (uuid); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
bpdm-common/src/main/kotlin/org/eclipse/tractusx/bpdm/common/model/BaseSyncRecord.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************* | ||
* 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.common.model | ||
|
||
import java.time.Instant | ||
|
||
interface BaseSyncRecord<SYNC_TYPE> { | ||
var type: SYNC_TYPE | ||
|
||
var status: SyncStatus | ||
|
||
var fromTime: Instant | ||
|
||
var progress: Float | ||
|
||
var count: Int | ||
|
||
var errorDetails: String? | ||
|
||
var errorSave: String? | ||
|
||
var startedAt: Instant? | ||
|
||
var finishedAt: Instant? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.