Ejemplo n.º 1
0
Archivo: create.go Proyecto: utako/atc
func (s *Server) CreateBuild(w http.ResponseWriter, r *http.Request) {
	var plan atc.Plan
	err := json.NewDecoder(r.Body).Decode(&plan)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	build, err := s.db.CreateOneOffBuild()
	if err != nil {
		s.logger.Error("failed-to-create-one-off-build", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	engineBuild, err := s.engine.CreateBuild(build, plan)
	if err != nil {
		s.logger.Error("failed-to-start-build", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	go engineBuild.Resume(s.logger)

	w.WriteHeader(http.StatusCreated)

	json.NewEncoder(w).Encode(present.Build(build))
}
Ejemplo n.º 2
0
Archivo: create.go Proyecto: ACPK/atc
func (s *Server) CreateBuild(w http.ResponseWriter, r *http.Request) {
	hLog := s.logger.Session("create-build")

	var plan atc.Plan
	err := json.NewDecoder(r.Body).Decode(&plan)
	if err != nil {
		hLog.Info("malformed-request", lager.Data{"error": err.Error()})
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	build, err := s.db.CreateOneOffBuild()

	if err != nil {
		hLog.Error("failed-to-create-one-off-build", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	engineBuild, err := s.engine.CreateBuild(hLog, build, plan)
	if err != nil {
		hLog.Error("failed-to-start-build", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	go engineBuild.Resume(hLog)

	w.WriteHeader(http.StatusCreated)

	json.NewEncoder(w).Encode(present.Build(build))
}
Ejemplo n.º 3
0
Archivo: get.go Proyecto: ACPK/atc
func (s *Server) GetBuild(w http.ResponseWriter, r *http.Request) {
	log := s.logger.Session("build-resources")
	buildID, err := strconv.Atoi(r.FormValue(":build_id"))
	if err != nil {
		log.Error("cannot-parse-build-id", err, lager.Data{"buildID": r.FormValue(":build_id")})
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	dbBuild, found, err := s.db.GetBuild(buildID)
	if err != nil {
		log.Error("cannot-find-build", err, lager.Data{"buildID": r.FormValue(":build_id")})
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	if !found {
		w.WriteHeader(http.StatusNotFound)
		return
	}

	w.WriteHeader(http.StatusOK)

	build := present.Build(dbBuild)

	json.NewEncoder(w).Encode(build)
}
Ejemplo n.º 4
0
func (s *Server) ListJobBuilds(pipelineDB db.PipelineDB) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		var (
			builds []db.Build
			err    error
			until  int
			since  int
			limit  int
		)

		jobName := r.FormValue(":job_name")

		urlUntil := r.FormValue(atc.PaginationQueryUntil)
		until, _ = strconv.Atoi(urlUntil)

		urlSince := r.FormValue(atc.PaginationQuerySince)
		since, _ = strconv.Atoi(urlSince)

		urlLimit := r.FormValue(atc.PaginationQueryLimit)
		limit, _ = strconv.Atoi(urlLimit)
		if limit == 0 {
			limit = atc.PaginationAPIDefaultLimit
		}

		builds, pagination, err := pipelineDB.GetJobBuilds(jobName, db.Page{
			Since: since,
			Until: until,
			Limit: limit,
		})
		if err != nil {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		if pagination.Next != nil {
			s.addNextLink(w, pipelineDB.GetPipelineName(), jobName, *pagination.Next)
		}

		if pagination.Previous != nil {
			s.addPreviousLink(w, pipelineDB.GetPipelineName(), jobName, *pagination.Previous)
		}

		w.WriteHeader(http.StatusOK)

		jobBuilds := make([]atc.Build, len(builds))
		for i := 0; i < len(builds); i++ {
			jobBuilds[i] = present.Build(builds[i])
		}
		json.NewEncoder(w).Encode(jobBuilds)
	})
}
Ejemplo n.º 5
0
Archivo: list.go Proyecto: utako/atc
func (s *Server) ListBuilds(w http.ResponseWriter, r *http.Request) {
	builds, err := s.db.GetAllBuilds()
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)

	atc := make([]atc.Build, len(builds))
	for i := 0; i < len(builds); i++ {
		atc[i] = present.Build(builds[i])
	}

	json.NewEncoder(w).Encode(atc)
}
Ejemplo n.º 6
0
func (s *Server) ListBuilds(w http.ResponseWriter, r *http.Request) {
	logger := s.logger.Session("list-builds")

	var (
		err   error
		until int
		since int
		limit int
	)

	urlUntil := r.FormValue(atc.PaginationQueryUntil)
	until, _ = strconv.Atoi(urlUntil)

	urlSince := r.FormValue(atc.PaginationQuerySince)
	since, _ = strconv.Atoi(urlSince)

	urlLimit := r.FormValue(atc.PaginationQueryLimit)

	limit, _ = strconv.Atoi(urlLimit)
	if limit == 0 {
		limit = atc.PaginationAPIDefaultLimit
	}

	builds, pagination, err := s.db.GetBuilds(db.Page{Until: until, Since: since, Limit: limit})
	if err != nil {
		logger.Error("failed-to-get-all-builds", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	if pagination.Next != nil {
		s.addNextLink(w, *pagination.Next)
	}

	if pagination.Previous != nil {
		s.addPreviousLink(w, *pagination.Previous)
	}

	w.WriteHeader(http.StatusOK)

	atc := make([]atc.Build, len(builds))
	for i := 0; i < len(builds); i++ {
		atc[i] = present.Build(builds[i])
	}

	json.NewEncoder(w).Encode(atc)
}
Ejemplo n.º 7
0
Archivo: list.go Proyecto: ACPK/atc
func (s *Server) ListBuilds(w http.ResponseWriter, r *http.Request) {
	logger := s.logger.Session("list-builds")
	builds, err := s.db.GetAllBuilds()
	if err != nil {
		logger.Error("failed-to-get-all-builds", err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)

	atc := make([]atc.Build, len(builds))
	for i := 0; i < len(builds); i++ {
		atc[i] = present.Build(builds[i])
	}

	json.NewEncoder(w).Encode(atc)
}
Ejemplo n.º 8
0
func (s *Server) CreateJobBuild(pipelineDB db.PipelineDB) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		logger := s.logger.Session("create-job-build")

		jobName := r.FormValue(":job_name")

		config, _, found, err := pipelineDB.GetConfig()
		if err != nil {
			logger.Error("could-not-get-pipeline-config", err)
			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		if !found {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		job, found := config.Jobs.Lookup(jobName)
		if !found {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		if job.DisableManualTrigger {
			w.WriteHeader(http.StatusConflict)
			return
		}

		scheduler := s.schedulerFactory.BuildScheduler(pipelineDB, s.externalURL)

		build, _, err := scheduler.TriggerImmediately(logger, job, config.Resources, config.ResourceTypes)
		if err != nil {
			logger.Error("failed-to-trigger", err)
			w.WriteHeader(http.StatusInternalServerError)
			fmt.Fprintf(w, "failed to trigger: %s", err)
			return
		}

		json.NewEncoder(w).Encode(present.Build(build))
	})
}
Ejemplo n.º 9
0
func (s *Server) ListJobBuilds(pipelineDB db.PipelineDB) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		jobName := r.FormValue(":job_name")

		builds, err := pipelineDB.GetAllJobBuilds(jobName)
		if err != nil {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		w.WriteHeader(http.StatusOK)

		resources := make([]atc.Build, len(builds))
		for i := 0; i < len(builds); i++ {
			resources[i] = present.Build(builds[i])
		}

		json.NewEncoder(w).Encode(resources)
	})
}
Ejemplo n.º 10
0
Archivo: get.go Proyecto: utako/atc
func (s *Server) GetBuild(w http.ResponseWriter, r *http.Request) {
	buildID, err := strconv.Atoi(r.FormValue(":build_id"))

	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	dbBuild, err := s.db.GetBuild(buildID)

	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)

	build := present.Build(dbBuild)

	json.NewEncoder(w).Encode(build)
}
Ejemplo n.º 11
0
func (s *Server) ListBuildsWithVersionAsOutput(pipelineDB db.PipelineDB) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		versionIDString := r.FormValue(":resource_version_id")
		versionID, _ := strconv.Atoi(versionIDString)

		builds, err := pipelineDB.GetBuildsWithVersionAsOutput(versionID)
		if err != nil {
			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		presentedBuilds := []atc.Build{}
		for _, build := range builds {
			presentedBuilds = append(presentedBuilds, present.Build(build))
		}

		w.Header().Set("Content-Type", "application/json")

		w.WriteHeader(http.StatusOK)

		json.NewEncoder(w).Encode(presentedBuilds)
	})
}
Ejemplo n.º 12
0
func (s *Server) GetJobBuild(pipelineDB db.PipelineDB) http.Handler {
	logger := s.logger.Session("get-job-build")
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		jobName := r.FormValue(":job_name")
		buildName := r.FormValue(":build_name")

		build, found, err := pipelineDB.GetJobBuild(jobName, buildName)
		if err != nil {
			logger.Error("failed-to-get-job-build", err)
			w.WriteHeader(http.StatusInternalServerError)
			return
		}

		if !found {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		w.WriteHeader(http.StatusOK)

		json.NewEncoder(w).Encode(present.Build(build))
	})
}