Ejemplo n.º 1
0
// NewStorage creates a new configured redis storage object.
func NewStorage(config StorageConfig) (spec.Storage, error) {
	newStorage := &storage{
		StorageConfig: config,

		ID:           id.MustNewID(),
		ShutdownOnce: sync.Once{},
		Type:         ObjectType,
	}

	// Dependencies.
	if newStorage.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newStorage.Pool == nil {
		return nil, maskAnyf(invalidConfigError, "connection pool must not be empty")
	}
	// Settings.
	if newStorage.BackoffFactory == nil {
		return nil, maskAnyf(invalidConfigError, "backoff factory must not be empty")
	}
	if newStorage.Prefix == "" {
		return nil, maskAnyf(invalidConfigError, "prefix must not be empty")
	}

	newStorage.Log.Register(newStorage.GetType())

	return newStorage, nil
}
Ejemplo n.º 2
0
// New creates a new configured feature set object. A feature set tries to
// detect all patterns within the configured input sequences.
func New(config Config) (spec.FeatureSet, error) {
	newFeatureSet := &featureSet{
		Config: config,
		ID:     id.MustNewID(),
		Mutex:  sync.Mutex{},
		Type:   ObjectTypeFeatureSet,
	}

	if newFeatureSet.MaxLength < -1 {
		return nil, maskAnyf(invalidConfigError, "MaxLength must be greater than -2")
	}
	if newFeatureSet.MinLength < 1 {
		return nil, maskAnyf(invalidConfigError, "MaxLength must be greater than 0")
	}
	if newFeatureSet.MaxLength != -1 && newFeatureSet.MaxLength < newFeatureSet.MinLength {
		return nil, maskAnyf(invalidConfigError, "MaxLength must be equal to or greater thanMinLength")
	}
	if newFeatureSet.MinCount < 0 {
		return nil, maskAnyf(invalidConfigError, "MinCount must be greater than -1")
	}
	if len(newFeatureSet.Sequences) == 0 {
		return nil, maskAnyf(invalidConfigError, "sequences must not be empty")
	}

	return newFeatureSet, nil
}
Ejemplo n.º 3
0
Archivo: main.go Proyecto: xh3b4sd/anna
// New creates a new configured annad object.
func New(config Config) (spec.Annad, error) {
	newAnna := &annad{
		Config: config,

		BootOnce:     sync.Once{},
		ID:           id.MustNewID(),
		ShutdownOnce: sync.Once{},
		Type:         ObjectType,
	}

	if newAnna.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newAnna.Network == nil {
		return nil, maskAnyf(invalidConfigError, "network must not be empty")
	}
	if newAnna.Server == nil {
		return nil, maskAnyf(invalidConfigError, "server must not be empty")
	}
	if newAnna.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "service collection must not be empty")
	}
	if newAnna.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}

	return newAnna, nil
}
Ejemplo n.º 4
0
// New creates a new configured forwarder object.
func New(config Config) (systemspec.Forwarder, error) {
	newForwarder := &forwarder{
		Config: config,

		ID:   id.MustNewID(),
		Type: ObjectType,
	}

	// Dependencies.
	if newForwarder.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "factory collection must not be empty")
	}
	if newForwarder.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newForwarder.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}

	// Settings.
	if newForwarder.MaxSignals == 0 {
		return nil, maskAnyf(invalidConfigError, "maximum signals must not be empty")
	}

	newForwarder.Log.Register(newForwarder.GetType())

	return newForwarder, nil
}
Ejemplo n.º 5
0
// New creates a new configured network object.
func New(config Config) (systemspec.Network, error) {
	newNetwork := &network{
		Config: config,

		BootOnce:     sync.Once{},
		Closer:       make(chan struct{}, 1),
		ID:           id.MustNewID(),
		ShutdownOnce: sync.Once{},
		Type:         ObjectType,
	}

	if newNetwork.Activator == nil {
		return nil, maskAnyf(invalidConfigError, "activator must not be empty")
	}
	if newNetwork.Forwarder == nil {
		return nil, maskAnyf(invalidConfigError, "forwarder must not be empty")
	}
	if newNetwork.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newNetwork.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "service collection must not be empty")
	}
	if newNetwork.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}
	if newNetwork.Tracker == nil {
		return nil, maskAnyf(invalidConfigError, "tracker must not be empty")
	}

	newNetwork.CLGs = newNetwork.newCLGs()
	newNetwork.Log.Register(newNetwork.GetType())

	return newNetwork, nil
}
Ejemplo n.º 6
0
// NewDistribution creates a new configured distribution object. A distribution
// represents a weighted analysis of vectors. A two dimensional distribution
// can be seen as bar chart.
//
//     ^
//     |         x
//     |         x
//     |         x    x
//   y |         x    x
//     |         x    x
//     |    x    x    x
//     |    x    x    x    x
//     |    x    x    x    x
//     +------------------------>
//                 x
//
func NewDistribution(config Config) (spec.Distribution, error) {
	newDistribution := &distribution{
		Config: config,
		ID:     id.MustNewID(),
		Mutex:  sync.Mutex{},
		Type:   ObjectTypeDistribution,
	}

	if newDistribution.Name == "" {
		return nil, maskAnyf(invalidConfigError, "name must not be empty")
	}
	if len(newDistribution.Vectors) == 0 {
		return nil, maskAnyf(invalidConfigError, "vectors must not be empty")
	}
	if !equalDimensionLength(newDistribution.Vectors) {
		return nil, maskAnyf(invalidConfigError, "vectors must have equal dimensions")
	}
	if len(newDistribution.StaticChannels) == 0 {
		return nil, maskAnyf(invalidConfigError, "vectors must not be empty")
	}
	if !uniqueFloat64(newDistribution.StaticChannels) {
		return nil, maskAnyf(invalidConfigError, "static channels must be unique")
	}

	sort.Float64s(newDistribution.StaticChannels)

	return newDistribution, nil
}
Ejemplo n.º 7
0
// NewFeature creates a new configured feature object. A feature represents a
// differentiable part of a given sequence.
func NewFeature(config FeatureConfig) (spec.Feature, error) {
	newFeature := &feature{
		Distribution:  nil,
		FeatureConfig: config,
		ID:            id.MustNewID(),
		Mutex:         sync.Mutex{},
		Type:          ObjectTypeFeature,
	}

	if len(newFeature.Positions) == 0 {
		return nil, maskAnyf(invalidConfigError, "positions must not be empty")
	}
	if newFeature.Sequence == "" {
		return nil, maskAnyf(invalidConfigError, "sequence must not be empty")
	}

	newConfig := distribution.DefaultConfig()
	newConfig.Name = newFeature.Sequence
	newConfig.Vectors = newFeature.Positions
	newDistribution, err := distribution.NewDistribution(newConfig)
	if err != nil {
		return nil, maskAnyf(invalidConfigError, err.Error())
	}
	newFeature.Distribution = newDistribution

	return newFeature, nil
}
Ejemplo n.º 8
0
Archivo: main.go Proyecto: xh3b4sd/anna
// DefaultConfig provides a default configuration to create a new command line
// object by best effort.
func DefaultConfig() Config {
	newLogControl, err := logcontrol.NewControl(logcontrol.DefaultControlConfig())
	if err != nil {
		panic(err)
	}

	newTextInterface, err := text.NewClient(text.DefaultClientConfig())
	if err != nil {
		panic(err)
	}

	newConfig := Config{
		// Dependencies.
		Log:               log.New(log.DefaultConfig()),
		LogControl:        newLogControl,
		ServiceCollection: service.MustNewCollection(),
		TextInterface:     newTextInterface,

		// Settings.
		Flags:     Flags{},
		SessionID: string(id.MustNewID()),
		Version:   version,
	}

	return newConfig
}
Ejemplo n.º 9
0
// New creates a new configured network payload object.
func New(config Config) (spec.NetworkPayload, error) {
	newObject := &networkPayload{
		Config: config,

		ID: id.MustNewID(),
	}

	return newObject, nil
}
Ejemplo n.º 10
0
Archivo: os.go Proyecto: xh3b4sd/anna
// NewFileSystem creates a new configured real OS file system.
func NewFileSystem(config Config) servicespec.FS {
	newFileSystem := &osFileSystem{
		Config: config,
		ID:     id.MustNewID(),
		Mutex:  sync.Mutex{},
		Type:   ObjectType,
	}

	newFileSystem.Log.Register(newFileSystem.GetType())

	return newFileSystem
}
Ejemplo n.º 11
0
// New creates a new configured context object.
func New(config Config) (spec.Context, error) {
	newContext := &context{
		Config: config,

		ID: string(id.MustNewID()),
	}

	if newContext.Context == nil {
		return nil, maskAnyf(invalidConfigError, "context must not be empty")
	}

	return newContext, nil
}
Ejemplo n.º 12
0
// New creates a new configured CLG collection object.
func New(config Config) (systemspec.CLGCollection, error) {
	newCollection := &collection{
		Config: config,

		ID:    id.MustNewID(),
		Mutex: sync.Mutex{},
		Type:  ObjectTypeCLGCollection,
	}

	newCollection.Log.Register(newCollection.GetType())

	return newCollection, nil
}
Ejemplo n.º 13
0
Archivo: log.go Proyecto: xh3b4sd/anna
// New creates a new configured log object.
func New(config Config) spec.Log {
	newLog := log{
		Config: config,

		ID:                id.MustNewID(),
		Mutex:             sync.Mutex{},
		RegisteredObjects: []spec.ObjectType{},
		Type:              ObjectType,
	}

	newLog.Register(newLog.GetType())

	return &newLog
}
Ejemplo n.º 14
0
Archivo: mem.go Proyecto: xh3b4sd/anna
// New creates a new configured memory file system.
func New(config Config) (servicespec.FS, error) {
	newService := &service{
		Config:  config,
		ID:      id.MustNewID(),
		Mutex:   sync.Mutex{},
		Storage: map[string][]byte{},
		Type:    ObjectType,
	}

	if newService.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}

	return newService, nil
}
Ejemplo n.º 15
0
// NewControl creates a new configured log control object.
func NewControl(config ControlConfig) (spec.LogControl, error) {
	newControl := &control{
		ControlConfig: config,
		ID:            id.MustNewID(),
		Mutex:         sync.Mutex{},
		Type:          ObjectType,
	}

	if newControl.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}

	newControl.Log.Register(newControl.GetType())

	return newControl, nil
}
Ejemplo n.º 16
0
// New creates a new configured server object.
func New(config Config) (spec.Server, error) {
	newServer := &server{
		Config: config,

		BootOnce:   sync.Once{},
		Closer:     make(chan struct{}, 1),
		GRPCServer: grpc.NewServer(),
		HTTPServer: &graceful.Server{
			NoSignalHandling: true,
			Server: &http.Server{
				Addr: config.HTTPAddr,
			},
			Timeout: 3 * time.Second,
		},
		ID:           id.MustNewID(),
		Mutex:        sync.Mutex{},
		ShutdownOnce: sync.Once{},
		Type:         spec.ObjectType(ObjectTypeServer),
	}

	// Dependencies.

	if newServer.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newServer.LogControl == nil {
		return nil, maskAnyf(invalidConfigError, "log control must not be empty")
	}
	if newServer.TextInterface == nil {
		return nil, maskAnyf(invalidConfigError, "text interface must not be empty")
	}

	// Settings.

	if newServer.GRPCAddr == "" {
		return nil, maskAnyf(invalidConfigError, "gRPC address must not be empty")
	}
	if newServer.HTTPAddr == "" {
		return nil, maskAnyf(invalidConfigError, "HTTP address must not be empty")
	}

	newServer.Log.Register(newServer.GetType())

	return newServer, nil
}
Ejemplo n.º 17
0
// NewStorage creates a new configured memory storage object. Therefore it
// manages an in-memory redis instance which can be shut down using the
// configured closer. This is used for local development.
func NewStorage(config StorageConfig) (spec.Storage, error) {
	addrChan := make(chan string, 1)
	closer := make(chan struct{}, 1)
	redisAddr := ""

	go func() {
		s, err := miniredis.Run()
		if err != nil {
			panic(err)
		}
		addrChan <- s.Addr()

		<-closer
		s.Close()
	}()

	select {
	case <-time.After(1 * time.Second):
		panic("starting miniredis timed out")
	case addr := <-addrChan:
		redisAddr = addr
	}

	newRedisStorageConfig := redis.DefaultStorageConfigWithAddr(redisAddr)
	newRedisStorageConfig.BackoffFactory = func() spec.Backoff {
		return backoff.NewExponentialBackOff()
	}
	newRedisStorage, err := redis.NewStorage(newRedisStorageConfig)
	if err != nil {
		return nil, maskAny(err)
	}

	newStorage := &storage{
		StorageConfig: config,

		Closer:       closer,
		ID:           id.MustNewID(),
		RedisStorage: newRedisStorage,
		ShutdownOnce: sync.Once{},
		Type:         ObjectType,
	}

	return newStorage, nil
}
Ejemplo n.º 18
0
// NewServer creates a new configured text interface object.
func NewServer(config ServerConfig) (TextInterfaceServer, error) {
	newServer := &server{
		ServerConfig: config,

		ID:    id.MustNewID(),
		Mutex: sync.Mutex{},
		Type:  ObjectType,
	}

	if newServer.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newServer.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "service collection must not be empty")
	}

	newServer.Log.Register(newServer.GetType())

	return newServer, nil
}
Ejemplo n.º 19
0
Archivo: main.go Proyecto: xh3b4sd/anna
// New creates a new configured command line object.
func New(config Config) (spec.Annactl, error) {
	// annactl
	newAnnactl := &annactl{
		Config: config,

		BootOnce:     sync.Once{},
		Closer:       make(chan struct{}, 1),
		ID:           id.MustNewID(),
		ShutdownOnce: sync.Once{},
		Type:         spec.ObjectType(ObjectType),
	}

	if newAnnactl.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newAnnactl.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "service collection must not be empty")
	}

	return newAnnactl, nil
}
Ejemplo n.º 20
0
// New creates a new configured activator object.
func New(config Config) (systemspec.Activator, error) {
	newActivator := &activator{
		Config: config,

		ID:   id.MustNewID(),
		Type: ObjectType,
	}

	if newActivator.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "factory collection must not be empty")
	}
	if newActivator.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newActivator.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}

	newActivator.Log.Register(newActivator.GetType())

	return newActivator, nil
}
Ejemplo n.º 21
0
// New creates a new configured CLG object.
func New(config Config) (spec.CLG, error) {
	newCLG := &clg{
		Config: config,
		ID:     id.MustNewID(),
		Name:   "islesser",
		Type:   ObjectType,
	}

	// Dependencies.
	if newCLG.ServiceCollection == nil {
		return nil, maskAnyf(invalidConfigError, "factory collection must not be empty")
	}
	if newCLG.Log == nil {
		return nil, maskAnyf(invalidConfigError, "logger must not be empty")
	}
	if newCLG.StorageCollection == nil {
		return nil, maskAnyf(invalidConfigError, "storage collection must not be empty")
	}

	newCLG.Log.Register(newCLG.GetType())

	return newCLG, nil
}