Frank Kobzik has uploaded a new change for review.

Change subject: core: Non-plugin automatic invocation of console session
......................................................................

core: Non-plugin automatic invocation of console session

This patch adds a native way of connecting to a (SPICE and VNC) console from
WA/UP using external viewer (virt-viewer) installed on client system. It is
achieved by implementing a servlet that generates a config file (with all
needed information to connect) for virt-viewer that is served to the client
afterwards.

The old way of invoking console viewer (browser plugin) is still
kept, the configuration is set in the database.

The behavior for SPICE is driven by configuration. There are three modes
of behavior:
 - Plugin - The "old" way - spice-xpi is used.
 - Native - The native client is used.
 - Auto - If plugin is installed, it is used. Otherwise "native" implementation
   is used.

As for VNC - it is set to use the native implementation by default (i.e. there
is no VNC connection info popup dialog).

Backend changes:
 - Added servlets for serving console configuration.
 - Added ClientConsoleMode to vdc_options (default setting is 'Auto') and
   modified related enums.

Change-Id: I18b9d2efad15f5e9bb98a8176112b721c810205f
Signed-off-by: Frantisek Kobzik <[email protected]>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=843410
---
M backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
M backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml
A 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/IniServlet.java
A 
backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/console/ConsoleConfigServlet.java
6 files changed, 119 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/02/11702/1

diff --git a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql 
b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
index e851ff0..93339bf 100644
--- a/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
+++ b/backend/manager/dbscripts/upgrade/pre_upgrade/0000_config.sql
@@ -490,6 +490,8 @@
 select 
fn_db_add_config_value('NetworkConnectivityCheckTimeoutInSeconds','120','general');
 -- AutoRecoveryConfiguration
 select fn_db_add_config_value('AutoRecoveryAllowedTypes','{\"storage 
domains\":\"true\",\"hosts\":\"true\"}','general');
+-- Client console mode settings (Auto, Native, Plugin)
+select fn_db_add_config_value('ClientConsoleMode','Auto','general');
 -- Gluster refresh rates (in seconds)
 select fn_db_add_config_value('GlusterRefreshRateLight', '5', 'general');
 select fn_db_add_config_value('GlusterRefreshRateHeavy', '300', 'general');
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
index 4a35584..e9a9a30 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/config/ConfigValues.java
@@ -1369,6 +1369,10 @@
     @DefaultValueAttribute("9")
     PgMajorRelease(418),
 
+    @TypeConverterAttribute(String.class)
+    @DefaultValueAttribute("Auto")
+    ClientConsoleMode(501),
+
     Invalid(65535);
 
     private int intValue;
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
index f43a828..a780763 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/ConfigurationValues.java
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.common.queries;
 
 public enum ConfigurationValues {
+    ClientConsoleMode(ConfigAuthType.User),
     MaxNumOfVmCpus(ConfigAuthType.User),
     MaxNumOfVmSockets(ConfigAuthType.User),
     MaxNumOfCpuPerSocket(ConfigAuthType.User),
diff --git a/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml 
b/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml
index d653621..da877be 100644
--- a/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml
+++ b/backend/manager/modules/root/src/main/webapp/WEB-INF/web.xml
@@ -47,6 +47,20 @@
     <url-pattern>/rhevm.ssh.key.txt</url-pattern>
   </servlet-mapping>
 
+  <!-- File servlet instance to serve spice/vnc descriptors -->
+  <servlet>
+    <servlet-name>ConsoleConfigServlet</servlet-name>
+    
<servlet-class>org.ovirt.engine.core.console.ConsoleConfigServlet</servlet-class>
+    <init-param>
+      <param-name>console-config-file</param-name>
+      <param-value>console.config.template</param-value>
+    </init-param>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>ConsoleConfigServlet</servlet-name>
+    <url-pattern>/console.config</url-pattern>
+  </servlet-mapping>
+
   <!-- Documentation: -->
   <servlet>
     <servlet-name>docs</servlet-name>
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/IniServlet.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/IniServlet.java
new file mode 100644
index 0000000..cb302ee
--- /dev/null
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/IniServlet.java
@@ -0,0 +1,51 @@
+package org.ovirt.engine.core;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Servlet for serving ini-like files built from GET params.
+ *
+ */
+public class IniServlet extends HttpServlet {
+
+    private static final long serialVersionUID = 119752080913341323L;
+    private static final Logger log = Logger.getLogger(IniServlet.class);
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+        try {
+            writeIniToStream(response.getOutputStream(), 
request.getParameterMap());
+        } catch (IOException e) {
+            log.error("Error when writing to response stream " + 
e.getMessage());
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    private void writeIniToStream(OutputStream out, Map<String, String[]> 
dictionary)
+            throws IOException
+    {
+        BufferedWriter writer = new BufferedWriter(new 
OutputStreamWriter(out));
+
+        for (String key : dictionary.keySet()) {
+            for (int i = 0; i < dictionary.get(key).length; i++) {
+                StringBuilder builder = new StringBuilder();
+                builder.append(key).append("=").append(dictionary.get(key)[i]);
+
+                writer.write(builder.toString());
+                writer.newLine();
+            }
+        }
+        writer.flush();
+    }
+}
diff --git 
a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/console/ConsoleConfigServlet.java
 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/console/ConsoleConfigServlet.java
new file mode 100644
index 0000000..b77c15f
--- /dev/null
+++ 
b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/console/ConsoleConfigServlet.java
@@ -0,0 +1,47 @@
+package org.ovirt.engine.core.console;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.ovirt.engine.core.IniServlet;
+
+/**
+ * Servlet for serving console config files.
+ *
+ */
+public class ConsoleConfigServlet extends IniServlet {
+
+    private static final long serialVersionUID = 8496520437603585173L;
+
+    private static final String CONFIG_FILE_HEADER = "[virt-viewer]";
+    private static final String HEADER_CONTENT_TYPE = "x-virt-viewer";
+    private static final String HEADER_CONTENT_FILENAME = "console.vv";
+
+    @Override
+    protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
+        setupHttpHeaders(response);
+        writeConfigFileHeader(response);
+
+        super.doGet(request, response);
+    }
+
+    private void setupHttpHeaders(HttpServletResponse response) {
+        response.setContentType(HEADER_CONTENT_TYPE);
+        response.setHeader("Content-Disposition", "attachment; filename=\"" + 
HEADER_CONTENT_FILENAME + "\"");
+        response.setHeader("Cache-Control", "no-cache, must-revalidate"); 
//disable caching HTTP/1.1
+        response.setHeader("Expires", "Sat, 26 Jul 1997 05:00:00 GMT"); 
//disable caching HTTP/1.0
+    }
+
+    private void writeConfigFileHeader(HttpServletResponse response) throws 
IOException {
+        BufferedWriter writer = new BufferedWriter(new 
OutputStreamWriter(response.getOutputStream()));
+
+        writer.write(CONFIG_FILE_HEADER);
+        writer.newLine();
+        writer.flush();
+    }
+}


--
To view, visit http://gerrit.ovirt.org/11702
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I18b9d2efad15f5e9bb98a8176112b721c810205f
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Frank Kobzik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to