// ReallocResource allow realloc container resource
540201
func (c *Calcium) ReallocResource(ctx context.Context, IDs []string, cpu float64, mem int64) (chan *types.ReallocResourceMessage, error) {
	ch := make(chan *types.ReallocResourceMessage)
	go func() {
		defer close(ch)
		// Container objs and their locks
		containers, _, containerLocks, err := c.doLockAndGetContainers(ctx, IDs)
		if err != nil {
			log.Errorf("[ReallocResource] Lock and get containers failed %v", err)
			for _, ID := range IDs {
				ch <- &types.ReallocResourceMessage{ContainerID: ID, Success: false}
			}
			return
		}
		defer c.doUnlockAll(containerLocks)
		// Pod-Node-Containers
		containersInfo := map[*types.Pod]nodeContainers{}
		// Pod cache
		podCache := map[string]*types.Pod{}
		// Node locks
		nodeLocks := map[string]lock.DistributedLock{}
		defer c.doUnlockAll(nodeLocks)
		// Node cache
		nodeCache := map[string]*types.Node{}

		for _, container := range containers {
			pod, ok := podCache[container.Podname]
			if !ok {
				pod, err = c.store.GetPod(ctx, container.Podname)
				if err != nil {
					ch <- &types.ReallocResourceMessage{ContainerID: container.ID, Success: false}
					continue
				}
				podCache[container.Podname] = pod
				containersInfo[pod] = nodeContainers{}
			}
			// 没锁过
			if _, ok := nodeLocks[container.Nodename]; !ok {
				node, nodeLock, err := c.doLockAndGetNode(ctx, container.Podname, container.Nodename)
				if err != nil {
					ch <- &types.ReallocResourceMessage{ContainerID: container.ID, Success: false}
					continue
				}
				nodeLocks[container.Nodename] = nodeLock
				nodeCache[container.Nodename] = node
				containersInfo[pod][node] = []*types.Container{container}
				continue
			}
			// 锁过
			node := nodeCache[container.Nodename]
			containersInfo[pod][node] = append(containersInfo[pod][node], container)
		}

		wg := sync.WaitGroup{}
		wg.Add(len(containersInfo))
		// deal with normal container
		for pod, nodeContainersInfo := range containersInfo {
			switch pod.Favor {
			case scheduler.MemoryPrior:
				go func(nodeContainersInfo nodeContainers) {
					defer wg.Done()
					c.doReallocContainerWithMemoryPrior(ctx, ch, nodeContainersInfo, cpu, mem)
				}(nodeContainersInfo)
			case scheduler.CPUPrior:
				go func(nodeContainersInfo nodeContainers) {
					defer wg.Done()
					c.doReallocContainersWithCPUPrior(ctx, ch, nodeContainersInfo, cpu, mem)
				}(nodeContainersInfo)
			default:
				log.Errorf("[ReallocResource] %v not support yet", pod.Favor)
				go func(nodeContainersInfo nodeContainers) {
					defer wg.Done()
					for _, containers := range nodeContainersInfo {
						for _, container := range containers {
							ch <- &types.ReallocResourceMessage{ContainerID: container.ID, Success: false}
						}
					}
				}(nodeContainersInfo)
			}
		}
		wg.Wait()
	}()
	return ch, nil
}
619148
func newOracleVolumeSource(env *OracleEnviron, name, uuid string, api StorageAPI, clock clock.Clock) (*oracleVolumeSource, error) {
	if env == nil {
		return nil, errors.NotFoundf("environ")
	}

	if api == nil {
		return nil, errors.NotFoundf("storage client")
	}

	return &oracleVolumeSource{
		env:       env,
		envName:   name,
		modelUUID: uuid,
		api:       api,
		clock:     clock,
	}, nil
}
594831
func NewLockedSource(seed int64) *lockedSource {
	return &lockedSource{
		src: rand.NewSource(seed).(rand.Source64),
	}
}
582603
func (r Network_Storage_Group_Nfs) GetServiceResource() (resp datatypes.Network_Service_Resource, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Storage_Group_Nfs", "getServiceResource", nil, &r.Options, &resp)
	return
}
1222860
func (c *Connect) FindStoragePoolSources(pooltype string, srcSpec string, flags uint32) (string, error) {
	cpooltype := C.CString(pooltype)
	defer C.free(unsafe.Pointer(cpooltype))
	var csrcSpec *C.char
	if srcSpec != "" {
		csrcSpec := C.CString(srcSpec)
		defer C.free(unsafe.Pointer(csrcSpec))
	}
	var err C.virError
	ret := C.virConnectFindStoragePoolSourcesWrapper(c.ptr, cpooltype, csrcSpec, C.uint(flags), &err)
	if ret == nil {
		return "", makeError(&err)
	}

	defer C.free(unsafe.Pointer(ret))

	return C.GoString(ret), nil
}
10295
func (t *Template) GetAllAWSElasticLoadBalancingV2LoadBalancerResources() map[string]*resources.AWSElasticLoadBalancingV2LoadBalancer {
	results := map[string]*resources.AWSElasticLoadBalancingV2LoadBalancer{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSElasticLoadBalancingV2LoadBalancer:
			results[name] = resource
		}
	}
	return results
}
1226994
func (r *Reflector) LastSyncResourceVersion() string {
	r.lastSyncResourceVersionMutex.RLock()
	defer r.lastSyncResourceVersionMutex.RUnlock()
	return r.lastSyncResourceVersion
}
86362
func (c *FakeDiscovery) ServerResources() ([]*metav1.APIResourceList, error) {
	_, rs, err := c.ServerGroupsAndResources()
	return rs, err
}
1044251
func genSource(paths *model.RevelContainer, dir, filename, templateSource string, args map[string]interface{}) error {

	return utils.GenerateTemplate(filepath.Join(paths.AppPath, dir, filename), templateSource, args)
}
490842
func (t *Template) GetAllAWSDocDBDBClusterResources() map[string]*resources.AWSDocDBDBCluster {
	results := map[string]*resources.AWSDocDBDBCluster{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSDocDBDBCluster:
			results[name] = resource
		}
	}
	return results
}
735904
func (t *Template) GetAllAWSCloudFormationCustomResourceResources() map[string]*resources.AWSCloudFormationCustomResource {
	results := map[string]*resources.AWSCloudFormationCustomResource{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSCloudFormationCustomResource:
			results[name] = resource
		}
	}
	return results
}
778471
func CreateNamedResource(r rest.NamedCreater, scope *RequestScope, admission admission.Interface) http.HandlerFunc {
	return createHandler(r, scope, admission, true)
}
1340464
func NewSearchSource() *SearchSource {
	return &SearchSource{
		from:            -1,
		size:            -1,
		trackScores:     false,
		sorts:           make([]SortInfo, 0),
		sorters:         make([]Sorter, 0),
		fieldDataFields: make([]string, 0),
		scriptFields:    make([]*ScriptField, 0),
		partialFields:   make([]*PartialField, 0),
		facets:          make(map[string]Facet),
		aggregations:    make(map[string]Aggregation),
		rescores:        make([]*Rescore, 0),
		indexBoosts:     make(map[string]float64),
		stats:           make([]string, 0),
		innerHits:       make(map[string]*InnerHit),
	}
}
984647
func (t *Template) GetAllAWSServiceCatalogPortfolioShareResources() map[string]*resources.AWSServiceCatalogPortfolioShare {
	results := map[string]*resources.AWSServiceCatalogPortfolioShare{}
	for name, untyped := range t.Resources {
		switch resource := untyped.(type) {
		case *resources.AWSServiceCatalogPortfolioShare:
			results[name] = resource
		}
	}
	return results
}
1009366
func ValidateCustomResourceDefinitionSubresources(subresources *apiextensions.CustomResourceSubresources, fldPath *field.Path) field.ErrorList {
	allErrs := field.ErrorList{}

	if subresources == nil {
		return allErrs
	}

	if subresources.Scale != nil {
		if len(subresources.Scale.SpecReplicasPath) == 0 {
			allErrs = append(allErrs, field.Required(fldPath.Child("scale.specReplicasPath"), ""))
		} else {
			// should be constrained json path under .spec
			if errs := validateSimpleJSONPath(subresources.Scale.SpecReplicasPath, fldPath.Child("scale.specReplicasPath")); len(errs) > 0 {
				allErrs = append(allErrs, errs...)
			} else if !strings.HasPrefix(subresources.Scale.SpecReplicasPath, ".spec.") {
				allErrs = append(allErrs, field.Invalid(fldPath.Child("scale.specReplicasPath"), subresources.Scale.SpecReplicasPath, "should be a json path under .spec"))
			}
		}

		if len(subresources.Scale.StatusReplicasPath) == 0 {
			allErrs = append(allErrs, field.Required(fldPath.Child("scale.statusReplicasPath"), ""))
		} else {
			// should be constrained json path under .status
			if errs := validateSimpleJSONPath(subresources.Scale.StatusReplicasPath, fldPath.Child("scale.statusReplicasPath")); len(errs) > 0 {
				allErrs = append(allErrs, errs...)
			} else if !strings.HasPrefix(subresources.Scale.StatusReplicasPath, ".status.") {
				allErrs = append(allErrs, field.Invalid(fldPath.Child("scale.statusReplicasPath"), subresources.Scale.StatusReplicasPath, "should be a json path under .status"))
			}
		}

		// if labelSelectorPath is present, it should be a constrained json path under .status
		if subresources.Scale.LabelSelectorPath != nil && len(*subresources.Scale.LabelSelectorPath) > 0 {
			if errs := validateSimpleJSONPath(*subresources.Scale.LabelSelectorPath, fldPath.Child("scale.labelSelectorPath")); len(errs) > 0 {
				allErrs = append(allErrs, errs...)
			} else if !strings.HasPrefix(*subresources.Scale.LabelSelectorPath, ".status.") {
				allErrs = append(allErrs, field.Invalid(fldPath.Child("scale.labelSelectorPath"), subresources.Scale.LabelSelectorPath, "should be a json path under .status"))
			}
		}
	}

	return allErrs
}
878346
func (e *azureStorageProvider) VolumeSource(cfg *storage.Config) (storage.VolumeSource, error) {
	// Check to see if the environment has a storage account,
	// which means it uses unmanaged disks. All models created
	// before Juju 2.3 will have a storage account already, so
	// it's safe to do the check up front.
	maybeStorageClient, maybeStorageAccount, err := e.env.maybeGetStorageClient()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return &azureVolumeSource{e.env, maybeStorageAccount, maybeStorageClient}, nil
}
303310
func NewSource(options ...Option) *Source {
	src := &Source{
		records:     make(chan record),
		maxRetries:  3,
		concurrency: 1,
	}

	for _, opt := range options {
		opt(src)
	}
	go src.getRecords()
	return src
}