changeset 2532:c8e331460b1e

Add DependencyServices.getRequiredService methods Refactor callsites which were using dependencyServices.getService followed by a null-check and thrown CommandException to use getRequiredService instead Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-November/021654.html
author Andrew Azores <aazores@redhat.com>
date Thu, 17 Nov 2016 12:47:48 -0500
parents 5525742413c3
children 3ab518b2f8c5
files agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/AgentApplication.java agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/locale/LocaleResources.java agent/cli/src/main/resources/com/redhat/thermostat/agent/cli/internal/strings.properties common/core/src/main/java/com/redhat/thermostat/common/cli/DependencyServices.java common/core/src/main/java/com/redhat/thermostat/common/cli/LocaleResources.java common/core/src/main/resources/com/redhat/thermostat/common/cli/locale/strings.properties common/core/src/test/java/com/redhat/thermostat/common/cli/DependencyServicesTest.java dev/storage-populator/command/src/main/java/com/redhat/thermostat/storage/populator/StoragePopulatorCommand.java dev/storage-populator/command/src/main/java/com/redhat/thermostat/storage/populator/internal/LocaleResources.java dev/storage-populator/command/src/main/resources/com/redhat/thermostat/storage/populator/command/locale/strings.properties dev/storage-populator/command/src/test/java/com/redhat/thermostat/storage/populator/StoragePopulatorCommandTest.java local/command/src/main/java/com/redhat/thermostat/local/command/internal/LocalCommand.java local/command/src/main/java/com/redhat/thermostat/local/command/internal/LocaleResources.java local/command/src/main/resources/com/redhat/thermostat/config/locale/strings.properties local/command/src/test/java/com/redhat/thermostat/local/command/internal/LocalCommandTest.java notes/client-cli/src/main/java/com/redhat/thermostat/notes/client/cli/internal/AbstractNotesCommand.java notes/client-cli/src/main/java/com/redhat/thermostat/notes/client/cli/locale/LocaleResources.java notes/client-cli/src/main/resources/com/redhat/thermostat/notes/client/cli/locale/strings.properties setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/LocaleResources.java setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/SetupCommand.java setup/command/src/main/resources/com/redhat/thermostat/setup/locale/strings.properties setup/command/src/test/java/com/redhat/thermostat/setup/command/internal/SetupCommandTest.java vm-byteman/client-cli/src/main/java/com/redhat/thermostat/vm/byteman/client/cli/BytemanControlCommand.java vm-byteman/client-cli/src/main/java/com/redhat/thermostat/vm/byteman/client/cli/internal/LocaleResources.java vm-byteman/client-cli/src/main/resources/com/redhat/thermostat/vm/byteman/client/cli/internal/strings.properties vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommand.java vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/LocaleResources.java vm-find/command/src/main/resources/com/redhat/thermostat/vm/find/command/locale/strings.properties vm-gc/command/src/main/java/com/redhat/thermostat/vm/gc/command/internal/ShowGcNameCommand.java vm-jmx/client-cli/src/main/java/com/redhat/thermostat/vm/jmx/client/cli/NotificationsCommand.java vm-jmx/client-cli/src/main/java/com/redhat/thermostat/vm/jmx/client/cli/locale/LocaleResources.java vm-jmx/client-cli/src/main/resources/com/redhat/thermostat/vm/jmx/client/cli/locale/strings.properties vm-profiler/client-cli/src/main/java/com/redhat/thermostat/vm/profiler/client/cli/internal/LocaleResources.java vm-profiler/client-cli/src/main/java/com/redhat/thermostat/vm/profiler/client/cli/internal/ProfileVmCommand.java vm-profiler/client-cli/src/main/resources/com/redhat/thermostat/vm/profiler/client/cli/internal/strings.properties
diffstat 35 files changed, 103 insertions(+), 167 deletions(-) [+]
line wrap: on
line diff
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/AgentApplication.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/AgentApplication.java	Thu Nov 17 12:47:48 2016 -0500
@@ -142,8 +142,8 @@
     private void runAgent(CommandContext ctx) throws CommandException {
         long startTime = System.currentTimeMillis();
         configuration.setStartTime(startTime);
-        
-        StorageCredentials creds = getServiceOrExit(StorageCredentials.class);
+
+        StorageCredentials creds = depServices.getRequiredService(StorageCredentials.class);
         final DbService dbService = dbServiceFactory.createDbService(
                 configuration.getDBConnectionString(), creds, sslConf);
         
@@ -225,14 +225,6 @@
         }
     }
 
