Skip to content

Commit f56662f

Browse files
committed
refactor(adc): add more adc sync result information
1 parent f83fca9 commit f56662f

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ARG ENABLE_PROXY=false
33
FROM node:22 AS node_builder
44

55
ARG TARGETARCH
6-
ARG ADC_COMMIT=250cef76fdb76e344bef3f42f85ac46ec71b17c8
6+
ARG ADC_COMMIT=78484e87a0168e0f86d130bfae8f808d0d1a1e41
77

88
WORKDIR /app
99

api/adc/types.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"strconv"
99
"strings"
10+
"time"
1011

1112
"github.com/incubator4/go-resty-expr/expr"
1213
)
@@ -500,3 +501,45 @@ type RedirectConfig struct {
500501
URI string `json:"uri,omitempty" yaml:"uri,omitempty"`
501502
RetCode int `json:"ret_code,omitempty" yaml:"ret_code,omitempty"`
502503
}
504+
505+
const (
506+
StatusSuccess = "success"
507+
StatusFailed = "failed"
508+
StatusPartialFailed = "partial_failed"
509+
)
510+
511+
type SyncResult struct {
512+
Status string `json:"status"`
513+
TotalResources int `json:"total_resources"`
514+
SuccessCount int `json:"success_count"`
515+
FailedCount int `json:"failed_count"`
516+
Success []SyncStatus `json:"success"`
517+
Failed []SyncStatus `json:"failed"`
518+
}
519+
520+
type SyncStatus struct {
521+
Event StatusEvent `json:"event"`
522+
FailedAt time.Time `json:"failed_at,omitempty"`
523+
SyncedAt time.Time `json:"synced_at,omitempty"`
524+
Reason string `json:"reason,omitempty"`
525+
Response ResponseDetails `json:"response,omitempty"`
526+
}
527+
528+
type StatusEvent struct {
529+
ResourceType string `json:"resourceType"`
530+
Type string `json:"type"`
531+
ResourceID string `json:"resourceId"`
532+
ResourceName string `json:"resourceName"`
533+
ParentID string `json:"parentId,omitempty"`
534+
}
535+
536+
type ResponseDetails struct {
537+
Status int `json:"status"`
538+
Headers map[string]string `json:"headers"`
539+
Data ResponseData `json:"data"`
540+
}
541+
542+
type ResponseData struct {
543+
Value map[string]interface{} `json:"value"`
544+
ErrorMsg string `json:"error_msg"`
545+
}

internal/provider/adc/adc.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package adc
33
import (
44
"bytes"
55
"context"
6+
"encoding/json"
67
"errors"
78
"os"
89
"os/exec"
@@ -140,11 +141,13 @@ func (d *adcClient) sync(task Task) error {
140141
cmd.Env = append(cmd.Env, os.Environ()...)
141142
cmd.Env = append(cmd.Env,
142143
"ADC_EXPERIMENTAL_FEATURE_FLAGS=remote-state-file,parallel-backend-request",
144+
"ADC_RUNNING_MODE=ingress",
143145
"ADC_BACKEND=api7ee",
144146
"ADC_SERVER="+d.ServerAddr,
145147
"ADC_TOKEN="+d.Token,
146148
)
147149

150+
var result types.SyncResult
148151
if err := cmd.Run(); err != nil {
149152
stderrStr := stderr.String()
150153
stdoutStr := stdout.String()
@@ -160,6 +163,21 @@ func (d *adcClient) sync(task Task) error {
160163
return errors.New("failed to sync resources: " + errMsg + ", exit err: " + err.Error())
161164
}
162165

163-
log.Debugw("adc sync success", zap.String("taskname", task.Name))
166+
output := stdout.Bytes()
167+
if err := json.Unmarshal(output, &result); err != nil {
168+
log.Errorw("failed to unmarshal adc output",
169+
zap.Error(err),
170+
zap.String("stdout", string(output)),
171+
)
172+
return errors.New("failed to unmarshal adc result: " + err.Error())
173+
}
174+
175+
if result.FailedCount > 0 {
176+
log.Errorw("adc sync failed", zap.Any("result", result))
177+
failed := result.Failed
178+
return errors.New(failed[0].Reason)
179+
}
180+
181+
log.Debugw("adc sync success", zap.Any("result", result))
164182
return nil
165183
}

0 commit comments

Comments
 (0)