예제 #1
0
func wrapSnapshotAction(config *config.TopLevelConfig, action func(config *config.TopLevelConfig, pool, volName string, volume *config.TenantConfig)) {
	pools, err := config.ListPools()
	if err != nil {
		panic(fmt.Sprintf("Runtime configuration incorrect: %v", err))
	}

	for _, pool := range pools {
		volumes, err := config.ListVolumes(pool)
		if err != nil {
			panic(fmt.Sprintf("Runtime configuration incorrect: %v", err))
		}

		for volName, volume := range volumes {
			if volume.Pool != pool {
				panic(fmt.Sprintf("Volume pool prefix %q is not the same as JSON imported %q", volume.Pool, pool))
			}

			duration, err := time.ParseDuration(volume.Snapshot.Frequency)
			if err != nil {
				panic(fmt.Sprintf("Runtime configuration incorrect; cannot use %q as a snapshot frequency", volume.Snapshot.Frequency))
			}

			if volume.UseSnapshots && time.Now().Unix()%int64(duration.Seconds()) == 0 {
				go action(config, pool, volName, volume)
			}
		}
	}
}
예제 #2
0
func iterateVolumes(config *config.TopLevelConfig, dispatch func(v *volumeDispatch)) {
	tenants, err := config.ListTenants()
	if err != nil {
		log.Warn("Could not locate any tenant information; sleeping.")
		return
	}

	for _, tenant := range tenants {
		volumes, err := config.ListVolumes(tenant)
		if err != nil {
			log.Warnf("Could not list volumes for tenant %q: sleeping.", tenant)
			return
		}

		dispatch(&volumeDispatch{config, tenant, volumes})
	}
}
예제 #3
0
func wrapSnapshotAction(config *config.TopLevelConfig, action func(config *config.TopLevelConfig, pool, volName string, volume *config.VolumeConfig)) {
	tenants, err := config.ListTenants()
	if err != nil {
		if conv, ok := err.(*etcd.EtcdError); ok && conv.ErrorCode == 100 {
			// should never be hit because we create it at volmaster boot, but yeah.
			return
		}

		log.Errorf("Runtime configuration incorrect: %v", err)
		return
	}

	for _, tenant := range tenants {
		volumes, err := config.ListVolumes(tenant)
		conv, ok := err.(*etcd.EtcdError)
		if err != nil {
			if ok && conv.ErrorCode == 100 {
				continue
			}

			log.Errorf("Runtime configuration incorrect: %v", err)
			return
		}

		for volName, volume := range volumes {
			duration, err := time.ParseDuration(volume.Options.Snapshot.Frequency)
			if err != nil {
				log.Errorf("Runtime configuration incorrect; cannot use %q as a snapshot frequency", volume.Options.Snapshot.Frequency)
				return
			}

			if volume.Options.UseSnapshots && time.Now().Unix()%int64(duration.Seconds()) == 0 {
				action(config, volume.Options.Pool, volName, volume)
			}
		}
	}
}