-    private StorageCredentials getServiceOrExit(Class<StorageCredentials> clazz) throws CommandException {
-        StorageCredentials creds = depServices.getService(clazz);
-        if (creds == null) {
-            throw new CommandException(t.localize(LocaleResources.STORAGE_CREDS_UNAVAILABLE));
-        }
-        return creds;
-    }
-    
     void setStorageCredentials(StorageCredentials creds) {
         if (creds == null) {
             depServices.removeService(StorageCredentials.class);
--- a/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/locale/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/agent/cli/src/main/java/com/redhat/thermostat/agent/cli/internal/locale/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -44,7 +44,6 @@
     LAUNCHER_UNAVAILABLE,
     UNEXPECTED_RESULT_STORAGE,
     STARTING_AGENT_FAILED,
-    STORAGE_CREDS_UNAVAILABLE,
     ;
 
     static final String RESOURCE_BUNDLE = "com.redhat.thermostat.agent.cli.internal.strings";
--- a/agent/cli/src/main/resources/com/redhat/thermostat/agent/cli/internal/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/agent/cli/src/main/resources/com/redhat/thermostat/agent/cli/internal/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -2,4 +2,3 @@
 LAUNCHER_UNAVAILABLE = Launcher is not available
 UNEXPECTED_RESULT_STORAGE = Unexpected result from storage.
 STARTING_AGENT_FAILED = Thermostat agent failed to start. See logs for details.
-STORAGE_CREDS_UNAVAILABLE = StorageCredentials are not available
--- a/common/core/src/main/java/com/redhat/thermostat/common/cli/DependencyServices.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/common/core/src/main/java/com/redhat/thermostat/common/cli/DependencyServices.java	Thu Nov 17 12:47:48 2016 -0500
@@ -36,6 +36,9 @@
 
 package com.redhat.thermostat.common.cli;
 
+import com.redhat.thermostat.shared.locale.LocalizedString;
+import com.redhat.thermostat.shared.locale.Translate;
+
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
@@ -52,6 +55,8 @@
  */
 public class DependencyServices {
 
+    private static final Translate<LocaleResources> t = LocaleResources.createLocalizer();
+
     private Map<Class<?>, BlockingQueue<?>> serviceHolder = new HashMap<>();
 
     private <T> BlockingQueue<T> getHolder(Class<T> serviceClass) {
@@ -97,4 +102,24 @@
         }
     }
 
+    /**
+     * @return the service
+     * @throws CommandException if the service is unavailable
+     */
+    public <T> T getRequiredService(Class<T> serviceClass) throws CommandException {
+        return getRequiredService(serviceClass, t.localize(LocaleResources.MISSING_REQUIRED_SERVICE, serviceClass.getSimpleName()));
+    }
+
+    /**
+     * @return the service
+     * @throws CommandException if the service is unavailable
+     */
+    public <T> T getRequiredService(Class<T> serviceClass, LocalizedString message) throws CommandException {
+        T svc = getService(serviceClass);
+        if (svc == null) {
+            throw new CommandException(message);
+        }
+        return svc;
+    }
+
 }
--- a/common/core/src/main/java/com/redhat/thermostat/common/cli/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/common/core/src/main/java/com/redhat/thermostat/common/cli/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -40,6 +40,7 @@
 
 public enum LocaleResources {
     MISSING_COMMAND_NAME,
+    MISSING_REQUIRED_SERVICE,
     ;
 
     public static final String RESOURCE_BUNDLE =
--- a/common/core/src/main/resources/com/redhat/thermostat/common/cli/locale/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/common/core/src/main/resources/com/redhat/thermostat/common/cli/locale/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -1,1 +1,2 @@
-MISSING_COMMAND_NAME=The implementation class {0} does not define an OSGi property for COMMAND_NAME, which is required.
\ No newline at end of file
+MISSING_COMMAND_NAME=The implementation class {0} does not define an OSGi property for COMMAND_NAME, which is required.
+MISSING_REQUIRED_SERVICE=Required service {0} is unavailable
\ No newline at end of file
--- a/common/core/src/test/java/com/redhat/thermostat/common/cli/DependencyServicesTest.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/common/core/src/test/java/com/redhat/thermostat/common/cli/DependencyServicesTest.java	Thu Nov 17 12:47:48 2016 -0500
@@ -37,8 +37,11 @@
 package com.redhat.thermostat.common.cli;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
 
+import com.redhat.thermostat.shared.locale.LocalizedString;
 import org.junit.Test;
 
 public class DependencyServicesTest {
@@ -73,4 +76,26 @@
         services.removeService(Object.class);
         assertNull(services.getService(Object.class));
     }
+
+    @Test
+    public void testGetRequiredServiceThrowsException() {
+        DependencyServices services = new DependencyServices();
+        try {
+            services.getRequiredService(Object.class);
+            fail("CommandException should have been thrown");
+        } catch (CommandException e) {
+            assertEquals(e.getTranslatedMessage().getContents(), "Required service Object is unavailable");
+        }
+    }
+
+    @Test
+    public void testGetRequiredServiceThrowsExceptionWithConfigurableMessage() {
+        DependencyServices services = new DependencyServices();
+        try {
+            services.getRequiredService(Object.class, new LocalizedString("test message"));
+            fail("CommandException should have been thrown");
+        } catch (CommandException e) {
+            assertEquals(e.getTranslatedMessage().getContents(), "test message");
+        }
+    }
 }
--- a/dev/storage-populator/command/src/main/java/com/redhat/thermostat/storage/populator/StoragePopulatorCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/dev/storage-populator/command/src/main/java/com/redhat/thermostat/storage/populator/StoragePopulatorCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -168,26 +168,12 @@
     public void run(CommandContext ctx) throws CommandException {
         console = ctx.getConsole();
 
-        paths = dependencyServices.getService(CommonPaths.class);
-        requireNonNull(paths,
-                translator.localize(LocaleResources.COMMON_PATHS_SERVICE_UNAVAILABLE));
-
-        hostInfoDAO = dependencyServices.getService(HostInfoDAO.class);
-        requireNonNull(hostInfoDAO, translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE));
-
-        agentInfoDAO = dependencyServices.getService(AgentInfoDAO.class);
-        requireNonNull(agentInfoDAO,
-                translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE));
-
-        vmInfoDAO = dependencyServices.getService(VmInfoDAO.class);
-        requireNonNull(vmInfoDAO, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE));
-
-        networkInfoDAO = dependencyServices.getService(NetworkInterfaceInfoDAO.class);
-        requireNonNull(networkInfoDAO,
-                translator.localize(LocaleResources.NETWORK_SERVICE_UNAVAILABLE));
-
-        threadDAO = dependencyServices.getService(ThreadDao.class);
-        requireNonNull(threadDAO, translator.localize(LocaleResources.THREAD_SERVICE_UNAVAILABLE));
+        paths = dependencyServices.getRequiredService(CommonPaths.class);
+        hostInfoDAO = dependencyServices.getRequiredService(HostInfoDAO.class);
+        agentInfoDAO = dependencyServices.getRequiredService(AgentInfoDAO.class);
+        vmInfoDAO = dependencyServices.getRequiredService(VmInfoDAO.class);
+        networkInfoDAO = dependencyServices.getRequiredService(NetworkInterfaceInfoDAO.class);
+        threadDAO = dependencyServices.getRequiredService(ThreadDao.class);
 
         HostInfoPopulator hostInfoPopulator = new HostInfoPopulator(hostInfoDAO);
         populators.put(hostInfoPopulator.getHandledCollection(), hostInfoPopulator);
