Skip to content

Commit

Permalink
Enable single pipe check on credo (#869)
Browse files Browse the repository at this point in the history
* Enable single pipe check on credo

* Apply credo rule
  • Loading branch information
arbulu89 authored Oct 4, 2022
1 parent e6fedd2 commit cd3aa6a
Show file tree
Hide file tree
Showing 31 changed files with 151 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
Expand Down Expand Up @@ -176,7 +177,6 @@
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.SeparateAliasRequire, []},
{Credo.Check.Readability.SingleFunctionToBlockPipe, []},
{Credo.Check.Readability.SinglePipe, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Readability.StrictModuleLayout, []},
{Credo.Check.Readability.WithCustomTaggedTuple, []},
Expand Down
5 changes: 2 additions & 3 deletions lib/trento/application/integration/checks/adapter/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule Trento.Integration.Checks.Runner do
end

defp build_payload(execution_id, cluster_id, provider, host_settings, selected_checks) do
%{
Jason.encode!(%{
execution_id: execution_id,
cluster_id: cluster_id,
provider: provider,
Expand All @@ -61,8 +61,7 @@ defmodule Trento.Integration.Checks.Runner do
user: host.user || host.default_user
}
end)
}
|> Jason.encode!()
})
end

defp runner_url,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ defmodule Trento.Integration.Discovery.CloudDiscoveryPayload do
:sku
])
|> cast_embed(:os_profile,
with: fn event, attrs -> event |> cast(attrs, [:admin_username]) end
with: fn event, attrs -> cast(event, attrs, [:admin_username]) end
)
|> cast_embed(:storage_profile,
with: fn event, attrs -> event |> cast(attrs, [:data_disks]) end
with: fn event, attrs -> cast(event, attrs, [:data_disks]) end
)
end
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ defmodule Trento.Integration.Discovery.ClusterDiscoveryPayload do
end

defp enrich_cluster_type(attrs),
do: attrs |> Map.put("cluster_type", parse_cluster_type(attrs))
do: Map.put(attrs, "cluster_type", parse_cluster_type(attrs))

defp enrich_cluster_sid(attrs), do: attrs |> Map.put("sid", parse_cluster_sid(attrs))
defp enrich_cluster_sid(attrs), do: Map.put(attrs, "sid", parse_cluster_sid(attrs))

defp parse_cluster_type(%{"crmmon" => %{"clones" => nil}}), do: :unknown

Expand Down Expand Up @@ -107,10 +107,10 @@ defmodule Trento.Integration.Discovery.ClusterDiscoveryPayload do
end

defp maybe_validate_required_fields(cluster, %{"cluster_type" => ClusterType.hana_scale_up()}),
do: cluster |> validate_required(@required_fields_hana)
do: validate_required(cluster, @required_fields_hana)

defp maybe_validate_required_fields(cluster, %{"cluster_type" => ClusterType.hana_scale_out()}),
do: cluster |> validate_required(@required_fields_hana)
do: validate_required(cluster, @required_fields_hana)

defp maybe_validate_required_fields(cluster, _),
do: cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ defmodule Trento.Integration.Discovery.ClusterDiscoveryPayload.Sbd do
end

defp transform_nil_lists(%{"devices" => devices} = attrs) do
attrs
|> Map.put("devices", ListHelper.to_list(devices))
Map.put(attrs, "devices", ListHelper.to_list(devices))
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do
end

def changeset(sap_system, attrs) do
modified_attrs =
attrs
|> databases_to_list
modified_attrs = databases_to_list(attrs)

sap_system
|> cast(modified_attrs, fields())
Expand Down Expand Up @@ -79,9 +77,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do
end

defp maybe_validate_required_fields(changeset, @application_type),
do:
changeset
|> validate_required(@application_required_fields)
do: validate_required(changeset, @application_required_fields)

defp maybe_validate_required_fields(changeset, _), do: changeset
end
Expand Down Expand Up @@ -187,8 +183,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do
end

defp find_property(property, %{"Properties" => properties}) do
properties
|> Enum.find_value(fn
Enum.find_value(properties, fn
%{"property" => ^property, "value" => value} -> value
_ -> nil
end)
Expand Down Expand Up @@ -352,8 +347,7 @@ defmodule Trento.Integration.Discovery.SapSystemDiscoveryPayload do
end

defp maybe_validate_replication_mode(changeset, local_site_id) do
changeset
|> validate_required([:"site/#{local_site_id}/REPLICATION_MODE"])
validate_required(changeset, [:"site/#{local_site_id}/REPLICATION_MODE"])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do
},
sid
) do
nodes
|> Enum.map(fn %{name: name, attributes: attributes} ->
Enum.map(nodes, fn %{name: name, attributes: attributes} ->
attributes =
Enum.reduce(attributes, %{}, fn %{name: name, value: value}, acc ->
Map.put(acc, name, value)
Expand Down Expand Up @@ -183,8 +182,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do
end

defp parse_cluster_fencing_type(%{resources: resources}) do
resources
|> Enum.find_value("", fn
Enum.find_value(resources, "", fn
%{agent: "stonith:" <> fencing_type} ->
fencing_type

Expand All @@ -209,8 +207,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do
end

defp parse_sbd_devices(%{devices: devices}) do
devices
|> Enum.map(fn %{device: device, status: status} ->
Enum.map(devices, fn %{device: device, status: status} ->
%{
device: device,
status: status
Expand Down Expand Up @@ -244,8 +241,8 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do
groups: groups,
clones: clones
}) do
primitives
|> Enum.concat(
Enum.concat(
primitives,
Enum.flat_map(clones, &Map.get(&1, :primitives, [])) ++
Enum.flat_map(groups, &Map.get(&1, :primitives, []))
)
Expand All @@ -255,8 +252,7 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do
virtual_ip_type_suffix = get_virtual_ip_type_suffix_by_provider(provider)

virtual_ip_resource_id =
node_resources
|> Enum.find_value(nil, fn %{type: virtual_ip_type, id: id} ->
Enum.find_value(node_resources, nil, fn %{type: virtual_ip_type, id: id} ->
if String.ends_with?(virtual_ip_type, virtual_ip_type_suffix), do: id
end)

Expand Down Expand Up @@ -304,8 +300,8 @@ defmodule Trento.Integration.Discovery.ClusterPolicy do
groups: groups,
clones: clones
}) do
resources
|> Enum.concat(
Enum.concat(
resources,
Enum.flat_map(clones, &Map.get(&1, :resources, [])) ++
Enum.flat_map(groups, &Map.get(&1, :resources, []))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ defmodule Trento.Integration.Discovery.SapSystemPolicy do
defp parse_sap_control_property(property, %Instance{
SAPControl: %SapControl{Properties: properties}
}) do
properties
|> Enum.find_value(fn
Enum.find_value(properties, fn
%{property: ^property, value: value} -> value
_ -> nil
end)
Expand All @@ -129,8 +128,7 @@ defmodule Trento.Integration.Discovery.SapSystemPolicy do
%Instance{SAPControl: %SapControl{Instances: instances}},
key
) do
instances
|> Enum.find_value(fn
Enum.find_value(instances, fn
%{current_instance: true} = current_instance -> Map.get(current_instance, key)
_ -> nil
end)
Expand Down
3 changes: 1 addition & 2 deletions lib/trento/application/integration/grafana/grafana.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ defmodule Trento.Integration.Grafana do
def init_dashboards do
dashboards = Application.fetch_env!(:trento, :grafana)[:dashboards]

dashboards
|> Enum.reduce_while(:ok, fn dashboard_name, _ ->
Enum.reduce_while(dashboards, :ok, fn dashboard_name, _ ->
case init_dashboard(dashboard_name) do
:ok ->
{:cont, :ok}
Expand Down
6 changes: 4 additions & 2 deletions lib/trento/application/projectors/check_result_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ defmodule Trento.CheckResultProjector do
},
fn multi ->
hosts_executions_changeset =
%HostChecksExecutionsReadModel{cluster_id: cluster_id, host_id: host_id}
|> HostChecksExecutionsReadModel.changeset(%{reachable: reachable, msg: msg})
HostChecksExecutionsReadModel.changeset(
%HostChecksExecutionsReadModel{cluster_id: cluster_id, host_id: host_id},
%{reachable: reachable, msg: msg}
)

multi = Ecto.Multi.update(multi, :hosts_executions, hosts_executions_changeset)

Expand Down
19 changes: 6 additions & 13 deletions lib/trento/application/projectors/cluster_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ defmodule Trento.ClusterProjector do
},
fn multi ->
changeset =
%ClusterReadModel{}
|> ClusterReadModel.changeset(%{
ClusterReadModel.changeset(%ClusterReadModel{}, %{
id: id,
name: name,
sid: sid,
Expand All @@ -64,8 +63,7 @@ defmodule Trento.ClusterProjector do
},
fn multi ->
changeset =
%ClusterReadModel{id: id}
|> ClusterReadModel.changeset(%{
ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{
checks_execution: :requested
})

Expand All @@ -79,8 +77,7 @@ defmodule Trento.ClusterProjector do
},
fn multi ->
changeset =
%ClusterReadModel{id: id}
|> ClusterReadModel.changeset(%{
ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{
checks_execution: :running
})

Expand All @@ -94,8 +91,7 @@ defmodule Trento.ClusterProjector do
},
fn multi ->
changeset =
%ClusterReadModel{id: id}
|> ClusterReadModel.changeset(%{
ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{
checks_execution: :not_running
})

Expand All @@ -116,8 +112,7 @@ defmodule Trento.ClusterProjector do
},
fn multi ->
changeset =
%ClusterReadModel{id: id}
|> ClusterReadModel.changeset(%{
ClusterReadModel.changeset(%ClusterReadModel{id: id}, %{
name: name,
sid: sid,
provider: provider,
Expand Down Expand Up @@ -152,9 +147,7 @@ defmodule Trento.ClusterProjector do
)

project(%ClusterHealthChanged{cluster_id: cluster_id, health: health}, fn multi ->
changeset =
%ClusterReadModel{id: cluster_id}
|> ClusterReadModel.changeset(%{health: health})
changeset = ClusterReadModel.changeset(%ClusterReadModel{id: cluster_id}, %{health: health})

Ecto.Multi.update(multi, :cluster, changeset)
end)
Expand Down
47 changes: 26 additions & 21 deletions lib/trento/application/projectors/database_projector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ defmodule Trento.DatabaseProjector do
%DatabaseRegistered{sap_system_id: sap_system_id, sid: sid, health: health},
fn multi ->
changeset =
%DatabaseReadModel{}
|> DatabaseReadModel.changeset(%{id: sap_system_id, sid: sid, health: health})
DatabaseReadModel.changeset(%DatabaseReadModel{}, %{
id: sap_system_id,
sid: sid,
health: health
})

Ecto.Multi.insert(multi, :database, changeset)
end
Expand All @@ -43,8 +46,7 @@ defmodule Trento.DatabaseProjector do
},
fn multi ->
changeset =
%DatabaseReadModel{id: sap_system_id}
|> DatabaseReadModel.changeset(%{health: health})
DatabaseReadModel.changeset(%DatabaseReadModel{id: sap_system_id}, %{health: health})

Ecto.Multi.update(multi, :database, changeset)
end
Expand All @@ -68,8 +70,7 @@ defmodule Trento.DatabaseProjector do
},
fn multi ->
database_instance_changeset =
%DatabaseInstanceReadModel{}
|> DatabaseInstanceReadModel.changeset(%{
DatabaseInstanceReadModel.changeset(%DatabaseInstanceReadModel{}, %{
sap_system_id: sap_system_id,
sid: sid,
instance_number: instance_number,
Expand Down Expand Up @@ -98,12 +99,14 @@ defmodule Trento.DatabaseProjector do
},
fn multi ->
changeset =
%DatabaseInstanceReadModel{
sap_system_id: sap_system_id,
host_id: host_id,
instance_number: instance_number
}
|> DatabaseInstanceReadModel.changeset(%{health: health})
DatabaseInstanceReadModel.changeset(
%DatabaseInstanceReadModel{
sap_system_id: sap_system_id,
host_id: host_id,
instance_number: instance_number
},
%{health: health}
)

Ecto.Multi.update(multi, :database_instance, changeset)
end
Expand All @@ -119,15 +122,17 @@ defmodule Trento.DatabaseProjector do
},
fn multi ->
changeset =
%DatabaseInstanceReadModel{
sap_system_id: sap_system_id,
host_id: host_id,
instance_number: instance_number
}
|> DatabaseInstanceReadModel.changeset(%{
system_replication: system_replication,
system_replication_status: system_replication_status
})
DatabaseInstanceReadModel.changeset(
%DatabaseInstanceReadModel{
sap_system_id: sap_system_id,
host_id: host_id,
instance_number: instance_number
},
%{
system_replication: system_replication,
system_replication_status: system_replication_status
}
)

Ecto.Multi.update(multi, :database_instance, changeset)
end
Expand Down
Loading

0 comments on commit cd3aa6a

Please sign in to comment.