Skip to content

Commit 4716fff

Browse files
committed
[core] Beginning of confsys.Service for configuration overhaul
1 parent ae13a7e commit 4716fff

1 file changed

Lines changed: 124 additions & 0 deletions

File tree

core/confsys/service.go

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* === This file is part of ALICE O² ===
3+
*
4+
* Copyright 2019 CERN and copyright holders of ALICE O².
5+
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*
20+
* In applying this license CERN does not waive the privileges and
21+
* immunities granted to it by virtue of its status as an
22+
* Intergovernmental Organization or submit itself to any jurisdiction.
23+
*/
24+
25+
package confsys
26+
27+
import (
28+
"io/ioutil"
29+
"strconv"
30+
"strings"
31+
32+
"github.com/AliceO2Group/Control/configuration"
33+
)
34+
35+
36+
type Service struct {
37+
src configuration.Source
38+
}
39+
40+
/* Expected structure:
41+
/o2/aliecs/
42+
{
43+
run_number_file: "/path/to/rn/file",
44+
- or -
45+
run_number: 47102,
46+
47+
settings: {
48+
log_level: "DEBUG"
49+
},
50+
global_vars: {
51+
n_flps: 42
52+
},
53+
repositories: {
54+
base: {
55+
url: "https://gitlab.cern.ch/foo/bar",
56+
user: "gituser",
57+
pass: "gitpass"
58+
},
59+
extra: {...}
60+
}
61+
}
62+
63+
*/
64+
func formatKey(key string) (consulKey string) {
65+
// Trim leading slashes
66+
consulKey = strings.TrimLeft(key, "/")
67+
return
68+
}
69+
70+
func NewService(uri string) (svc *Service, err error) {
71+
var src configuration.Source
72+
src, err = configuration.NewSource(uri)
73+
return &Service{src: src}, err
74+
}
75+
76+
func (s *Service) NewRunNumber() (runNumber uint64, err error) {
77+
if cSrc, ok := s.src.(*configuration.ConsulSource); ok {
78+
return cSrc.GetNextUInt64("o2/control/run_number")
79+
} else {
80+
// Unsafe check-and-set, only for file backend
81+
var rnf string
82+
rnf, err = s.src.Get("o2/control/run_number_file")
83+
if err != nil {
84+
return
85+
}
86+
var raw []byte
87+
raw, err = ioutil.ReadFile(rnf)
88+
if err != nil {
89+
return
90+
}
91+
runNumber, err = strconv.ParseUint(string(raw[:]), 10, 64)
92+
if err != nil {
93+
return
94+
}
95+
runNumber++
96+
raw = []byte(strconv.FormatUint(runNumber, 10))
97+
err = ioutil.WriteFile(rnf, raw, 0)
98+
return
99+
}
100+
}
101+
102+
func (s *Service) GetROSource() configuration.ROSource {
103+
return s.src
104+
}
105+
106+
// maybe this one shouldn't exist at all, because vars should get inserted
107+
// response: but not all of them! some vars will likely only get parsed at deployment time i.e. right
108+
// before pushing TaskInfos
109+
func (s *Service) GetVars() map[string]string {
110+
//FIXME: implement
111+
return nil
112+
}
113+
114+
// Or maybe even "RefreshConfig" which will refresh all the things that happen to be runtime-refreshable
115+
func (s *Service) RefreshRepositories() {
116+
panic("not implemented yet")
117+
}
118+
119+
// Returns a YAML file OR even a structure made of Roles or Nodes with:
120+
// import() functions already computed and resolved
121+
// vars inserted (todo: figure out which vars get parsed when and where)
122+
func (s *Service) GenerateWorkflowDescriptor(wfPath string, vars map[string]string /*vars from cli/gui*/) string {
123+
panic("not implemented yet")
124+
}

0 commit comments

Comments
 (0)