--- a/dev/storage-populator/command/src/main/java/com/redhat/thermostat/storage/populator/internal/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/dev/storage-populator/command/src/main/java/com/redhat/thermostat/storage/populator/internal/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -41,12 +41,6 @@
 
 public enum LocaleResources {
 
-    COMMON_PATHS_SERVICE_UNAVAILABLE,
-    HOST_SERVICE_UNAVAILABLE,
-    AGENT_SERVICE_UNAVAILABLE,
-    VM_SERVICE_UNAVAILABLE,
-    NETWORK_SERVICE_UNAVAILABLE,
-    THREAD_SERVICE_UNAVAILABLE,
     DAO_NOT_INITIALIZED,
     WAITING_FOR_ARRIVAL,
     ITEMS_HAVE_ARRIVED,
--- a/dev/storage-populator/command/src/main/resources/com/redhat/thermostat/storage/populator/command/locale/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/dev/storage-populator/command/src/main/resources/com/redhat/thermostat/storage/populator/command/locale/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -1,9 +1,3 @@
-COMMON_PATHS_SERVICE_UNAVAILABLE = Unable to get CommonPaths service.
-HOST_SERVICE_UNAVAILABLE = Unable to get HostInfoDAO service.
-AGENT_SERVICE_UNAVAILABLE = Unable to get AgentInfoDAO service.
-VM_SERVICE_UNAVAILABLE = Unable to get VmInfoDAO service.
-NETWORK_SERVICE_UNAVAILABLE = Unable to get NetworkInterfaceInfoDAO service.
-THREAD_SERVICE_UNAVAILABLE = Unable to get ThreadDao service.
 DAO_NOT_INITIALIZED = DAO must be initialized to populate.
 WAITING_FOR_ARRIVAL = Waiting for storage items to arrive at backend...
 ITEMS_HAVE_ARRIVED = Items have arrived.
--- a/dev/storage-populator/command/src/test/java/com/redhat/thermostat/storage/populator/StoragePopulatorCommandTest.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/dev/storage-populator/command/src/test/java/com/redhat/thermostat/storage/populator/StoragePopulatorCommandTest.java	Thu Nov 17 12:47:48 2016 -0500
@@ -123,7 +123,7 @@
             command.run(ctx);
             fail("A CommandException was expected but not thrown.");
         } catch (CommandException e) {
-            assertTrue(e.getMessage().matches("Unable to get .* service\\."));
+            assertTrue(e.getMessage().matches("Required service .* is unavailable"));
         }
     }
 
