vagrant-bosh 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -6
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/agent-log +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/agent-run +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/agent.cert +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/agent.json +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/agent.key +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/bosh-agent +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/bosh-agent-rc +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/agent/bosh-blobstore-dav +0 -0
- data/bosh-provisioner/assets/bosh-provisioner +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/monit/monit +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/monit/monit-log +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/monit/monit-run +0 -0
- data/{lib/vagrant-bosh → bosh-provisioner}/assets/monit/monitrc +0 -0
- data/dev/Vagrantfile +1 -1
- data/dev/example-bosh-manifest.yml +12 -12
- data/lib/vagrant-bosh/bootstrapper.rb +6 -2
- data/lib/vagrant-bosh/config.rb +1 -1
- data/lib/vagrant-bosh/provisioner.rb +1 -1
- data/lib/vagrant-bosh/version.rb +1 -1
- data/vagrant-bosh.gemspec +3 -1
- metadata +20 -139
- data/go/.gitignore +0 -11
- data/go/bin/build +0 -10
- data/go/bin/build-linux-amd64 +0 -9
- data/go/bin/env +0 -13
- data/go/bin/go +0 -5
- data/go/bin/golint +0 -19
- data/go/bin/test +0 -37
- data/go/src/boshprovisioner/agent/client/client_interface.go +0 -73
- data/go/src/boshprovisioner/agent/client/fakes/fake_client.go +0 -81
- data/go/src/boshprovisioner/agent/client/http_client.go +0 -299
- data/go/src/boshprovisioner/agent/client/http_client_envelope.go +0 -107
- data/go/src/boshprovisioner/deployment/deployment.go +0 -221
- data/go/src/boshprovisioner/deployment/instance.go +0 -54
- data/go/src/boshprovisioner/deployment/manifest/deployment.go +0 -84
- data/go/src/boshprovisioner/deployment/manifest/ips.go +0 -23
- data/go/src/boshprovisioner/deployment/manifest/manifest.go +0 -143
- data/go/src/boshprovisioner/deployment/manifest/manifest_suite_test.go +0 -13
- data/go/src/boshprovisioner/deployment/manifest/manifest_test.go +0 -86
- data/go/src/boshprovisioner/deployment/manifest/syntax_validator.go +0 -186
- data/go/src/boshprovisioner/deployment/manifest/watch_time.go +0 -43
- data/go/src/boshprovisioner/deployment/manifest_reader.go +0 -46
- data/go/src/boshprovisioner/deployment/reader_factory.go +0 -25
- data/go/src/boshprovisioner/deployment/semantic_validator.go +0 -111
- data/go/src/boshprovisioner/downloader/blobstore_downloader.go +0 -55
- data/go/src/boshprovisioner/downloader/default_mux_downloader.go +0 -22
- data/go/src/boshprovisioner/downloader/downloader_interface.go +0 -6
- data/go/src/boshprovisioner/downloader/http_downloader.go +0 -53
- data/go/src/boshprovisioner/downloader/local_fs_downloader.go +0 -48
- data/go/src/boshprovisioner/downloader/mux_downloader.go +0 -69
- data/go/src/boshprovisioner/eventlog/log.go +0 -72
- data/go/src/boshprovisioner/eventlog/stage.go +0 -39
- data/go/src/boshprovisioner/eventlog/task.go +0 -58
- data/go/src/boshprovisioner/index/file_index.go +0 -289
- data/go/src/boshprovisioner/index/file_index_test.go +0 -296
- data/go/src/boshprovisioner/index/index_interface.go +0 -18
- data/go/src/boshprovisioner/index/index_suite_test.go +0 -13
- data/go/src/boshprovisioner/instance/instance.go +0 -43
- data/go/src/boshprovisioner/instance/instance_provisioner.go +0 -48
- data/go/src/boshprovisioner/instance/templatescompiler/concrete_templates_compiler.go +0 -284
- data/go/src/boshprovisioner/instance/templatescompiler/erbrenderer/erb_renderer.go +0 -117
- data/go/src/boshprovisioner/instance/templatescompiler/erbrenderer/erbrenderer_suite_test.go +0 -13
- data/go/src/boshprovisioner/instance/templatescompiler/erbrenderer/render_properties.go +0 -77
- data/go/src/boshprovisioner/instance/templatescompiler/erbrenderer/render_properties_test.go +0 -193
- data/go/src/boshprovisioner/instance/templatescompiler/erbrenderer/template_evaluation_context.go +0 -85
- data/go/src/boshprovisioner/instance/templatescompiler/erbrenderer/template_evaluation_context_rb.go +0 -155
- data/go/src/boshprovisioner/instance/templatescompiler/jobsrepo/concrete_jobs_repository.go +0 -86
- data/go/src/boshprovisioner/instance/templatescompiler/jobsrepo/concrete_runtime_packages_repository.go +0 -113
- data/go/src/boshprovisioner/instance/templatescompiler/jobsrepo/concrete_template_to_job_repository.go +0 -86
- data/go/src/boshprovisioner/instance/templatescompiler/jobsrepo/jobs_repository_interface.go +0 -49
- data/go/src/boshprovisioner/instance/templatescompiler/rendered_archives_compiler.go +0 -81
- data/go/src/boshprovisioner/instance/templatescompiler/templates_compiler_interface.go +0 -20
- data/go/src/boshprovisioner/instance/templatescompiler/templatesrepo/ct_repository.go +0 -54
- data/go/src/boshprovisioner/instance/templatescompiler/templatesrepo/templates_repository_interface.go +0 -16
- data/go/src/boshprovisioner/instance/updater/applier/applier.go +0 -93
- data/go/src/boshprovisioner/instance/updater/applier/empty_state.go +0 -66
- data/go/src/boshprovisioner/instance/updater/applier/job_state.go +0 -178
- data/go/src/boshprovisioner/instance/updater/drainer.go +0 -72
- data/go/src/boshprovisioner/instance/updater/starter.go +0 -36
- data/go/src/boshprovisioner/instance/updater/stopper.go +0 -36
- data/go/src/boshprovisioner/instance/updater/updater.go +0 -97
- data/go/src/boshprovisioner/instance/updater/updater_factory.go +0 -80
- data/go/src/boshprovisioner/instance/updater/updater_suite_test.go +0 -13
- data/go/src/boshprovisioner/instance/updater/waiter.go +0 -77
- data/go/src/boshprovisioner/instance/updater/waiter_test.go +0 -147
- data/go/src/boshprovisioner/main/config.go +0 -95
- data/go/src/boshprovisioner/main/config_test.go +0 -67
- data/go/src/boshprovisioner/main/main.go +0 -185
- data/go/src/boshprovisioner/main/main_suite_test.go +0 -13
- data/go/src/boshprovisioner/main/repos_factory.go +0 -86
- data/go/src/boshprovisioner/packagescompiler/compiledpackagesrepo/compiled_packages_repository_interface.go +0 -17
- data/go/src/boshprovisioner/packagescompiler/compiledpackagesrepo/concrete_compiled_packages_repository.go +0 -61
- data/go/src/boshprovisioner/packagescompiler/concrete_packages_compiler.go +0 -179
- data/go/src/boshprovisioner/packagescompiler/concrete_packages_compiler_factory.go +0 -48
- data/go/src/boshprovisioner/packagescompiler/packages_compiler_interface.go +0 -20
- data/go/src/boshprovisioner/packagescompiler/packagesrepo/concrete_packages_repository.go +0 -65
- data/go/src/boshprovisioner/packagescompiler/packagesrepo/packages_repository_interface.go +0 -16
- data/go/src/boshprovisioner/provisioner/blobstore_config.go +0 -65
- data/go/src/boshprovisioner/provisioner/blobstore_provisioner.go +0 -38
- data/go/src/boshprovisioner/provisioner/deployment_provisioner_interface.go +0 -10
- data/go/src/boshprovisioner/provisioner/release_compiler.go +0 -95
- data/go/src/boshprovisioner/provisioner/single_configured_vm_provisioner.go +0 -124
- data/go/src/boshprovisioner/provisioner/single_non_configured_vm_provisioner.go +0 -40
- data/go/src/boshprovisioner/provisioner/single_vm_provisioner_factory.go +0 -68
- data/go/src/boshprovisioner/release/dir_reader.go +0 -146
- data/go/src/boshprovisioner/release/job/job.go +0 -86
- data/go/src/boshprovisioner/release/job/manifest/manifest.go +0 -79
- data/go/src/boshprovisioner/release/job/manifest/manifest_suite_test.go +0 -13
- data/go/src/boshprovisioner/release/job/manifest/manifest_test.go +0 -59
- data/go/src/boshprovisioner/release/job/manifest/syntax_validator.go +0 -43
- data/go/src/boshprovisioner/release/job/reader_factory.go +0 -34
- data/go/src/boshprovisioner/release/job/tar_reader.go +0 -133
- data/go/src/boshprovisioner/release/manifest/manifest.go +0 -120
- data/go/src/boshprovisioner/release/manifest/manifest_suite_test.go +0 -13
- data/go/src/boshprovisioner/release/manifest/manifest_test.go +0 -126
- data/go/src/boshprovisioner/release/manifest/syntax_validator.go +0 -134
- data/go/src/boshprovisioner/release/reader_factory.go +0 -45
- data/go/src/boshprovisioner/release/reader_interface.go +0 -6
- data/go/src/boshprovisioner/release/release.go +0 -144
- data/go/src/boshprovisioner/release/release_suite_test.go +0 -13
- data/go/src/boshprovisioner/release/release_test.go +0 -129
- data/go/src/boshprovisioner/release/tar_reader.go +0 -141
- data/go/src/boshprovisioner/tar/cmd_compressor.go +0 -68
- data/go/src/boshprovisioner/tar/cmd_extractor.go +0 -47
- data/go/src/boshprovisioner/tar/compressor_interface.go +0 -6
- data/go/src/boshprovisioner/tar/extractor_interface.go +0 -6
- data/go/src/boshprovisioner/util/possible_base64.go +0 -21
- data/go/src/boshprovisioner/util/string_keyed.go +0 -70
- data/go/src/boshprovisioner/vm/vagrant/agent_provisioner.go +0 -296
- data/go/src/boshprovisioner/vm/vagrant/asset_manager.go +0 -61
- data/go/src/boshprovisioner/vm/vagrant/configured_vm.go +0 -29
- data/go/src/boshprovisioner/vm/vagrant/deps_provisioner.go +0 -214
- data/go/src/boshprovisioner/vm/vagrant/monit_provisioner.go +0 -85
- data/go/src/boshprovisioner/vm/vagrant/non_configured_vm.go +0 -26
- data/go/src/boshprovisioner/vm/vagrant/runit_provisioner.go +0 -229
- data/go/src/boshprovisioner/vm/vagrant/simple_cmds.go +0 -54
- data/go/src/boshprovisioner/vm/vagrant/vcap_user_provisioner.go +0 -167
- data/go/src/boshprovisioner/vm/vagrant/vm_provisioner.go +0 -119
- data/go/src/boshprovisioner/vm/vagrant/vm_provisioner_factory.go +0 -101
- data/go/src/boshprovisioner/vm/vm_interface.go +0 -45
- data/lib/vagrant-bosh/assets/provisioner +0 -0
@@ -1,72 +0,0 @@
|
|
1
|
-
package eventlog
|
2
|
-
|
3
|
-
import (
|
4
|
-
"encoding/json"
|
5
|
-
"io"
|
6
|
-
"os"
|
7
|
-
|
8
|
-
bosherr "bosh/errors"
|
9
|
-
boshlog "bosh/logger"
|
10
|
-
)
|
11
|
-
|
12
|
-
const logLogTag = "Log"
|
13
|
-
|
14
|
-
type Log struct {
|
15
|
-
writer io.Writer
|
16
|
-
logger boshlog.Logger
|
17
|
-
}
|
18
|
-
|
19
|
-
type logEntry struct {
|
20
|
-
Time int64 `json:"time"`
|
21
|
-
|
22
|
-
Stage string `json:"stage"`
|
23
|
-
Task string `json:"task"`
|
24
|
-
Tags []string `json:"tags"`
|
25
|
-
|
26
|
-
Total int `json:"total"`
|
27
|
-
Index int `json:"index"`
|
28
|
-
|
29
|
-
State string `json:"state"`
|
30
|
-
Progress int `json:"progress"`
|
31
|
-
|
32
|
-
// Might contain error key
|
33
|
-
Data map[string]interface{} `json:"data,omitempty"`
|
34
|
-
}
|
35
|
-
|
36
|
-
func NewLog(logger boshlog.Logger) Log {
|
37
|
-
return Log{
|
38
|
-
writer: os.Stdout,
|
39
|
-
logger: logger,
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
func (l Log) BeginStage(name string, total int) *Stage {
|
44
|
-
return &Stage{
|
45
|
-
log: l,
|
46
|
-
name: name,
|
47
|
-
total: total,
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
func (l Log) writeLogEntryNoErr(entry logEntry) {
|
52
|
-
err := l.writeLogEntry(entry)
|
53
|
-
if err != nil {
|
54
|
-
l.logger.Error(logLogTag, "Failed writing log entry %s", err.Error())
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
func (l Log) writeLogEntry(entry logEntry) error {
|
59
|
-
bytes, err := json.Marshal(entry)
|
60
|
-
if err != nil {
|
61
|
-
return bosherr.WrapError(err, "Marshalling log entry")
|
62
|
-
}
|
63
|
-
|
64
|
-
bytes = append(bytes, []byte("\n")...)
|
65
|
-
|
66
|
-
_, err = l.writer.Write(bytes)
|
67
|
-
if err != nil {
|
68
|
-
return bosherr.WrapError(err, "Writing log entry")
|
69
|
-
}
|
70
|
-
|
71
|
-
return nil
|
72
|
-
}
|
@@ -1,39 +0,0 @@
|
|
1
|
-
package eventlog
|
2
|
-
|
3
|
-
import (
|
4
|
-
"sync"
|
5
|
-
)
|
6
|
-
|
7
|
-
type Stage struct {
|
8
|
-
log Log
|
9
|
-
|
10
|
-
name string
|
11
|
-
|
12
|
-
total int
|
13
|
-
currTaskIndex int
|
14
|
-
|
15
|
-
indexLock sync.Mutex
|
16
|
-
}
|
17
|
-
|
18
|
-
func (s *Stage) BeginTask(name string) Task {
|
19
|
-
s.indexLock.Lock()
|
20
|
-
|
21
|
-
index := s.currTaskIndex
|
22
|
-
s.currTaskIndex++
|
23
|
-
|
24
|
-
s.indexLock.Unlock()
|
25
|
-
|
26
|
-
task := Task{
|
27
|
-
log: s.log,
|
28
|
-
|
29
|
-
stageName: s.name,
|
30
|
-
name: name,
|
31
|
-
|
32
|
-
total: s.total,
|
33
|
-
index: index,
|
34
|
-
}
|
35
|
-
|
36
|
-
task.Start()
|
37
|
-
|
38
|
-
return task
|
39
|
-
}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
package eventlog
|
2
|
-
|
3
|
-
import (
|
4
|
-
"time"
|
5
|
-
)
|
6
|
-
|
7
|
-
type Task struct {
|
8
|
-
log Log
|
9
|
-
|
10
|
-
stageName string
|
11
|
-
name string
|
12
|
-
|
13
|
-
total int
|
14
|
-
index int
|
15
|
-
}
|
16
|
-
|
17
|
-
func (t Task) Start() {
|
18
|
-
entry := logEntry{
|
19
|
-
Time: time.Now().Unix(),
|
20
|
-
|
21
|
-
Stage: t.stageName,
|
22
|
-
Task: t.name,
|
23
|
-
|
24
|
-
Total: t.total,
|
25
|
-
Index: t.index,
|
26
|
-
|
27
|
-
State: "started",
|
28
|
-
Progress: 0,
|
29
|
-
}
|
30
|
-
|
31
|
-
t.log.writeLogEntryNoErr(entry)
|
32
|
-
}
|
33
|
-
|
34
|
-
func (t Task) End(err error) error {
|
35
|
-
entry := logEntry{
|
36
|
-
Time: time.Now().Unix(),
|
37
|
-
|
38
|
-
Stage: t.stageName,
|
39
|
-
Task: t.name,
|
40
|
-
|
41
|
-
Total: t.total,
|
42
|
-
Index: t.index,
|
43
|
-
|
44
|
-
State: "finished",
|
45
|
-
Progress: 100,
|
46
|
-
}
|
47
|
-
|
48
|
-
if err != nil {
|
49
|
-
entry.State = "failed"
|
50
|
-
entry.Data = map[string]interface{}{
|
51
|
-
"error": err.Error(),
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
t.log.writeLogEntryNoErr(entry)
|
56
|
-
|
57
|
-
return err
|
58
|
-
}
|
@@ -1,289 +0,0 @@
|
|
1
|
-
package index
|
2
|
-
|
3
|
-
import (
|
4
|
-
"encoding/json"
|
5
|
-
"reflect"
|
6
|
-
|
7
|
-
bosherr "bosh/errors"
|
8
|
-
boshsys "bosh/system"
|
9
|
-
)
|
10
|
-
|
11
|
-
type FileIndex struct {
|
12
|
-
path string
|
13
|
-
fs boshsys.FileSystem
|
14
|
-
}
|
15
|
-
|
16
|
-
type indexEntry struct {
|
17
|
-
Key map[string]interface{}
|
18
|
-
Value json.RawMessage
|
19
|
-
}
|
20
|
-
|
21
|
-
func NewFileIndex(path string, fs boshsys.FileSystem) FileIndex {
|
22
|
-
return FileIndex{path: path, fs: fs}
|
23
|
-
}
|
24
|
-
|
25
|
-
func (ri FileIndex) List(entries interface{}) error {
|
26
|
-
rawEntries, err := ri.readRawEntries()
|
27
|
-
if err != nil {
|
28
|
-
return err
|
29
|
-
}
|
30
|
-
|
31
|
-
var rawEntryValues []json.RawMessage
|
32
|
-
|
33
|
-
for _, rawEntry := range rawEntries {
|
34
|
-
rawEntryValues = append(rawEntryValues, rawEntry.Value)
|
35
|
-
}
|
36
|
-
|
37
|
-
// todo avoid serializing already collected entries
|
38
|
-
rawEntryValuesBytes, err := json.Marshal(rawEntryValues)
|
39
|
-
if err != nil {
|
40
|
-
return err
|
41
|
-
}
|
42
|
-
|
43
|
-
err = json.Unmarshal(rawEntryValuesBytes, entries)
|
44
|
-
if err != nil {
|
45
|
-
return err
|
46
|
-
}
|
47
|
-
|
48
|
-
return nil
|
49
|
-
}
|
50
|
-
|
51
|
-
func (ri FileIndex) ListKeys(keys interface{}) error {
|
52
|
-
rawEntries, err := ri.readRawEntries()
|
53
|
-
if err != nil {
|
54
|
-
return err
|
55
|
-
}
|
56
|
-
|
57
|
-
keysElem := reflect.ValueOf(keys).Elem()
|
58
|
-
|
59
|
-
for _, rawEntry := range rawEntries {
|
60
|
-
key, err := ri.mapToStructFromSlice(rawEntry.Key, keys)
|
61
|
-
if err != nil {
|
62
|
-
return err
|
63
|
-
}
|
64
|
-
|
65
|
-
keysElem.Set(reflect.Append(keysElem, key))
|
66
|
-
}
|
67
|
-
|
68
|
-
return nil
|
69
|
-
}
|
70
|
-
|
71
|
-
func (ri FileIndex) Find(key interface{}, entry interface{}) error {
|
72
|
-
rawEntries, err := ri.readRawEntries()
|
73
|
-
if err != nil {
|
74
|
-
return err
|
75
|
-
}
|
76
|
-
|
77
|
-
rawKey, err := ri.structToMap(key)
|
78
|
-
if err != nil {
|
79
|
-
return err
|
80
|
-
}
|
81
|
-
|
82
|
-
for _, rawEntry := range rawEntries {
|
83
|
-
if reflect.DeepEqual(rawEntry.Key, rawKey) {
|
84
|
-
err := json.Unmarshal(rawEntry.Value, entry)
|
85
|
-
if err != nil {
|
86
|
-
return err
|
87
|
-
}
|
88
|
-
|
89
|
-
return nil
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
return ErrNotFound
|
94
|
-
}
|
95
|
-
|
96
|
-
func (ri FileIndex) Save(key interface{}, entry interface{}) error {
|
97
|
-
rawEntries, err := ri.readRawEntries()
|
98
|
-
if err != nil {
|
99
|
-
return err
|
100
|
-
}
|
101
|
-
|
102
|
-
rawKey, err := ri.structToMap(key)
|
103
|
-
if err != nil {
|
104
|
-
return err
|
105
|
-
}
|
106
|
-
|
107
|
-
rawValue, err := json.Marshal(entry)
|
108
|
-
if err != nil {
|
109
|
-
return err
|
110
|
-
}
|
111
|
-
|
112
|
-
foundI := -1
|
113
|
-
|
114
|
-
for i, rawEntry := range rawEntries {
|
115
|
-
if reflect.DeepEqual(rawEntry.Key, rawKey) {
|
116
|
-
foundI = i
|
117
|
-
break
|
118
|
-
}
|
119
|
-
}
|
120
|
-
|
121
|
-
if foundI >= 0 {
|
122
|
-
rawEntries[foundI].Value = rawValue
|
123
|
-
} else {
|
124
|
-
rawEntries = append(rawEntries, indexEntry{
|
125
|
-
Key: rawKey,
|
126
|
-
Value: rawValue,
|
127
|
-
})
|
128
|
-
}
|
129
|
-
|
130
|
-
err = ri.writeRawEntries(rawEntries)
|
131
|
-
if err != nil {
|
132
|
-
return err
|
133
|
-
}
|
134
|
-
|
135
|
-
return nil
|
136
|
-
}
|
137
|
-
|
138
|
-
func (ri FileIndex) Remove(key interface{}) error {
|
139
|
-
rawEntries, err := ri.readRawEntries()
|
140
|
-
if err != nil {
|
141
|
-
return err
|
142
|
-
}
|
143
|
-
|
144
|
-
rawKey, err := ri.structToMap(key)
|
145
|
-
if err != nil {
|
146
|
-
return err
|
147
|
-
}
|
148
|
-
|
149
|
-
for i, rawEntry := range rawEntries {
|
150
|
-
if reflect.DeepEqual(rawEntry.Key, rawKey) {
|
151
|
-
rawEntries = append(rawEntries[:i], rawEntries[i+1:]...)
|
152
|
-
break
|
153
|
-
}
|
154
|
-
}
|
155
|
-
|
156
|
-
err = ri.writeRawEntries(rawEntries)
|
157
|
-
if err != nil {
|
158
|
-
return err
|
159
|
-
}
|
160
|
-
|
161
|
-
return nil
|
162
|
-
}
|
163
|
-
|
164
|
-
func (ri FileIndex) readRawEntries() ([]indexEntry, error) {
|
165
|
-
var entries []indexEntry
|
166
|
-
|
167
|
-
if ri.fs.FileExists(ri.path) {
|
168
|
-
bytes, err := ri.fs.ReadFile(ri.path)
|
169
|
-
if err != nil {
|
170
|
-
return entries, bosherr.WrapError(err, "Reading index file %s", ri.path)
|
171
|
-
}
|
172
|
-
|
173
|
-
err = json.Unmarshal(bytes, &entries)
|
174
|
-
if err != nil {
|
175
|
-
return entries, bosherr.WrapError(err, "Unmarshalling index entries")
|
176
|
-
}
|
177
|
-
}
|
178
|
-
|
179
|
-
return entries, nil
|
180
|
-
}
|
181
|
-
|
182
|
-
func (ri FileIndex) writeRawEntries(entries []indexEntry) error {
|
183
|
-
bytes, err := json.Marshal(entries)
|
184
|
-
if err != nil {
|
185
|
-
return bosherr.WrapError(err, "Marshalling index entries")
|
186
|
-
}
|
187
|
-
|
188
|
-
err = ri.fs.WriteFile(ri.path, bytes)
|
189
|
-
if err != nil {
|
190
|
-
return bosherr.WrapError(err, "Writing index file %s", ri.path)
|
191
|
-
}
|
192
|
-
|
193
|
-
return nil
|
194
|
-
}
|
195
|
-
|
196
|
-
// structToMap extracts fields from a struct and populates a map
|
197
|
-
func (ri FileIndex) structToMap(s interface{}) (map[string]interface{}, error) {
|
198
|
-
res := map[string]interface{}{}
|
199
|
-
st := reflect.TypeOf(s)
|
200
|
-
stv := reflect.ValueOf(s)
|
201
|
-
|
202
|
-
if stv.Kind() != reflect.Struct {
|
203
|
-
return res, bosherr.New(
|
204
|
-
"Must be reflect.Struct: %#v (%#v)", stv, ri.kindToStr(stv.Kind()))
|
205
|
-
}
|
206
|
-
|
207
|
-
for i := 0; i < st.NumField(); i++ {
|
208
|
-
res[st.Field(i).Name] = stv.Field(i).Interface()
|
209
|
-
}
|
210
|
-
|
211
|
-
return res, nil
|
212
|
-
}
|
213
|
-
|
214
|
-
// mapToStruct returns new struct value with data from a map
|
215
|
-
func (ri FileIndex) mapToStruct(m map[string]interface{}, t interface{}) (reflect.Value, error) {
|
216
|
-
return ri.mapToNewStruct(m, reflect.ValueOf(t).Elem().Type())
|
217
|
-
}
|
218
|
-
|
219
|
-
// mapToStructFromSlice returns new struct value with data from a map
|
220
|
-
func (ri FileIndex) mapToStructFromSlice(m map[string]interface{}, t interface{}) (reflect.Value, error) {
|
221
|
-
slice := reflect.ValueOf(t).Elem()
|
222
|
-
|
223
|
-
if slice.Kind() != reflect.Slice {
|
224
|
-
return reflect.Value{}, bosherr.New(
|
225
|
-
"Must be reflect.Slice: %#v (%#v)",
|
226
|
-
slice, ri.kindToStr(slice.Kind()),
|
227
|
-
)
|
228
|
-
}
|
229
|
-
|
230
|
-
return ri.mapToNewStruct(m, slice.Type().Elem())
|
231
|
-
}
|
232
|
-
|
233
|
-
// mapToNewStruct returns new struct of type t with data from a map
|
234
|
-
func (ri FileIndex) mapToNewStruct(m map[string]interface{}, t reflect.Type) (reflect.Value, error) {
|
235
|
-
if t.Kind() != reflect.Struct {
|
236
|
-
return reflect.Value{}, bosherr.New(
|
237
|
-
"Must be reflect.Struct: %#v (%#v)",
|
238
|
-
t, ri.kindToStr(t.Kind()),
|
239
|
-
)
|
240
|
-
}
|
241
|
-
|
242
|
-
newStruct := reflect.New(t).Elem()
|
243
|
-
|
244
|
-
for k, v := range m {
|
245
|
-
f := newStruct.FieldByName(k)
|
246
|
-
if f.IsValid() && f.CanSet() {
|
247
|
-
// todo float64 -> int
|
248
|
-
// todo pointer values
|
249
|
-
// todo slices
|
250
|
-
f.Set(reflect.ValueOf(v))
|
251
|
-
}
|
252
|
-
}
|
253
|
-
|
254
|
-
return newStruct, nil
|
255
|
-
}
|
256
|
-
|
257
|
-
var kindToStrMap = map[reflect.Kind]string{
|
258
|
-
reflect.Invalid: "Invalid",
|
259
|
-
reflect.Bool: "Bool",
|
260
|
-
reflect.Int: "Int",
|
261
|
-
reflect.Int8: "Int8",
|
262
|
-
reflect.Int16: "Int16",
|
263
|
-
reflect.Int32: "Int32",
|
264
|
-
reflect.Int64: "Int64",
|
265
|
-
reflect.Uint: "Uint",
|
266
|
-
reflect.Uint8: "Uint8",
|
267
|
-
reflect.Uint16: "Uint16",
|
268
|
-
reflect.Uint32: "Uint32",
|
269
|
-
reflect.Uint64: "Uint64",
|
270
|
-
reflect.Uintptr: "Uintptr",
|
271
|
-
reflect.Float32: "Float32",
|
272
|
-
reflect.Float64: "Float64",
|
273
|
-
reflect.Complex64: "Complex64",
|
274
|
-
reflect.Complex128: "Complex128",
|
275
|
-
reflect.Array: "Array",
|
276
|
-
reflect.Chan: "Chan",
|
277
|
-
reflect.Func: "Func",
|
278
|
-
reflect.Interface: "Interface",
|
279
|
-
reflect.Map: "Map",
|
280
|
-
reflect.Ptr: "Ptr",
|
281
|
-
reflect.Slice: "Slice",
|
282
|
-
reflect.String: "String",
|
283
|
-
reflect.Struct: "Struct",
|
284
|
-
reflect.UnsafePointer: "UnsafePointer",
|
285
|
-
}
|
286
|
-
|
287
|
-
func (ri FileIndex) kindToStr(k reflect.Kind) string {
|
288
|
-
return kindToStrMap[k]
|
289
|
-
}
|