func (app *App) handleModel(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": vars := mux.Vars(r) name := vars["name"] user, ok := app.getUser(r) if !ok { http.Error(w, "Unauthorized", http.StatusUnauthorized) return } tx, err := app.db.Begin() if err != nil { app.dbError(w, r, err) return } defer tx.Rollback() model, err := db.GetModel(tx, user.Name, name) if err != nil { if db.IsNotFound(err) { http.Error(w, "Model not found", http.StatusNotFound) } else { app.dbError(w, r, err) } return } v := model.ActiveVersion activeVersion, err := db.GetModelVersion(tx, user.Name, name, v) if err != nil { if db.IsNotFound(err) { http.Error(w, "Model not found", http.StatusNotFound) } else { app.dbError(w, r, err) } return } app.writeJson(w, map[string]interface{}{ "Model": model, "Version": activeVersion, }) default: http.Error(w, "I only respond to GETs", http.StatusNotImplemented) } }
func (s *storage) Get(user, model string, version int) (*mps.DeployInfo, string, error) { tx, err := s.app.db.Begin() if err != nil { return nil, "", fmt.Errorf("database unavailabled: %v", err) } defer tx.Rollback() modelVersion, err := db.GetModelVersion(tx, user, model, version) if err != nil { if db.IsNotFound(err) { return nil, "", errors.New("model version not found") } return nil, "", fmt.Errorf("could not query model version: %v", err) } baseImage, err := db.GetBaseImage(tx, modelVersion.Lang) if err != nil && err != sql.ErrNoRows { return nil, "", fmt.Errorf("could not query baseImage: %v", err) } // TODO: Conda channels, CRAN mirror and apt-get sources info := &mps.DeployInfo{ Username: user, Modelname: model, Version: version, Lang: modelVersion.Lang, LanguagePackages: modelVersion.LangPackages, UbuntuPackages: modelVersion.UbuntuPackages, BaseImage: baseImage, } if modelVersion.BundleFilename == "" { return nil, "", fmt.Errorf("no bundle file provided") } bundlePath := filepath.Join(s.app.bundleDir, modelVersion.BundleFilename) log.Println("bundle path is", bundlePath) return info, bundlePath, nil }