Skip to content

Commit

Permalink
fixed linting issues (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored Feb 4, 2019
1 parent 6b564a5 commit 9945273
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 62 deletions.
2 changes: 1 addition & 1 deletion packaging/debian_amd64/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: vault
Version: 1.1.4+use-metrics
Version: 1.1.4+lint-issues
Architecture: amd64
Maintainer: Jan Cajthaml <jan.cajthaml@gmail.com>
Depends: init-system-helpers (>= 1.18~), libzmq5 (= 4.2.1-4)
Expand Down
42 changes: 27 additions & 15 deletions services/vault-rest/actor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,46 @@
package actor

import (
"fmt"

"github.com/jancajthaml-openbank/vault-rest/daemon"
"github.com/jancajthaml-openbank/vault-rest/model"

system "github.com/jancajthaml-openbank/actor-system"
log "github.com/sirupsen/logrus"
)

var nilCoordinates = system.Coordinates{}

func asEnvelopes(s *daemon.ActorSystem, parts []string) (system.Coordinates, system.Coordinates, string, error) {
if len(parts) < 4 {
return nilCoordinates, nilCoordinates, "", fmt.Errorf("invalid message received %+v", parts)
}

region, receiver, sender, payload := parts[0], parts[1], parts[2], parts[3]

from := system.Coordinates{
Name: sender,
Region: region,
}

to := system.Coordinates{
Name: receiver,
Region: s.Name,
}

return from, to, payload, nil
}

// ProcessRemoteMessage processing of remote message to this wall
func ProcessRemoteMessage(s *daemon.ActorSystem) system.ProcessRemoteMessage {
return func(parts []string) {
if len(parts) < 4 {
log.Warnf("invalid message received %+v", parts)
from, to, payload, err := asEnvelopes(s, parts)
if err != nil {
log.Warn(err.Error())
return
}

region, receiver, sender, payload := parts[0], parts[1], parts[2], parts[3]

// FIXME receiver and sender are swapped
from := system.Coordinates{
Name: sender,
Region: region,
}

to := system.Coordinates{
Name: receiver,
Region: s.Name,
}

defer func() {
if r := recover(); r != nil {
log.Errorf("procesRemoteMessage recovered in [remote %v -> local %v] : %+v", from, to, r)
Expand Down
2 changes: 1 addition & 1 deletion services/vault-rest/boot/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (app Application) WaitReady(deadline time.Duration) (err error) {
case error:
err = x
default:
err = fmt.Errorf("Unknown panic")
err = fmt.Errorf("unknown panic")
}
}
}()
Expand Down
14 changes: 7 additions & 7 deletions services/vault-rest/daemon/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ import (
log "github.com/sirupsen/logrus"
)

// Snapshot holds metrics snapshot status
type Snapshot struct {
GetAccountLatency float64 `json:"getAccountLatency"`
CreateAccountLatency float64 `json:"createAccountLatency"`
CreatedAccounts int64 `json:"createdAccounts"`
}

// Metrics represents metrics subroutine
type Metrics struct {
Support
Expand All @@ -57,6 +50,13 @@ func NewMetrics(ctx context.Context, cfg config.Configuration) Metrics {
}
}

// Snapshot holds metrics snapshot status
type Snapshot struct {
GetAccountLatency float64 `json:"getAccountLatency"`
CreateAccountLatency float64 `json:"createAccountLatency"`
CreatedAccounts int64 `json:"createdAccounts"`
}

// NewSnapshot returns metrics snapshot
func NewSnapshot(metrics Metrics) Snapshot {
return Snapshot{
Expand Down
17 changes: 9 additions & 8 deletions services/vault-rest/daemon/system_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
log "github.com/sirupsen/logrus"
)

// SystemControl represents systemctl subroutine
type SystemControl struct {
Support
underlying *dbus.Conn
Expand Down Expand Up @@ -78,26 +79,26 @@ func (sys SystemControl) DisableUnit(name string) error {

// FIXME
if _, err := sys.underlying.StopUnit(name, "replace", ch); err != nil {
return fmt.Errorf("Unable to stop unit %s because %+v", name, err)
return fmt.Errorf("unable to stop unit %s because %+v", name, err)
}

select {

case result := <-ch:
if result != "done" {
return fmt.Errorf("Unable to stop unit %s", name)
return fmt.Errorf("unable to stop unit %s", name)
}
log.Infof("Stopped unit %s", name)
log.Infof("Disabling unit %s", name)

if _, err := sys.underlying.DisableUnitFiles([]string{name}, false); err != nil {
return fmt.Errorf("Unable to disable unit %s because %+v", name, err)
return fmt.Errorf("unable to disable unit %s because %+v", name, err)
}

return nil

case <-time.After(3 * time.Second):
return fmt.Errorf("Unable to stop unit %s because timeout", name)
return fmt.Errorf("unable to stop unit %s because timeout", name)

}
}
Expand All @@ -107,26 +108,26 @@ func (sys SystemControl) EnableUnit(name string) error {
log.Debugf("Enabling units %s", name)

if _, _, err := sys.underlying.EnableUnitFiles([]string{name}, false, false); err != nil {
return fmt.Errorf("Unable to enable unit %s because %+v", name, err)
return fmt.Errorf("unable to enable unit %s because %+v", name, err)
}

ch := make(chan string)

if _, err := sys.underlying.StartUnit(name, "replace", ch); err != nil {
return fmt.Errorf("Unable to start unit %s because %+v", name, err)
return fmt.Errorf("unable to start unit %s because %+v", name, err)
}

select {

case result := <-ch:
if result != "done" {
return fmt.Errorf("Unable to start unit %s", name)
return fmt.Errorf("unable to start unit %s", name)
}
log.Infof("Started unit %s", name)
return nil

case <-time.After(3 * time.Second):
return fmt.Errorf("Unable to start unit %s because timeout", name)
return fmt.Errorf("unable to start unit %s because timeout", name)

}

Expand Down
1 change: 1 addition & 0 deletions services/vault-rest/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Account struct {
IsBalanceCheck bool `json:"isBalanceCheck"`
}

// UnmarshalJSON unmarshal json of Account entity
func (entity *Account) UnmarshalJSON(data []byte) error {
if entity == nil {
return fmt.Errorf("cannot unmarshall to nil pointer")
Expand Down
1 change: 1 addition & 0 deletions services/vault-rest/utils/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package utils

// AccountsPath returns filepath for accounts
func AccountsPath(tenant string) string {
return tenant + "/account"
}
73 changes: 43 additions & 30 deletions services/vault-unit/actor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package actor

import (
"fmt"

"github.com/jancajthaml-openbank/vault-unit/daemon"
"github.com/jancajthaml-openbank/vault-unit/model"

Expand All @@ -23,6 +25,8 @@ import (
money "gopkg.in/inf.v0"
)

var nilCoordinates = system.Coordinates{}

// ProcessLocalMessage processing of local message to this vault
func ProcessLocalMessage(s *daemon.ActorSystem) system.ProcessLocalMessage {
return func(message interface{}, to system.Coordinates, from system.Coordinates) {
Expand All @@ -44,30 +48,52 @@ func ProcessLocalMessage(s *daemon.ActorSystem) system.ProcessLocalMessage {
}
}

func asEnvelopes(s *daemon.ActorSystem, parts []string) (system.Coordinates, system.Coordinates, string, error) {
if len(parts) < 4 {
return nilCoordinates, nilCoordinates, "", fmt.Errorf("invalid message received %+v", parts)
}

region, receiver, sender, payload := parts[0], parts[1], parts[2], parts[3]

from := system.Coordinates{
Name: sender,
Region: region,
}

to := system.Coordinates{
Name: receiver,
Region: s.Name,
}

return from, to, payload, nil
}

func spawnAccountActor(s *daemon.ActorSystem, name string) (*system.Envelope, error) {
envelope := system.NewEnvelope(name, model.NewAccount(name))

err := s.RegisterActor(envelope, NilAccount(s))
if err != nil {
log.Warnf("%s ~ Spawning Actor Error unable to register", name)
return nil, err
}

log.Debugf("%s ~ Actor Spawned", name)
return envelope, nil
}

// ProcessRemoteMessage processing of remote message to this vault
func ProcessRemoteMessage(s *daemon.ActorSystem) system.ProcessRemoteMessage {
return func(parts []string) {
if len(parts) < 4 {
log.Warnf("invalid message received %+v", parts)
from, to, payload, err := asEnvelopes(s, parts)
if err != nil {
log.Warn(err.Error())
return
}

region, receiver, sender, payload := parts[0], parts[1], parts[2], parts[3]

from := system.Coordinates{
Name: sender,
Region: region,
}

to := system.Coordinates{
Name: receiver,
Region: s.Name,
}

defer func() {
if r := recover(); r != nil {
log.Errorf("procesRemoteMessage recovered in [remote %v -> local %v] : %+v", from, to, r)
s.SendRemote(region, FatalErrorMessage(to.Name, from.Name))
s.SendRemote(from.Region, FatalErrorMessage(to.Name, from.Name))
}
}()

Expand All @@ -78,7 +104,7 @@ func ProcessRemoteMessage(s *daemon.ActorSystem) system.ProcessRemoteMessage {

if err != nil {
log.Warnf("Actor not found [remote %v -> local %v]", from, to)
s.SendRemote(region, FatalErrorMessage(to.Name, from.Name))
s.SendRemote(from.Region, FatalErrorMessage(to.Name, from.Name))
return
}

Expand Down Expand Up @@ -135,23 +161,10 @@ func ProcessRemoteMessage(s *daemon.ActorSystem) system.ProcessRemoteMessage {

if message == nil {
log.Warnf("Deserialization of unsuported message [remote %v -> local %v] : %+v", from, to, parts)
s.SendRemote(region, FatalErrorMessage(to.Name, from.Name))
s.SendRemote(from.Region, FatalErrorMessage(to.Name, from.Name))
return
}

ref.Tell(message, from)
}
}

func spawnAccountActor(s *daemon.ActorSystem, name string) (*system.Envelope, error) {
envelope := system.NewEnvelope(name, model.NewAccount(name))

err := s.RegisterActor(envelope, NilAccount(s))
if err != nil {
log.Warnf("%s ~ Spawning Actor Error unable to register", name)
return nil, err
}

log.Debugf("%s ~ Actor Spawned", name)
return envelope, nil
}

0 comments on commit 9945273

Please sign in to comment.