public Service getService(final String svcName) { final List<Service> pkgSvcs = getServices(); for (final Service svc : pkgSvcs) { if (svc.getName().equalsIgnoreCase(svcName)) return svc; } throw new IllegalArgumentException("Service name not part of package!"); }
/** * Returns true if the service is part of the package and the status of the * service is set to "on". Returns false if the service is not in the * package or it is but the status of the service is set to "off". * * @param svcName * The service name to lookup. * @return a boolean. */ public boolean serviceInPackageAndEnabled(final String svcName) { for (final Service service : getServices()) { if (service.getName().equalsIgnoreCase(svcName)) { // OK it's in the package. Now check the status of the service. if ("on".equals(service.getStatus())) return true; } } return false; }
/** * Gets the service object. * * @param config the Collectd's configuration * @param service the service's name * @return the service object */ private Service getServiceObject(CollectdConfiguration config, String service) { for (Package pkg : config.getPackages()) { for (Service svc : pkg.getServices()) { if (svc.getName().equals(service)) { return svc; } } } return null; }
public CollectdConfiguration getCollectdConfigurationForPackages(List<String> collectionPackageNames) { if (collectionPackageNames == null || collectionPackageNames.size() < 1) return null; final Set<String> seenCollectors = new HashSet<>(); final CollectdConfiguration newConfig = new CollectdConfiguration(); newConfig.setThreads(getThreads()); // Add all requested polling packages to the config boolean foundPackage = false; for (String packageName : collectionPackageNames) { final Package pkg = getPackage(packageName); if (pkg != null) { newConfig.addPackage(pkg); foundPackage = true; for (final Service service : pkg.getServices()) { seenCollectors.add(service.getName()); } } } // If the list of polling packages doesn't match anything, then return null if (!foundPackage) return null; for (final Collector collector : getCollectors()) { if (seenCollectors.contains(collector.getService())) { newConfig.addCollector(collector); } } return newConfig; }