Beispiel #1
0
// scale a node down a certain number of instances
func (operation *ScaleOperation) ScaleDownNumber(logger log.Log, instances libs.Instances, number int) int {

	count := 0
	instancesOrder := []string{}
	for _, instanceId := range instances.InstancesOrder() {
		instancesOrder = append([]string{instanceId}, instancesOrder...)
	}

InstanceScaleReturn:
	for _, instanceId := range instancesOrder {
		if instance, ok := instances.Instance(instanceId); ok {
			client := instance.Client()

			if !client.IsRunning() {
				continue InstanceScaleReturn
			}

			logger.Info("Node Scaling down. Stopping instance :" + instanceId)
			client.Stop(logger, operation.force, operation.timeout)

			if operation.removeStopped {
				client.Remove(logger, operation.force)
			}

			count++
			if count >= number {
				return count
			}
		}
	}

	return count
}
Beispiel #2
0
// scale a node up a certain number of instances
func (operation *ScaleOperation) ScaleUpNumber(logger log.Log, instances libs.Instances, number int) int {
	count := 0
	instancesOrder := instances.InstancesOrder()

InstanceScaleReturn:
	for _, instanceId := range instancesOrder {
		if instance, ok := instances.Instance(instanceId); ok {
			client := instance.Client()

			if client.IsRunning() {
				continue InstanceScaleReturn
			} else if !client.HasContainer() {
				// create a new container for this instance
				client.Create(logger, []string{}, false)
			}

			logger.Info("Node Scaling up. Starting instance :" + instanceId)
			client.Start(logger, false)

			count++
			if count >= number {
				return count
			}
		}
	}

	return count
}