generated from snivilised/astrolib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
builders.go
128 lines (112 loc) Β· 2.75 KB
/
builders.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package age
import (
"github.com/snivilised/agenor/enums"
"github.com/snivilised/agenor/internal/enclave"
"github.com/snivilised/agenor/internal/kernel"
"github.com/snivilised/agenor/internal/third/lo"
"github.com/snivilised/agenor/pref"
)
type buildArtefacts struct {
o *pref.Options
kc enclave.KernelController
plugins []enclave.Plugin
ext extent
swappable enclave.Swapper
}
// Builders performs build orchestration via its buildAll method. Builders
// is instructed by the factories (via Configure) of which there are 2; one
// for Walk and one for Run. The Prime/Resume extents create the Builders
// instance.
type Builders struct {
facade pref.Facade
scaffold scaffoldBuilder
navigator kernel.NavigatorBuilder
plugins pluginsBuilder
extent extentBuilder
}
func (bs *Builders) buildAll(addons ...Addon) (*buildArtefacts, error) {
// BUILD SCAFFOLD
//
scaffold, err := bs.scaffold.build(addons...)
harvest := scaffold.harvest()
ext := scaffold.extent()
o := harvest.Options()
if err != nil {
o.Monitor.Log.Error(err.Error())
return &buildArtefacts{
o: o,
kc: kernel.HadesNav(o, err),
ext: ext,
}, err
}
// BUILD NAVIGATOR
//
artefacts := bs.navigator.Build(&kernel.Inception{
Facade: ext.facade(),
Subscription: ext.subscription(),
Harvest: harvest,
Resources: &enclave.Resources{
Forest: ext.forest(),
Supervisor: enclave.NewSupervisor(),
Binder: harvest.Binder(),
},
})
if artefacts.Error != nil {
return &buildArtefacts{
o: o,
kc: kernel.HadesNav(o, err),
ext: ext,
swappable: artefacts.Mediator,
}, artefacts.Error
}
// BUILD PLUGINS
//
plugins, err := bs.plugins.build(o,
ext,
artefacts,
ext.plugin(artefacts),
)
if err != nil {
o.Monitor.Log.Error(err.Error())
return &buildArtefacts{
o: o,
kc: kernel.HadesNav(o, err),
ext: ext,
swappable: artefacts.Mediator,
}, err
}
// INIT PLUGINS
//
activeRoles := lo.Map(plugins,
func(plugin enclave.Plugin, _ int) enums.Role {
return plugin.Role()
},
)
order := manifest(activeRoles)
artefacts.Mediator.Arrange(activeRoles, order)
pi := &enclave.PluginInit{
O: o,
Kontroller: artefacts.Kontroller,
Controls: harvest.Binder().Controls,
Resources: artefacts.Resources,
}
for _, p := range plugins {
if err := p.Init(pi); err != nil {
o.Monitor.Log.Error(err.Error())
return &buildArtefacts{
o: o,
kc: artefacts.Kontroller,
plugins: plugins,
ext: ext,
swappable: artefacts.Mediator,
}, err
}
}
return &buildArtefacts{
o: o,
kc: artefacts.Kontroller,
plugins: plugins,
ext: ext,
swappable: artefacts.Mediator,
}, nil
}