Skip to content

Commit

Permalink
containerid string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmaykm committed Jan 8, 2020
1 parent f0ca051 commit cf5d30a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/containerid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,19 @@ function parse_container_id(cidstr::String)
attemptid_proto = ApplicationAttemptIdProto(; application_id=appid_proto, attemptId=attemptid)
ContainerIdProto(; app_id=appid_proto, app_attempt_id=attemptid_proto, id=cid)
end

function container_id_string(cid::ContainerIdProto)
app_id = isdefined(cid, :app_id) ? cid.app_id : cid.app_attempt_id.application_id
attempt_id = isdefined(cid, :app_attempt_id) ? cid.app_attempt_id.attemptId : 0
id = cid.id
epoch = id >> 40
id = CONTAINER_ID_BITMASK & id

parts = [CONTAINER_PREFIX]
(epoch > 0) && push!(parts, EPOCH_PREFIX * lpad(epoch, 2, "0"))
push!(parts, string(app_id.cluster_timestamp))
push!(parts, lpad(app_id.id, 4, "0"))
push!(parts, lpad(attempt_id, 2, "0"))
push!(parts, lpad(id, 6, "0"))
join(parts, CONTAINER_ID_SPLITTER)
end
16 changes: 14 additions & 2 deletions test/yarntests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,29 @@ end

function test_container_id()
@info("testing container ids")
cid = Elly.parse_container_id("container_1577681661884_0005_01_000001")
cidstr = "container_1577681661884_0005_01_000001"
cid = Elly.parse_container_id(cidstr)
@test cid.id == 1
@test cid.app_id.cluster_timestamp == 1577681661884
@test cid.app_id.id == 5
@test cid.app_attempt_id.attemptId == 1
@test Elly.container_id_string(cid) == cidstr

cid = Elly.parse_container_id("container_e17_1410901177871_0001_01_000005")
cidstr = "container_e17_1410901177871_0001_01_000005"
cid = Elly.parse_container_id(cidstr)
@test cid.id == 18691697672197
@test cid.app_id.cluster_timestamp == 1410901177871
@test cid.app_id.id == 1
@test cid.app_attempt_id.attemptId == 1
@test Elly.container_id_string(cid) == cidstr

cidstr = "container_e03_1465095377475_0007_02_000001"
cid = Elly.parse_container_id(cidstr)
@test cid.id == 3298534883329
@test cid.app_id.cluster_timestamp == 1465095377475
@test cid.app_id.id == 7
@test cid.app_attempt_id.attemptId == 2
@test Elly.container_id_string(cid) == cidstr

nothing
end
Expand Down

0 comments on commit cf5d30a

Please sign in to comment.