Mercurial > hg > thermostat-ng > agent
changeset 2633:1887270ae88b
Prepare storage-core for new DAO implementations
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-May/022937.html
line wrap: on
line diff
--- a/distribution/assembly/core-assembly.xml Fri May 05 12:11:28 2017 -0400 +++ b/distribution/assembly/core-assembly.xml Fri May 05 12:12:46 2017 -0400 @@ -73,6 +73,8 @@ <include>io.netty:netty-handler</include> <include>commons-codec:commons-codec</include> <include>org.apache.httpcomponents:httpclient-osgi</include> + <include>org.eclipse.jetty:jetty-client</include> + <include>javax.servlet:javax.servlet-api</include> <!-- Remove once upstream has OSGi metadata --> <include>com.redhat.thermostat:jnr-x86asm</include> </includes>
--- a/main/src/main/resources/com/redhat/thermostat/main/internal/bootstrapbundles.properties Fri May 05 12:11:28 2017 -0400 +++ b/main/src/main/resources/com/redhat/thermostat/main/internal/bootstrapbundles.properties Fri May 05 12:12:46 2017 -0400 @@ -6,3 +6,10 @@ jline-@jline.version@.jar, \ commons-cli-@commons-cli.version@.jar, \ org.apache.felix.scr-@felix.scr.version@.jar, \ + gson-@gson.version@.jar, \ + jetty-client-@jetty.version@.jar, \ + jetty-http-@jetty.version@.jar, \ + jetty-io-@jetty.version@.jar, \ + jetty-util-@jetty.version@.jar, \ + javax.servlet-api-@jetty.javax.servlet.osgi.version@.jar +# FIXME Remove gson and everything below once DAOs moved out of storage-core
--- a/pom.xml Fri May 05 12:11:28 2017 -0400 +++ b/pom.xml Fri May 05 12:12:46 2017 -0400 @@ -769,6 +769,11 @@ <classifier>native</classifier> </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-client</artifactId> + <version>${jetty.version}</version> + </dependency> </dependencies> </dependencyManagement>
--- a/storage/core/pom.xml Fri May 05 12:11:28 2017 -0400 +++ b/storage/core/pom.xml Fri May 05 12:12:46 2017 -0400 @@ -123,6 +123,20 @@ <artifactId>thermostat-common-core</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> + <dependency> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-client</artifactId> + </dependency> + <!-- This will likely have to match what jetty-project's pom uses --> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>${jetty.javax.servlet.osgi.version}</version> + </dependency> </dependencies> </project>
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/Activator.java Fri May 05 12:11:28 2017 -0400 +++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/Activator.java Fri May 05 12:12:46 2017 -0400 @@ -63,7 +63,6 @@ private static final String WRITER_UUID = UUID.randomUUID().toString(); - ServiceTracker tracker; List<ServiceRegistration<?>> regs; public Activator() { @@ -72,52 +71,32 @@ @Override public void start(final BundleContext context) throws Exception { - Class<?>[] deps = new Class<?>[] { - Storage.class, - }; - // WriterID has to be registered unconditionally (at least not as part // of the Storage.class tracker, since that is only registered once // storage is connected). final WriterID writerID = new WriterIDImpl(WRITER_UUID); - final ServiceRegistration<?> reg = context.registerService(WriterID.class, writerID, null); + ServiceRegistration<?> reg = context.registerService(WriterID.class, writerID, null); regs.add(reg); - tracker = new ServiceTracker(context, Storage.class.getName(), null) { - - public Object addingService(ServiceReference reference) { - Storage storage = (Storage) super.addingService(reference); - SchemaInfoDAO schemaInfoDAO = new SchemaInfoDAOImpl(storage); - ServiceRegistration<?> reg = context.registerService(SchemaInfoDAO.class.getName(), schemaInfoDAO, null); - regs.add(reg); - - AgentInfoDAO agentInfoDao = new AgentInfoDAOImpl(storage); - reg = context.registerService(AgentInfoDAO.class.getName(), agentInfoDao, null); - regs.add(reg); - - BackendInfoDAO backendInfoDao = new BackendInfoDAOImpl(storage); - reg = context.registerService(BackendInfoDAO.class.getName(), backendInfoDao, null); - regs.add(reg); - - NetworkInterfaceInfoDAO networkInfoDao = new NetworkInterfaceInfoDAOImpl(storage); - reg = context.registerService(NetworkInterfaceInfoDAO.class.getName(), networkInfoDao, null); - regs.add(reg); - - VmInfoDAO vmInfoDao = new VmInfoDAOImpl(storage); - reg = context.registerService(VmInfoDAO.class.getName(), vmInfoDao, null); - regs.add(reg); - - return storage; - } + SchemaInfoDAO schemaInfoDAO = new SchemaInfoDAOImpl(); + reg = context.registerService(SchemaInfoDAO.class.getName(), schemaInfoDAO, null); + regs.add(reg); + + AgentInfoDAO agentInfoDao = new AgentInfoDAOImpl(); + reg = context.registerService(AgentInfoDAO.class.getName(), agentInfoDao, null); + regs.add(reg); - @Override - public void removedService(ServiceReference reference, Object service) { - unregisterServices(); - super.removedService(reference, service); - } - }; + BackendInfoDAO backendInfoDao = new BackendInfoDAOImpl(); + reg = context.registerService(BackendInfoDAO.class.getName(), backendInfoDao, null); + regs.add(reg); - tracker.open(); + NetworkInterfaceInfoDAO networkInfoDao = new NetworkInterfaceInfoDAOImpl(); + reg = context.registerService(NetworkInterfaceInfoDAO.class.getName(), networkInfoDao, null); + regs.add(reg); + + VmInfoDAO vmInfoDao = new VmInfoDAOImpl(); + reg = context.registerService(VmInfoDAO.class.getName(), vmInfoDao, null); + regs.add(reg); } private void unregisterServices() { @@ -130,7 +109,6 @@ @Override public void stop(BundleContext context) throws Exception { unregisterServices(); - tracker.close(); } }
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/DAOImplStatementDescriptorRegistration.java Fri May 05 12:11:28 2017 -0400 +++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/DAOImplStatementDescriptorRegistration.java Fri May 05 12:12:46 2017 -0400 @@ -52,26 +52,6 @@ @Override public Set<String> getStatementDescriptors() { Set<String> daoDescs = new HashSet<>(); - daoDescs.add(AgentInfoDAOImpl.QUERY_AGENT_INFO); - daoDescs.add(AgentInfoDAOImpl.QUERY_ALIVE_AGENTS); - daoDescs.add(AgentInfoDAOImpl.QUERY_ALL_AGENTS); - daoDescs.add(AgentInfoDAOImpl.AGGREGATE_COUNT_ALL_AGENTS); - daoDescs.add(AgentInfoDAOImpl.DESC_ADD_AGENT_INFO); - daoDescs.add(AgentInfoDAOImpl.DESC_REMOVE_AGENT_INFO); - daoDescs.add(AgentInfoDAOImpl.DESC_UPDATE_AGENT_INFO); - daoDescs.add(BackendInfoDAOImpl.QUERY_BACKEND_INFO); - daoDescs.add(BackendInfoDAOImpl.DESC_ADD_BACKEND_INFO); - daoDescs.add(BackendInfoDAOImpl.DESC_REMOVE_BACKEND_INFO); - daoDescs.add(NetworkInterfaceInfoDAOImpl.QUERY_NETWORK_INFO); - daoDescs.add(NetworkInterfaceInfoDAOImpl.DESC_REPLACE_NETWORK_INFO); - daoDescs.add(NetworkInterfaceInfoDAOImpl.AGGREGATE_COUNT_ALL_NETWORK_INTERFACES); - daoDescs.add(VmInfoDAOImpl.QUERY_ALL_VMS_FOR_AGENT); - daoDescs.add(VmInfoDAOImpl.QUERY_ALL_VMS); - daoDescs.add(VmInfoDAOImpl.QUERY_VM_INFO); - daoDescs.add(VmInfoDAOImpl.AGGREGATE_COUNT_ALL_VMS); - daoDescs.add(VmInfoDAOImpl.DESC_ADD_VM_INFO); - daoDescs.add(VmInfoDAOImpl.DESC_UPDATE_VM_STOP_TIME); - daoDescs.add(VmInfoDAOImpl.QUERY_VM_FROM_ID); daoDescs.add(SchemaInfoDAOImpl.QUERY_ALL_COLLECTIONS); return daoDescs;
--- a/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/SchemaInfoDAOImpl.java Fri May 05 12:11:28 2017 -0400 +++ b/storage/core/src/main/java/com/redhat/thermostat/storage/internal/dao/SchemaInfoDAOImpl.java Fri May 05 12:12:46 2017 -0400 @@ -36,6 +36,7 @@ package com.redhat.thermostat.storage.internal.dao; +import java.util.Collections; import java.util.List; import java.util.logging.Logger; @@ -47,24 +48,19 @@ import com.redhat.thermostat.storage.dao.SimpleDaoQuery; import com.redhat.thermostat.storage.model.SchemaInformation; +// TODO Remove this class in the near future public class SchemaInfoDAOImpl extends AbstractDao implements SchemaInfoDAO { private static final Logger logger = LoggingUtils.getLogger(SchemaInfoDAOImpl.class); static final String QUERY_ALL_COLLECTIONS = "QUERY " + SchemaInfo.CATEGORY.getName(); - private final Storage storage; - - public SchemaInfoDAOImpl(Storage storage) { - this.storage = storage; - storage.registerCategory(SchemaInfo.CATEGORY); - } @Override public List<SchemaInformation> getSchemaInfos() { - return executeQuery(new SimpleDaoQuery<>(storage, SchemaInfo.CATEGORY, QUERY_ALL_COLLECTIONS)).asList(); + return Collections.emptyList(); } @Override protected Logger getLogger() { return logger; } -} \ No newline at end of file +}
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/ActivatorTest.java Fri May 05 12:11:28 2017 -0400 +++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/ActivatorTest.java Fri May 05 12:12:46 2017 -0400 @@ -64,37 +64,8 @@ public class ActivatorTest { @Test - public void verifyActivatorDoesNotRegisterServiceOnMissingDeps() throws Exception { - StubBundleContext context = new StubBundleContext(); - - Activator activator = new Activator(); - - activator.start(context); - - // WriterID should get registered unconditionally - assertEquals("At least WriterID service must be registered", 1, context.getAllServices().size()); - assertEquals(1, context.getServiceListeners().size()); - - activator.stop(context); - assertEquals(0, context.getAllServices().size()); - assertEquals(0, context.getServiceListeners().size()); - } - - @Test public void verifyActivatorRegistersServices() throws Exception { StubBundleContext context = new StubBundleContext(); - Storage storage = mock(Storage.class); - - ApplicationService appService = mock(ApplicationService.class); - TimerFactory timerFactory = mock(TimerFactory.class); - when(appService.getTimerFactory()).thenReturn(timerFactory); - - Timer timer = mock(Timer.class); - when(timerFactory.createTimer()).thenReturn(timer); - - context.registerService(ApplicationService.class, appService, null); - context.registerService(Storage.class, storage, null); - Activator activator = new Activator(); activator.start(context); @@ -110,24 +81,12 @@ assertEquals(0, context.getServiceListeners().size()); - assertEquals(2, context.getAllServices().size()); + assertEquals(0, context.getAllServices().size()); } @Test public void verifyActivatorUnregistersServices() throws Exception { StubBundleContext context = new StubBundleContext(); - Storage storage = mock(Storage.class); - - ApplicationService appService = mock(ApplicationService.class); - TimerFactory timerFactory = mock(TimerFactory.class); - when(appService.getTimerFactory()).thenReturn(timerFactory); - - Timer timer = mock(Timer.class); - when(timerFactory.createTimer()).thenReturn(timer); - - context.registerService(Storage.class, storage, null); - context.registerService(ApplicationService.class, appService, null); - Activator activator = new Activator(); activator.start(context); @@ -142,7 +101,7 @@ assertFalse(context.isServiceRegistered(WriterID.class.getName(), WriterIDImpl.class)); assertEquals(0, context.getServiceListeners().size()); - assertEquals(2, context.getAllServices().size()); + assertEquals(0, context.getAllServices().size()); } @Test
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/DAOImplStatementDescriptorRegistrationTest.java Fri May 05 12:11:28 2017 -0400 +++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/DAOImplStatementDescriptorRegistrationTest.java Fri May 05 12:12:46 2017 -0400 @@ -56,7 +56,7 @@ public void registersAllQueries() { DAOImplStatementDescriptorRegistration reg = new DAOImplStatementDescriptorRegistration(); Set<String> descriptors = reg.getStatementDescriptors(); - assertEquals(21, descriptors.size()); + assertEquals(1, descriptors.size()); assertFalse(descriptors.contains(null)); }
--- a/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/SchemaInfoDAOTest.java Fri May 05 12:11:28 2017 -0400 +++ b/storage/core/src/test/java/com/redhat/thermostat/storage/internal/dao/SchemaInfoDAOTest.java Fri May 05 12:12:46 2017 -0400 @@ -45,6 +45,7 @@ import java.util.List; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -59,6 +60,7 @@ import com.redhat.thermostat.storage.core.Storage; import com.redhat.thermostat.storage.model.SchemaInformation; +@Ignore // TODO Remove along with SchemaInfoDAO public class SchemaInfoDAOTest { private SchemaInformation schemaInfo; @@ -111,7 +113,7 @@ @SuppressWarnings("unchecked") PreparedStatement<SchemaInformation> stmt = (PreparedStatement<SchemaInformation>) mock(PreparedStatement.class); ArgumentCaptor<StatementDescriptor> messageCaptor = ArgumentCaptor.forClass(StatementDescriptor.class); - SchemaInfoDAOImpl dao = new SchemaInfoDAOImpl(storage); + SchemaInfoDAOImpl dao = new SchemaInfoDAOImpl(); when(storage.prepareStatement(messageCaptor.capture())).thenReturn(stmt); when(stmt.executeQuery()).thenReturn(schemaCursor); @@ -146,4 +148,4 @@ assertEquals(schemaInfo2, result); } -} \ No newline at end of file +}