本文整理汇总了Golang中github.com/concourse/atc/db.PipelineDB.GetResource方法的典型用法代码示例。如果您正苦于以下问题:Golang PipelineDB.GetResource方法的具体用法?Golang PipelineDB.GetResource怎么用?Golang PipelineDB.GetResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/concourse/atc/db.PipelineDB
的用法示例。
在下文中一共展示了PipelineDB.GetResource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ListResources
func (s *Server) ListResources(pipelineDB db.PipelineDB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var resources []atc.Resource
config, _, err := pipelineDB.GetConfig()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
showCheckErr := s.validator.IsAuthenticated(r)
for _, resource := range config.Resources {
dbResource, err := pipelineDB.GetResource(resource.Name)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
resources = append(
resources,
present.Resource(
resource,
config.Groups,
dbResource,
showCheckErr,
),
)
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(resources)
})
}
示例2: UnpauseResource
func (s *Server) UnpauseResource(pipelineDB db.PipelineDB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
resourceName := rata.Param(r, "resource_name")
_, found, err := pipelineDB.GetResource(resourceName)
if err != nil {
s.logger.Error("failed-to-get-resource", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
s.logger.Debug("resource-not-found", lager.Data{"resource": resourceName})
w.WriteHeader(http.StatusNotFound)
return
}
err = pipelineDB.UnpauseResource(resourceName)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
})
}
示例3: GetResource
func (s *Server) GetResource(pipelineDB db.PipelineDB) http.Handler {
logger := s.logger.Session("get-resource")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
config, _, found, err := pipelineDB.GetConfig()
if err != nil {
logger.Error("failed-to-get-config", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
logger.Info("config-not-found")
w.WriteHeader(http.StatusNotFound)
return
}
resourceName := r.FormValue(":resource_name")
resourceConfig, resourceFound := config.Resources.Lookup(resourceName)
if !resourceFound {
logger.Info("resource-not-in-config")
w.WriteHeader(http.StatusNotFound)
return
}
dbResource, found, err := pipelineDB.GetResource(resourceName)
if err != nil {
logger.Error("failed-to-get-resource", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
logger.Debug("resource-not-found", lager.Data{"resource": resourceName})
w.WriteHeader(http.StatusNotFound)
return
}
resource := present.Resource(
resourceConfig,
config.Groups,
dbResource,
auth.IsAuthenticated(r),
)
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(resource)
})
}
示例4: ListResources
func (s *Server) ListResources(pipelineDB db.PipelineDB) http.Handler {
logger := s.logger.Session("list-resources")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var resources []atc.Resource
config, _, found, err := pipelineDB.GetConfig()
if err != nil {
logger.Error("failed-to-get-config", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
showCheckErr := auth.IsAuthenticated(r)
for _, resource := range config.Resources {
dbResource, found, err := pipelineDB.GetResource(resource.Name)
if err != nil {
logger.Error("failed-to-get-resource", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
logger.Debug("resource-not-found", lager.Data{"resource": resource})
w.WriteHeader(http.StatusNotFound)
return
}
resources = append(
resources,
present.Resource(
resource,
config.Groups,
dbResource,
showCheckErr,
),
)
}
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(resources)
})
}
示例5:
lease.Break()
time.Sleep(time.Second)
newLease, leased, err := pipelineDB.LeaseScheduling(1 * time.Second)
Expect(err).NotTo(HaveOccurred())
Expect(leased).To(BeTrue())
newLease.Break()
})
})
})
Describe("taking out a lease on resource checking", func() {
BeforeEach(func() {
_, err := pipelineDB.GetResource("some-resource")
Expect(err).NotTo(HaveOccurred())
})
Context("when there has been a check recently", func() {
Context("when acquiring immediately", func() {
It("gets the lease", func() {
lease, leased, err := pipelineDB.LeaseResourceChecking("some-resource", 1*time.Second, false)
Expect(err).NotTo(HaveOccurred())
Expect(leased).To(BeTrue())
lease.Break()
lease, leased, err = pipelineDB.LeaseResourceChecking("some-resource", 1*time.Second, true)
Expect(err).NotTo(HaveOccurred())
Expect(leased).To(BeTrue())
示例6:
Eventually(page.FindByLink("resource-name")).Should(BeFound())
Expect(page.FindByLink("resource-name").Click()).To(Succeed())
// resource detail -> paused resource detail
Expect(page).Should(HaveURL(withPath("/resources/resource-name")))
Expect(page.Find("h1")).To(HaveText("resource-name"))
Authenticate(page, "admin", "password")
Expect(page.Find(".js-resource .js-pauseUnpause").Click()).To(Succeed())
Eventually(page.Find(".header i.fa-play")).Should(BeFound())
page.Refresh()
Eventually(page.Find(".header i.fa-play")).Should(BeFound())
resource, err := pipelineDB.GetResource("resource-name")
Ω(err).ShouldNot(HaveOccurred())
err = pipelineDB.SetResourceCheckError(resource, errors.New("failed to foo the bar"))
Ω(err).ShouldNot(HaveOccurred())
page.Refresh()
Eventually(page.Find(".header h3")).Should(HaveText("checking failed"))
Eventually(page.Find(".build-step .step-body")).Should(HaveText("failed to foo the bar"))
})
})
})
})