Skip to content

Adds support for enabling and Disabling relays #572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Apr 25, 2016

Conversation

mpeck
Copy link
Contributor

@mpeck mpeck commented Apr 23, 2016

This adds a couple functions to the Cog.Relay.Relays module to enable and disable relays.

@mpeck mpeck added the review label Apr 23, 2016
relay_id = Map.fetch!(announcement, "relay")

online_status = case Map.fetch!(announcement, "online") do
true -> :online
false -> :offline
end

enabled_status = cond do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an if would be a bit more straightforward than a cond for this.

|> MapSet.to_list
end

defp in_tracker?(tracker, relay_id) do
relays = Enum.reduce(tracker.map, MapSet.new(), fn({_, relays}, acc) ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be able to simplify this a bit and make the whole thing a pipeline by calling Map.values(tracker.map) first.

bundle = bundle("relay-enable-bundle-1")
relay_group = relay_group("relay-enable-group-1")
add_relay_to_group(relay_group.id, relay.id)
assign_bundle_to_group(relay_group.id, bundle.id)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making some helper methods that can do all this in one shot, like we now do with cogctl.

I definitely think we should still have the fine-grained helpers that you've got here, but I think it'd help the tests to put a lot of that tedious setup logic behind some well-named helpers that can do it all in one shot.

@kevsmith kevsmith modified the milestone: Cog 0.5.0 Apr 25, 2016
@@ -46,6 +46,10 @@ defmodule Cog.V1.RelayController do
changeset = Relay.changeset(relay, relay_params)
case Repo.update(changeset) do
{:ok, relay} ->
# If the enabled flag has changed we need to enable/disable the relay
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this functionality needs to move out of the controller and closer to the core. That is, whenever we update a relay from anywhere, we should be sure that the state of the system is consistent.

One way to do it is to put the database operations (like Repo.update, here) behind another Cog-specific interface, which acts as a DDD-style "repository". The only way to update a relay would be to go through that interface, and behind it, we're free to do whatever we want. In this case, we can just make the call to update the status, but in the future it opens up more possibilities (e.g., emitting events that arbitrary system components can listen for and then take action on, etc.).

I started this with triggers - https://github.com/operable/cog/blob/master/lib/cog/repository/triggers.ex - thinking that each "thing" could perhaps have it's own "repository". That could ultimately change, but it seemed like a decent way to decompose things to start with.

@mpeck mpeck force-pushed the peck/enable-disable-relays branch from 9c8d1e0 to a0f6d12 Compare April 25, 2016 20:15
@mpeck mpeck self-assigned this Apr 25, 2016
"""
def create_relay_bundle_and_group(name, opts \\ []) do
relay = relay("relay-#{name}",
Keyword.get(opts, :token, "sekrit"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documenting the options each test function takes would be nice

@christophermaier
Copy link
Collaborator

👍

@mpeck mpeck force-pushed the peck/enable-disable-relays branch from 8ea6c01 to 5acacea Compare April 25, 2016 21:01
@mpeck mpeck merged commit 5acacea into master Apr 25, 2016
@mpeck mpeck deleted the peck/enable-disable-relays branch April 25, 2016 21:07
@mpeck mpeck removed the review label Apr 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants