diff --git a/agreementbot/consumer_protocol_handler.go b/agreementbot/consumer_protocol_handler.go index a6e8ba469..7cc93a64e 100644 --- a/agreementbot/consumer_protocol_handler.go +++ b/agreementbot/consumer_protocol_handler.go @@ -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 @@ -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 } @@ -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 diff --git a/events/events.go b/events/events.go index eef9d253a..05b165d2b 100644 --- a/events/events.go +++ b/events/events.go @@ -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 {