Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG ENABLE_PROXY=false
FROM node:22 AS node_builder

ARG TARGETARCH
ARG ADC_COMMIT=250cef76fdb76e344bef3f42f85ac46ec71b17c8
ARG ADC_COMMIT=78484e87a0168e0f86d130bfae8f808d0d1a1e41

WORKDIR /app

Expand Down
43 changes: 43 additions & 0 deletions api/adc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"strconv"
"strings"
"time"

"github.com/incubator4/go-resty-expr/expr"
)
Expand Down Expand Up @@ -500,3 +501,45 @@ type RedirectConfig struct {
URI string `json:"uri,omitempty" yaml:"uri,omitempty"`
RetCode int `json:"ret_code,omitempty" yaml:"ret_code,omitempty"`
}

const (
StatusSuccess = "success"
StatusFailed = "failed"
StatusPartialFailed = "partial_failed"
)

type SyncResult struct {
Status string `json:"status"`
TotalResources int `json:"total_resources"`
SuccessCount int `json:"success_count"`
FailedCount int `json:"failed_count"`
Success []SyncStatus `json:"success"`
Failed []SyncStatus `json:"failed"`
}

type SyncStatus struct {
Event StatusEvent `json:"event"`
FailedAt time.Time `json:"failed_at,omitempty"`
SyncedAt time.Time `json:"synced_at,omitempty"`
Reason string `json:"reason,omitempty"`
Response ResponseDetails `json:"response,omitempty"`
}

type StatusEvent struct {
ResourceType string `json:"resourceType"`
Type string `json:"type"`
ResourceID string `json:"resourceId"`
ResourceName string `json:"resourceName"`
ParentID string `json:"parentId,omitempty"`
}

type ResponseDetails struct {
Status int `json:"status"`
Headers map[string]string `json:"headers"`
Data ResponseData `json:"data"`
}

type ResponseData struct {
Value map[string]interface{} `json:"value"`
ErrorMsg string `json:"error_msg"`
}
20 changes: 19 additions & 1 deletion internal/provider/adc/adc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package adc
import (
"bytes"
"context"
"encoding/json"
"errors"
"os"
"os/exec"
Expand Down Expand Up @@ -140,11 +141,13 @@ func (d *adcClient) sync(task Task) error {
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env,
"ADC_EXPERIMENTAL_FEATURE_FLAGS=remote-state-file,parallel-backend-request",
"ADC_RUNNING_MODE=ingress",
"ADC_BACKEND=api7ee",
"ADC_SERVER="+d.ServerAddr,
"ADC_TOKEN="+d.Token,
)

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

log.Debugw("adc sync success", zap.String("taskname", task.Name))
output := stdout.Bytes()
if err := json.Unmarshal(output, &result); err != nil {
log.Errorw("failed to unmarshal adc output",
zap.Error(err),
zap.String("stdout", string(output)),
)
return errors.New("failed to unmarshal adc result: " + err.Error())
}

if result.FailedCount > 0 {
log.Errorw("adc sync failed", zap.Any("result", result))
failed := result.Failed
return errors.New(failed[0].Reason)
}

log.Debugw("adc sync success", zap.Any("result", result))
return nil
}
Loading