--- a/local/command/src/main/java/com/redhat/thermostat/local/command/internal/LocalCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/local/command/src/main/java/com/redhat/thermostat/local/command/internal/LocalCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -55,10 +55,8 @@
     private CommonPaths paths;
 
     public void run(CommandContext ctx) throws CommandException {
-        this.paths = dependentServices.getService(CommonPaths.class);
-        requireNonNull(paths, t.localize(LocaleResources.SERVICE_UNAVAILABLE_MESSAGE, "CommonPaths"));
-        this.launcher = dependentServices.getService(Launcher.class);
-        requireNonNull(launcher, t.localize(LocaleResources.SERVICE_UNAVAILABLE_MESSAGE, "Launcher"));
+        this.paths = dependentServices.getRequiredService(CommonPaths.class);
+        this.launcher = dependentServices.getRequiredService(Launcher.class);
 
         ServiceLauncher serviceLauncher = createServiceLauncher();
         serviceLauncher.start();
--- a/local/command/src/main/java/com/redhat/thermostat/local/command/internal/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/local/command/src/main/java/com/redhat/thermostat/local/command/internal/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -41,7 +41,6 @@
 
 public enum LocaleResources {
 
-    SERVICE_UNAVAILABLE_MESSAGE,
     ERROR_STARTING_SERVICE,
     STOPPING_SERVICE_INTERRUPTED,
     SERVICE_WAIT_INTERRUPTED,
--- a/local/command/src/main/resources/com/redhat/thermostat/config/locale/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/local/command/src/main/resources/com/redhat/thermostat/config/locale/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -1,4 +1,3 @@
-SERVICE_UNAVAILABLE_MESSAGE={0} service dependency unavailable
 ERROR_STARTING_SERVICE="Error starting {0}"
 STOPPING_SERVICE_INTERRUPTED=Stopping {0} was interrupted
 SERVICE_WAIT_INTERRUPTED=Waiting for {0} interrupted
--- a/local/command/src/test/java/com/redhat/thermostat/local/command/internal/LocalCommandTest.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/local/command/src/test/java/com/redhat/thermostat/local/command/internal/LocalCommandTest.java	Thu Nov 17 12:47:48 2016 -0500
@@ -77,7 +77,7 @@
             cmd.run(ctxt);
             fail();
         } catch (CommandException e) {
-            assertTrue(e.getMessage().contains("CommonPaths service dependency unavailable"));
+            assertTrue(e.getMessage().contains("Required service CommonPaths is unavailable"));
         }
     }
 
@@ -89,7 +89,7 @@
             cmd.run(ctxt);
             fail();
         } catch (CommandException e) {
-            assertTrue(e.getMessage().contains("Launcher service dependency unavailable"));
+            assertTrue(e.getMessage().contains("Required service Launcher is unavailable"));
         }
     }
 
--- a/notes/client-cli/src/main/java/com/redhat/thermostat/notes/client/cli/internal/AbstractNotesCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/notes/client-cli/src/main/java/com/redhat/thermostat/notes/client/cli/internal/AbstractNotesCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -75,16 +75,11 @@
     }
 
     protected void setupServices() throws CommandException {
-        vmInfoDAO = dependencyServices.getService(VmInfoDAO.class);
-        requireNonNull(vmInfoDAO, translator.localize(LocaleResources.VM_INFO_DAO_UNAVAILABLE));
-        hostInfoDAO = dependencyServices.getService(HostInfoDAO.class);
-        requireNonNull(hostInfoDAO, translator.localize(LocaleResources.HOST_INFO_DAO_UNAVAILABLE));
-        agentInfoDAO = dependencyServices.getService(AgentInfoDAO.class);
-        requireNonNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_INFO_DAO_UNAVAILABLE));
-        vmNoteDAO = dependencyServices.getService(VmNoteDAO.class);
-        requireNonNull(vmNoteDAO, translator.localize(LocaleResources.VM_NOTE_DAO_UNAVAILABLE));
-        hostNoteDAO = dependencyServices.getService(HostNoteDAO.class);
-        requireNonNull(hostNoteDAO, translator.localize(LocaleResources.HOST_NOTE_DAO_UNAVAILABLE));
+        vmInfoDAO = dependencyServices.getRequiredService(VmInfoDAO.class);
+        hostInfoDAO = dependencyServices.getRequiredService(HostInfoDAO.class);
+        agentInfoDAO = dependencyServices.getRequiredService(AgentInfoDAO.class);
+        vmNoteDAO = dependencyServices.getRequiredService(VmNoteDAO.class);
+        hostNoteDAO = dependencyServices.getRequiredService(HostNoteDAO.class);
     }
 
     protected static void assertExpectedAgentAndVmArgsProvided(Arguments args) throws CommandException {
--- a/notes/client-cli/src/main/java/com/redhat/thermostat/notes/client/cli/locale/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/notes/client-cli/src/main/java/com/redhat/thermostat/notes/client/cli/locale/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -47,12 +47,6 @@
     INVALID_VMID,
     INVALID_AGENTID,
 
-    VM_INFO_DAO_UNAVAILABLE,
-    HOST_INFO_DAO_UNAVAILABLE,
-    AGENT_INFO_DAO_UNAVAILABLE,
-    VM_NOTE_DAO_UNAVAILABLE,
-    HOST_NOTE_DAO_UNAVAILABLE,
-
     NOTE_ID_COLUMN,
     TIMESTAMP_COLUMN,
     CONTENT_COLUMN,
--- a/notes/client-cli/src/main/resources/com/redhat/thermostat/notes/client/cli/locale/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/notes/client-cli/src/main/resources/com/redhat/thermostat/notes/client/cli/locale/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -5,12 +5,6 @@
 INVALID_VMID=No VM exists with the specified ID: {0}
 INVALID_AGENTID=No Agent exists with the specified ID: {0}
 
-VM_INFO_DAO_UNAVAILABLE=VM Info DAO unavailable
-HOST_INFO_DAO_UNAVAILABLE=Host Info DAO unavailable
-AGENT_INFO_DAO_UNAVAILABLE=Agent Info DAO unavailable
-VM_NOTE_DAO_UNAVAILABLE=VM Notes DAO unavailable
-HOST_NOTE_DAO_UNAVAILABLE=Host Notes DAO unavailable
-
 NOTE_ID_COLUMN=note-id
 TIMESTAMP_COLUMN=timestamp
 CONTENT_COLUMN=content
--- a/setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -68,7 +68,6 @@
     THERMOSTAT_BLURB,
     STORAGE_FAILED,
     STORAGE_RUNNING,
-    SERVICE_UNAVAILABLE_MESSAGE,
     SETUP_FAILED,
     SETUP_INTERRUPTED,
     SETUP_CANCELLED,
--- a/setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/SetupCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/setup/command/src/main/java/com/redhat/thermostat/setup/command/internal/SetupCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -97,18 +97,13 @@
             }
         }
 
-        ExitStatus exitStatus = dependentServices.getService(ExitStatus.class);
-        requireNonNull(exitStatus, t.localize(LocaleResources.SERVICE_UNAVAILABLE_MESSAGE, "ExitStatus"));
+        ExitStatus exitStatus = dependentServices.getRequiredService(ExitStatus.class);
 
         try {
-            this.paths = dependentServices.getService(CommonPaths.class);
-            requireNonNull(paths, t.localize(LocaleResources.SERVICE_UNAVAILABLE_MESSAGE, "CommonPaths"));
-            this.launcher = dependentServices.getService(Launcher.class);
-            requireNonNull(launcher, t.localize(LocaleResources.SERVICE_UNAVAILABLE_MESSAGE, "Launcher"));
-            this.keyring = dependentServices.getService(Keyring.class);
-            requireNonNull(keyring, t.localize(LocaleResources.SERVICE_UNAVAILABLE_MESSAGE, "Keyring"));
-            this.processHandler = dependentServices.getService(ProcessHandler.class);
-            requireNonNull(processHandler, t.localize(LocaleResources.SERVICE_UNAVAILABLE_MESSAGE, "UnixProcessHandler"));
+            this.paths = dependentServices.getRequiredService(CommonPaths.class);
+            this.launcher = dependentServices.getRequiredService(Launcher.class);
+            this.keyring = dependentServices.getRequiredService(Keyring.class);
+            this.processHandler = dependentServices.getRequiredService(ProcessHandler.class);
             ThermostatSetup setup = createSetup();
 
             if (args.hasArgument(NON_GUI_OPTION_NAME) || isHeadless()) {
--- a/setup/command/src/main/resources/com/redhat/thermostat/setup/locale/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/setup/command/src/main/resources/com/redhat/thermostat/setup/locale/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -77,8 +77,6 @@
 
 CLIENT_HELP_INFO=Use these credentials for "thermostat gui" or any other thermostat CLI command except for "thermostat agent"
 
-SERVICE_UNAVAILABLE_MESSAGE={0} service dependency unavailable
-
 SETUP_FAILED=Setup failed.
 
 SETUP_INTERRUPTED=Setup was interrupted.
--- a/setup/command/src/test/java/com/redhat/thermostat/setup/command/internal/SetupCommandTest.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/setup/command/src/test/java/com/redhat/thermostat/setup/command/internal/SetupCommandTest.java	Thu Nov 17 12:47:48 2016 -0500
@@ -181,7 +181,7 @@
             cmd.run(ctxt);
             fail();
         } catch (CommandException e) {
-            assertTrue(e.getMessage().contains("CommonPaths service dependency unavailable"));
+            assertTrue(e.getMessage().contains("Required service CommonPaths is unavailable"));
         }
     }
     
@@ -195,7 +195,7 @@
             cmd.run(ctxt);
             fail();
         } catch (CommandException e) {
-            assertTrue(e.getMessage().contains("Launcher service dependency unavailable"));
+            assertTrue(e.getMessage().contains("Required service Launcher is unavailable"));
         }
     }
     
@@ -207,7 +207,7 @@
             cmd.run(ctxt);
             fail();
         } catch (CommandException e) {
-            assertTrue(e.getMessage().contains("ExitStatus service dependency unavailable"));
+            assertTrue(e.getMessage().contains("Required service ExitStatus is unavailable"));
         }
     }
 
@@ -515,7 +515,7 @@
             cmd.run(ctxt);
             fail();
         } catch (CommandException e) {
-            assertTrue(e.getMessage().contains("Keyring service dependency unavailable"));
+            assertTrue(e.getMessage().contains("Required service Keyring is unavailable"));
         }
     }
     
--- a/vm-byteman/client-cli/src/main/java/com/redhat/thermostat/vm/byteman/client/cli/BytemanControlCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-byteman/client-cli/src/main/java/com/redhat/thermostat/vm/byteman/client/cli/BytemanControlCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -126,15 +126,13 @@
         VmArgument vmArgument = VmArgument.required(ctx.getArguments());
         VmId vmId = vmArgument.getVmId();
         
