Skip to content
application.go 3.38 KiB
Newer Older
Timothee Gosselin's avatar
Timothee Gosselin committed
/*

Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.gnu.org/licenses/agpl-3.0.html

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.
*/

package application

import (
	settings "k8s.libre.sh/application/settings"
	"k8s.libre.sh/meta"
	"k8s.libre.sh/status"
)

type Meta struct {
	Version  string
	Instance string
	// Name  string
	Component string
	PartOf    string
	ManagedBy string
Timothee Gosselin's avatar
Timothee Gosselin committed
	// Namespace string
Timothee Gosselin's avatar
Timothee Gosselin committed
type Application struct {
	meta.Instance
	Settings   map[string]settings.Component
	Components map[string]Component
	Jobs       map[string]Component
	Owner      status.ObjectWithStatus
	Status     *status.ApplicationStatus
Timothee Gosselin's avatar
Timothee Gosselin committed
	Version    string
}

func (app *Application) GetVersion() string { return app.Version }
Timothee Gosselin's avatar
Timothee Gosselin committed

func (app *Application) GetJobs() map[string]Component { return app.Jobs }
Timothee Gosselin's avatar
Timothee Gosselin committed

func (app *Application) GetApplicationStatus() *status.ApplicationStatus { return app.Status }
Timothee Gosselin's avatar
Timothee Gosselin committed

func (app *Application) GetComponents() map[string]Component { return app.Components }
Timothee Gosselin's avatar
Timothee Gosselin committed

func (app *Application) GetOwner() status.ObjectWithStatus { return app.Owner }
Timothee Gosselin's avatar
Timothee Gosselin committed

func (app *Application) GetSettings() map[string]settings.Component { return app.Settings }
Timothee Gosselin's avatar
Timothee Gosselin committed

func (app *Application) SetDefaults() {}

/* func NewApplication(i Instance) *Application {
Timothee Gosselin's avatar
Timothee Gosselin committed

	app := &Application{}
	app.Settings = make(map[string]settings.Component, len(i.GetSettings()))
	app.Components = make(map[string]Component, len(i.GetComponents()))
	app.Jobs = make(map[string]Component, len(i.GetJobs()))

	for k, v := range i.GetSettings() {
		v.SetDefaults()
		app.Settings[k] = settings.NewSettings(v.GetCreateOptions(), v.GetSources(), v.GetParameters())
Timothee Gosselin's avatar
Timothee Gosselin committed
	}

	for k, v := range i.GetComponents() {
		v.SetDefaults()
		app.Components[k] = v
	}

	for k, v := range i.GetJobs() {
		v.Init()
		v.SetDefaults()
		app.Jobs[k] = v
	}

	om := &meta.ObjectMeta{
		Labels:      i.GetLabels(),
		Annotations: i.GetLabels(),
		Name:        i.GetName(),
		Namespace:   i.GetNamespace(),
	}
	app.Instance = om
	app.Owner = i.GetOwner()
	app.Version = i.GetVersion()
	app.Status = i.GetApplicationStatus()
Timothee Gosselin's avatar
Timothee Gosselin committed

	return app
}
*/
func NewApplication(setts map[string]settings.Component, cpts, jobs map[string]Component, owner status.ObjectWithStatus, m meta.Instance) *Application {
Timothee Gosselin's avatar
Timothee Gosselin committed

	app := &Application{}
	app.Settings = make(map[string]settings.Component, len(setts))
	app.Components = make(map[string]Component, len(cpts))
	app.Jobs = make(map[string]Component, len(jobs))

	for k, v := range setts {
		//	v.SetDefaults()
Timothee Gosselin's avatar
Timothee Gosselin committed
		app.Settings[k] = settings.NewSettings(v.GetCreateOptions(), v.GetSources(), v.GetParameters())
	}

	for k, v := range cpts {
		//	v.SetDefaults()
Timothee Gosselin's avatar
Timothee Gosselin committed
		app.Components[k] = v
	}

	for k, v := range jobs {
		//	v.SetDefaults()
Timothee Gosselin's avatar
Timothee Gosselin committed
		app.Jobs[k] = v
	}

	/* 	om := &meta.ObjectMeta{
Timothee Gosselin's avatar
Timothee Gosselin committed
		//		Labels:      i.GetLabels(),
		//		Annotations: i.GetLabels(),
		Name:      m.GetName(),
		Namespace: m.GetNamespace(),
	} */
	app.Instance = m
Timothee Gosselin's avatar
Timothee Gosselin committed
	app.Owner = owner
	app.Version = m.GetVersion()
	ownerStatus := owner.GetApplicationStatus()
	app.Status = ownerStatus.DeepCopy()
Timothee Gosselin's avatar
Timothee Gosselin committed
	return app
}