Skip to content

Commit

Permalink
chore: add detailed debug to manifest delete
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMenoti committed May 10, 2024
1 parent a0f64da commit ee1bdd1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions messages/manifest/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import "errors"
var (
ErrorUnmarshalAzionJsonFile = errors.New("Failed to parse the given 'azion.json' file. Verify if the file format is JSON or fix its content according to the JSON format specification at https://www.json.org/json-en.html")
ErrorCacheNotFound = errors.New("Could not find this cache setting")
ErrorFunctionNotFound = errors.New("Could not find this edge function")
ErrorOriginNotFound = errors.New("Could not find this origin")
)
1 change: 1 addition & 0 deletions pkg/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type AzionJsonDataFunction struct {
Args string `json:"args"`
InstanceID int64 `json:"instance-id"`
InstanceName string `json:"instance-name"`
CacheId int64 `json:"cache-id"`
}

type AzionJsonDataApplication struct {
Expand Down
8 changes: 4 additions & 4 deletions pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (man *ManifestInterpreter) CreateResources(conf *contracts.AzionApplication
ruleConf = append(ruleConf, newRule)
delete(RuleIds, rule.Name)
} else {
requestCreate, err := makeRuleRequestCreate(rule, CacheIds, conf, OriginIds, client, ctx)
requestCreate, err := makeRuleRequestCreate(rule, conf, client, ctx)
if err != nil {
return err
}
Expand Down Expand Up @@ -262,7 +262,7 @@ func deleteResources(ctx context.Context, f *cmdutil.Factory, conf *contracts.Az
if err != nil {
return err
}
logger.FInfo(f.IOStreams.Out, fmt.Sprintf(msgrule.DeleteOutputSuccess, value))
logger.FInfo(f.IOStreams.Out, fmt.Sprintf(msgrule.DeleteOutputSuccess+"\n", value))
}

for i, value := range OriginKeys {
Expand All @@ -273,15 +273,15 @@ func deleteResources(ctx context.Context, f *cmdutil.Factory, conf *contracts.Az
if err != nil {
return err
}
logger.FInfo(f.IOStreams.Out, fmt.Sprintf(msgorigin.DeleteOutputSuccess, value))
logger.FInfo(f.IOStreams.Out, fmt.Sprintf(msgorigin.DeleteOutputSuccess+"\n", value))
}

for _, value := range CacheIds {
err := clientCache.Delete(ctx, conf.Application.ID, value)
if err != nil {
return err
}
logger.FInfo(f.IOStreams.Out, fmt.Sprintf(msgcache.DeleteOutputSuccess, value))
logger.FInfo(f.IOStreams.Out, fmt.Sprintf(msgcache.DeleteOutputSuccess+"\n", value))
}

return nil
Expand Down
19 changes: 14 additions & 5 deletions pkg/manifest/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func makeRuleRequestUpdate(rule contracts.RuleEngine, conf *contracts.AzionAppli
behaviorString.SetTarget(str)
delete(CacheIds, v.RulesEngineBehaviorString.Target)
} else {
logger.Debug("Cache Setting not found", zap.Any("Target", v.RulesEngineBehaviorString.Target))
return nil, msg.ErrorCacheNotFound
}
} else if v.RulesEngineBehaviorString.Name == "run_function" {
Expand All @@ -206,7 +207,8 @@ func makeRuleRequestUpdate(rule contracts.RuleEngine, conf *contracts.AzionAppli
behaviorString.SetTarget(str)
delete(OriginKeys, v.RulesEngineBehaviorString.Target)
} else {
return nil, msg.ErrorCacheNotFound
logger.Debug("Origin not found", zap.Any("Target", v.RulesEngineBehaviorString.Target))
return nil, msg.ErrorOriginNotFound
}
} else {
behaviorString.SetTarget(v.RulesEngineBehaviorString.Target)
Expand All @@ -225,8 +227,7 @@ func makeRuleRequestUpdate(rule contracts.RuleEngine, conf *contracts.AzionAppli
return request, nil
}


func makeRuleRequestCreate(rule contracts.RuleEngine, cacheIds map[string]int64, conf *contracts.AzionApplicationOptions, originIds map[string]int64, client *apiEdgeApplications.Client, ctx context.Context) (*apiEdgeApplications.CreateRulesEngineRequest, error) {
func makeRuleRequestCreate(rule contracts.RuleEngine, conf *contracts.AzionApplicationOptions, client *apiEdgeApplications.Client, ctx context.Context) (*apiEdgeApplications.CreateRulesEngineRequest, error) {
request := &apiEdgeApplications.CreateRulesEngineRequest{}

if rule.Description != nil {
Expand Down Expand Up @@ -277,6 +278,7 @@ func makeRuleRequestCreate(rule contracts.RuleEngine, cacheIds map[string]int64,
behaviorString.SetTarget(str)
delete(CacheIds, v.RulesEngineBehaviorString.Target)
} else {
logger.Debug("Cache Setting not found", zap.Any("Target", v.RulesEngineBehaviorString.Target))
return nil, msg.ErrorCacheNotFound
}
} else if v.RulesEngineBehaviorString.Name == "run_function" {
Expand All @@ -293,11 +295,12 @@ func makeRuleRequestCreate(rule contracts.RuleEngine, cacheIds map[string]int64,
str := strconv.FormatInt(conf.Function.InstanceID, 10)
behaviorString.SetTarget(str)
} else if v.RulesEngineBehaviorString.Name == "set_origin" {
if id := originIds[v.RulesEngineBehaviorString.Target]; id > 0 {
if id := OriginIds[v.RulesEngineBehaviorString.Target]; id > 0 {
str := strconv.FormatInt(id, 10)
behaviorString.SetTarget(str)
delete(OriginKeys, v.RulesEngineBehaviorString.Target)
} else {
logger.Debug("Origin not found", zap.Any("Target", v.RulesEngineBehaviorString.Target))
return nil, msg.ErrorOriginNotFound
}
} else {
Expand Down Expand Up @@ -352,8 +355,11 @@ func makeOriginUpdateRequest(origin contracts.Origin, conf *contracts.AzionAppli
}

func doCacheForRule(ctx context.Context, client *apiEdgeApplications.Client, conf *contracts.AzionApplicationOptions) (int64, error) {
if conf.Function.CacheId > 0 {
return conf.Function.CacheId, nil
}
var reqCache apiEdgeApplications.CreateCacheSettingsRequest
reqCache.SetName("function policy")
reqCache.SetName("function-policy")
reqCache.SetBrowserCacheSettings("honor")
reqCache.SetCdnCacheSettings("honor")
reqCache.SetCdnCacheSettingsMaximumTtl(0)
Expand All @@ -366,5 +372,8 @@ func doCacheForRule(ctx context.Context, client *apiEdgeApplications.Client, con
logger.Debug("Error while creating Cache Settings", zap.Error(err))
return 0, err
}

conf.Function.CacheId = cache.GetId()

return cache.GetId(), nil
}

0 comments on commit ee1bdd1

Please sign in to comment.