Skip to content

Commit

Permalink
restructuralisation of modules (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
jancajthaml authored May 21, 2019
1 parent eb05ff9 commit bc850ec
Show file tree
Hide file tree
Showing 29 changed files with 309 additions and 307 deletions.
14 changes: 13 additions & 1 deletion dev/lifecycle/debian
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ generate_changelog() {
rm -f ${target}.gz
fi

if [ -f ${target}.Debian.gz ] ; then
rm -f ${target}.Debian.gz
fi

touch ${target}

VER="${VERSION}"
Expand Down Expand Up @@ -149,7 +153,15 @@ generate_changelog() {
fi
done

cat ${target} | gzip -n -9 > ${target}.gz
case "${VERSION}" in
*+*)
cat ${target} | gzip -n -9 > ${target}.Debian.gz
;;
*)
cat ${target} | gzip -n -9 > ${target}.gz
;;
esac

rm ${target}
}

Expand Down
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.2.6+bbtest-message-expectation-flake
Version: 1.2.6+single-app-struct
Section: misc
Priority: extra
Architecture: amd64
Expand Down
Binary file not shown.
21 changes: 10 additions & 11 deletions services/vault-rest/actor/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package actor
import (
"time"

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

"github.com/rs/xid"
Expand All @@ -27,8 +26,8 @@ import (
)

// CreateAccount creates new account for target tenant vault
func CreateAccount(s *daemon.ActorSystem, tenant string, account model.Account) (result interface{}) {
s.Metrics.TimeCreateAccount(func() {
func CreateAccount(sys *ActorSystem, tenant string, account model.Account) (result interface{}) {
sys.Metrics.TimeCreateAccount(func() {
// FIXME properly determine fail states
// input validation -> input error
// system in invalid state (and panics) -> fatal error
Expand All @@ -46,13 +45,13 @@ func CreateAccount(s *daemon.ActorSystem, tenant string, account model.Account)
defer close(ch)

envelope := system.NewEnvelope("relay/"+xid.New().String(), nil)
defer s.UnregisterActor(envelope.Name)
defer sys.UnregisterActor(envelope.Name)

s.RegisterActor(envelope, func(state interface{}, context system.Context) {
sys.RegisterActor(envelope, func(state interface{}, context system.Context) {
ch <- context.Data
})

s.SendRemote(CreateAccountMessage(tenant, envelope.Name, account.Name, account.Currency, account.IsBalanceCheck))
sys.SendRemote(CreateAccountMessage(tenant, envelope.Name, account.Name, account.Currency, account.IsBalanceCheck))

select {

Expand All @@ -68,8 +67,8 @@ func CreateAccount(s *daemon.ActorSystem, tenant string, account model.Account)
}

// GetAccount retrives account state from target tenant vault
func GetAccount(s *daemon.ActorSystem, tenant string, name string) (result interface{}) {
s.Metrics.TimeGetAccount(func() {
func GetAccount(sys *ActorSystem, tenant string, name string) (result interface{}) {
sys.Metrics.TimeGetAccount(func() {
// FIXME properly determine fail states
// input validation -> input error
// system in invalid state (and panics) -> fatal error
Expand All @@ -87,13 +86,13 @@ func GetAccount(s *daemon.ActorSystem, tenant string, name string) (result inter
defer close(ch)

envelope := system.NewEnvelope("relay/"+xid.New().String(), nil)
defer s.UnregisterActor(envelope.Name)
defer sys.UnregisterActor(envelope.Name)

s.RegisterActor(envelope, func(state interface{}, context system.Context) {
sys.RegisterActor(envelope, func(state interface{}, context system.Context) {
ch <- context.Data
})

s.SendRemote(GetAccountMessage(tenant, envelope.Name, name))
sys.SendRemote(GetAccountMessage(tenant, envelope.Name, name))

select {

Expand Down
9 changes: 3 additions & 6 deletions services/vault-rest/actor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@ import (
"fmt"
"strings"

"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, msg string) (system.Coordinates, system.Coordinates, []string, error) {
func asEnvelopes(s *ActorSystem, msg string) (system.Coordinates, system.Coordinates, []string, error) {
parts := strings.Split(msg, " ")

if len(parts) < 5 {
return nilCoordinates, nilCoordinates, nil, fmt.Errorf("invalid message received %+v", parts)
return system.Coordinates{}, system.Coordinates{}, nil, fmt.Errorf("invalid message received %+v", parts)
}

recieverRegion, senderRegion, receiverName, senderName := parts[0], parts[1], parts[2], parts[3]
Expand All @@ -50,7 +47,7 @@ func asEnvelopes(s *daemon.ActorSystem, msg string) (system.Coordinates, system.
}

// ProcessRemoteMessage processing of remote message to this wall
func ProcessRemoteMessage(s *daemon.ActorSystem) system.ProcessRemoteMessage {
func ProcessRemoteMessage(s *ActorSystem) system.ProcessRemoteMessage {
return func(msg string) {
from, to, parts, err := asEnvelopes(s, msg)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package daemon
package actor

import (
"context"
"fmt"
"time"

"github.com/jancajthaml-openbank/vault-rest/config"
"github.com/jancajthaml-openbank/vault-rest/metrics"

system "github.com/jancajthaml-openbank/actor-system"
)

// ActorSystem represents actor system subroutine
type ActorSystem struct {
system.Support
Metrics *Metrics
Metrics *metrics.Metrics
}

// NewActorSystem returns actor system fascade
func NewActorSystem(ctx context.Context, cfg config.Configuration, metrics *Metrics) ActorSystem {
return ActorSystem{
Support: system.NewSupport(ctx, "VaultRest", cfg.LakeHostname),
func NewActorSystem(ctx context.Context, lakeEndpoint string, metrics *metrics.Metrics) ActorSystem {
result := ActorSystem{
Support: system.NewSupport(ctx, "VaultRest", lakeEndpoint),
Metrics: metrics,
}

result.Support.RegisterOnRemoteMessage(ProcessRemoteMessage(&result))

return result
}

// GreenLight daemon noop
Expand All @@ -60,7 +64,7 @@ func (system ActorSystem) WaitReady(deadline time.Duration) (err error) {

ticker := time.NewTicker(deadline)
select {
case <-system.IsReady:
case <-system.Support.IsReady:
ticker.Stop()
err = nil
return
Expand Down
24 changes: 11 additions & 13 deletions services/vault-rest/api/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ import (
"net/http"

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

"github.com/gorilla/mux"
localfs "github.com/jancajthaml-openbank/local-fs"
)

// AccountPartial returns http handler for single account
func AccountPartial(system *daemon.ActorSystem) func(w http.ResponseWriter, r *http.Request) {
func AccountPartial(server *Server) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

Expand All @@ -46,7 +44,7 @@ func AccountPartial(system *daemon.ActorSystem) func(w http.ResponseWriter, r *h
switch r.Method {

case "GET":
GetAccount(system, tenant, id, w, r)
GetAccount(server, tenant, id, w, r)
return

default:
Expand All @@ -60,7 +58,7 @@ func AccountPartial(system *daemon.ActorSystem) func(w http.ResponseWriter, r *h
}

// AccountsPartial returns http handler for accounts
func AccountsPartial(system *daemon.ActorSystem, storage *localfs.Storage) func(w http.ResponseWriter, r *http.Request) {
func AccountsPartial(server *Server) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)

Expand All @@ -76,11 +74,11 @@ func AccountsPartial(system *daemon.ActorSystem, storage *localfs.Storage) func(
switch r.Method {

case "GET":
GetAccounts(storage, tenant, w, r)
GetAccounts(server, tenant, w, r)
return

case "POST":
CreateAccount(system, tenant, w, r)
CreateAccount(server, tenant, w, r)
return

default:
Expand All @@ -95,7 +93,7 @@ func AccountsPartial(system *daemon.ActorSystem, storage *localfs.Storage) func(
}

// CreateAccount creates new account
func CreateAccount(system *daemon.ActorSystem, tenant string, w http.ResponseWriter, r *http.Request) {
func CreateAccount(server *Server, tenant string, w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
defer r.Body.Close()
if err != nil {
Expand All @@ -114,7 +112,7 @@ func CreateAccount(system *daemon.ActorSystem, tenant string, w http.ResponseWri
return
}

switch actor.CreateAccount(system, tenant, *req).(type) {
switch actor.CreateAccount(server.ActorSystem, tenant, *req).(type) {

case *model.AccountCreated:
resp, err := utils.JSON.Marshal(req)
Expand Down Expand Up @@ -146,8 +144,8 @@ func CreateAccount(system *daemon.ActorSystem, tenant string, w http.ResponseWri
}

// GetAccounts returns list of existing accounts
func GetAccounts(storage *localfs.Storage, tenant string, w http.ResponseWriter, r *http.Request) {
accounts, err := persistence.LoadAccounts(storage, tenant)
func GetAccounts(server *Server, tenant string, w http.ResponseWriter, r *http.Request) {
accounts, err := persistence.LoadAccounts(server.Storage, tenant)
if err != nil {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
Expand All @@ -168,8 +166,8 @@ func GetAccounts(storage *localfs.Storage, tenant string, w http.ResponseWriter,
}

// GetAccount returns snapshot existing account
func GetAccount(system *daemon.ActorSystem, tenant string, id string, w http.ResponseWriter, r *http.Request) {
switch result := actor.GetAccount(system, tenant, id).(type) {
func GetAccount(server *Server, tenant string, id string, w http.ResponseWriter, r *http.Request) {
switch result := actor.GetAccount(server.ActorSystem, tenant, id).(type) {

case *model.AccountMissing:
w.Header().Set("Content-Type", "application/json")
Expand Down
10 changes: 6 additions & 4 deletions services/vault-rest/api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ package api
import "net/http"

// HealtCheck returns 200 OK
func HealtCheck(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(emptyJSONObject)
func HealtCheck(server *Server) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(emptyJSONObject)
}
}
Loading

0 comments on commit bc850ec

Please sign in to comment.