diff --git a/generated/models/dlq_job.go b/generated/models/dlq_job.go index d50ead8..ef70f7e 100644 --- a/generated/models/dlq_job.go +++ b/generated/models/dlq_job.go @@ -46,6 +46,9 @@ type DlqJob struct { // Shield's project slug Project string `json:"project,omitempty"` + // replicas + Replicas int64 `json:"replicas,omitempty"` + // resource id ResourceID string `json:"resource_id,omitempty"` @@ -57,6 +60,9 @@ type DlqJob struct { // Enum: [pending error running stopped] Status string `json:"status,omitempty"` + // stopped + Stopped bool `json:"stopped,omitempty"` + // topic Topic string `json:"topic,omitempty"` diff --git a/internal/server/v1/dlq/mapper.go b/internal/server/v1/dlq/mapper.go new file mode 100644 index 0000000..78ab0a2 --- /dev/null +++ b/internal/server/v1/dlq/mapper.go @@ -0,0 +1,98 @@ +package dlq + +import ( + "fmt" + + entropyv1beta1 "buf.build/gen/go/gotocompany/proton/protocolbuffers/go/gotocompany/entropy/v1beta1" + "google.golang.org/protobuf/types/known/structpb" + + "github.com/goto/dex/entropy" + "github.com/goto/dex/generated/models" + "github.com/goto/dex/internal/server/utils" +) + +func mapToEntropyResource(job *models.DlqJob) (*entropyv1beta1.Resource, error) { + cfgStruct, err := makeConfigStruct(job) + if err != nil { + return nil, err + } + + return &entropyv1beta1.Resource{ + Urn: job.Urn, + Kind: entropy.ResourceKindJob, + Name: buildResourceName(job), + Project: job.Project, + Labels: buildResourceLabels(job), + Spec: &entropyv1beta1.ResourceSpec{ + Configs: cfgStruct, + }, + }, nil +} + +func makeConfigStruct(job *models.DlqJob) (*structpb.Value, error) { + return utils.GoValToProtoStruct(entropy.JobConfig{ + Stopped: job.Stopped, + Replicas: int32(job.Replicas), + Namespace: "", // decide with streaming where to store namespace + Name: "", // decide with streaming job name + Containers: []entropy.JobContainer{ + { + Name: "dlq", + Image: "test-image", // ask streaming for image name, and also if it can be modified via UI/client + ImagePullPolicy: "Always", + Command: []string{""}, // confirm with streaming team for commands + SecretsVolumes: []entropy.JobSecret{ // confirm with streaming for required secrets + { + Name: "", + Mount: "", + }, + }, + ConfigMapsVolumes: []entropy.JobConfigMap{ // confirm with streaming for required secrets + { + Name: "", + Mount: "", + }, + }, + Limits: &entropy.UsageSpec{ + CPU: "", + Memory: "", + }, + Requests: &entropy.UsageSpec{ + CPU: "", + Memory: "", + }, + EnvConfigMaps: []string{}, + EnvVariables: map[string]string{}, + }, + }, + JobLabels: map[string]string{}, + Volumes: []entropy.JobVolume{ + { + Name: "", + Kind: "", + }, + }, + }) +} + +func buildResourceLabels(job *models.DlqJob) map[string]string { + return map[string]string{ + "batch_size": fmt.Sprintf("%d", job.BatchSize), + "blob_batch": fmt.Sprintf("%d", job.BlobBatch), + "num_threads": job.ErrorTypes, + "date": job.Date, + "resource_id": job.ResourceID, + "resource_type": job.ResourceType, + "topic": job.Topic, + } +} + +func buildResourceName(job *models.DlqJob) string { + return fmt.Sprintf( + "%s-%s-%s-%s", + job.ResourceID, + job.ResourceType, + job.Topic, + job.Date, + ) +} diff --git a/swagger.yml b/swagger.yml index 531154f..df5664a 100644 --- a/swagger.yml +++ b/swagger.yml @@ -1229,6 +1229,10 @@ definitions: date: type: string example: "2012-10-30" + stopped: + type: boolean + replicas: + type: integer status: type: string enum: