# HG changeset patch # User Lukasz Dracz # Date 1435609748 14400 # Node ID 7ec7c131b3dbac596100d52d49f177fdff09cbcd # Parent 2b7c063009555b60b853653914487b7fad45c8bd Add AgentIdsFinder Reviewed-by:omajid Review-thread:http://icedtea.classpath.org/pipermail/thermostat/2015-June/014332.html PR2646 diff -r 2b7c06300955 -r 7ec7c131b3db launcher/src/main/java/com/redhat/thermostat/launcher/internal/AgentIdsFinder.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/AgentIdsFinder.java Mon Jun 29 16:29:08 2015 -0400 @@ -0,0 +1,71 @@ +/* + * Copyright 2012-2015 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * . + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.launcher.internal; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.redhat.thermostat.storage.core.HostRef; +import com.redhat.thermostat.storage.dao.HostInfoDAO; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public class AgentIdsFinder implements IdFinder { + + private BundleContext context; + + public AgentIdsFinder(BundleContext context) { + this.context = context; + } + + @Override + public List findIds() { + List agentIds = new ArrayList<>(); + ServiceReference hostsDAORef = context.getServiceReference(HostInfoDAO.class.getName()); + HostInfoDAO hostsDAO = (HostInfoDAO) context.getService(hostsDAORef); + + Collection hosts = hostsDAO.getHosts(); + context.ungetService(hostsDAORef); + + for (HostRef host : hosts) { + agentIds.add(host.getAgentId()); + } + + return agentIds; + } +} diff -r 2b7c06300955 -r 7ec7c131b3db launcher/src/main/java/com/redhat/thermostat/launcher/internal/TabCompletion.java --- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/TabCompletion.java Mon Jun 29 15:36:20 2015 -0400 +++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/TabCompletion.java Mon Jun 29 16:29:08 2015 -0400 @@ -76,6 +76,8 @@ setupCompletion(command, option, new StringsCompleter(logLevels)); } else if (option.getLongOpt().equals("vmId")) { setupCompletion(command, option, new IdCompleter(new VmIdsFinder(context), storageState)); + } else if (option.getLongOpt().equals("agentId")) { + setupCompletion(command, option, new IdCompleter(new AgentIdsFinder(context), storageState)); } else { setupDefaultCompletion(command, option); }