-        VmInfoDAO vmInfoDAO = depServices.getService(VmInfoDAO.class);
+        VmInfoDAO vmInfoDAO = depServices.getRequiredService(VmInfoDAO.class);
         
-        requireNonNull(vmInfoDAO, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE));
         final VmInfo vmInfo = vmInfoDAO.getVmInfo(vmId);
         requireNonNull(vmInfo, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE));
 
-        AgentInfoDAO agentInfoDAO = depServices.getService(AgentInfoDAO.class);
+        AgentInfoDAO agentInfoDAO = depServices.getRequiredService(AgentInfoDAO.class);
         final AgentId agentId = new AgentId(vmInfo.getAgentId());
-        requireNonNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE));
 
         AgentInformation agentInfo = agentInfoDAO.getAgentInformation(agentId);
         if (agentInfo == null) {
@@ -150,8 +148,7 @@
         if (nonOptionargs.size() != 1) {
             throw new CommandException(translator.localize(LocaleResources.COMMAND_EXPECTED));
         }
-        VmBytemanDAO bytemanDao = depServices.getService(VmBytemanDAO.class);
-        requireNonNull(bytemanDao, translator.localize(LocaleResources.BYTEMAN_METRICS_SERVICE_UNAVAILABLE));
+        VmBytemanDAO bytemanDao = depServices.getRequiredService(VmBytemanDAO.class);
 
         String command = nonOptionargs.get(0);
 
@@ -176,7 +173,7 @@
     /* Unloads byteman rules */
     private void unloadRules(InetSocketAddress target, VmInfo vmInfo, CommandContext ctx, VmBytemanDAO bytemanDao) throws CommandException {
         VmId vmId = new VmId(vmInfo.getVmId());
-        RequestQueue requestQueue = getRequestQueue();
+        RequestQueue requestQueue = depServices.getRequiredService(RequestQueue.class);
         VmBytemanStatus status = getVmBytemanStatus(vmId, bytemanDao);
         int listenPort = status.getListenPort();
         Request unloadRequest = BytemanRequest.create(target, vmInfo, RequestAction.UNLOAD_RULES, listenPort);
@@ -207,7 +204,7 @@
         if (status != null) {
             listenPort = status.getListenPort();
         }
-        RequestQueue requestQueue = getRequestQueue();
+        RequestQueue requestQueue = depServices.getRequiredService(RequestQueue.class);
         Request request = BytemanRequest.create(target, vmInfo, RequestAction.LOAD_RULES, listenPort, rulesContent);
         submitRequest(ctx, requestQueue, request);
     }
@@ -283,13 +280,7 @@
             // ignore
         }
     }
-    
-    private RequestQueue getRequestQueue() throws CommandException {
-        RequestQueue requestQueue = depServices.getService(RequestQueue.class);
-        requireNonNull(requestQueue, translator.localize(LocaleResources.QUEUE_SERVICE_UNAVAILABLE));
-        return requestQueue;
-    }
-    
+
     private VmBytemanStatus getVmBytemanStatus(VmId vmId, VmBytemanDAO bytemanDao) throws CommandException {
         VmBytemanStatus status = bytemanDao.findBytemanStatus(vmId);
         if (status == null) {
--- a/vm-byteman/client-cli/src/main/java/com/redhat/thermostat/vm/byteman/client/cli/internal/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-byteman/client-cli/src/main/java/com/redhat/thermostat/vm/byteman/client/cli/internal/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -41,9 +41,6 @@
 public enum LocaleResources {
 
     VM_SERVICE_UNAVAILABLE,
-    AGENT_SERVICE_UNAVAILABLE,
-    QUEUE_SERVICE_UNAVAILABLE,
-    BYTEMAN_METRICS_SERVICE_UNAVAILABLE,
     AGENT_NOT_FOUND,
     AGENT_DEAD,
     COMMAND_EXPECTED,
--- a/vm-byteman/client-cli/src/main/resources/com/redhat/thermostat/vm/byteman/client/cli/internal/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-byteman/client-cli/src/main/resources/com/redhat/thermostat/vm/byteman/client/cli/internal/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -1,7 +1,4 @@
 VM_SERVICE_UNAVAILABLE = VM information is not available
-AGENT_SERVICE_UNAVAILABLE = Agent information is not available
-QUEUE_SERVICE_UNAVAILABLE = Sending requests to the agent is not possible
-BYTEMAN_METRICS_SERVICE_UNAVAILABLE = Byteman metrics DAO service is not available
 COMMAND_EXPECTED = A valid subcommand is expected.
 UNKNOWN_COMMAND = Unknown command: {0}
 AGENT_NOT_FOUND = Agent with id {0} not found.
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/FindVmCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -96,12 +96,9 @@
     }
 
     void setServices() throws CommandException {
-        agentInfoDAO = services.getService(AgentInfoDAO.class);
-        requireNonNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE));
-        hostInfoDAO = services.getService(HostInfoDAO.class);
-        requireNonNull(hostInfoDAO, translator.localize(LocaleResources.HOST_SERVICE_UNAVAILABLE));
-        vmInfoDAO = services.getService(VmInfoDAO.class);
-        requireNonNull(vmInfoDAO, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE));
+        agentInfoDAO = services.getRequiredService(AgentInfoDAO.class);
+        hostInfoDAO = services.getRequiredService(HostInfoDAO.class);
+        vmInfoDAO = services.getRequiredService(VmInfoDAO.class);
     }
 
     void initDaoData() {
--- a/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-find/command/src/main/java/com/redhat/thermostat/vm/find/command/internal/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -40,10 +40,6 @@
 
 public enum LocaleResources {
 
-    COMMAND_INTERRUPTED,
-    AGENT_SERVICE_UNAVAILABLE,
-    HOST_SERVICE_UNAVAILABLE,
-    VM_SERVICE_UNAVAILABLE,
     NO_CRITERIA_GIVEN,
     AGENT_FLAGS_CLASH,
     UNRECOGNIZED_ARGUMENT,
--- a/vm-find/command/src/main/resources/com/redhat/thermostat/vm/find/command/locale/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-find/command/src/main/resources/com/redhat/thermostat/vm/find/command/locale/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -1,7 +1,3 @@
-COMMAND_INTERRUPTED = Command interrupted while waiting for services.
-AGENT_SERVICE_UNAVAILABLE = Unable to get agent information (AgentInfoDAO is unavailable)
-HOST_SERVICE_UNAVAILABLE = Unable to get host information (HostInfoDAO is unavailable)
-VM_SERVICE_UNAVAILABLE = Unable to get vm information (VmInfoDAO is unavailable)
 NO_CRITERIA_GIVEN = No filtering criteria were specified
 AGENT_FLAGS_CLASH = --{0} and --{1} cannot be used in conjunction
 UNRECOGNIZED_ARGUMENT = {0} {1} does not recognize provided argument "{2}". Expected: {3}
\ No newline at end of file
--- a/vm-gc/command/src/main/java/com/redhat/thermostat/vm/gc/command/internal/ShowGcNameCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-gc/command/src/main/java/com/redhat/thermostat/vm/gc/command/internal/ShowGcNameCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -80,11 +80,10 @@
     
     @Override
     public void run(CommandContext ctx) throws CommandException {
-        this.vmInfoDao = services.getService(VmInfoDAO.class);
-        this.gcDao = services.getService(VmGcStatDAO.class);
-        
-        requireNonNull(vmInfoDao, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE));
-        requireNonNull(gcDao, translator.localize(LocaleResources.GC_STAT_DAO_SERVICE_UNAVAILABLE));
+        this.vmInfoDao = services.getRequiredService(VmInfoDAO.class,
+                translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE));
+        this.gcDao = services.getRequiredService(VmGcStatDAO.class,
+                translator.localize(LocaleResources.GC_STAT_DAO_SERVICE_UNAVAILABLE));
 
         Arguments arguments = ctx.getArguments();
 
--- a/vm-jmx/client-cli/src/main/java/com/redhat/thermostat/vm/jmx/client/cli/NotificationsCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-jmx/client-cli/src/main/java/com/redhat/thermostat/vm/jmx/client/cli/NotificationsCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -104,13 +104,13 @@
         }
         String subcommand = args.getNonOptionArguments().get(0);
 
-        ApplicationService applicationService = getService(ApplicationService.class);
-        Clock clock = getService(Clock.class);
-        RequestQueue queue = getService(RequestQueue.class);
-        HostInfoDAO hostInfoDAO = getService(HostInfoDAO.class);
-        AgentInfoDAO agentInfoDAO = getService(AgentInfoDAO.class);
-        VmInfoDAO vmInfoDAO = getService(VmInfoDAO.class);
-        JmxNotificationDAO jmxNotificationDAO = getService(JmxNotificationDAO.class);
+        ApplicationService applicationService = dependencyServices.getRequiredService(ApplicationService.class);
+        Clock clock = dependencyServices.getRequiredService(Clock.class);
+        RequestQueue queue = dependencyServices.getRequiredService(RequestQueue.class);
+        HostInfoDAO hostInfoDAO = dependencyServices.getRequiredService(HostInfoDAO.class);
+        AgentInfoDAO agentInfoDAO = dependencyServices.getRequiredService(AgentInfoDAO.class);
+        VmInfoDAO vmInfoDAO = dependencyServices.getRequiredService(VmInfoDAO.class);
+        JmxNotificationDAO jmxNotificationDAO = dependencyServices.getRequiredService(JmxNotificationDAO.class);
 
         VmRef vmRef = getVmRef(args, vmInfoDAO, hostInfoDAO);
 
@@ -149,12 +149,6 @@
         }
     }
 
