// Get Random Allocation ID from a known jobID. Prefer to use a running allocation,
// but use a dead allocation if no running allocations are found
518236
func getRandomJobAlloc(client *api.Client, jobID string) (string, error) {
	var runningAllocs []*api.AllocationListStub
	allocs, _, err := client.Jobs().Allocations(jobID, false, nil)

	// Check that the job actually has allocations
	if len(allocs) == 0 {
		return "", fmt.Errorf("job %q doesn't exist or it has no allocations", jobID)
	}

	for _, v := range allocs {
		if v.ClientStatus == "running" {
			runningAllocs = append(runningAllocs, v)
		}
	}
	// If we don't have any allocations running, use dead allocations
	if len(runningAllocs) < 1 {
		runningAllocs = allocs
	}

	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	allocID := runningAllocs[r.Intn(len(runningAllocs))].ID
	return allocID, err
}
1057221
func (p *PullRequest) GetID() int64 {
	if p == nil || p.ID == nil {
		return 0
	}
	return *p.ID
}
1015955
func (c *CheckSuite) GetID() int64 {
	if c == nil || c.ID == nil {
		return 0
	}
	return *c.ID
}
947225
func FindById(id string) (*Job, error) {
	job := &Job{}
	t := newTransaction()
	t.scanJobById(id, job)
	if err := t.exec(); err != nil {
		switch e := err.(type) {
		case ErrorJobNotFound:
			// If the job was not found, add the id to the error
			// so that the caller can get a more useful error message.
			e.id = id
			return nil, e
		default:
			return nil, err
		}
	}
	return job, nil
}
321435
func (i *Installation) GetTargetID() int64 {
	if i == nil || i.TargetID == nil {
		return 0
	}
	return *i.TargetID
}
1271757
func GenerateID() string {
	b := make([]byte, 32)
	rand.Read(b)
	return hex.EncodeToString(b)
}
547928
func (a *Allocator) GetNoCache(ctx context.Context, key AllocatorKey) (idpool.ID, error) {
	// GetPrefix() will choose any "first" key with the same prefix as the
	// specified key. In the worst case this may alternate between
	// returning the prefix that is specified and returning a key with a
	// longer prefix (even if this exact prefix already exists in the
	// kvstore). In that case, we will potentially allocate duplicate
	// identities for the same set of labels. This is not efficient, but
	// should have the correct identity properties.
	prefix := path.Join(a.valuePrefix, key.GetKey())
	k, v, err := kvstore.GetPrefix(ctx, prefix)
	kvstore.Trace("AllocateGet", err, logrus.Fields{fieldPrefix: prefix, fieldKey: k, fieldValue: v})
	if err != nil || v == nil || !prefixMatchesKey(prefix, k) {
		return 0, err
	}

	id, err := strconv.ParseUint(string(v), 10, 64)
	if err != nil {
		return idpool.NoID, fmt.Errorf("unable to parse value '%s': %s", v, err)
	}

	return idpool.ID(id), nil
}
1291
func GenerateJobID(hostID, uuid string) string {
	if uuid == "" {
		uuid = random.UUID()
	}
	return hostID + "-" + uuid
}
23226
func (s *SourceImportAuthor) GetID() int64 {
	if s == nil || s.ID == nil {
		return 0
	}
	return *s.ID
}
1141977
func GetID(id uint32) (*loadbalancer.L3n4AddrID, error) {
	if enableGlobalServiceIDs {
		return getGlobalID(id)
	}

	return serviceIDAlloc.getLocalID(id)
}
723704
func (pool *IDPool) Get() (id uint32) {
	pool.Lock()
	defer pool.Unlock()

	// Pick a value that's been returned, if any.
	for key := range pool.used {
		delete(pool.used, key)
		return key
	}

	// No recycled IDs are available, so increase the pool size.
	pool.maxUsed += 1
	return pool.maxUsed
}
218781
func (a *Allocator) Get(ctx context.Context, key AllocatorKey) (idpool.ID, error) {
	if id := a.mainCache.get(key.GetKey()); id != idpool.NoID {
		return id, nil
	}

	return a.GetNoCache(ctx, key)
}
851960
func (g *GistFork) GetID() string {
	if g == nil || g.ID == nil {
		return ""
	}
	return *g.ID
}
1255334
func randomId() string {
	b := randomBytesMod(idLen, byte(len(idChars)))
	for i, c := range b {
		b[i] = idChars[c]
	}
	return string(b)
}
152468
func (u *UserLDAPMapping) GetID() int64 {
	if u == nil || u.ID == nil {
		return 0
	}
	return *u.ID
}
659632
func (net *Network) GetRandomUpNode(excludeIDs ...enode.ID) *Node {
	net.lock.RLock()
	defer net.lock.RUnlock()
	return net.getRandomUpNode(excludeIDs...)
}
1180647
func (c *Host) GetJob(id string) (*host.ActiveJob, error) {
	var res host.ActiveJob
	err := c.c.Get(fmt.Sprintf("/host/jobs/%s", id), &res)
	return &res, err
}