Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 8cba7ca

Browse files
committed
Commmit everything for real this time
Signed-off-by: Kevin Hoffman <[email protected]>
1 parent 40c9835 commit 8cba7ca

File tree

4 files changed

+13
-122
lines changed

4 files changed

+13
-122
lines changed

lib/lattice_observer/observed/event_processor.ex

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ defmodule LatticeObserver.Observed.EventProcessor do
6363
}
6464
end
6565

66-
def put_actor_instance(l = %Lattice{}, host_id, pk, instance_id, spec, stamp, claims)
66+
def put_actor_instance(l = %Lattice{}, host_id, pk, instance_id, spec, _stamp, claims)
6767
when is_binary(pk) and is_binary(instance_id) and is_binary(spec) do
6868
actor = Map.get(l.actors, pk, Actor.new(pk, "unavailable"))
6969
actor = merge_actor(actor, l, claims)
@@ -80,9 +80,7 @@ defmodule LatticeObserver.Observed.EventProcessor do
8080

8181
%Lattice{
8282
l
83-
| actors: Map.put(l.actors, pk, actor),
84-
instance_tracking:
85-
Map.put(l.instance_tracking, instance.id, timestamp_from_iso8601(stamp))
83+
| actors: Map.put(l.actors, pk, actor)
8684
}
8785
end
8886

@@ -133,6 +131,8 @@ defmodule LatticeObserver.Observed.EventProcessor do
133131
def remove_provider_instance(l, source_host, pk, link_name, _spec) do
134132
provider = l.providers[{pk, link_name}]
135133

134+
# only one provider+link name can exist per host, so this is guaranteed to
135+
# remove that provider since the key is already pk+link.
136136
if provider != nil do
137137
provider = %Provider{
138138
provider
@@ -376,19 +376,22 @@ defmodule LatticeObserver.Observed.EventProcessor do
376376
}
377377
end
378378

379-
def remove_actor_instance(l = %Lattice{}, _host_id, pk, instance_id, _spec) do
379+
def remove_actor_instance(l = %Lattice{}, host_id, pk, instance_id, _spec) do
380380
actor = l.actors[pk]
381381

382382
if actor != nil do
383+
# Since there's no longer any unique distinction between actor instances on
384+
# the host, we can simply remove any one we like
385+
instances_on_host = Enum.filter(actor.instances, fn i -> i.host_id == host_id end)
386+
383387
actor = %Actor{
384388
actor
385-
| instances: actor.instances |> Enum.reject(fn i -> i.id == instance_id end)
389+
| instances: Enum.drop(instances_on_host, 1)
386390
}
387391

388392
%Lattice{
389393
l
390-
| actors: Map.put(l.actors, pk, actor),
391-
instance_tracking: l.instance_tracking |> Map.delete(instance_id)
394+
| actors: Map.put(l.actors, pk, actor)
392395
}
393396
|> strip_instanceless_entities()
394397
else

test/observed/actors_test.exs

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
defmodule LatticeObserverTest.Observed.ActorsTest do
22
use ExUnit.Case
3-
alias LatticeObserver.Observed.{Lattice, Instance, Actor, EventProcessor}
3+
alias LatticeObserver.Observed.{Lattice, Instance, Actor}
44
alias TestSupport.CloudEvents
55

66
@test_spec "testapp"
7-
@test_spec_2 "othertestapp"
87
@test_host "Nxxx"
98

109
describe "Observed Lattice Monitors Actor Events" do
1110
test "Adds and Removes actors" do
1211
start = CloudEvents.actor_started("Mxxx", "abc123", @test_spec, @test_host)
1312
l = Lattice.new()
1413
l = Lattice.apply_event(l, start)
15-
stamp1 = EventProcessor.timestamp_from_iso8601(start.time)
16-
17-
# ensure idempotence
18-
# l = Lattice.apply_event(l, start)
1914

2015
assert l == %Lattice{
2116
Lattice.new()
@@ -50,9 +45,7 @@ defmodule LatticeObserverTest.Observed.ActorsTest do
5045
version: "1.0"
5146
}
5247
},
53-
instance_tracking: %{
54-
"abc123" => stamp1
55-
}
48+
instance_tracking: %{}
5649
}
5750

