/*
NewParallel starts it's members simultaneously.  Use a parallel group to describe a set
of concurrent but independent processes.
*/
197232
func NewParallel(terminationSignal os.Signal, members Members) ifrit.Runner {
	return parallelGroup{
		terminationSignal: terminationSignal,
		pool:              make(map[string]ifrit.Process),
		members:           members,
	}
}
692831
func (s *AutoScaleService) NewDisableAutoScaleVmGroupParams(id string) *DisableAutoScaleVmGroupParams {
	p := &DisableAutoScaleVmGroupParams{}
	p.p = make(map[string]interface{})
	p.p["id"] = id
	return p
}
445058
func (s *LoadBalancerService) NewListGlobalLoadBalancerRulesParams() *ListGlobalLoadBalancerRulesParams {
	p := &ListGlobalLoadBalancerRulesParams{}
	p.p = make(map[string]interface{})
	return p
}
801719
func (s *ParallelismConfigurationUpdate) SetParallelismUpdate(v int64) *ParallelismConfigurationUpdate {
	s.ParallelismUpdate = &v
	return s
}
1337292
func (s *AutoScaleService) CreateAutoScaleVmGroup(p *CreateAutoScaleVmGroupParams) (*CreateAutoScaleVmGroupResponse, error) {
	resp, err := s.cs.newRequest("createAutoScaleVmGroup", p.toURLValues())
	if err != nil {
		return nil, err
	}

	var r CreateAutoScaleVmGroupResponse
	if err := json.Unmarshal(resp, &r); err != nil {
		return nil, err
	}

	// If we have a async client, we need to wait for the async result
	if s.cs.async {
		b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
		if err != nil {
			if err == AsyncTimeoutErr {
				return &r, err
			}
			return nil, err
		}

		b, err = getRawValue(b)
		if err != nil {
			return nil, err
		}

		if err := json.Unmarshal(b, &r); err != nil {
			return nil, err
		}
	}

	return &r, nil
}
371050
func (s *VMGroupService) NewListInstanceGroupsParams() *ListInstanceGroupsParams {
	p := &ListInstanceGroupsParams{}
	p.p = make(map[string]interface{})
	return p
}
735059
func (p *Plugin) NewProcessFromTemplate(tmp *process.Template) ProcessInstance {
	newTmpPr, err := p.templateToProcess(tmp)
	if err != nil {
		p.Log.Errorf("cannot create a process from template: %v", err)
		return nil
	}
	p.processes = append(p.processes, newTmpPr)

	go newTmpPr.watch()

	return newTmpPr
}
927980
func (b *Bucket) CopyLargeFileInParallel(sourcePath string, destPath string, contentType string, perm ACL, options Options, maxConcurrency int) error {

	if maxConcurrency < 1 {
		maxConcurrency = 1
	}

	currentLength, err := b.GetContentLength(sourcePath)

	log.Printf("Parallel Copy large file[size: %d] from %s to %s\n", currentLength, sourcePath, destPath)

	if err != nil {
		return err
	}

	if currentLength < maxCopytSize {
		_, err := b.PutCopy(destPath, perm,
			CopyOptions{},
			b.Path(sourcePath))
		return err
	}

	multi, err := b.InitMulti(destPath, contentType, perm, options)
	if err != nil {
		return err
	}

	numParts := (currentLength + defaultChunkSize - 1) / defaultChunkSize
	completedParts := make([]Part, numParts)

	errChan := make(chan error, numParts)
	limiter := make(chan struct{}, maxConcurrency)

	var start int64 = 0
	var to int64 = 0
	var partNumber = 0
	sourcePathForCopy := b.Path(sourcePath)

	for start = 0; start < currentLength; start = to {
		to = start + defaultChunkSize
		if to > currentLength {
			to = currentLength
		}
		partNumber++

		rangeStr := fmt.Sprintf("bytes=%d-%d", start, to-1)
		limiter <- struct{}{}
		go func(partNumber int, rangeStr string) {
			_, part, err := multi.PutPartCopyWithContentLength(partNumber,
				CopyOptions{CopySourceOptions: rangeStr},
				sourcePathForCopy, currentLength)
			if err == nil {
				completedParts[partNumber-1] = part
			} else {
				log.Printf("Unable in PutPartCopy of part %d for %s: %v\n", partNumber, sourcePathForCopy, err)
			}
			errChan <- err
			<-limiter
		}(partNumber, rangeStr)
	}

	fullyCompleted := true
	for range completedParts {
		err := <-errChan
		if err != nil {
			fullyCompleted = false
		}
	}

	if fullyCompleted {
		err = multi.Complete(completedParts)
	} else {
		err = multi.Abort()
	}

	return err
}
749010
func NewComparablePrincipalSet(set policies.PrincipalSet) ComparablePrincipalSet {
	var res ComparablePrincipalSet
	for _, principal := range set {
		cp := NewComparablePrincipal(principal)
		if cp == nil {
			return nil
		}
		res = append(res, cp)
	}
	return res
}
851289
func NewProtoWrapperWithSerializer(db keyval.CoreBrokerWatcher, serializer keyval.Serializer) *ProtoWrapper {
	// OBSOLETE, use NewProtoWrapper
	return NewProtoWrapper(db, serializer)
}
848969
func NewWithParamsNonce(params *Parameters, nonce utils.NonceGenerator) *Client {
	return NewWithParamsAsyncFactoryNonce(params, NewWebsocketAsynchronousFactory(params), nonce)
}
30557
func (s *AutoScaleService) NewEnableAutoScaleVmGroupParams(id string) *EnableAutoScaleVmGroupParams {
	p := &EnableAutoScaleVmGroupParams{}
	p.p = make(map[string]interface{})
	p.p["id"] = id
	return p
}
604110
func NewGroupMembersRemoveArg(Group *GroupSelector, Users []*UserSelectorArg) *GroupMembersRemoveArg {
	s := new(GroupMembersRemoveArg)
	s.Group = Group
	s.Users = Users
	s.ReturnMembers = true
	return s
}
449351
func NewParams() *Params {
	return &Params{
		Package: make([]string, 0),
		Watcher: make(map[string]string),
	}
}
1284476
func jobHasDesiredParallelism(jobClient batchclient.JobsGetter, job *batch.Job) wait.ConditionFunc {
	return func() (bool, error) {
		job, err := jobClient.Jobs(job.Namespace).Get(job.Name, metav1.GetOptions{})
		if err != nil {
			return false, err
		}

		// desired parallelism can be either the exact number, in which case return immediately
		if job.Status.Active == *job.Spec.Parallelism {
			return true, nil
		}
		if job.Spec.Completions == nil {
			// A job without specified completions needs to wait for Active to reach Parallelism.
			return false, nil
		}

		// otherwise count successful
		progress := *job.Spec.Completions - job.Status.Active - job.Status.Succeeded
		return progress <= 0, nil
	}
}
818147
func NewWithParamsAsyncFactory(params *Parameters, async AsynchronousFactory) *Client {
	return NewWithParamsAsyncFactoryNonce(params, async, utils.NewEpochNonceGenerator())
}
829220
func (s *ParallelismConfigurationDescription) SetParallelism(v int64) *ParallelismConfigurationDescription {
	s.Parallelism = &v
	return s
}