-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
151 additions
and
48 deletions.
There are no files selected for viewing
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
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
51 changes: 51 additions & 0 deletions
51
core.coordinator/src/main/scala/dev/kamu/cli/commands/AssignWatermarkCommand.scala
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,51 @@ | ||
/* | ||
* Copyright (c) 2018 kamu.dev | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package dev.kamu.cli.commands | ||
|
||
import java.time.Instant | ||
|
||
import dev.kamu.cli.metadata.MetadataRepository | ||
import dev.kamu.core.manifests.{DatasetID, MetadataBlock} | ||
import dev.kamu.core.utils.Clock | ||
import org.apache.log4j.LogManager | ||
|
||
class AssignWatermarkCommand( | ||
systemClock: Clock, | ||
metadataRepository: MetadataRepository, | ||
ids: Seq[String], | ||
watermark: Instant | ||
) extends Command { | ||
private val logger = LogManager.getLogger(getClass.getName) | ||
|
||
def run(): Unit = { | ||
val datasetIDs = ids.map(DatasetID) | ||
|
||
val numUpdated = datasetIDs.map(assignWatermark).count(b => b) | ||
|
||
logger.info(s"Updated $numUpdated datasets") | ||
} | ||
|
||
def assignWatermark(datasetID: DatasetID): Boolean = { | ||
val metaChain = metadataRepository.getMetadataChain(datasetID) | ||
|
||
val newBlock = metaChain.append( | ||
MetadataBlock( | ||
prevBlockHash = metaChain.getBlocks().last.blockHash, | ||
systemTime = systemClock.instant(), | ||
outputWatermark = Some(watermark) | ||
) | ||
) | ||
|
||
logger.info( | ||
s"Committed new block: $datasetID (${newBlock.blockHash})" | ||
) | ||
|
||
true | ||
} | ||
} |
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
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
Submodule core.manifests
updated
4 files