~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/tools.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
        "github.com/juju/errors"
17
17
        "github.com/juju/utils"
 
18
        "github.com/juju/version"
18
19
 
19
20
        "github.com/juju/juju/apiserver/common"
20
21
        "github.com/juju/juju/apiserver/params"
21
22
        "github.com/juju/juju/environs"
22
23
        envtools "github.com/juju/juju/environs/tools"
23
24
        "github.com/juju/juju/state"
24
 
        "github.com/juju/juju/state/toolstorage"
 
25
        "github.com/juju/juju/state/binarystorage"
25
26
        "github.com/juju/juju/tools"
26
 
        "github.com/juju/juju/version"
27
27
)
28
28
 
29
29
// toolsHandler handles tool upload through HTTPS in the API server.
91
91
                return nil, errors.Annotate(err, "error getting tools storage")
92
92
        }
93
93
        defer storage.Close()
94
 
        _, reader, err := storage.Tools(version)
 
94
        _, reader, err := storage.Open(version.String())
95
95
        if errors.IsNotFound(err) {
96
 
                // Tools could not be found in toolstorage,
 
96
                // Tools could not be found in tools storage,
97
97
                // so look for them in simplestreams, fetch
98
 
                // them and cache in toolstorage.
 
98
                // them and cache in tools storage.
99
99
                logger.Infof("%v tools not found locally, fetching", version)
100
100
                reader, err = h.fetchAndCacheTools(version, storage, st)
101
101
                if err != nil {
114
114
}
115
115
 
116
116
// fetchAndCacheTools fetches tools with the specified version by searching for a URL
117
 
// in simplestreams and GETting it, caching the result in toolstorage before returning
 
117
// in simplestreams and GETting it, caching the result in tools storage before returning
118
118
// to the caller.
119
 
func (h *toolsDownloadHandler) fetchAndCacheTools(v version.Binary, stor toolstorage.Storage, st *state.State) (io.ReadCloser, error) {
 
119
func (h *toolsDownloadHandler) fetchAndCacheTools(v version.Binary, stor binarystorage.Storage, st *state.State) (io.ReadCloser, error) {
120
120
        envcfg, err := st.ModelConfig()
121
121
        if err != nil {
122
122
                return nil, err
155
155
                return nil, errors.Errorf("hash mismatch for %s", tools.URL)
156
156
        }
157
157
 
158
 
        // Cache tarball in toolstorage before returning.
159
 
        metadata := toolstorage.Metadata{
160
 
                Version: v,
 
158
        // Cache tarball in tools storage before returning.
 
159
        metadata := binarystorage.Metadata{
 
160
                Version: v.String(),
161
161
                Size:    tools.Size,
162
162
                SHA256:  tools.SHA256,
163
163
        }
164
 
        if err := stor.AddTools(bytes.NewReader(data), metadata); err != nil {
 
164
        if err := stor.Add(bytes.NewReader(data), metadata); err != nil {
165
165
                return nil, errors.Annotate(err, "error caching tools")
166
166
        }
167
167
        return ioutil.NopCloser(bytes.NewReader(data)), nil
258
258
 
259
259
        // TODO(wallyworld): check integrity of tools tarball.
260
260
 
261
 
        // Store tools and metadata in toolstorage.
 
261
        // Store tools and metadata in tools storage.
262
262
        for _, v := range toolsVersions {
263
 
                metadata := toolstorage.Metadata{
264
 
                        Version: v,
 
263
                metadata := binarystorage.Metadata{
 
264
                        Version: v.String(),
265
265
                        Size:    int64(len(data)),
266
266
                        SHA256:  sha256,
267
267
                }
268
268
                logger.Debugf("uploading tools %+v to storage", metadata)
269
 
                if err := storage.AddTools(bytes.NewReader(data), metadata); err != nil {
 
269
                if err := storage.Add(bytes.NewReader(data), metadata); err != nil {
270
270
                        return nil, err
271
271
                }
272
272
        }