5851
stop = CloudEvents.actor_stopped("Mxxx", "abc123", @test_spec, @test_host)
@@ -77,106 +70,5 @@ defmodule LatticeObserverTest.Observed.ActorsTest do
7770
}
7871
}
7972
end
80-
81-
test "Stores the same actor belonging to multiple specs" do
82-
start = CloudEvents.actor_started("Mxxx", "abc123", @test_spec, @test_host)
83-
l = Lattice.new()
84-
l = Lattice.apply_event(l, start)
85-
start2 = CloudEvents.actor_started("Mxxx", "abc345", @test_spec_2, @test_host)
86-
l = Lattice.apply_event(l, start2)
87-
stamp1 = EventProcessor.timestamp_from_iso8601(start.time)
88-
stamp2 = EventProcessor.timestamp_from_iso8601(start2.time)
89-
90-
assert l == %Lattice{
91-
Lattice.new()
92-
| actors: %{
93-
"Mxxx" => %Actor{
94-
call_alias: "",
95-
capabilities: ["test", "test2"],
96-
id: "Mxxx",
97-
instances: [
98-
%Instance{
99-
host_id: "Nxxx",
100-
id: "abc345",
101-
revision: 0,
102-
spec_id: "othertestapp",
103-
version: "1.0"
104-
},
105-
%Instance{
106-
host_id: "Nxxx",
107-
id: "abc123",
108-
revision: 0,
109-
spec_id: "testapp",
110-
version: "1.0"
111-
}
112-
],
113-
issuer: "ATESTxxx",
114-
name: "Test Actor",
115-
tags: ""
116-
}
117-
},
118-
claims: %{
119-
"Mxxx" => %LatticeObserver.Observed.Claims{
120-
call_alias: "",
121-
caps: "test,test2",
122-
iss: "ATESTxxx",
123-
name: "Test Actor",
124-
rev: 0,
125-
sub: "Mxxx",
126-
tags: "",
127-
version: "1.0"
128-
}
129-
},
130-
instance_tracking: %{
131-
"abc123" => stamp1,
132-
"abc345" => stamp2
133-
}
134-
}
135-
136-
assert Lattice.actors_in_appspec(l, "testapp") == [
137-
%{actor_id: "Mxxx", host_id: "Nxxx", instance_id: "abc123"}
138-
]
139-
140-
stop = CloudEvents.actor_stopped("Mxxx", "abc123", @test_spec, @test_host)
141-
l = Lattice.apply_event(l, stop)
142-
143-
assert l == %LatticeObserver.Observed.Lattice{
144-
Lattice.new()
145-
| actors: %{
146-
"Mxxx" => %Actor{
147-
call_alias: "",
148-
capabilities: ["test", "test2"],
149-
id: "Mxxx",
150-
instances: [
151-
%Instance{
152-
host_id: "Nxxx",
153-
id: "abc345",
154-
revision: 0,
155-
spec_id: "othertestapp",
156-
version: "1.0"
157-
}
158-
],
159-
issuer: "ATESTxxx",
160-
name: "Test Actor",
161-
tags: ""
162-
}
163-
},
164-
claims: %{
165-
"Mxxx" => %LatticeObserver.Observed.Claims{
166-
call_alias: "",
167-
caps: "test,test2",
168-
iss: "ATESTxxx",
169-
name: "Test Actor",
170-
rev: 0,
171-
sub: "Mxxx",
172-
tags: "",
173-
version: "1.0"
174-
}
175-
},
176-
instance_tracking: %{
177-
"abc345" => stamp2
178-
}
179-
}
180-
end
18173
end
18274
end

test/observed/hosts_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ defmodule LatticeObserverTest.Observed.HostsTest do
4848

4949
assert Map.keys(l.hosts) == ["Nxxxy"]
5050
assert (l.hosts |> Map.values() |> List.first()).friendly_name == "yellow-cat-6"
51-
assert Map.keys(l.instance_tracking) == ["abc123", "abc456", "abc789"]
5251
assert l.providers == %{}
5352
assert l.actors == %{}
5453
end
@@ -83,7 +82,6 @@ defmodule LatticeObserverTest.Observed.HostsTest do
8382

8483
assert Map.keys(l.hosts) == ["Nxxx"]
8584
assert (l.hosts |> Map.values() |> List.first()).friendly_name == "orange-button-5"
86-
assert Map.keys(l.instance_tracking) == ["abc123", "abc456", "abc789"]
8785

8886
# Host is killed forcefully and starts again using the same seed private key
8987
l =

test/observed/providers_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ defmodule LatticeObserverTest.Observed.ProvidersTest do
2424
l = Lattice.new()
2525
l = Lattice.apply_event(l, start)
2626
stamp1 = EventProcessor.timestamp_from_iso8601(start.time)
27-
# ensure idempotence
28-
l = Lattice.apply_event(l, start)
2927

3028
orig_desired = %Lattice{
3129
Lattice.new()

0 commit comments

Comments
 (0)