Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
Signed-off-by: Le Zhang <zhangl@us.ibm.com>
  • Loading branch information
LiilyZhang committed Oct 11, 2024
1 parent 49422c6 commit 81eaebd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
45 changes: 33 additions & 12 deletions agreementbot/consumer_protocol_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,10 @@ func (b *BaseConsumerProtocolHandler) HandlePolicyChangeForAgreement(ag persiste
// if it's not in the old policy, cancel
choice := -1

nextPriority := policy.GetNextWorkloadChoice(busPol.Workloads, choice)
nextPriority := policy.GetNextWorkloadChoice(busPol.Workloads, choice) // return 6.0.0 workload
wl := nextPriority

// check what is returned as wlUsage
wlUsage, err := b.db.FindSingleWorkloadUsageByDeviceAndPolicyName(ag.DeviceId, ag.PolicyName)
if err != nil {
return false, false, false
Expand All @@ -472,20 +473,32 @@ func (b *BaseConsumerProtocolHandler) HandlePolicyChangeForAgreement(ag persiste
if wlUsage != nil {
wlUsagePriority = wlUsage.Priority
}
if glog.V(5) {
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("for agreement(%v), wlUsage is: %v", ag.CurrentAgreementId, wlUsage)))
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("for agreement(%v), nextPriority is: %v", ag.CurrentAgreementId, nextPriority)))

if currentWL := policy.GetWorkloadWithPriority(busPol.Workloads, wlUsagePriority); currentWL == nil {
// the current workload priority is no longer in the deployment policy
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("current workload priority %v is no longer in policy for agreement %v", wlUsagePriority, ag.CurrentAgreementId)))
return true, false, false
} else {
wl = currentWL
}

// currentWl is from busPol, wlUsagePriority is from db
// if currentWL := policy.GetWorkloadWithPriority(busPol.Workloads, wlUsagePriority); currentWL == nil {
// // the current workload priority is no longer in the deployment policy
// glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("current workload priority %v is no longer in policy for agreement %v", wlUsagePriority, ag.CurrentAgreementId)))
// return true, false, false
// } else {
// wl = currentWL
// }

if oldPolicy != nil {
for choice <= wlUsagePriority && nextPriority != nil {
choice = nextPriority.Priority.PriorityValue
choice = nextPriority.Priority.PriorityValue //1
matchingWL := policy.GetWorkloadWithPriority(oldPolicy.Workloads, choice)
if matchingWL == nil || !matchingWL.IsSame(*nextPriority) {
glog.V(5).Infof(BCPHlogstring(b.Name(), fmt.Sprintf("for agreement(%v), matchingWL (workload with choice %v in the old policy) is: %v", ag.CurrentAgreementId, choice, matchingWL)))
if matchingWL == nil || !matchingWL.IsSame(*nextPriority) { //matchingWL is from oldPolicy, nextPriority is from busPol
if matchingWL == nil {
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("for agreement(%v), matchingWL is nil", ag.CurrentAgreementId)))
} else if !matchingWL.IsSame(*nextPriority) {
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("for agreement(%v), matchingWL %v is different from nextPriority %v", ag.CurrentAgreementId, matchingWL, nextPriority)))
}
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("Higher priority version added or modified. Cancelling agreement %v", ag.CurrentAgreementId)))
return true, false, false
}
Expand All @@ -494,13 +507,21 @@ func (b *BaseConsumerProtocolHandler) HandlePolicyChangeForAgreement(ag persiste

// check if cluster namespace is changed in new policy
if dev.NodeType == persistence.DEVICE_TYPE_CLUSTER && busPol.ClusterNamespace != oldPolicy.ClusterNamespace {
glog.V(5).Infof(BCPHlogstring(b.Name(), fmt.Sprintf("cluster namespace is changed from %v to %v in busiess policy for agreement %v, checking cluster namespace compatibility ...", oldPolicy.ClusterNamespace, busPol.ClusterNamespace, ag.CurrentAgreementId)))
if glog.V(5) {
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("cluster namespace is changed from %v to %v in busiess policy for agreement %v, checking cluster namespace compatibility ...", oldPolicy.ClusterNamespace, busPol.ClusterNamespace, ag.CurrentAgreementId)))
}

t_comp, consumerNamespace, t_reason := compcheck.CheckClusterNamespaceCompatibility(dev.NodeType, dev.ClusterNamespace, dev.IsNamespaceScoped, busPol.ClusterNamespace, wl.ClusterDeployment, ag.Pattern, false, msgPrinter)
if !t_comp {
glog.V(5).Infof(BCPHlogstring(b.Name(), fmt.Sprintf("cluster namespace %v is not longer compatible for agreement %v. Reason is: %v", consumerNamespace, ag.CurrentAgreementId, t_reason)))
if glog.V(5) {
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("cluster namespace %v is not longer compatible for agreement %v. Reason is: %v", consumerNamespace, ag.CurrentAgreementId, t_reason)))
}
return true, true, false
} else if consumerNamespace != oldPolicy.ClusterNamespace {
glog.V(5).Infof(BCPHlogstring(b.Name(), fmt.Sprintf("cluster namespace has changed from %v to %v for agreement %v", oldPolicy.ClusterNamespace, consumerNamespace, ag.CurrentAgreementId)))
if glog.V(5) {
glog.Infof(BCPHlogstring(b.Name(), fmt.Sprintf("cluster namespace has changed from %v to %v for agreement %v", oldPolicy.ClusterNamespace, consumerNamespace, ag.CurrentAgreementId)))
}

return true, true, false
}
// new cluster namespace is still compatible, namespace still same
Expand Down
2 changes: 1 addition & 1 deletion events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ type PolicyChangedMessage struct {
}

func (e PolicyChangedMessage) String() string {
return fmt.Sprintf("event: %v, file: %v, name: %v, org: %v, policy: %v", e.event, e.fileName, e.name, e.org, e.policy)
return fmt.Sprintf("event: %v, file: %v, name: %v, org: %v, policy: %v, oldPolicy: %v", e.event, e.fileName, e.name, e.org, e.policy, e.oldPolicy)
}

func (e PolicyChangedMessage) ShortString() string {
Expand Down

0 comments on commit 81eaebd

Please sign in to comment.