model

package
v0.0.0-...-bc7948d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2016 Nuxeo SA (http://nuxeo.com/) and others.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	START_ACTION         = "start"
	STOP_ACTION          = "stop"
	DELETE_ACTION        = "delete"
	UPDATE_ACTION        = "update"
	UPGRADE_ACTION       = "upgrade"
	FINISHUPGRADE_ACTION = "finishupgrade"
	ROLLBACK_ACTION      = "rollback"
)
View Source
const (
	STARTING_STATUS   = "starting"
	STARTED_STATUS    = "started"
	STOPPING_STATUS   = "stopping"
	STOPPED_STATUS    = "stopped"
	ERROR_STATUS      = "error"
	WARNING_STATUS    = "warning"
	NA_STATUS         = "n/a"
	PASSIVATED_STATUS = "passivated"
)

Variables

This section is empty.

Functions

func AddAction

func AddAction(s *Service, actions ...string)

func FromInterfaceChannel

func FromInterfaceChannel(fromChannel chan interface{}) chan *ModelEvent

Transform a generic interface channel to a *ModelEvent channel

func GetActions

func GetActions(s *Service) []string

compute default actions based on the status of the service avoids to return a list of actions when the service is in starting or stopping status doesn't modify the list of actions on the service, and returns a simple string array as the actions are persisted

func InitActions

func InitActions(s *Service) []string

called on create service, the service is stopped

Types

type Broadcaster

type Broadcaster struct {
	// contains filtered or unexported fields
}

Simple structure that implements a publish/subscribe mecanism.

func NewBroadcaster

func NewBroadcaster() *Broadcaster

func (*Broadcaster) Listen

func (b *Broadcaster) Listen() chan interface{}

func (*Broadcaster) Write

func (b *Broadcaster) Write(message interface{})

type Domain

type Domain struct {
	NodeKey string `json:"-"`
	Name    string `json:"name,omitempty"`
	Typ     string `json:"type,omitempty"`
	Value   string `json:"value,omitempty"`
}

A Domain in the Arken model is of a given and may point to a service (if type is service)

func (*Domain) Equals

func (domain *Domain) Equals(other *Domain) bool

func (*Domain) String

func (d *Domain) String() string

type FleetInfoType

type FleetInfoType struct {
	UnitName string
}

type Location

type Location struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

func (*Location) Equals

func (s *Location) Equals(other *Location) bool

func (*Location) IsFullyDefined

func (s *Location) IsFullyDefined() bool

func (Location) String

func (s Location) String() string

type Model

type Model struct {
	Domains  map[string]*Domain
	Services map[string]*Service
	// contains filtered or unexported fields
}

The Arken model is a structure that holds a map of Services and a map of Domain. A Model MUST be backed by a PersistenceDriver and MAY drivre ServiceDriver.

func NewArkenModel

func NewArkenModel(sDriver ServiceDriver, pDriver PersistenceDriver) (*Model, error)

Create an ArkenModel base on a serviceDriver and a PersistenceDriver. The ServiceDriver is optional.

func (*Model) CreateDomain

func (m *Model) CreateDomain(domain *Domain) (*Domain, error)

Creates a Domain

func (*Model) CreateService

func (m *Model) CreateService(service *Service, startOnCreate bool) (*Service, error)

Creates a Service and starts it if asked. If the Domain of the service is provided, then the corresponding domain is also created.

func (*Model) DestroyDomain

func (m *Model) DestroyDomain(domain *Domain) error

Destroys a Domain

func (*Model) DestroyService

func (m *Model) DestroyService(service *Service) error

Destroys a service (only works if ServiceDriver is set)

func (*Model) FinishUpgradeService

func (m *Model) FinishUpgradeService(service *Service) (*Service, error)

func (*Model) Init

func (m *Model) Init() error

Inits the model. It loads the model from the persistence driver and then listen to changes. It also starts listening on service driver updates.

func (*Model) Listen

func (m *Model) Listen() chan *ModelEvent

Returns a channel of ModelEvent where all changes in the model (Service or Domain) are published.

func (*Model) NeedToBeUpgraded

func (m *Model) NeedToBeUpgraded(service *Service) (bool, error)

func (*Model) PassivateService

func (m *Model) PassivateService(service *Service) (*Service, error)

Passivates a service (only works if ServiceDriver is set)

func (*Model) RollbackService

func (m *Model) RollbackService(service *Service) (*Service, error)

func (*Model) StartService

func (m *Model) StartService(service *Service) (*Service, error)

Starts a service (only works if ServiceDriver is set)

func (*Model) StopService

func (m *Model) StopService(service *Service) (*Service, error)

Stops a service (only works if ServiceDriver is set)

func (*Model) SyncService

func (m *Model) SyncService(service *Service)

Synchronize ServiceDriver state with internal Arken state

func (*Model) UpdateDomain

func (m *Model) UpdateDomain(domain *Domain) (*Domain, error)

Updates a domain

func (*Model) UpdateService

func (m *Model) UpdateService(service *Service) (*Service, error)

func (*Model) UpgradeService

func (m *Model) UpgradeService(service *Service) (*Service, error)

type ModelByTime

type ModelByTime []*ModelEvent

This type allow to sort ModelEvents by creation time.

func (ModelByTime) Len

func (m ModelByTime) Len() int

