// CheckScale examines sirenia cluster formation to check if cluster
// has been scaled up yet.
// Returns true if scaled, false if not.
776867
func CheckScale(app, controllerKey, procName string, logger log15.Logger) (bool, error) {
	logger = logger.New("fn", "CheckScale")
	// Connect to controller.
	logger.Info("connecting to controller")
	client, err := controller.NewClient("", controllerKey)
	if err != nil {
		logger.Error("controller client error", "err", err)
		return false, err
	}

	// Retrieve app release.
	logger.Info("retrieving app release", "app", app)
	release, err := client.GetAppRelease(app)
	if err == controller.ErrNotFound {
		logger.Error("release not found", "app", app)
		return false, err
	} else if err != nil {
		logger.Error("get release error", "app", app, "err", err)
		return false, err
	}

	// Retrieve current formation.
	logger.Info("retrieving formation", "app", app, "release_id", release.ID)
	formation, err := client.GetFormation(app, release.ID)
	if err == controller.ErrNotFound {
		logger.Error("formation not found", "app", app, "release_id", release.ID)
		return false, err
	} else if err != nil {
		logger.Error("formation error", "app", app, "release_id", release.ID, "err", err)
		return false, err
	}

	// Database hasn't been scaled up yet
	if formation.Processes[procName] == 0 {
		return false, nil
	}

	return true, nil

}
951128
func (idsc IsDockerSystemdCheck) Check() (warnings, errorList []error) {
	warnings = []error{}
	driver, err := util.GetCgroupDriverDocker(exec.New())
	if err != nil {
		errorList = append(errorList, err)
		return nil, errorList
	}
	if driver != util.CgroupDriverSystemd {
		err = errors.Errorf("detected %q as the Docker cgroup driver. "+
			"The recommended driver is %q. "+
			"Please follow the guide at https://kubernetes.io/docs/setup/cri/",
			driver,
			util.CgroupDriverSystemd)
		warnings = append(warnings, err)
	}
	return warnings, nil
}
806083
func FormatCheck(i Info) bool {
	return (C.sf_format_check((*C.SF_INFO)(unsafe.Pointer(&i))) == C.SF_TRUE)
}
966792
func (c *Checker) Check(rel string, recurse bool, beforeRev, afterRev string) ([]Change, error) {
	// If revision is unset use VCS's default revision
	dBefore, dAfter := c.vcs.DefaultRevision()
	if beforeRev == "" {
		beforeRev = dBefore
	}
	if afterRev == "" {
		afterRev = dAfter
	}
	c.recurse = recurse

	var err error
	c.path, err = importPathTo(rel)
	if err != nil {
		return nil, err
	}

	c.logf("import path: %q before: %q after: %q recursive: %v\n", c.path, beforeRev, afterRev, c.recurse)

	// Parse revisions from VCS into go/ast
	start := time.Now()
	if c.b, err = c.parse(beforeRev); err != nil {
		return nil, err
	}
	if c.a, err = c.parse(afterRev); err != nil {
		return nil, err
	}
	parse := time.Since(start)

	start = time.Now()
	changes, err := c.compareDecls()
	if err != nil {
		var buf bytes.Buffer
		fmt.Fprintf(&buf, "error comparing declarations: %s\n", err)
		if derr, ok := err.(*diffError); ok {
			_ = ast.Fprint(&buf, c.b[derr.pkg].fset, derr.bdecl, ast.NotNilFilter)
			_ = ast.Fprint(&buf, c.a[derr.pkg].fset, derr.adecl, ast.NotNilFilter)
		}
		return nil, errors.New(buf.String())
	}
	diff := time.Since(start)

	start = time.Now()
	sort.Sort(byID(changes))
	sort := time.Since(start)

	c.logf("Timing: parse: %v, diff: %v, sort: %v, total: %v\n", parse, diff, sort, parse+diff+sort)
	c.logf("Changes detected: %v\n", len(changes))

	return changes, nil
}
653696
func (s *ColumnInfo) SetScale(v int64) *ColumnInfo {
	s.Scale = &v
	return s
}
160543
func (p *Project) Scale(c *check.C, service string, count int) {
	c.Assert(p.project.Scale(service, count), check.IsNil,
		check.Commentf("error while scaling the service '%s'", service))
}
441415
func (s *UpdateTaskSetInput) SetScale(v *Scale) *UpdateTaskSetInput {
	s.Scale = v
	return s
}
639850
func tryScale(service *swarm.Service, opts data.Options) {
	// ignore services with global mode
	if service.Spec.Mode.Replicated == nil {
		return
	}

	var (
		min    uint64 = 2
		max    uint64 = 8
		step   uint64 = 2
		window        = 3 * time.Minute
		policy        = policyAny
		args   data.Options
	)
	for _, opt := range opts {
		switch opt.Name {
		case "min":
			min = cast.ToUint64(opt.Value, min)
		case "max":
			max = cast.ToUint64(opt.Value, max)
		case "step":
			step = cast.ToUint64(opt.Value, step)
		case "window":
			window = cast.ToDuration(opt.Value, window)
		case "policy":
			policy = policyType(opt.Value)
		default:
			args = append(args, opt)
		}
	}

	// ignore services that have been updated in window period.
	if service.UpdatedAt.Add(window).After(time.Now()) {
		return
	}

	result := check(service, policy, args)
	if result.Type == scaleNone {
		return
	}

	logger := log.Get("scaler")
	replicas := *service.Spec.Mode.Replicated.Replicas
	if result.Type == scaleUp {
		if replicas < max {
			if err := docker.ServiceScale(service.Spec.Name, service.Version.Index, replicas+step); err != nil {
				logger.Errorf("scaler > Failed to scale service '%s': %v", service.Spec.Name, err)
			} else {
				logger.Infof("scaler > Service '%s' scaled up for: %v", service.Spec.Name, result.Reasons)
			}
		}
	} else if result.Type == scaleDown {
		if replicas > min {
			if err := docker.ServiceScale(service.Spec.Name, service.Version.Index, replicas-step); err != nil {
				logger.Errorf("scaler > Failed to scale service '%s': %v", service.Spec.Name, err)
			} else {
				logger.Infof("scaler > Service '%s' scaled down for: %v", service.Spec.Name, result.Reasons)
			}
		}
	}
}
1163443
func (f *ResourceFilter) Check(n *NodeInfo) bool {
	if f.reservations.NanoCPUs > n.AvailableResources.NanoCPUs {
		return false
	}

	if f.reservations.MemoryBytes > n.AvailableResources.MemoryBytes {
		return false
	}

	for _, v := range f.reservations.Generic {
		enough, err := genericresource.HasEnough(n.AvailableResources.Generic, v)
		if err != nil || !enough {
			return false
		}
	}

	return true
}
1275524
func (c *constraint) check(v *Version) bool {
	return c.function(v, c)
}
1030640
func checkLease(clusterMap *Map, leaseMap *leases.Map, clusterName string) (*containerservice.ContainerService, error) {
	cluster, _ := clusterMap.ClusterByName(clusterName)
	_, isLeased := leaseMap.LeaseByClusterName(clusterName)
	if !isLeased {
		return cluster, nil
	}
	return nil, errUnusedAzureClusterNotFound
}
188318
func (s *Service) Scale(ctx context.Context, scale int, timeout int) error {
	if s.specificiesHostPort() {
		logrus.Warnf("The \"%s\" service specifies a port on the host. If multiple containers for this service are created on a single host, the port will clash.", s.Name())
	}

	containers, err := s.collectContainers(ctx)
	if err != nil {
		return err
	}
	if len(containers) > scale {
		foundCount := 0
		for _, c := range containers {
			foundCount++
			if foundCount > scale {
				timeout = s.stopTimeout(timeout)
				if err := c.Stop(ctx, timeout); err != nil {
					return err
				}
				// FIXME(vdemeester) remove volume in scale by default ?
				if err := c.Remove(ctx, false); err != nil {
					return err
				}
			}
		}
	}

	if err != nil {
		return err
	}

	if len(containers) < scale {
		err := s.ensureImageExists(ctx, false, false)
		if err != nil {
			return err
		}

		if _, err = s.constructContainers(ctx, scale); err != nil {
			return err
		}
	}

	return s.up(ctx, "", false, options.Up{})
}
130885
func (c *HostCertParams) Check() error {
	if c.HostID == "" && len(c.Principals) == 0 {
		return trace.BadParameter("HostID [%q] or Principals [%q] are required",
			c.HostID, c.Principals)
	}
	if c.ClusterName == "" {
		return trace.BadParameter("ClusterName [%q] is required", c.ClusterName)
	}

	if err := c.Roles.Check(); err != nil {
		return trace.Wrap(err)
	}

	return nil
}
715706
func (t *Text) SetScale(s float32) bool {
	if s > t.ScaleMax || s < t.ScaleMin {
		return false
	}
	t.Scale = s
	t.scaleMatrix = mgl32.Scale3D(s, s, s)
	return true
}
977646
func (z *Big) SetScale(scale int) *Big {
	z.exp = -scale
	return z
}
830821
func (z *Dec) SetScale(scale Scale) *Dec {
	z.scale = scale
	return z
}
1348253
func (c *UpdatesClient) Check(ctx context.Context) (*apitypes.UpdateInfo, error) {
	var needsUpdate apitypes.UpdateInfo
	err := c.client.DaemonRoundTrip(ctx, "GET", "/updates", nil, nil, &needsUpdate, nil)
	return &needsUpdate, err
}