Skip to content

Commit

Permalink
feat(publisher): update publish state with redis (#183)
Browse files Browse the repository at this point in the history
Signed-off-by: wuhuizuo <[email protected]>

Signed-off-by: wuhuizuo <[email protected]>
  • Loading branch information
wuhuizuo authored Oct 17, 2024
1 parent 00c2f08 commit ed099a3
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 74 deletions.
20 changes: 10 additions & 10 deletions publisher/cmd/publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"goa.design/clue/log"
"gopkg.in/yaml.v3"

"github.com/PingCAP-QE/ee-apps/publisher"
tiup "github.com/PingCAP-QE/ee-apps/publisher/gen/tiup"
gentiup "github.com/PingCAP-QE/ee-apps/publisher/gen/tiup"
"github.com/PingCAP-QE/ee-apps/publisher/pkg/config"
"github.com/PingCAP-QE/ee-apps/publisher/pkg/impl/tiup"
)

func main() {
Expand Down Expand Up @@ -56,18 +56,18 @@ func main() {
zerolog.SetGlobalLevel(logLevel)

// Initialize the services.
tiupSvc, err := initService(*configFile)
tiupSvc, err := initTiupService(*configFile)
if err != nil {
log.Fatalf(ctx, err, "failed to initialize service")
}

// Wrap the services in endpoints that can be invoked from other services
// potentially running in different processes.
var (
tiupEndpoints *tiup.Endpoints
tiupEndpoints *gentiup.Endpoints
)
{
tiupEndpoints = tiup.NewEndpoints(tiupSvc)
tiupEndpoints = gentiup.NewEndpoints(tiupSvc)
tiupEndpoints.Use(debug.LogPayloads())
tiupEndpoints.Use(log.Endpoint)
}
Expand Down Expand Up @@ -128,20 +128,20 @@ func main() {
log.Printf(ctx, "exited")
}

func initService(configFile string) (tiup.Service, error) {
func initTiupService(configFile string) (gentiup.Service, error) {
// Load and parse configuration
var config config.Service
{
configData, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("Error reading config file: %v", err)
return nil, fmt.Errorf("error reading config file: %v", err)
}
if err := yaml.Unmarshal(configData, &config); err != nil {
return nil, fmt.Errorf("Error parsing config file: %v", err)
return nil, fmt.Errorf("error parsing config file: %v", err)
}
}

logger := zerolog.New(os.Stderr).With().Timestamp().Str("service", tiup.ServiceName).Logger()
logger := zerolog.New(os.Stderr).With().Timestamp().Str("service", gentiup.ServiceName).Logger()

// Configure Kafka kafkaWriter
kafkaWriter := kafka.NewWriter(kafka.WriterConfig{
Expand All @@ -159,5 +159,5 @@ func initService(configFile string) (tiup.Service, error) {
DB: config.Redis.DB,
})

return publisher.NewTiup(&logger, kafkaWriter, redisClient, config.EventSource), nil
return tiup.NewTiup(&logger, kafkaWriter, redisClient, config.EventSource), nil
}
2 changes: 1 addition & 1 deletion publisher/cmd/worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"gopkg.in/yaml.v3"

"github.com/PingCAP-QE/ee-apps/publisher/pkg/config"
"github.com/PingCAP-QE/ee-apps/publisher/pkg/tiup"
"github.com/PingCAP-QE/ee-apps/publisher/pkg/impl/tiup"
)

func main() {
Expand Down
4 changes: 3 additions & 1 deletion publisher/design/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ var _ = Service("tiup", func() {
Attribute("request_id", String, "request track id")
Required("request_id")
})
Result(String, "request state")
Result(String, "request state", func() {
Enum("queued", "processing", "success", "failed")
})
HTTP(func() {
GET("/publish-request/{request_id}")
Response(StatusOK)
Expand Down
18 changes: 9 additions & 9 deletions publisher/gen/http/cli/publisher/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion publisher/gen/http/openapi.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"swagger":"2.0","info":{"title":"Publish API","description":"Publish API","contact":{"name":"WuHui Zuo","email":"[email protected]","url":"https://github.com/wuhuizuo"},"version":"1.0.0"},"host":"0.0.0.0:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/tiup/publish-request":{"post":{"tags":["tiup"],"summary":"request-to-publish tiup","operationId":"tiup#request-to-publish","parameters":[{"name":"Request-To-PublishRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TiupRequestToPublishRequestBody","required":["artifact_url","tiup-mirror"]}}],"responses":{"200":{"description":"OK response.","schema":{"type":"array","items":{"type":"string","example":"Sed illo harum quis voluptatem."}}}},"schemes":["http"]}},"/tiup/publish-request/{request_id}":{"get":{"tags":["tiup"],"summary":"query-publishing-status tiup","operationId":"tiup#query-publishing-status","parameters":[{"name":"request_id","in":"path","description":"request track id","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string"}}},"schemes":["http"]}}},"definitions":{"TiupRequestToPublishRequestBody":{"title":"TiupRequestToPublishRequestBody","type":"object","properties":{"artifact_url":{"type":"string","description":"The full url of the pushed image, contain the tag part. It will parse the repo from it.","example":"Et ullam."},"request_id":{"type":"string","description":"The request id","example":"Assumenda tempora autem accusantium est."},"tiup-mirror":{"type":"string","description":"Staging is http://tiup.pingcap.net:8988, product is http://tiup.pingcap.net:8987.","default":"http://tiup.pingcap.net:8988","example":"Ab expedita repellendus."},"version":{"type":"string","description":"Force set the version. Default is the artifact version read from `org.opencontainers.image.version` of the manifest config.","example":"Et suscipit et."}},"example":{"artifact_url":"Corrupti ut natus aut ipsam reprehenderit.","request_id":"Rerum tempore voluptas.","tiup-mirror":"Laboriosam optio omnis cupiditate magnam nisi.","version":"Et eum odit eos ratione."},"required":["artifact_url","tiup-mirror"]}}}
{"swagger":"2.0","info":{"title":"Publish API","description":"Publish API","contact":{"name":"WuHui Zuo","email":"[email protected]","url":"https://github.com/wuhuizuo"},"version":"1.0.0"},"host":"0.0.0.0:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/tiup/publish-request":{"post":{"tags":["tiup"],"summary":"request-to-publish tiup","operationId":"tiup#request-to-publish","parameters":[{"name":"Request-To-PublishRequestBody","in":"body","required":true,"schema":{"$ref":"#/definitions/TiupRequestToPublishRequestBody","required":["artifact_url","tiup-mirror"]}}],"responses":{"200":{"description":"OK response.","schema":{"type":"array","items":{"type":"string","example":"Cupiditate suscipit hic quidem voluptates nostrum necessitatibus."}}}},"schemes":["http"]}},"/tiup/publish-request/{request_id}":{"get":{"tags":["tiup"],"summary":"query-publishing-status tiup","operationId":"tiup#query-publishing-status","parameters":[{"name":"request_id","in":"path","description":"request track id","required":true,"type":"string"}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","enum":["queued","processing","success","failed"]}}},"schemes":["http"]}}},"definitions":{"TiupRequestToPublishRequestBody":{"title":"TiupRequestToPublishRequestBody","type":"object","properties":{"artifact_url":{"type":"string","description":"The full url of the pushed image, contain the tag part. It will parse the repo from it.","example":"Optio necessitatibus ipsa incidunt."},"request_id":{"type":"string","description":"The request id","example":"Et ullam."},"tiup-mirror":{"type":"string","description":"Staging is http://tiup.pingcap.net:8988, product is http://tiup.pingcap.net:8987.","default":"http://tiup.pingcap.net:8988","example":"Illo harum quis voluptatem."},"version":{"type":"string","description":"Force set the version. Default is the artifact version read from `org.opencontainers.image.version` of the manifest config.","example":"Expedita et necessitatibus ut molestias."}},"example":{"artifact_url":"Et suscipit et.","request_id":"Corrupti ut natus aut ipsam reprehenderit.","tiup-mirror":"Assumenda tempora autem accusantium est.","version":"Ab expedita repellendus."},"required":["artifact_url","tiup-mirror"]}}}
23 changes: 14 additions & 9 deletions publisher/gen/http/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ paths:
type: array
items:
type: string
example: Sed illo harum quis voluptatem.
example: Cupiditate suscipit hic quidem voluptates nostrum necessitatibus.
schemes:
- http
/tiup/publish-request/{request_id}:
Expand All @@ -59,6 +59,11 @@ paths:
description: OK response.
schema:
type: string
enum:
- queued
- processing
- success
- failed
schemes:
- http
definitions:
Expand All @@ -69,25 +74,25 @@ definitions:
artifact_url:
type: string
description: The full url of the pushed image, contain the tag part. It will parse the repo from it.
example: Et ullam.
example: Optio necessitatibus ipsa incidunt.
request_id:
type: string
description: The request id
example: Assumenda tempora autem accusantium est.
example: Et ullam.
tiup-mirror:
type: string
description: Staging is http://tiup.pingcap.net:8988, product is http://tiup.pingcap.net:8987.
default: http://tiup.pingcap.net:8988
example: Ab expedita repellendus.
example: Illo harum quis voluptatem.
version:
type: string
description: Force set the version. Default is the artifact version read from `org.opencontainers.image.version` of the manifest config.
example: Et suscipit et.
example: Expedita et necessitatibus ut molestias.
example:
artifact_url: Corrupti ut natus aut ipsam reprehenderit.
request_id: Rerum tempore voluptas.
tiup-mirror: Laboriosam optio omnis cupiditate magnam nisi.
version: Et eum odit eos ratione.
artifact_url: Et suscipit et.
request_id: Corrupti ut natus aut ipsam reprehenderit.
tiup-mirror: Assumenda tempora autem accusantium est.
version: Ab expedita repellendus.
required:
- artifact_url
- tiup-mirror
2 changes: 1 addition & 1 deletion publisher/gen/http/openapi3.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openapi":"3.0.3","info":{"title":"Publish API","description":"Publish API","contact":{"name":"WuHui Zuo","url":"https://github.com/wuhuizuo","email":"[email protected]"},"version":"1.0.0"},"servers":[{"url":"http://0.0.0.0:80"}],"paths":{"/tiup/publish-request":{"post":{"tags":["tiup"],"summary":"request-to-publish tiup","operationId":"tiup#request-to-publish","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RequestToPublishRequestBody"},"example":{"artifact_url":"A facilis.","request_id":"Sequi placeat blanditiis est iusto quia eum.","tiup-mirror":"Sunt voluptates.","version":"Rerum consectetur deleniti."}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"array","items":{"type":"string","example":"Distinctio voluptates voluptatem accusamus nisi omnis quia."},"description":"request track ids","example":["Voluptates possimus pariatur consequuntur itaque est dignissimos.","Atque amet optio et aliquam ut.","Nulla at error qui dolores et ipsa.","Rem nisi non."]},"example":["Molestiae vitae ut commodi voluptatem consectetur.","Magnam aut et labore."]}}}}}},"/tiup/publish-request/{request_id}":{"get":{"tags":["tiup"],"summary":"query-publishing-status tiup","operationId":"tiup#query-publishing-status","parameters":[{"name":"request_id","in":"path","description":"request track id","required":true,"schema":{"type":"string","description":"request track id","example":"Facere maiores tenetur mollitia consequatur perferendis sint."},"example":"Nisi earum earum pariatur et animi."}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","description":"request state","example":"Necessitatibus officia distinctio officia voluptas laudantium iure."},"example":"Aperiam consequatur consequatur."}}}}}}},"components":{"schemas":{"RequestToPublishRequestBody":{"type":"object","properties":{"artifact_url":{"type":"string","description":"The full url of the pushed image, contain the tag part. It will parse the repo from it.","example":"Voluptas ratione hic libero nisi."},"request_id":{"type":"string","description":"The request id","example":"Quibusdam nisi quam."},"tiup-mirror":{"type":"string","description":"Staging is http://tiup.pingcap.net:8988, product is http://tiup.pingcap.net:8987.","default":"http://tiup.pingcap.net:8988","example":"Magni quia adipisci excepturi."},"version":{"type":"string","description":"Force set the version. Default is the artifact version read from `org.opencontainers.image.version` of the manifest config.","example":"Rerum voluptate accusantium optio."}},"example":{"artifact_url":"Atque vero in molestiae odit consequatur.","request_id":"Eos eveniet vero.","tiup-mirror":"Nemo rerum voluptas.","version":"Eum saepe nihil omnis dolorem eveniet."},"required":["artifact_url","tiup-mirror"]}}},"tags":[{"name":"tiup","description":"TiUP Publisher service"}]}
{"openapi":"3.0.3","info":{"title":"Publish API","description":"Publish API","contact":{"name":"WuHui Zuo","url":"https://github.com/wuhuizuo","email":"[email protected]"},"version":"1.0.0"},"servers":[{"url":"http://0.0.0.0:80"}],"paths":{"/tiup/publish-request":{"post":{"tags":["tiup"],"summary":"request-to-publish tiup","operationId":"tiup#request-to-publish","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RequestToPublishRequestBody"},"example":{"artifact_url":"Omnis expedita.","request_id":"Est sequi placeat.","tiup-mirror":"Pariatur rerum consectetur deleniti architecto sunt.","version":"Dicta id perferendis rem a."}}}},"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"array","items":{"type":"string","example":"Eum saepe nihil omnis dolorem eveniet."},"description":"request track ids","example":["Rerum voluptas dolore.","Eveniet vero voluptas.","Voluptates voluptatem accusamus nisi omnis quia molestias."]},"example":["Pariatur consequuntur itaque est.","Exercitationem atque amet optio."]}}}}}},"/tiup/publish-request/{request_id}":{"get":{"tags":["tiup"],"summary":"query-publishing-status tiup","operationId":"tiup#query-publishing-status","parameters":[{"name":"request_id","in":"path","description":"request track id","required":true,"schema":{"type":"string","description":"request track id","example":"Aliquam ut laborum nulla."},"example":"Error qui dolores et."}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"string","description":"request state","example":"queued","enum":["queued","processing","success","failed"]},"example":"failed"}}}}}}},"components":{"schemas":{"RequestToPublishRequestBody":{"type":"object","properties":{"artifact_url":{"type":"string","description":"The full url of the pushed image, contain the tag part. It will parse the repo from it.","example":"Et eum odit eos ratione."},"request_id":{"type":"string","description":"The request id","example":"Voluptas ratione hic libero nisi."},"tiup-mirror":{"type":"string","description":"Staging is http://tiup.pingcap.net:8988, product is http://tiup.pingcap.net:8987.","default":"http://tiup.pingcap.net:8988","example":"Rerum tempore voluptas."},"version":{"type":"string","description":"Force set the version. Default is the artifact version read from `org.opencontainers.image.version` of the manifest config.","example":"Laboriosam optio omnis cupiditate magnam nisi."}},"example":{"artifact_url":"Rerum voluptate accusantium optio.","request_id":"Atque vero in molestiae odit consequatur.","tiup-mirror":"Quibusdam nisi quam.","version":"Magni quia adipisci excepturi."},"required":["artifact_url","tiup-mirror"]}}},"tags":[{"name":"tiup","description":"TiUP Publisher service"}]}
Loading

0 comments on commit ed099a3

Please sign in to comment.