// parameters: // - interval(duration): interval (default: 0 msecs) // // should support dynamic reloading func (d *Dumb) LoadConfig(cfg config.Config) error { log.Debugf("CONFIG: %s", cfg.AllSettings()) paramInterval := "explorepolicyparam.interval" if cfg.IsSet(paramInterval) { d.Interval = cfg.GetDuration(paramInterval) log.Infof("Set interval=%s", d.Interval) } else { log.Infof("Using default interval=%s", d.Interval) } return nil }
// parameters: // - minInterval(duration): min interval in millisecs (default: 0 msecs) // // - maxInterval(duration): max interval (default == minInterval) // // - prioritizedEntities([]string): prioritized entity string (default: empty) // // - shellActionInterval(duration): interval in millisecs for injecting ShellAction (default: 0) // NOTE: this can be 0 only if shellFaultCommand=""(empty string)) // // - shellActionCommand(string): command string for injecting ShellAction (default: empty string "") // NOTE: the command execution blocks. // // - faultActionProbability(float64): probability (0.0-1.0) of PacketFaultAction/FilesystemFaultAction. // // should support dynamic reloading func (r *Random) LoadConfig(cfg config.Config) error { epp := "explorepolicyparam." paramMinInterval := epp + "minInterval" if cfg.IsSet(paramMinInterval) { r.MinInterval = cfg.GetDuration(paramMinInterval) log.Infof("Set minInterval=%s", r.MinInterval) } else { log.Infof("Using default minInterval=%s", r.MinInterval) } paramMaxInterval := epp + "maxInterval" if cfg.IsSet(paramMaxInterval) { r.MaxInterval = cfg.GetDuration(paramMaxInterval) log.Infof("Set maxInterval=%s", r.MaxInterval) } else { // set non-zero default value r.MaxInterval = r.MinInterval log.Infof("Using default maxInterval=%s", r.MaxInterval) } paramPrioritizedEntities := epp + "prioritizedEntities" if cfg.IsSet(paramPrioritizedEntities) { slice := cfg.GetStringSlice(paramPrioritizedEntities) if slice != nil { for i := 0; i < len(slice); i++ { r.PrioritizedEntities[slice[i]] = true } log.Debugf("Set prioritizedEntities=%s", r.PrioritizedEntities) } } paramShellActionInterval := epp + "shellActionInterval" if cfg.IsSet(paramShellActionInterval) { r.ShellActionInterval = cfg.GetDuration(paramShellActionInterval) log.Infof("Set shellActionInterval=%s", r.ShellActionInterval) } paramShellActionCommand := epp + "shellActionCommand" if cfg.IsSet(paramShellActionCommand) { r.ShellActionCommand = cfg.GetString(paramShellActionCommand) log.Infof("Set shellActionCommand=%s", r.ShellActionCommand) } if r.ShellActionInterval < 0 { return fmt.Errorf("shellActionInterval(=%s) must be non-negative value", r.ShellActionInterval) } if r.ShellActionInterval == 0 && r.ShellActionCommand != "" { log.Warn("shellActionCommand will be ignored, because shellActionInterval is zero.") } if r.ShellActionInterval > 0 && !r.shelActionRoutineRunning { // FIXME: not thread safe! r.shelActionRoutineRunning = true go r.shellFaultInjectionRoutine() } paramFaultActionProbability := epp + "faultActionProbability" if cfg.IsSet(paramFaultActionProbability) { r.FaultActionProbability = cfg.GetFloat64(paramFaultActionProbability) log.Infof("Set faultActionProbability=%f", r.FaultActionProbability) } if r.FaultActionProbability < 0.0 || r.FaultActionProbability > 1.0 { return fmt.Errorf("bad faultActionProbability %f", r.FaultActionProbability) } return nil }