Mercurial > hg > thermostat-ng > web-gateway
changeset 1:1b1599b190f2
Server plugin: Add preliminary structures for server and user configuration via properties files. Restructure auth files.
line wrap: on
line diff
--- a/server/command/src/main/java/com/redhat/thermostat/server/command/WebEndpointCommand.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/command/src/main/java/com/redhat/thermostat/server/command/WebEndpointCommand.java Thu Feb 02 15:36:26 2017 -0500 @@ -36,6 +36,8 @@ package com.redhat.thermostat.server.command; +import java.io.IOException; +import java.util.Map; import java.util.Properties; import org.apache.felix.scr.annotations.Component; @@ -48,6 +50,7 @@ import com.redhat.thermostat.common.cli.Command; import com.redhat.thermostat.common.cli.CommandContext; import com.redhat.thermostat.common.cli.CommandException; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; import com.redhat.thermostat.server.core.CoreServer; import com.redhat.thermostat.shared.config.CommonPaths; @@ -62,9 +65,17 @@ @Reference private CommonPaths paths; + @Reference + private ConfigurationInfoSource config; + @Override public void run(CommandContext ctx) throws CommandException { - coreServer.buildServer(new Properties()); + try { + Map<String, String> serverConfig = config.getConfiguration("web-server", "server-config.properties"); + Map<String, String> userConfig = config.getConfiguration("web-server", "user-config.properties"); + coreServer.buildServer(serverConfig, userConfig); + } catch (IOException e) { + } Server server = coreServer.getServer(); try { server.start();
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/CoreServer.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/CoreServer.java Thu Feb 02 15:36:26 2017 -0500 @@ -4,11 +4,10 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.Properties; +import java.util.Map; import javax.ws.rs.core.UriBuilder; -import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Service; import org.eclipse.jetty.server.Connector; @@ -24,59 +23,59 @@ import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature; +import com.redhat.thermostat.server.core.internal.security.UserStore; import com.redhat.thermostat.server.core.internal.security.auth.proxy.ProxyAuthFilter; -import com.redhat.thermostat.server.core.internal.storage.MongoStorage; +import com.redhat.thermostat.server.core.internal.storage.ThermostatMongoStorage; import com.redhat.thermostat.server.core.internal.web.handler.http.HttpHandler; import com.redhat.thermostat.server.core.internal.web.handler.storage.MongoStorageHandler; @Component @Service(CoreServer.class) public class CoreServer { - private Server server; - public void buildServer(Properties properties) { - MongoStorage.start("thermostat", 27518); + public void buildServer(Map<String, String> serverConfig, Map<String, String> userConfig) { + ThermostatMongoStorage.start(27518); URI baseUri = UriBuilder.fromUri("http://localhost").port(8080).build(); - ResourceConfig config = new ResourceConfig(); - setupResourceConfig(config); - - server = JettyHttpContainerFactory.createServer(baseUri, config, false); - + ResourceConfig resourceConfig = new ResourceConfig(); + setupResourceConfig(serverConfig, userConfig, resourceConfig); - ServerConnector httpConnector = new ServerConnector(server); - setupConnector(httpConnector); - server.setConnectors(new Connector[]{httpConnector}); - + server = JettyHttpContainerFactory.createServer(baseUri, resourceConfig, false); - HandlerList handlers = new HandlerList(); - setupHandlers(handlers); + setupConnectors(serverConfig); - server.setHandler(handlers); + setupHandlers(serverConfig); } - private void setupResourceConfig(ResourceConfig config) { - config.register(new HttpHandler(new MongoStorageHandler())); - config.register(new ProxyAuthFilter()); - config.register(new RolesAllowedDynamicFeature()); + private void setupResourceConfig(Map<String, String> serverConfig, Map<String, String> userConfig, ResourceConfig resourceConfig) { + resourceConfig.register(new HttpHandler(new MongoStorageHandler())); + resourceConfig.register(new ProxyAuthFilter(new UserStore(userConfig))); + resourceConfig.register(new RolesAllowedDynamicFeature()); } - private void setupConnector(ServerConnector httpConnector) { + private void setupConnectors(Map<String, String> serverConfig) { HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.addCustomizer(new org.eclipse.jetty.server.ForwardedRequestCustomizer()); + ServerConnector httpConnector = new ServerConnector(server); httpConnector.addConnectionFactory(new HttpConnectionFactory(httpConfig)); httpConnector.setHost("localhost"); httpConnector.setPort(8090); httpConnector.setIdleTimeout(30000); + + server.setConnectors(new Connector[]{httpConnector}); } - private void setupHandlers(HandlerList handlers) { + private void setupHandlers(Map<String, String> serverConfig) { Handler originalHandler = server.getHandler(); + + HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { createSwaggerResource(), originalHandler}); + + server.setHandler(handlers); } private Handler createSwaggerResource() { @@ -100,6 +99,6 @@ } public void finish() { - MongoStorage.finish(); + ThermostatMongoStorage.finish(); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/configuration/ServerConfiguration.java Thu Feb 02 15:36:26 2017 -0500 @@ -0,0 +1,16 @@ +package com.redhat.thermostat.server.core.internal.configuration; + +public class ServerConfiguration { + public enum ServerOptions { + SECURITY_PROXY, + SECURITY_BASIC, + SECURITY_BASIC_SSL, + + SERVER_PORT, + SERVER_URL, + + SWAGGER_ENABLED, + + } + +}
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/AuthWebUser.java Wed Feb 01 16:17:58 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Copyright 2012-2017 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 - * <http://www.gnu.org/licenses/>. - * - * 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.server.core.internal.security; - -import java.util.List; - -public class AuthWebUser implements WebUser { - private final String username; - private final List<String> roles; - private final char[] password; - - public AuthWebUser(String username, char[] password, List<String> roles) { - this.username = username; - this.roles = roles; - this.password = password; - } - - @Override - public String getUsername() { - return this.username; - } - - @Override - public boolean isUserInRole(String role) { - return this.roles.contains(role); - } - - public String getPassword() { - return new String(password); - } -}
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/BasicWebUser.java Wed Feb 01 16:17:58 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright 2012-2017 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 - * <http://www.gnu.org/licenses/>. - * - * 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.server.core.internal.security; - -import java.util.List; - -public class BasicWebUser implements WebUser { - private final String username; - private final List<String> roles; - - public BasicWebUser(String username, List<String> roles) { - this.username = username; - this.roles = roles; - } - - public String getUsername() { - return this.username; - } - - public boolean isUserInRole(String role) { - return this.roles.contains(role); - } -}
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/UserStore.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/UserStore.java Thu Feb 02 15:36:26 2017 -0500 @@ -41,13 +41,29 @@ import java.util.HashMap; import java.util.Map; +import com.redhat.thermostat.server.core.internal.security.auth.basic.BasicWebUser; +import com.redhat.thermostat.server.core.internal.security.auth.proxy.ProxyWebUser; + public class UserStore { - private final Map<String, WebUser> userStore; + private final Map<String, WebUser> userStore = new HashMap<>(); public UserStore() { - userStore = new HashMap<>(); - userStore.put("admin@EXAMPLE.COM", new BasicWebUser("admin@EXAMPLE.COM", new ArrayList<>(Arrays.asList("admin@EXAMPLE.COM", "user")))); - userStore.put("user@EXAMPLE.COM", new BasicWebUser("user@EXAMPLE.COM", new ArrayList<>(Arrays.asList("user@EXAMPLE.COM", "user")))); + userStore.put("admin@EXAMPLE.COM", new ProxyWebUser("admin@EXAMPLE.COM", new ArrayList<>(Arrays.asList("admin@EXAMPLE.COM", "user")))); + userStore.put("user@EXAMPLE.COM", new ProxyWebUser("user@EXAMPLE.COM", new ArrayList<>(Arrays.asList("user@EXAMPLE.COM", "user")))); + } + + public UserStore(Map<String, String> users) { + for (Map.Entry<String, String> entry : users.entrySet()) { + String username = entry.getKey(); + ArrayList<String> items = new ArrayList<>(Arrays.asList(entry.getValue().split(","))); + WebUser user; + if (items.get(0).equals("proxy")) { + user = new ProxyWebUser(username, new ArrayList<>(items.subList(1, items.size()))); + } else { + user = new BasicWebUser(username, items.get(1).toCharArray(), items.subList(2, items.size())); + } + userStore.put(username, user); + } } public WebUser getUser(String userName) {
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/basic/BasicAuthFilter.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/basic/BasicAuthFilter.java Thu Feb 02 15:36:26 2017 -0500 @@ -49,7 +49,6 @@ import javax.ws.rs.ext.Provider; import javax.xml.bind.DatatypeConverter; -import com.redhat.thermostat.server.core.internal.security.AuthWebUser; import com.redhat.thermostat.server.core.internal.security.UserStore; @Provider @@ -58,10 +57,6 @@ private final UserStore userStore; - public BasicAuthFilter() { - this(new UserStore()); - } - public BasicAuthFilter(UserStore userStore) { this.userStore = userStore; } @@ -87,12 +82,12 @@ String username = values[0]; String password = values[1]; - AuthWebUser user = (AuthWebUser) userStore.getUser(username); + BasicWebUser user = (BasicWebUser) userStore.getUser(username); if (user == null) { throw new NotAuthorizedException("Authentication credentials are required"); } - if (!new String(user.getPassword()).equals(password)) { + if (!user.getPassword().equals(password)) { throw new NotAuthorizedException("Authentication credentials are required"); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/basic/BasicWebUser.java Thu Feb 02 15:36:26 2017 -0500 @@ -0,0 +1,67 @@ +/* + * Copyright 2012-2017 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 + * <http://www.gnu.org/licenses/>. + * + * 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.server.core.internal.security.auth.basic; + +import java.util.List; + +import com.redhat.thermostat.server.core.internal.security.WebUser; + +public class BasicWebUser implements WebUser { + private final String username; + private final List<String> roles; + private final char[] password; + + public BasicWebUser(String username, char[] password, List<String> roles) { + this.username = username; + this.roles = roles; + this.password = password; + } + + @Override + public String getUsername() { + return this.username; + } + + @Override + public boolean isUserInRole(String role) { + return this.roles.contains(role); + } + + public String getPassword() { + return new String(password); + } +}
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/proxy/ProxyAuthFilter.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/proxy/ProxyAuthFilter.java Thu Feb 02 15:36:26 2017 -0500 @@ -52,7 +52,11 @@ @Priority(Priorities.AUTHENTICATION) public class ProxyAuthFilter implements ContainerRequestFilter{ - private final UserStore userStore = new UserStore(); + private final UserStore userStore; + + public ProxyAuthFilter(UserStore userStore) { + this.userStore = userStore; + } @Override public void filter(ContainerRequestContext requestContext) throws IOException {
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/proxy/ProxySecurityContext.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/proxy/ProxySecurityContext.java Thu Feb 02 15:36:26 2017 -0500 @@ -42,7 +42,7 @@ import com.redhat.thermostat.server.core.internal.security.WebUser; -public class ProxySecurityContext implements SecurityContext{ +class ProxySecurityContext implements SecurityContext{ private final WebUser user; public ProxySecurityContext(WebUser user) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/security/auth/proxy/ProxyWebUser.java Thu Feb 02 15:36:26 2017 -0500 @@ -0,0 +1,59 @@ +/* + * Copyright 2012-2017 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 + * <http://www.gnu.org/licenses/>. + * + * 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.server.core.internal.security.auth.proxy; + +import java.util.List; + +import com.redhat.thermostat.server.core.internal.security.WebUser; + +public class ProxyWebUser implements WebUser { + private final String username; + private final List<String> roles; + + public ProxyWebUser(String username, List<String> roles) { + this.username = username; + this.roles = roles; + } + + public String getUsername() { + return this.username; + } + + public boolean isUserInRole(String role) { + return this.roles.contains(role); + } +}
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/storage/MongoStorage.java Wed Feb 01 16:17:58 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -/* - * Copyright 2012-2017 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 - * <http://www.gnu.org/licenses/>. - * - * 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.server.core.internal.storage; - -import java.util.Collections; - -import com.mongodb.MongoClient; -import com.mongodb.MongoClientOptions; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; -import com.mongodb.client.MongoDatabase; - -public class MongoStorage { - private static MongoClient mongoClient; - - private static final String username = "mongodevuser"; - private static final char[] password = "mongodevpassword".toCharArray(); - private static String dbName; - - public static void start(final String dbName, int port) { - MongoStorage.dbName = dbName; - MongoCredential credential = MongoCredential.createCredential(username, dbName, password); - ServerAddress address = new ServerAddress("127.0.0.1", port); - mongoClient = new MongoClient(address, Collections.singletonList(credential), new MongoClientOptions.Builder().serverSelectionTimeout(0).build()); - } - - public static boolean isConnected() { - try { - mongoClient.getAddress(); - return true; - } catch (Exception e) { - return false; - } - } - - public static void finish() { - mongoClient.close(); - } - - public static MongoDatabase getDatabase() { - return MongoStorage.mongoClient.getDatabase(MongoStorage.dbName); - } -} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/storage/ThermostatMongoStorage.java Thu Feb 02 15:36:26 2017 -0500 @@ -0,0 +1,76 @@ +/* + * Copyright 2012-2017 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 + * <http://www.gnu.org/licenses/>. + * + * 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.server.core.internal.storage; + +import java.util.Collections; + +import com.mongodb.MongoClient; +import com.mongodb.MongoClientOptions; +import com.mongodb.MongoCredential; +import com.mongodb.ServerAddress; +import com.mongodb.client.MongoDatabase; + +public class ThermostatMongoStorage { + private static MongoClient mongoClient; + + private static final String username = "mongodevuser"; + private static final char[] password = "mongodevpassword".toCharArray(); + private static final String dbName = "thermostat"; + + public static void start(int port) { + MongoCredential credential = MongoCredential.createCredential(username, dbName, password); + ServerAddress address = new ServerAddress("127.0.0.1", port); + mongoClient = new MongoClient(address, Collections.singletonList(credential), new MongoClientOptions.Builder().serverSelectionTimeout(0).build()); + } + + public static boolean isConnected() { + try { + mongoClient.getAddress(); + return true; + } catch (Exception e) { + return false; + } + } + + public static void finish() { + mongoClient.close(); + } + + public static MongoDatabase getDatabase() { + return ThermostatMongoStorage.mongoClient.getDatabase(ThermostatMongoStorage.dbName); + } +} \ No newline at end of file
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/http/HttpHandler.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/http/HttpHandler.java Thu Feb 02 15:36:26 2017 -0500 @@ -69,10 +69,10 @@ @Path("agents/{agentId}") @Produces(MediaType.APPLICATION_JSON) public void getAgent(@Context SecurityContext securityContext, - @Suspended final AsyncResponse asyncResponse, - @PathParam("agentId") String agentId, - @QueryParam("size") @DefaultValue("1") String count, - @QueryParam("sort") @DefaultValue("-1") String sort) { + @Suspended final AsyncResponse asyncResponse, + @PathParam("agentId") String agentId, + @QueryParam("size") @DefaultValue("1") String count, + @QueryParam("sort") @DefaultValue("-1") String sort) { handler.getAgent(securityContext, asyncResponse, agentId, count, sort); } @@ -88,11 +88,11 @@ @Path("agents/{agentId}/host/cpu") @Produces(MediaType.APPLICATION_JSON) public Response getHostCpuInfo(@Context SecurityContext securityContext, - @PathParam("agentId") String agentId, - @QueryParam("size") @DefaultValue("1") String count, - @QueryParam("sort") @DefaultValue("-1") String sort, - @QueryParam("maxTimestamp") String maxTimestamp, - @QueryParam("minTimestamp") String minTimestamp) { + @PathParam("agentId") String agentId, + @QueryParam("size") @DefaultValue("1") String count, + @QueryParam("sort") @DefaultValue("-1") String sort, + @QueryParam("maxTimestamp") String maxTimestamp, + @QueryParam("minTimestamp") String minTimestamp) { return handler.getHostCpuInfo(securityContext, agentId, count, sort, maxTimestamp, minTimestamp); } @@ -100,7 +100,7 @@ @Path("stream/agents/{agentId}/host/cpu") @Produces(MediaType.APPLICATION_JSON) public ChunkedOutput<String> streamHostCpuInfo(@Context SecurityContext securityContext, - @PathParam("agentId") String agentId) { + @PathParam("agentId") String agentId) { return handler.streamHostCpuInfo(securityContext, agentId); } } \ No newline at end of file
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/HibernateStorageHandler.java Wed Feb 01 16:17:58 2017 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright 2012-2017 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 - * <http://www.gnu.org/licenses/>. - * - * 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.server.core.internal.web.handler.storage; - -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.SecurityContext; - -import org.glassfish.jersey.server.ChunkedOutput; - -public class HibernateStorageHandler implements StorageHandler { - @Override - public void getAgent(SecurityContext securityContext, AsyncResponse asyncResponse, String agentId, String count, String sort) { - } - - @Override - public Response putAgent(String body, SecurityContext context) { - return null; - } - - @Override - public Response getHostCpuInfo(SecurityContext securityContext, String agentId, String count, String sort, String maxTimestamp, String minTimestamp) { - return null; - } - - @Override - public ChunkedOutput<String> streamHostCpuInfo(SecurityContext securityContext, String agentId) { - return null; - } -}
--- a/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/MongoStorageHandler.java Wed Feb 01 16:17:58 2017 -0500 +++ b/server/core/src/main/java/com/redhat/thermostat/server/core/internal/web/handler/storage/MongoStorageHandler.java Thu Feb 02 15:36:26 2017 -0500 @@ -50,7 +50,7 @@ import com.mongodb.BasicDBObject; import com.mongodb.client.FindIterable; -import com.redhat.thermostat.server.core.internal.storage.MongoStorage; +import com.redhat.thermostat.server.core.internal.storage.ThermostatMongoStorage; import com.redhat.thermostat.server.core.internal.web.filters.RequestFilters; import com.redhat.thermostat.server.core.internal.web.json.DocumentBuilder; import com.redhat.thermostat.server.core.internal.web.request.TimedRequest; @@ -69,7 +69,7 @@ new Thread(new Runnable() { @Override public void run() { - if (!MongoStorage.isConnected()) { + if (!ThermostatMongoStorage.isConnected()) { asyncResponse.resume(Response.status(Response.Status.OK).entity("GET " + agentId + " " + count + " " + sort + " " + securityContext.getUserPrincipal().getName()).build()); return; } @@ -84,7 +84,7 @@ FindIterable<Document> documents = timedRequest.run(new TimedRequest.TimedRunnable<FindIterable<Document>>() { @Override public FindIterable<Document> run() { - return MongoStorage.getDatabase().getCollection("agents").find(filter).sort(new BasicDBObject("_id", sortOrder)).limit(limit); + return ThermostatMongoStorage.getDatabase().getCollection("agents").find(filter).sort(new BasicDBObject("_id", sortOrder)).limit(limit); } }); @@ -96,7 +96,7 @@ @Override public Response putAgent(String body, @Context SecurityContext context) { - if (!MongoStorage.isConnected()) { + if (!ThermostatMongoStorage.isConnected()) { return Response.status(Response.Status.OK).entity("PUT " + context.getUserPrincipal().getName() + "\n\n" + body).build(); } @@ -111,7 +111,7 @@ timedRequest.run(new TimedRequest.TimedRunnable<FindIterable<Document>>() { @Override public FindIterable<Document> run() { - MongoStorage.getDatabase().getCollection("agents").insertOne(item); + ThermostatMongoStorage.getDatabase().getCollection("agents").insertOne(item); return null; } }); @@ -126,7 +126,7 @@ String sort, String maxTimestamp, String minTimestamp) { - if (!MongoStorage.isConnected()) { + if (!ThermostatMongoStorage.isConnected()) { return Response.status(Response.Status.OK).entity(agentId + count + sort + maxTimestamp + minTimestamp).build(); } @@ -141,7 +141,7 @@ FindIterable<Document> documents = request.run(new TimedRequest.TimedRunnable<FindIterable<Document>>() { @Override public FindIterable<Document> run() { - return MongoStorage.getDatabase().getCollection("cpu-stats").find(filter).sort(new BasicDBObject("_id", sortOrder)).limit(size); + return ThermostatMongoStorage.getDatabase().getCollection("cpu-stats").find(filter).sort(new BasicDBObject("_id", sortOrder)).limit(size); } }); @@ -161,7 +161,7 @@ FindIterable<Document> documents = request.run(new TimedRequest.TimedRunnable<FindIterable<Document>>() { @Override public FindIterable<Document> run() { - return MongoStorage.getDatabase().getCollection("cpu-stats").find().sort(new BasicDBObject("_id", -1)).limit(1); + return ThermostatMongoStorage.getDatabase().getCollection("cpu-stats").find().sort(new BasicDBObject("_id", -1)).limit(1); } }); output.write(MongoResponseBuilder.buildJsonResponse(documents, request.getElapsed()));