func (ModelByTime) Less

func (m ModelByTime) Less(i, j int) bool

func (ModelByTime) Swap

func (m ModelByTime) Swap(i, j int)

type ModelEvent

type ModelEvent struct {
	EventType string
	ModelType string
	Model     interface{}
	Time      time.Time
}

That struct hold an event for a Model (Service, ServiceCluster or Domain)

func NewModelEvent

func NewModelEvent(eventType string, model interface{}) *ModelEvent

Creates a new ModelEvent

func (*ModelEvent) String

func (me *ModelEvent) String() string

type PassivationConfig

type PassivationConfig struct {
	DelayInSeconds int    `json:"delayInSeconds,omitempty"`
	Enabled        bool   `json:"enabled,omitempty"`
	Action         string `json:"action,omitempty"`
}

func DefaultPassivation

func DefaultPassivation() *PassivationConfig

type PersistenceDriver

type PersistenceDriver interface {
	LoadAllServices() (map[string]*Service, error)
	LoadService(serviceName string) (*Service, error)
	PersistService(*Service) (*Service, error)
	DestroyService(*Service) error

	LoadAllDomains() (map[string]*Domain, error)
	LoadDomain(serviceName string) (*Domain, error)
	PersistDomain(*Domain) (*Domain, error)
	DestroyDomain(*Domain) error

	Listen() chan *ModelEvent
}

This drivers allow to persist the model in a backend.

type PrettyAction

type PrettyAction struct {
	//the name of the action
	Name string `json:"name"`
	//is a POST/PUT /DELETE
	Method string `json:"method"`
	//the url to invoke to execute this action on the service
	Url string `json:"url"`
}

represents the action as returned in the service

func GetPrettyActions

func GetPrettyActions(s *Service, url *url.URL) []PrettyAction

returns an array of actions with more details ( method, url)

type RancherInfoType

type RancherInfoType struct {
	EnvironmentId   string    `json:"environmentId,omitempty"`
	EnvironmentName string    `json:"environmentName,omitempty"`
	Location        *Location `json:"location,omitempty"`
	HealthState     string    `json:"healthState,omitempty"`
	CurrentStatus   string    `json:"currentStatus,omitempty"`
	TemplateId      string    `json:"templateId,omitempty"`
}

func (RancherInfoType) String

func (r RancherInfoType) String() string

type Service

type Service struct {
	NodeKey    string         `json:"-"`
	Location   *Location      `json:"location"`
	Domain     string         `json:"domain"`
	Name       string         `json:"name"`
	Status     *Status        `json:"status"`
	Actions    interface{}    `json:"actions"`
	LastAccess *time.Time     `json:"lastAccess"`
	Config     *ServiceConfig `json:"config"`
	// contains filtered or unexported fields
}

Holds information about a given service

func (*Service) Equals

func (service *Service) Equals(other *Service) bool

func (*Service) Init

func (s *Service) Init() *Service

func (*Service) StartedSince

func (s *Service) StartedSince() *time.Time

type ServiceConfig

type ServiceConfig struct {
	Robots      string                 `json:"robots"`
	Environment map[string]interface{} `json:"environment,omitempty"`
	// Rancher backed service information
	RancherInfo *RancherInfoType `json:"rancherInfo,omitempty"`
	// Fleet backed service information
	FleetInfo   *FleetInfoType     `json:"fleetInfo,omitempty"`
	Passivation *PassivationConfig `json:"passivation,omitempty`
}

Holds configuration of the service

func (*ServiceConfig) Equals

func (config *ServiceConfig) Equals(other *ServiceConfig) bool

type ServiceDriver

type ServiceDriver interface {
	// Creates a service and start it if asked.
	Create(s *Service, startOnCreate bool) (interface{}, error)

	// Starts a given service
	Start(s *Service) (interface{}, error)

	// Upgrades a given service
	Upgrade(s *Service) (interface{}, error)

	//Finishes the upgrade
	FinishUpgrade(s *Service) (interface{}, error)

	//Rollbacks after the upgrade
	Rollback(s *Service) (interface{}, error)

	// Stops a given service
	Stop(s *Service) (interface{}, error)

	// Destroys a given service
	Destroy(s *Service) error

	// Returns a channell where ModelEvent are published by the service driver
	Listen() chan *ModelEvent

	// Returns the driver's information for a given service
	GetInfo(s *Service) (interface{}, error)

	// Tells if the service need to be upgrade when compared to its definition
	NeedToBeUpgraded(s *Service) (bool, error)
}

A driver knows how to create and manage Services.

type Status

type Status struct {
	// Is the service alive
	Alive string `json:"alive"`

	// Current status of the service
	Current string `json:"current"`

	// Expected status of the service
	Expected string `json:"expected"`

	Service *Service `json:"-"`
}

Represents the combined status of a service

func NewInitialStatus

func NewInitialStatus(initialStatus string, service *Service) *Status

Creates a Status for a service with an initial value

func (*Status) Compute

func (s *Status) Compute() string

Computes the real status of the service made by the combination of current and expected state.

func (*Status) Equals

func (s *Status) Equals(other *Status) bool

type StatusError

type StatusError struct {
	ComputedStatus string
	Status         *Status
}

Represents an error for a given status.

func (StatusError) Error

func (s StatusError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL