// readPriority reads the PRI as defined in RFC-5424 and assigns Severity and
// Facility accordingly.
490761
func (m *Message) readPriority(r io.RuneScanner) error {
	ch, _, err := r.ReadRune()
	if err != nil {
		return err
	}
	if ch != '<' {
		return badFormat("Priority")
	}

	rv := &bytes.Buffer{}
	for {
		ch, _, err := r.ReadRune()
		if err != nil {
			return err
		}
		if unicode.IsDigit(ch) {
			rv.WriteRune(ch)
			continue
		}
		if ch != '>' {
			return badFormat("Priority")
		}

		// We have a complete integer expression
		priority, err := strconv.ParseInt(string(rv.Bytes()), 10, 32)
		if err != nil {
			return badFormat("Priority")
		}
		m.Priority = Priority(priority)
		return nil
	}
}
622811
func NormalizeReduce(maxPriority int, reverse bool) PriorityReduceFunction {
	return func(
		_ *v1.Pod,
		_ interface{},
		_ map[string]*schedulernodeinfo.NodeInfo,
		result schedulerapi.HostPriorityList) error {

		var maxCount int
		for i := range result {
			if result[i].Score > maxCount {
				maxCount = result[i].Score
			}
		}

		if maxCount == 0 {
			if reverse {
				for i := range result {
					result[i].Score = maxPriority
				}
			}
			return nil
		}

		for i := range result {
			score := result[i].Score

			score = maxPriority * score / maxCount
			if reverse {
				score = maxPriority - score
			}

			result[i].Score = score
		}
		return nil
	}
}
154509
func (s *WorkflowExecutionContinuedAsNewEventAttributes) SetTaskPriority(v string) *WorkflowExecutionContinuedAsNewEventAttributes {
	s.TaskPriority = &v
	return s
}
944084
func getNodePriority(ip string, nodes []string) int {
	return 100 + stringSlice(nodes).pos(ip)
}
150617
func (s *GetMaintenanceWindowExecutionTaskOutput) SetPriority(v int64) *GetMaintenanceWindowExecutionTaskOutput {
	s.Priority = &v
	return s
}
773535
func (s *JobQueueDetail) SetPriority(v int64) *JobQueueDetail {
	s.Priority = &v
	return s
}
941379
func JoinOptionPriority(ep Endpoint, prio int) EndpointOption {
	return func(ep *endpoint) {
		// ep lock already acquired
		c := ep.network.getController()
		c.Lock()
		sb, ok := c.sandboxes[ep.sandboxID]
		c.Unlock()
		if !ok {
			logrus.Errorf("Could not set endpoint priority value during Join to endpoint %s: No sandbox id present in endpoint", ep.id)
			return
		}
		sb.epPriority[ep.id] = prio
	}
}
370570
func parsePriorityStats(line string, ps *PriorityStats) error {
	var (
		value uint64
		err   error
	)
	switch {
	case strings.HasPrefix(line, "Unused:"):
		fields := strings.Fields(line)
		rawValue := fields[len(fields)-1]
		valueStr := strings.TrimSuffix(rawValue, "%")
		value, err = strconv.ParseUint(valueStr, 10, 64)
		if err != nil {
			return err
		}
		ps.UnusedPercent = value
	case strings.HasPrefix(line, "Metadata:"):
		fields := strings.Fields(line)
		rawValue := fields[len(fields)-1]
		valueStr := strings.TrimSuffix(rawValue, "%")
		value, err = strconv.ParseUint(valueStr, 10, 64)
		if err != nil {
			return err
		}
		ps.MetadataPercent = value
	}
	return nil
}
701882
func SetLowPriority() error {
	// Process zero is "self", niceness value 9 is something between 0
	// (default) and 19 (worst priority).
	const (
		pidSelf       = 0
		wantNiceLevel = 9
	)

	if cur, err := syscall.Getpriority(syscall.PRIO_PROCESS, pidSelf); err == nil && cur >= wantNiceLevel {
		// We're done here.
		return nil
	}

	err := syscall.Setpriority(syscall.PRIO_PROCESS, pidSelf, wantNiceLevel)
	return errors.Wrap(err, "set niceness") // wraps nil as nil
}
355700
func (r *ResourceAllocationPriority) PriorityMap(
	pod *v1.Pod,
	meta interface{},
	nodeInfo *schedulernodeinfo.NodeInfo) (schedulerapi.HostPriority, error) {
	node := nodeInfo.Node()
	if node == nil {
		return schedulerapi.HostPriority{}, fmt.Errorf("node not found")
	}
	allocatable := nodeInfo.AllocatableResource()

	var requested schedulernodeinfo.Resource
	if priorityMeta, ok := meta.(*priorityMetadata); ok {
		requested = *priorityMeta.nonZeroRequest
	} else {
		// We couldn't parse metadata - fallback to computing it.
		requested = *getNonZeroRequests(pod)
	}

	requested.MilliCPU += nodeInfo.NonZeroRequest().MilliCPU
	requested.Memory += nodeInfo.NonZeroRequest().Memory
	var score int64
	// Check if the pod has volumes and this could be added to scorer function for balanced resource allocation.
	if len(pod.Spec.Volumes) >= 0 && utilfeature.DefaultFeatureGate.Enabled(features.BalanceAttachedNodeVolumes) && nodeInfo.TransientInfo != nil {
		score = r.scorer(&requested, &allocatable, true, nodeInfo.TransientInfo.TransNodeInfo.RequestedVolumes, nodeInfo.TransientInfo.TransNodeInfo.AllocatableVolumesCount)
	} else {
		score = r.scorer(&requested, &allocatable, false, 0, 0)
	}

	if klog.V(10) {
		if len(pod.Spec.Volumes) >= 0 && utilfeature.DefaultFeatureGate.Enabled(features.BalanceAttachedNodeVolumes) && nodeInfo.TransientInfo != nil {
			klog.Infof(
				"%v -> %v: %v, capacity %d millicores %d memory bytes, %d volumes, total request %d millicores %d memory bytes %d volumes, score %d",
				pod.Name, node.Name, r.Name,
				allocatable.MilliCPU, allocatable.Memory, nodeInfo.TransientInfo.TransNodeInfo.AllocatableVolumesCount,
				requested.MilliCPU, requested.Memory,
				nodeInfo.TransientInfo.TransNodeInfo.RequestedVolumes,
				score,
			)
		} else {
			klog.Infof(
				"%v -> %v: %v, capacity %d millicores %d memory bytes, total request %d millicores %d memory bytes, score %d",
				pod.Name, node.Name, r.Name,
				allocatable.MilliCPU, allocatable.Memory,
				requested.MilliCPU, requested.Memory,
				score,
			)
		}
	}

	return schedulerapi.HostPriority{
		Host:  node.Name,
		Score: int(score),
	}, nil
}
803121
func HashPriority(certs []*x509.Certificate) int {
	ret := 0.0
	for i, cert := range certs {
		f1 := 1.0 / (float64(i) + 1.0)
		f2 := 1.0 - f1
		ret = ret*f2 + float64(hashPriority(cert))*f1
	}
	return int(ret)
}
32293
func (s *UpdateMaintenanceWindowTaskInput) SetPriority(v int64) *UpdateMaintenanceWindowTaskInput {
	s.Priority = &v
	return s
}
206921
func NewServiceAntiAffinityPriority(podLister algorithm.PodLister, serviceLister algorithm.ServiceLister, label string) (PriorityMapFunction, PriorityReduceFunction) {
	antiAffinity := &ServiceAntiAffinity{
		podLister:     podLister,
		serviceLister: serviceLister,
		label:         label,
	}
	return antiAffinity.CalculateAntiAffinityPriorityMap, antiAffinity.CalculateAntiAffinityPriorityReduce
}
694173
func (s *ContinueAsNewWorkflowExecutionDecisionAttributes) SetTaskPriority(v string) *ContinueAsNewWorkflowExecutionDecisionAttributes {
	s.TaskPriority = &v
	return s
}
1131928
func (s *UpdateJobPriorityOutput) SetPriority(v int64) *UpdateJobPriorityOutput {
	s.Priority = &v
	return s
}
803550
func WithPrioritySelector(value PrioritySelector) copts.Opt {
	return WithPeerSorter(func(peers []fab.Peer) []fab.Peer {
		return sortPeers(peers, value)
	})
}
210862
func (n *HTTPNode) SetPriority(prio int) bool {
	if n.Priority == prio {
		return false
	}
	n.Priority = prio
	n.Updated = time.Now()
	n.readyStateGCHandler()
	return true
}