return new ServiceConfig();
}
+void
+Adaptation::Config::removeService(const String& service)
+{
+ removeRule(service);
+ const Groups& groups = AllGroups();
+ for (unsigned int i = 0; i < groups.size(); ) {
+ const ServiceGroupPointer group = groups[i];
+ const ServiceGroup::Store& services = group->services;
+ typedef ServiceGroup::Store::const_iterator SGSI;
+ for (SGSI it = services.begin(); it != services.end(); ++it) {
+ if (*it == service) {
+ group->removedServices.push_back(service);
+ group->services.prune(service);
+ debugs(93, 5, HERE << "adaptation service " << service <<
+ " removed from group " << group->id);
+ break;
+ }
+ }
+ if (services.empty()) {
+ removeRule(group->id);
+ AllGroups().prune(group);
+ } else {
+ ++i;
+ }
+ }
+}
+
+void
+Adaptation::Config::removeRule(const String& id)
+{
+ typedef AccessRules::const_iterator ARI;
+ const AccessRules& rules = AllRules();
+ for (ARI it = rules.begin(); it != rules.end(); ++it) {
+ AccessRule* rule = *it;
+ if (rule->groupId == id) {
+ debugs(93, 5, HERE << "removing access rules for:" << id);
+ AllRules().prune(rule);
+ delete (rule);
+ break;
+ }
+ }
+}
+
+void
+Adaptation::Config::clear()
+{
+ debugs(93, 3, HERE << "rules: " << AllRules().size() << ", groups: " <<
+ AllGroups().size() << ", services: " << serviceConfigs.size());
+ typedef ServiceConfigs::const_iterator SCI;
+ const ServiceConfigs& configs = serviceConfigs;
+ for (SCI cfg = configs.begin(); cfg != configs.end(); ++cfg)
+ removeService((*cfg)->key);
+ serviceConfigs.clean();
+ debugs(93, 3, HERE << "rules: " << AllRules().size() << ", groups: " <<
+ AllGroups().size() << ", services: " << serviceConfigs.size());
+}
+
void
Adaptation::Config::parseService()
{
}
}
-void
+bool
Adaptation::Config::finalize()
{
+ if (!onoff) {
+ clear();
+ return false;
+ }
+
// create service reps from service configs
int created = 0;
// services remember their configs; we do not have to
serviceConfigs.clean();
+ return true;
}
// poor man for_each
void dumpService(StoreEntry *, const char *) const;
ServicePointer findService(const String&);
- virtual void finalize();
+ /**
+ * Creates and starts the adaptation services. In the case the adaptation
+ * mechanism is disabled then removes any reference to the services from
+ * access rules and service groups, and returns false.
+ * \return true if the services are ready and running, false otherwise
+ */
+ virtual bool finalize();
protected:
+ /// Removes any reference to the services from configuration
+ virtual void clear();
+
/// creates service configuration object that will parse and keep cfg info
virtual ServiceConfig *newServiceConfig() const;
+ /// Removes the given service from all service groups.
+ void removeService(const String& service);
+
+ /// Removes access rules of the given service or group
+ void removeRule(const String& id);
+
private:
Config(const Config &); // unsupported
Config &operator =(const Config &); // unsupported
// 2) warn if all-same services have different bypass status
// 3) warn if there are seemingly identical services in the group
// TODO: optimize by remembering ServicePointers rather than IDs
+ if (!removedServices.empty()) {
+ String s;
+ for (Store::iterator it = removedServices.begin(); it != removedServices.end(); ++it) {
+ s.append(*it);
+ s.append(',');
+ }
+ s.cut(s.size() - 1);
+ debugs(93, DBG_IMPORTANT, "Adaptation group '" << id << "' contains disabled member(s) after reconfiguration: " << s);
+ removedServices.clean();
+ }
String baselineKey;
bool baselineBypass = false;