Skip to content

Commit

Permalink
renamed server package to metricsendpoint (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd authored Nov 12, 2016
1 parent 772e04d commit df3935d
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 59 deletions.
13 changes: 0 additions & 13 deletions annactl/service_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/xh3b4sd/anna/service/network"
"github.com/xh3b4sd/anna/service/permutation"
"github.com/xh3b4sd/anna/service/random"
"github.com/xh3b4sd/anna/service/server"
"github.com/xh3b4sd/anna/service/spec"
"github.com/xh3b4sd/anna/service/textendpoint"
"github.com/xh3b4sd/anna/service/textinput"
Expand All @@ -37,7 +36,6 @@ func (a *annactl) newServiceCollection() spec.Collection {
collection.SetNetwork(a.newNetworkService())
collection.SetPermutation(a.newPermutationService())
collection.SetRandom(a.newRandomService())
collection.SetServer(a.newServerService())
collection.SetTextEndpoint(a.newTextEndpointService())
collection.SetTextInput(a.newTextInputService())
collection.SetTextOutput(a.newTextOutputService())
Expand All @@ -52,7 +50,6 @@ func (a *annactl) newServiceCollection() spec.Collection {
collection.Network().SetServiceCollection(collection)
collection.Permutation().SetServiceCollection(collection)
collection.Random().SetServiceCollection(collection)
collection.Server().SetServiceCollection(collection)
collection.TextEndpoint().SetServiceCollection(collection)
collection.TextInput().SetServiceCollection(collection)
collection.TextOutput().SetServiceCollection(collection)
Expand All @@ -70,7 +67,6 @@ func (a *annactl) newServiceCollection() spec.Collection {
panicOnError(collection.Network().Validate())
panicOnError(collection.Permutation().Validate())
panicOnError(collection.Random().Validate())
panicOnError(collection.Server().Validate())
panicOnError(collection.TextEndpoint().Validate())
panicOnError(collection.TextInput().Validate())
panicOnError(collection.TextOutput().Validate())
Expand All @@ -88,7 +84,6 @@ func (a *annactl) newServiceCollection() spec.Collection {
panicOnError(collection.Network().Configure())
panicOnError(collection.Permutation().Configure())
panicOnError(collection.Random().Configure())
panicOnError(collection.Server().Configure())
panicOnError(collection.TextEndpoint().Configure())
panicOnError(collection.TextInput().Configure())
panicOnError(collection.TextOutput().Configure())
Expand Down Expand Up @@ -144,14 +139,6 @@ func (a *annactl) newRandomService() spec.Random {
return newService
}

func (a *annactl) newServerService() spec.Server {
newService := server.New()

newService.SetHTTPAddress(a.flags.HTTPAddr)

return newService
}

func (a *annactl) newTextEndpointService() spec.TextEndpoint {
newService := textendpoint.New()

Expand Down
5 changes: 2 additions & 3 deletions annad/annad.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ func (a *annad) ExecAnnadCmd(cmd *cobra.Command, args []string) {
a.Service().Log().Line("msg", "booting network")
go a.Service().Network().Boot()

// TODO rename to instrumentation endpoint
a.Service().Log().Line("msg", "booting server")
go a.Service().Server().Boot()
a.Service().Log().Line("msg", "booting metrics endpoint")
go a.Service().MetricsEndpoint().Boot()

a.Service().Log().Line("msg", "booting text endpoint")
go a.Service().TextEndpoint().Boot()
Expand Down
4 changes: 2 additions & 2 deletions annad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ func (a *annad) Shutdown() {

wg.Add(1)
go func() {
a.Service().Log().Line("msg", "shutting down server")
a.Service().Server().Shutdown()
a.Service().Log().Line("msg", "shutting down metrics endpoint")
a.Service().MetricsEndpoint().Shutdown()
wg.Done()
}()

Expand Down
26 changes: 13 additions & 13 deletions annad/service_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/xh3b4sd/anna/service/id"
"github.com/xh3b4sd/anna/service/instrumentor/prometheus"
"github.com/xh3b4sd/anna/service/log"
"github.com/xh3b4sd/anna/service/metricsendpoint"
"github.com/xh3b4sd/anna/service/network"
"github.com/xh3b4sd/anna/service/permutation"
"github.com/xh3b4sd/anna/service/random"
"github.com/xh3b4sd/anna/service/server"
"github.com/xh3b4sd/anna/service/spec"
"github.com/xh3b4sd/anna/service/storage"
"github.com/xh3b4sd/anna/service/storage/memory"
Expand All @@ -39,10 +39,10 @@ func (a *annad) newServiceCollection() spec.Collection {
collection.SetID(a.newIDService())
collection.SetInstrumentor(a.newInstrumentorService())
collection.SetLog(a.newLogService())
collection.SetMetricsEndpoint(a.newMetricsEndpointService())
collection.SetNetwork(a.newNetworkService())
collection.SetPermutation(a.newPermutationService())
collection.SetRandom(a.newRandomService())
collection.SetServer(a.newServerService())
collection.SetStorageCollection(a.newStorageCollection())
collection.SetTextEndpoint(a.newTextEndpointService())
collection.SetTextInput(a.newTextInputService())
Expand All @@ -56,10 +56,10 @@ func (a *annad) newServiceCollection() spec.Collection {
collection.ID().SetServiceCollection(collection)
collection.Instrumentor().SetServiceCollection(collection)
collection.Log().SetServiceCollection(collection)
collection.MetricsEndpoint().SetServiceCollection(collection)
collection.Network().SetServiceCollection(collection)
collection.Permutation().SetServiceCollection(collection)
collection.Random().SetServiceCollection(collection)
collection.Server().SetServiceCollection(collection)
collection.Storage().Connection().SetServiceCollection(collection)
collection.Storage().Feature().SetServiceCollection(collection)
collection.Storage().General().SetServiceCollection(collection)
Expand All @@ -78,10 +78,10 @@ func (a *annad) newServiceCollection() spec.Collection {
panicOnError(collection.ID().Validate())
panicOnError(collection.Instrumentor().Validate())
panicOnError(collection.Log().Validate())
panicOnError(collection.MetricsEndpoint().Validate())
panicOnError(collection.Network().Validate())
panicOnError(collection.Permutation().Validate())
panicOnError(collection.Random().Validate())
panicOnError(collection.Server().Validate())
panicOnError(collection.Storage().Validate())
panicOnError(collection.Storage().Connection().Validate())
panicOnError(collection.Storage().Feature().Validate())
Expand All @@ -101,10 +101,10 @@ func (a *annad) newServiceCollection() spec.Collection {
panicOnError(collection.ID().Configure())
panicOnError(collection.Instrumentor().Configure())
panicOnError(collection.Log().Configure())
panicOnError(collection.MetricsEndpoint().Configure())
panicOnError(collection.Network().Configure())
panicOnError(collection.Permutation().Configure())
panicOnError(collection.Random().Configure())
panicOnError(collection.Server().Configure())
panicOnError(collection.Storage().Configure())
panicOnError(collection.Storage().Connection().Configure())
panicOnError(collection.Storage().Feature().Configure())
Expand Down Expand Up @@ -156,6 +156,14 @@ func (a *annad) newLogService() spec.Log {
return newService
}

func (a *annad) newMetricsEndpointService() spec.MetricsEndpoint {
newService := metricsendpoint.New()

newService.SetHTTPAddress(a.flags.HTTPAddr)

return newService
}

func (a *annad) newNetworkService() spec.Network {
return network.New()
}
Expand All @@ -172,14 +180,6 @@ func (a *annad) newRandomService() spec.Random {
return newService
}

func (a *annad) newServerService() spec.Server {
newService := server.New()

newService.SetHTTPAddress(a.flags.HTTPAddr)

return newService
}

func (a *annad) newStorageCollection() spec.StorageCollection {
newCollection := storage.NewCollection()

Expand Down
32 changes: 16 additions & 16 deletions service/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ type collection struct {
id spec.ID
instrumentor spec.Instrumentor
log spec.Log
metricsEndpoint spec.MetricsEndpoint
network spec.Network
permutation spec.Permutation
random spec.Random
server spec.Server
storageCollection spec.StorageCollection
textEndpoint spec.TextEndpoint
textInput spec.TextInput
Expand Down Expand Up @@ -84,14 +84,18 @@ func (c *collection) Log() spec.Log {
return c.log
}

func (c *collection) Network() spec.Network {
return c.network
}

func (c *collection) Metadata() map[string]string {
return c.metadata
}

func (c *collection) MetricsEndpoint() spec.MetricsEndpoint {
return c.metricsEndpoint
}

func (c *collection) Network() spec.Network {
return c.network
}

func (c *collection) Permutation() spec.Permutation {
return c.permutation
}
Expand All @@ -100,10 +104,6 @@ func (c *collection) Random() spec.Random {
return c.random
}

func (c *collection) Server() spec.Server {
return c.server
}

func (c *collection) Storage() spec.StorageCollection {
return c.storageCollection
}
Expand Down Expand Up @@ -136,6 +136,10 @@ func (c *collection) SetLog(l spec.Log) {
c.log = l
}

func (c *collection) SetMetricsEndpoint(s spec.MetricsEndpoint) {
c.metricsEndpoint = s
}

func (c *collection) SetNetwork(n spec.Network) {
c.network = n
}
Expand All @@ -148,10 +152,6 @@ func (c *collection) SetRandom(r spec.Random) {
c.random = r
}

func (c *collection) SetServer(s spec.Server) {
c.server = s
}

func (c *collection) SetStorageCollection(sc spec.StorageCollection) {
c.storageCollection = sc
}
Expand Down Expand Up @@ -231,15 +231,15 @@ func (c *collection) Validate() error {
if c.log == nil {
return maskAnyf(invalidConfigError, "log service must not be empty")
}
if c.metricsEndpoint == nil {
return maskAnyf(invalidConfigError, "metricsEndpoint service must not be empty")
}
if c.permutation == nil {
return maskAnyf(invalidConfigError, "permutation service must not be empty")
}
if c.random == nil {
return maskAnyf(invalidConfigError, "random service must not be empty")
}
if c.server == nil {
return maskAnyf(invalidConfigError, "server service must not be empty")
}
if c.storageCollection == nil {
return maskAnyf(invalidConfigError, "storage collection must not be empty")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package server
package metricsendpoint

import (
"fmt"
Expand Down
11 changes: 6 additions & 5 deletions service/server/service.go → service/metricsendpoint/service.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Package server implements a HTTP server to provide Anna's API over network.
package server
// Package metricsendpoint implements a HTTP server to provide Anna's metrics
// over network.
package metricsendpoint

import (
"net/http"
Expand All @@ -11,8 +12,8 @@ import (
servicespec "github.com/xh3b4sd/anna/service/spec"
)

// New creates a new server service.
func New() servicespec.Server {
// New creates a new metricsendpoint service.
func New() servicespec.MetricsEndpoint {
return &service{}
}

Expand Down Expand Up @@ -69,7 +70,7 @@ func (s *service) Configure() error {
}
s.metadata = map[string]string{
"id": id,
"name": "server",
"name": "metricsendpoint",
"type": "service",
}

Expand Down
6 changes: 3 additions & 3 deletions service/spec/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Collection interface {

Instrumentor() Instrumentor

MetricsEndpoint() MetricsEndpoint

// Log returns a log service. It is used to print log messages.
Log() Log

Expand All @@ -31,8 +33,6 @@ type Collection interface {
// Random returns a random service. It is used to create random numbers.
Random() Random

Server() Server

Storage() StorageCollection

// Shutdown ends all processes of the service collection like shutting down a
Expand All @@ -47,10 +47,10 @@ type Collection interface {
SetID(id ID)
SetInstrumentor(i Instrumentor)
SetLog(l Log)
SetMetricsEndpoint(s MetricsEndpoint)
SetNetwork(n Network)
SetPermutation(p Permutation)
SetRandom(r Random)
SetServer(s Server)
SetStorageCollection(sc StorageCollection)
SetTextEndpoint(te TextEndpoint)
SetTextInput(ti TextInput)
Expand Down
6 changes: 3 additions & 3 deletions service/spec/server.go → service/spec/metrics_endpoint.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package spec

// Server represents a simple bootable object being able to serve network
// resources.
type Server interface {
// MetricsEndpoint represents a simple bootable object being able to serve
// network resources.
type MetricsEndpoint interface {
// Boot initializes and starts the whole server like booting a machine.
// Listening to a socket should be done here internally. The call to Boot
// blocks forever.
Expand Down

0 comments on commit df3935d

Please sign in to comment.