docker - Artifactory getStats 总是返回空对象
问题描述
我正在尝试在服务器上的 groovy 插件中获取我们在自己的工件服务器上托管的 docker 映像的下载统计信息。到目前为止,该manifest.json
文件似乎包含我正在寻找的统计信息。
repositories.getStats(RepoPath)
应该返回一个StatsInfo
具有getDownloadCount()
.
但是,无论我传递给它什么,repositories.getStats()
它总是返回一个null
对象。
我试过了:
- 码头工人本地
- 码头工人本地/人工智能
- 码头工人本地/人工智能/最新
- docker-local/ai/latest/manifest.json
但仍然repositories.getStats()
返回一个空对象。
我希望以下工作:
def stats = repositories.getStats(RepoPathFactory.create('docker-local','ai/latest/manifest.json'))
def dlCount = stats.getDownloadCount()
但它不断返回错误:
"Cannot invoke method getDownloadCount() on null object"
?stats
通过REST API调用manifest.json
有效,它返回一个带有下载统计信息的 json 格式的字符串。前任:
my-artifactory-server.io/api/storage/docker-local/ai/latest/manifest.json?stats
"uri" : "my-artifactory-server.io/api/storage/docker-local/ai/latest/manifest.json",
"downloadCount" : 10,
"lastDownloaded" : 1593160404880,
"lastDownloadedBy" : "Peter Griffin",
"remoteDownloadCount" : 0,
"remoteLastDownloaded" : 0
我究竟做错了什么?
解决方案
你试过的看起来不错,可能是你需要强制stats
对象必须是StatsInfo
下面是我测试和工作的代码,它打印下载计数manifest.json
import org.artifactory.repo.RepoPathFactory
import org.artifactory.fs.StatsInfo
executions {
getDockerStats() {
def statsInfo = (StatsInfo) repositories.getStats(RepoPathFactory.create("docker-local","hello-world/latest/manifest.json"))
log.info("stats download count : ${statsInfo.getDownloadCount()}")
}
}
并在日志中
[getDockerStats:12 ] [http-nio-8081-exec-5] - stats download count : 2
推荐阅读
- c# - iText7 从 IFormFile 创建一个文档
- python - TypeError: update_graph_scatter() 接受 0 个位置参数,但给出了 1 个
- django - 在 django 模型字段中保存 get_absolute_url 的结果
- android-studio - 折射错误,我无法提取方法错误消息
- python - 扫描 ODE 函数 python 的参数
- vhdl - 分配中的宽度不匹配:VHDL
- swift - Swift:无法将 Int 转换为 String,为什么会发生这种情况?
- c# - C# | 如何用字典中的TValue替换输入字符串
- node.js - Mongoose 无法获取数据,仅显示空数组
- unit-testing - 在 Dart 中抛出异常的异步函数中测试副作用