Пример #1
0
func (f *NormalFactory) Upgrade(r *RancherService, force bool) error {
	existingService, err := r.FindExisting(r.Name())
	if err != nil || existingService == nil {
		return err
	}

	if existingService.State != "active" {
		return fmt.Errorf("Service %s must be state=active to upgrade, currently: state=%s", r.Name(), existingService.State)
	}

	existingHash, _ := digest.LookupHash(existingService)
	secondaryNames := []string{}

	hash, err := f.Hash(r)
	if err != nil {
		return err
	}

	service := hash.Service != existingHash.Service || force
	launchConfig := hash.LaunchConfig != existingHash.LaunchConfig || force
	for newSecondary, newHash := range hash.SecondaryLaunchConfigs {
		if oldHash, ok := existingHash.SecondaryLaunchConfigs[newSecondary]; ok {
			if oldHash != newHash || force {
				secondaryNames = append(secondaryNames, newSecondary)
			}
		} else {
			return fmt.Errorf("Existing service %s does not have a sidekick named %s", r.Name(), newSecondary)
		}
	}

	return f.upgrade(r, existingService, service, launchConfig, secondaryNames)
}
Пример #2
0
func (r *RancherService) isOutOfSync(service *client.Service) bool {
	if service == nil {
		return false
	}

	hash, ok := digest.LookupHash(service)
	if !ok {
		return true
	}

	factory, err := GetFactory(r)
	if err != nil {
		logrus.Errorf("Failed to find factory to service %s: %v", r.name, err)
		return false
	}

	newHash, err := factory.Hash(r)
	if err != nil {
		logrus.Errorf("Failed to calculate hash for service %s: %v", r.name, err)
		return false
	}

	logrus.Debugf("Comparing hashes for %s: old: %#v new: %#v", r.name, hash, newHash)
	return !hash.Equals(newHash)
}
Пример #3
0
func (f *NormalFactory) Upgrade(r *RancherService, force bool, selected []string) error {
	existingService, err := r.FindExisting(r.Name())
	if err != nil || existingService == nil {
		return err
	}

	if existingService.State != "active" && existingService.State != "inactive" {
		return fmt.Errorf("Service %s must be state=active or inactive to upgrade, currently: state=%s", r.Name(), existingService.State)
	}

	existingHash, _ := digest.LookupHash(existingService)
	secondaryNames := []string{}
	removedSecondaryNames := []string{}

	hash, err := f.Hash(r)
	if err != nil {
		return err
	}

	service := hash.Service != existingHash.Service || isForce(r.Name(), force, selected)
	launchConfig := hash.LaunchConfig != existingHash.LaunchConfig || isForce(r.Name(), force, selected)
	for oldSecondary, _ := range existingHash.SecondaryLaunchConfigs {
		if _, ok := hash.SecondaryLaunchConfigs[oldSecondary]; !ok {
			removedSecondaryNames = append(removedSecondaryNames, oldSecondary)
		}
	}
	for newSecondary, newHash := range hash.SecondaryLaunchConfigs {
		if oldHash, ok := existingHash.SecondaryLaunchConfigs[newSecondary]; ok {
			if oldHash != newHash || isForce(newSecondary, force, selected) {
				secondaryNames = append(secondaryNames, newSecondary)
			}
		} else {
			secondaryNames = append(secondaryNames, newSecondary)
		}
	}

	return f.upgrade(r, existingService, service, launchConfig, secondaryNames, removedSecondaryNames)
}
Пример #4
0
func hasOldHash(service *client.Service) bool {
	_, ok := digest.LookupHash(service)
	return ok
}