-    private <T> T getService(Class<T> klazz) throws CommandException {
-        T service = dependencyServices.getService(klazz);
-        requireNonNull(service, t.localize(LocaleResources.MISSING_REQUIRED_SERVICE));
-        return service;
-    }
-
     private VmRef getVmRef(Arguments arguments, VmInfoDAO vmInfoDAO, HostInfoDAO hostInfoDAO) throws CommandException {
         VmId vmId = VmArgument.required(arguments).getVmId();
         VmInfo vmInfo = vmInfoDAO.getVmInfo(vmId);
--- a/vm-jmx/client-cli/src/main/java/com/redhat/thermostat/vm/jmx/client/cli/locale/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-jmx/client-cli/src/main/java/com/redhat/thermostat/vm/jmx/client/cli/locale/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -43,8 +43,6 @@
     EXPECTED_ONE_NONOPTION_ARG,
     UNRECOGNIZED_SUBCOMMAND,
 
-    MISSING_REQUIRED_SERVICE,
-
     UNKNOWN_VMID,
     UNKNOWN_HOST,
 
--- a/vm-jmx/client-cli/src/main/resources/com/redhat/thermostat/vm/jmx/client/cli/locale/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-jmx/client-cli/src/main/resources/com/redhat/thermostat/vm/jmx/client/cli/locale/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -1,8 +1,6 @@
 EXPECTED_ONE_NONOPTION_ARG=Expected one non-option argument (subcommand)
 UNRECOGNIZED_SUBCOMMAND=Unrecognized subcommand: {0}
 
-MISSING_REQUIRED_SERVICE=Required service {0} is missing
-
 UNKNOWN_VMID=Unknown VM ID: {0}
 UNKNOWN_HOST=Unknown host
 
--- a/vm-profiler/client-cli/src/main/java/com/redhat/thermostat/vm/profiler/client/cli/internal/LocaleResources.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-profiler/client-cli/src/main/java/com/redhat/thermostat/vm/profiler/client/cli/internal/LocaleResources.java	Thu Nov 17 12:47:48 2016 -0500
@@ -40,11 +40,6 @@
 
 public enum LocaleResources {
 
-    VM_SERVICE_UNAVAILABLE,
-    HOST_SERVICE_UNAVAILABLE,
-    AGENT_SERVICE_UNAVAILABLE,
-    QUEUE_SERVICE_UNAVAILABLE,
-
     COMMAND_EXPECTED,
     UNKNOWN_COMMAND,
     INTERRUPTED_WAITING_FOR_RESPONSE,
--- a/vm-profiler/client-cli/src/main/java/com/redhat/thermostat/vm/profiler/client/cli/internal/ProfileVmCommand.java	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-profiler/client-cli/src/main/java/com/redhat/thermostat/vm/profiler/client/cli/internal/ProfileVmCommand.java	Thu Nov 17 12:47:48 2016 -0500
@@ -83,19 +83,15 @@
     @Override
     public void run(CommandContext ctx) throws CommandException {
 
-        AgentInfoDAO agentInfoDAO = myServices.getService(AgentInfoDAO.class);
-        VmInfoDAO vmInfoDAO = myServices.getService(VmInfoDAO.class);
+        AgentInfoDAO agentInfoDAO = myServices.getRequiredService(AgentInfoDAO.class);
+        VmInfoDAO vmInfoDAO = myServices.getRequiredService(VmInfoDAO.class);
 
         VmArgument vmArgument = VmArgument.required(ctx.getArguments());
         VmId vmId = vmArgument.getVmId();
         final VmInfo vmInfo = vmInfoDAO.getVmInfo(vmId);
         final AgentId agentId = new AgentId(vmInfo.getAgentId());
 
-        requireNonNull(agentInfoDAO, translator.localize(LocaleResources.AGENT_SERVICE_UNAVAILABLE));
-        requireNonNull(vmInfoDAO, translator.localize(LocaleResources.VM_SERVICE_UNAVAILABLE));
-
-        RequestQueue requestQueue = myServices.getService(RequestQueue.class);
-        requireNonNull(requestQueue, translator.localize(LocaleResources.QUEUE_SERVICE_UNAVAILABLE));
+        RequestQueue requestQueue = myServices.getRequiredService(RequestQueue.class);
 
         AgentInformation agentInfo = agentInfoDAO.getAgentInformation(agentId);
         if (agentInfo == null) {
--- a/vm-profiler/client-cli/src/main/resources/com/redhat/thermostat/vm/profiler/client/cli/internal/strings.properties	Thu Nov 17 12:38:08 2016 -0500
+++ b/vm-profiler/client-cli/src/main/resources/com/redhat/thermostat/vm/profiler/client/cli/internal/strings.properties	Thu Nov 17 12:47:48 2016 -0500
@@ -1,8 +1,3 @@
-VM_SERVICE_UNAVAILABLE = VM information is not available
-HOST_SERVICE_UNAVAILABLE = Host information is not available
-AGENT_SERVICE_UNAVAILABLE = Agent information is not available
-QUEUE_SERVICE_UNAVAILABLE = Sending requests to the agent is not possible
-
 COMMAND_EXPECTED = A valid subcommand is expected.
 UNKNOWN_COMMAND = Unknown command: {0}
 INTERRUPTED_WAITING_FOR_RESPONSE = Interrupted while waiting for a response from agent