You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/03/26 18:10:23 UTC

[1/6] git commit: refs/heads/quickcloud - QuickCloud: Remove reference to unused code

Updated Branches:
  refs/heads/quickcloud 894375ea2 -> 841a8570e


QuickCloud: Remove reference to unused code


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f28d788a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f28d788a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f28d788a

Branch: refs/heads/quickcloud
Commit: f28d788a99dccb8cd33183d27673125d4bbba3d9
Parents: 894375e
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Mon Mar 25 12:13:51 2013 -0700
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Mon Mar 25 12:13:51 2013 -0700

----------------------------------------------------------------------
 .../cloud/api/commands/DestroyConsoleProxyCmd.java |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f28d788a/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java b/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java
index 829283e..f3210ce 100644
--- a/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java
+++ b/api/src/com/cloud/api/commands/DestroyConsoleProxyCmd.java
@@ -17,14 +17,12 @@
 package com.cloud.api.commands;
 
 import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.ApiErrorCode;
 import org.apache.cloudstack.api.BaseAsyncCmd;
 import org.apache.cloudstack.api.Parameter;
-import org.apache.cloudstack.api.ServerApiException;
-import org.apache.cloudstack.api.response.SuccessResponse;
 import org.apache.log4j.Logger;
 
 import com.cloud.event.EventTypes;
+import com.cloud.exception.UnsupportedServiceException;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 
@@ -82,12 +80,6 @@ public class DestroyConsoleProxyCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        boolean result = _consoleProxyService.destroyConsoleProxy(this);
-        if (result) {
-            SuccessResponse response = new SuccessResponse(getCommandName());
-            this.setResponseObject(response);
-        } else {
-            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to destroy console proxy");
-        }
+        throw new UnsupportedServiceException("Use destroySystemVm API instead");
     }
 }


[4/6] git commit: refs/heads/quickcloud - QuickCloud: remove some dead code in ConsoleProxyManager

Posted by ch...@apache.org.
QuickCloud: remove some dead code in ConsoleProxyManager


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/53918521
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/53918521
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/53918521

Branch: refs/heads/quickcloud
Commit: 539185217a55f40709e9544bdae4d1143dd7462e
Parents: a32a150
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Tue Mar 26 10:03:56 2013 -0700
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Tue Mar 26 10:03:56 2013 -0700

----------------------------------------------------------------------
 .../cloud/consoleproxy/ConsoleProxyManager.java    |   17 +--------------
 .../consoleproxy/ConsoleProxyManagerImpl.java      |    2 +-
 .../cloud/consoleproxy/ConsoleProxyService.java    |    9 ++++++++
 3 files changed, 11 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53918521/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java
index 6ebf3bc..faec513 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManager.java
@@ -16,17 +16,9 @@
 // under the License.
 package com.cloud.consoleproxy;
 
-import com.cloud.agent.api.AgentControlAnswer;
-import com.cloud.agent.api.ConsoleAccessAuthenticationCommand;
-import com.cloud.agent.api.ConsoleProxyLoadReportCommand;
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.host.HostVO;
-import com.cloud.host.Status;
-import com.cloud.host.Host.Type;
-import com.cloud.info.ConsoleProxyInfo;
 import com.cloud.utils.component.Manager;
 import com.cloud.vm.ConsoleProxyVO;
-public interface ConsoleProxyManager extends Manager {
+public interface ConsoleProxyManager extends Manager, ConsoleProxyService {
 	
 	public static final int DEFAULT_PROXY_CAPACITY = 50;
 	public static final int DEFAULT_STANDBY_CAPACITY = 10;
@@ -45,16 +37,9 @@ public interface ConsoleProxyManager extends Manager {
     public ConsoleProxyManagementState getManagementState();
     public void resumeLastManagementState();
 	
-	public ConsoleProxyInfo assignProxy(long dataCenterId, long userVmId);
-	
 	public ConsoleProxyVO startProxy(long proxyVmId);
 	public boolean stopProxy(long proxyVmId);
 	public boolean rebootProxy(long proxyVmId);
 	public boolean destroyProxy(long proxyVmId);
-
-	public void onLoadReport(ConsoleProxyLoadReportCommand cmd);
-	public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticationCommand cmd);
 	
-    public void onAgentConnect(HostVO host, StartupCommand cmd);
-	public void onAgentDisconnect(long agentId, Status state);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53918521/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 6b68c73..1dead8f 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -165,7 +165,7 @@ import com.google.gson.GsonBuilder;
 // Starting, HA, Migrating, Running state are all counted as "Open" for available capacity calculation
 // because sooner or later, it will be driven into Running state
 //
-@Local(value = { ConsoleProxyManager.class })
+@Local(value = { ConsoleProxyManager.class, ConsoleProxyService.class })
 public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxyManager,
         AgentHook, VirtualMachineGuru<ConsoleProxyVO>, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
     private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/53918521/server/src/com/cloud/consoleproxy/ConsoleProxyService.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyService.java b/server/src/com/cloud/consoleproxy/ConsoleProxyService.java
new file mode 100644
index 0000000..e43e5c3
--- /dev/null
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyService.java
@@ -0,0 +1,9 @@
+package com.cloud.consoleproxy;
+
+import com.cloud.info.ConsoleProxyInfo;
+
+public interface ConsoleProxyService {
+
+    public abstract ConsoleProxyInfo assignProxy(long dataCenterId, long userVmId);
+
+}
\ No newline at end of file


[2/6] git commit: refs/heads/quickcloud - QuickCloud: start console proxy service from mvn exec:java

Posted by ch...@apache.org.
QuickCloud: start console proxy service from mvn exec:java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e8197534
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e8197534
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e8197534

Branch: refs/heads/quickcloud
Commit: e8197534ae978486836a25062496fcb8f5a1ee8f
Parents: f28d788
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Mon Mar 25 12:15:14 2013 -0700
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Mon Mar 25 12:17:50 2013 -0700

----------------------------------------------------------------------
 services/console-proxy/server/conf/log4j-cloud.xml |    2 +-
 services/console-proxy/server/pom.xml              |   38 +++++++++++++++
 2 files changed, 39 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e8197534/services/console-proxy/server/conf/log4j-cloud.xml
----------------------------------------------------------------------
diff --git a/services/console-proxy/server/conf/log4j-cloud.xml b/services/console-proxy/server/conf/log4j-cloud.xml
index 5b31c9d..2d1d361 100644
--- a/services/console-proxy/server/conf/log4j-cloud.xml
+++ b/services/console-proxy/server/conf/log4j-cloud.xml
@@ -27,7 +27,7 @@ under the License.
 
    <!-- A time/date based rolling appender -->
    <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
-      <param name="File" value="/var/log/cloud/systemvm.log"/>
+      <param name="File" value="${log.home}systemvm.log"/>
       <param name="Append" value="true"/>
       <param name="Threshold" value="DEBUG"/>
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e8197534/services/console-proxy/server/pom.xml
----------------------------------------------------------------------
diff --git a/services/console-proxy/server/pom.xml b/services/console-proxy/server/pom.xml
index 0df7559..a618d1b 100644
--- a/services/console-proxy/server/pom.xml
+++ b/services/console-proxy/server/pom.xml
@@ -242,6 +242,44 @@
       </plugins>
       </build>
     </profile>
+    <profile>
+      <id>quickcloud</id>
+      <activation>
+        <property>
+          <name>quickcloud</name>
+        </property>
+      </activation>
+      <build>
+      <plugins>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>exec-maven-plugin</artifactId>
+        <version>1.2.1</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>java</goal>
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <mainClass>com.cloud.agent.AgentShell</mainClass>
+          <arguments>
+            <argument>zone=1</argument>
+            <argument>pod=1</argument>
+            <argument>host=192.168.56.1</argument>
+          </arguments>
+          <systemProperties>
+            <systemProperty>
+              <key>javax.net.ssl.trustStore</key>
+              <value>certs/realhostip.keystore</value>
+            </systemProperty>
+          </systemProperties>
+        </configuration>
+      </plugin>
+      </plugins>
+    </build>
+  </profile>
   </profiles>
 
 </project>


[6/6] git commit: refs/heads/quickcloud - QuickCloud: also look for consoleproxy.properties using PropertiesUtil. When executed with mvn exec:java, the path 'conf' is not on the classpath

Posted by ch...@apache.org.
QuickCloud: also look for consoleproxy.properties using PropertiesUtil.
When executed with mvn exec:java, the path 'conf' is not on the classpath


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/841a8570
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/841a8570
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/841a8570

Branch: refs/heads/quickcloud
Commit: 841a8570e2c2cab54c871ab6150b3cba6ca1923b
Parents: e2fdd72
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Tue Mar 26 10:06:46 2013 -0700
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Tue Mar 26 10:06:46 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/consoleproxy/ConsoleProxy.java   |   16 +++++++++++++-
 1 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/841a8570/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
----------------------------------------------------------------------
diff --git a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
index b5c2989..2abce56 100644
--- a/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
+++ b/services/console-proxy/server/src/com/cloud/consoleproxy/ConsoleProxy.java
@@ -17,6 +17,8 @@
 package com.cloud.consoleproxy;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
@@ -34,6 +36,7 @@ import org.apache.commons.codec.binary.Base64;
 import org.apache.log4j.xml.DOMConfigurator;
 
 import com.cloud.consoleproxy.util.Logger;
+import com.cloud.utils.PropertiesUtil;
 import com.google.gson.Gson;
 import com.sun.net.httpserver.HttpServer;
 
@@ -282,8 +285,17 @@ public class ConsoleProxy {
         InputStream confs = ConsoleProxy.class.getResourceAsStream("/conf/consoleproxy.properties");
         Properties props = new Properties();
         if (confs == null) {
-            s_logger.info("Can't load consoleproxy.properties from classpath, will use default configuration");
-        } else {
+            final File file = PropertiesUtil.findConfigFile("consoleproxy.properties");
+            if (file == null)
+                s_logger.info("Can't load consoleproxy.properties from classpath, will use default configuration");
+            else
+                try {
+                    confs = new FileInputStream(file);
+                } catch (FileNotFoundException e) {
+                    s_logger.info("Ignoring file not found exception and using defaults");
+                }
+        } 
+        if (confs != null) {
             try {
                 props.load(confs);
                 


[3/6] git commit: refs/heads/quickcloud - QuickCloud: Remove reference to unused code

Posted by ch...@apache.org.
QuickCloud: Remove reference to unused code


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a32a150c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a32a150c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a32a150c

Branch: refs/heads/quickcloud
Commit: a32a150c6fc968b5c40efbbec10bc45e1f095c61
Parents: e819753
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Mon Mar 25 13:37:31 2013 -0700
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Mon Mar 25 13:37:31 2013 -0700

----------------------------------------------------------------------
 .../cloud/consoleproxy/ConsoleProxyService.java    |   23 ---------------
 api/src/org/apache/cloudstack/api/BaseCmd.java     |    3 --
 .../consoleproxy/ConsoleProxyManagerImpl.java      |   22 ++-----------
 3 files changed, 4 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a32a150c/api/src/com/cloud/consoleproxy/ConsoleProxyService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/consoleproxy/ConsoleProxyService.java b/api/src/com/cloud/consoleproxy/ConsoleProxyService.java
deleted file mode 100644
index c347e0b..0000000
--- a/api/src/com/cloud/consoleproxy/ConsoleProxyService.java
+++ /dev/null
@@ -1,23 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements.  See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership.  The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License.  You may obtain a copy of the License at
-//
-//   http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.  See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.consoleproxy;
-
-import com.cloud.api.commands.DestroyConsoleProxyCmd;
-
-public interface ConsoleProxyService {
-    boolean destroyConsoleProxy(DestroyConsoleProxyCmd cmd);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a32a150c/api/src/org/apache/cloudstack/api/BaseCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseCmd.java b/api/src/org/apache/cloudstack/api/BaseCmd.java
index 8b7f43f..c320b34 100644
--- a/api/src/org/apache/cloudstack/api/BaseCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseCmd.java
@@ -28,12 +28,10 @@ import java.util.regex.Pattern;
 import javax.inject.Inject;
 
 import org.apache.cloudstack.query.QueryService;
-import org.apache.cloudstack.region.RegionService;
 import org.apache.cloudstack.usage.UsageService;
 import org.apache.log4j.Logger;
 
 import com.cloud.configuration.ConfigurationService;
-import com.cloud.consoleproxy.ConsoleProxyService;
 import com.cloud.dao.EntityManager;
 import com.cloud.domain.Domain;
 import com.cloud.exception.ConcurrentOperationException;
@@ -109,7 +107,6 @@ public abstract class BaseCmd {
     @Inject public TemplateService _templateService;
     @Inject public SecurityGroupService _securityGroupService;
     @Inject public SnapshotService _snapshotService;
-    @Inject public ConsoleProxyService _consoleProxyService;
     @Inject public VpcVirtualNetworkApplianceService _routerService;
     @Inject public ResponseGenerator _responseGenerator;
     @Inject public EntityManager _entityMgr;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a32a150c/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
index 544a803..6b68c73 100755
--- a/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
+++ b/server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java
@@ -30,7 +30,6 @@ import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.apache.cloudstack.api.ServerApiException;
 import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
 import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
 import org.apache.log4j.Logger;
@@ -54,7 +53,6 @@ import com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand;
 import com.cloud.agent.api.to.NicTO;
 import com.cloud.agent.api.to.VirtualMachineTO;
 import com.cloud.agent.manager.Commands;
-import com.cloud.api.commands.DestroyConsoleProxyCmd;
 import com.cloud.certificate.dao.CertificateDao;
 import com.cloud.cluster.ClusterManager;
 import com.cloud.configuration.Config;
@@ -71,7 +69,6 @@ import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.AgentUnavailableException;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.OperationTimedoutException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.exception.StorageUnavailableException;
@@ -113,8 +110,8 @@ import com.cloud.servlet.ConsoleProxyServlet;
 import com.cloud.storage.StorageManager;
 import com.cloud.storage.StoragePoolStatus;
 import com.cloud.storage.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.dao.DiskOfferingDao;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VMTemplateHostDao;
@@ -127,7 +124,6 @@ import com.cloud.utils.DateUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
 import com.cloud.utils.Ternary;
-import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.GlobalLock;
@@ -169,8 +165,9 @@ import com.google.gson.GsonBuilder;
 // Starting, HA, Migrating, Running state are all counted as "Open" for available capacity calculation
 // because sooner or later, it will be driven into Running state
 //
-@Local(value = { ConsoleProxyManager.class, ConsoleProxyService.class })
-public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxyManager, ConsoleProxyService, AgentHook, VirtualMachineGuru<ConsoleProxyVO>, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
+@Local(value = { ConsoleProxyManager.class })
+public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxyManager,
+        AgentHook, VirtualMachineGuru<ConsoleProxyVO>, SystemVmLoadScanHandler<Long>, ResourceStateAdapter {
     private static final Logger s_logger = Logger.getLogger(ConsoleProxyManagerImpl.class);
 
     private static final int DEFAULT_CAPACITY_SCAN_INTERVAL = 30000; // 30 seconds
@@ -1547,18 +1544,7 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
         return true;
     }
 
-    @Override
-    public boolean destroyConsoleProxy(DestroyConsoleProxyCmd cmd) throws ServerApiException {
-        Long proxyId = cmd.getId();
 
-        // verify parameters
-        ConsoleProxyVO proxy = _consoleProxyDao.findById(proxyId);
-        if (proxy == null) {
-            throw new InvalidParameterValueException("unable to find a console proxy with id " + proxyId);
-        }
-
-        return destroyProxy(proxyId);
-    }
 
     protected ConsoleProxyManagerImpl() {
     }


[5/6] git commit: refs/heads/quickcloud - QuickCloud: copy authorization code from ConsoleProxyManagerImpl

Posted by ch...@apache.org.
QuickCloud: copy authorization code from ConsoleProxyManagerImpl


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e2fdd720
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e2fdd720
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e2fdd720

Branch: refs/heads/quickcloud
Commit: e2fdd720c0a75f0c7a9f1c6a491bebc41cb87ba9
Parents: 5391852
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Tue Mar 26 10:05:06 2013 -0700
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Tue Mar 26 10:05:06 2013 -0700

----------------------------------------------------------------------
 .../consoleproxy/StaticConsoleProxyManager.java    |  268 ++++++++++++++-
 1 files changed, 257 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e2fdd720/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
index 3ba98a9..04e6f24 100755
--- a/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
+++ b/server/src/com/cloud/consoleproxy/StaticConsoleProxyManager.java
@@ -16,29 +16,74 @@
 // under the License.
 package com.cloud.consoleproxy;
 
+
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
+import java.util.UUID;
 
 import javax.ejb.Local;
 import javax.inject.Inject;
 import javax.naming.ConfigurationException;
 
-import org.springframework.stereotype.Component;
+import org.apache.log4j.Logger;
 
+import com.cloud.agent.api.AgentControlAnswer;
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ConsoleAccessAuthenticationAnswer;
+import com.cloud.agent.api.ConsoleAccessAuthenticationCommand;
+import com.cloud.agent.api.GetVncPortAnswer;
+import com.cloud.agent.api.GetVncPortCommand;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.agent.api.StartupProxyCommand;
+import com.cloud.agent.api.proxy.StartConsoleProxyAgentHttpHandlerCommand;
+import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.OperationTimedoutException;
 import com.cloud.host.Host.Type;
 import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
 import com.cloud.info.ConsoleProxyInfo;
+import com.cloud.keystore.KeystoreDao;
+import com.cloud.keystore.KeystoreManager;
 import com.cloud.resource.ResourceManager;
+import com.cloud.resource.ResourceStateAdapter;
+import com.cloud.resource.ServerResource;
+import com.cloud.resource.UnableDeleteHostException;
+import com.cloud.servlet.ConsoleProxyServlet;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.Ternary;
 import com.cloud.vm.VMInstanceVO;
+import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.dao.ConsoleProxyDao;
+import com.cloud.vm.dao.VMInstanceDao;
 
 @Local(value={ConsoleProxyManager.class})
-public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager implements ConsoleProxyManager {
-    String _ip = null;
-    @Inject ConsoleProxyDao _proxyDao;
-    @Inject ResourceManager _resourceMgr;
-    @Inject ConfigurationDao _configDao;
+public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager implements ConsoleProxyManager,
+        ResourceStateAdapter {
+    private static final Logger s_logger = Logger.getLogger(StaticConsoleProxyManager.class);
+
+    @Inject
+    ConsoleProxyDao _proxyDao;
+    @Inject
+    ResourceManager _resourceMgr;
+    @Inject
+    ConfigurationDao _configDao;
+    @Inject
+    private VMInstanceDao _instanceDao;
+    @Inject
+    KeystoreDao _ksDao;
+    @Inject
+    private KeystoreManager _ksMgr;
+    @Inject
+    private HostDao _hostDao;
+    private final Random _random = new Random(System.currentTimeMillis());
+    private String _hashKey;
+    private String _ip = null;
+
+
 
     @Override
     protected HostVO findHost(VMInstanceVO vm) {
@@ -50,20 +95,221 @@ public class StaticConsoleProxyManager extends AgentBasedConsoleProxyManager imp
 
     @Override
     public ConsoleProxyInfo assignProxy(long dataCenterId, long userVmId) {
-        return new ConsoleProxyInfo(false, _ip, _consoleProxyPort, _consoleProxyUrlPort, _consoleProxyUrlDomain);
+        return new ConsoleProxyInfo(_sslEnabled, _ip, _consoleProxyPort, _consoleProxyUrlPort, _consoleProxyUrlDomain);
     }
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
         super.configure(name, params);
-
-        Map<String, String> dbParams = _configDao.getConfiguration("ManagementServer", params);
-
-        _ip = dbParams.get("public.ip");
+        _ip = _configDao.getValue("consoleproxy.static.publicIp");
         if (_ip == null) {
             _ip = "127.0.0.1";
         }
 
+
+        String value = (String) params.get("consoleproxy.sslEnabled");
+        if (value != null && value.equalsIgnoreCase("true")) {
+            _sslEnabled = true;
+        }
+        int defaultPort = 8088;
+        if (_sslEnabled)
+            defaultPort = 8443;
+        _consoleProxyUrlPort = NumbersUtil.parseInt(_configDao.getValue("consoleproxy.static.port"), defaultPort);
+
+        _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
+
         return true;
     }
+
+    @Override
+    public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
+        if (!(cmd[0] instanceof StartupProxyCommand)) {
+            return null;
+        }
+
+        host.setType(com.cloud.host.Host.Type.ConsoleProxy);
+        return host;
+    }
+
+    @Override
+    public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource,
+            Map<String, String> details, List<String> hostTags) {
+        return null;
+    }
+
+    @Override
+    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage)
+            throws UnableDeleteHostException {
+        return null;
+    }
+
+    @Override
+    public void startAgentHttpHandlerInVM(StartupProxyCommand startupCmd) {
+        StartConsoleProxyAgentHttpHandlerCommand cmd = null;
+        if (_configDao.isPremium()) {
+            String storePassword = String.valueOf(_random.nextLong());
+            byte[] ksBits =
+                    _ksMgr.getKeystoreBits(ConsoleProxyManager.CERTIFICATE_NAME, ConsoleProxyManager.CERTIFICATE_NAME,
+                            storePassword);
+
+            assert (ksBits != null);
+            if (ksBits == null) {
+                s_logger.error("Could not find and construct a valid SSL certificate");
+            }
+            cmd = new StartConsoleProxyAgentHttpHandlerCommand(ksBits, storePassword);
+            cmd.setEncryptorPassword(getHashKey());
+        } else {
+            cmd = new StartConsoleProxyAgentHttpHandlerCommand();
+            cmd.setEncryptorPassword(getHashKey());
+        }
+        HostVO consoleProxyHost = findConsoleProxyHost(startupCmd.getGuid());
+
+        Answer answer;
+        try {
+            answer = _agentMgr.send(consoleProxyHost.getId(), cmd);
+            if (answer == null || !answer.getResult()) {
+                s_logger.error("Console proxy agent reported that it failed to execute http handling startup command");
+            } else {
+                s_logger.info("Successfully sent out command to start HTTP handling in console proxy agent");
+            }
+        } catch (AgentUnavailableException e) {
+            s_logger.error("Failed to send http start up command to console proxy due to ", e);
+        } catch (OperationTimedoutException e) {
+            s_logger.error("Failed to send http start up command to console proxy due to ", e);
+        }
+
+
+    }
+
+    private HostVO findConsoleProxyHost(String guid) {
+        return _hostDao.findByGuid(guid);
+    }
+
+    public String getHashKey() {
+        // although we may have race conditioning here, database transaction
+        // serialization should
+        // give us the same key
+        if (_hashKey == null) {
+            _hashKey =
+                    _configDao.getValueAndInitIfNotExist(Config.HashKey.key(), Config.HashKey.getCategory(), UUID
+                            .randomUUID().toString());
+        }
+        return _hashKey;
+    }
+
+    public AgentControlAnswer onConsoleAccessAuthentication(ConsoleAccessAuthenticationCommand cmd) {
+        Long vmId = null;
+
+        String ticketInUrl = cmd.getTicket();
+        if (ticketInUrl == null) {
+            s_logger.error("Access ticket could not be found, you could be running an old version of console proxy. vmId: "
+                    + cmd.getVmId());
+            return new ConsoleAccessAuthenticationAnswer(cmd, false);
+        }
+
+        if (s_logger.isDebugEnabled()) {
+            s_logger.debug("Console authentication. Ticket in url for " + cmd.getHost() + ":" + cmd.getPort() + "-"
+                    + cmd.getVmId() + " is " + ticketInUrl);
+        }
+
+        if (!cmd.isReauthenticating()) {
+            String ticket =
+                    ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId());
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Console authentication. Ticket in 1 minute boundary for " + cmd.getHost() + ":"
+                        + cmd.getPort() + "-" + cmd.getVmId() + " is " + ticket);
+            }
+
+            if (!ticket.equals(ticketInUrl)) {
+                Date now = new Date();
+                // considering of minute round-up
+                String minuteEarlyTicket =
+                        ConsoleProxyServlet.genAccessTicket(cmd.getHost(), cmd.getPort(), cmd.getSid(), cmd.getVmId(),
+                                new Date(now.getTime() - 60 * 1000));
+
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug("Console authentication. Ticket in 2-minute boundary for " + cmd.getHost() + ":"
+                            + cmd.getPort() + "-" + cmd.getVmId() + " is " + minuteEarlyTicket);
+                }
+
+                if (!minuteEarlyTicket.equals(ticketInUrl)) {
+                    s_logger.error("Access ticket expired or has been modified. vmId: " + cmd.getVmId()
+                            + "ticket in URL: " + ticketInUrl + ", tickets to check against: " + ticket + ","
+                            + minuteEarlyTicket);
+                    return new ConsoleAccessAuthenticationAnswer(cmd, false);
+                }
+            }
+        }
+
+        if (cmd.getVmId() != null && cmd.getVmId().isEmpty()) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Invalid vm id sent from proxy(happens when proxy session has terminated)");
+            }
+            return new ConsoleAccessAuthenticationAnswer(cmd, false);
+        }
+
+        VirtualMachine vm = _instanceDao.findByUuid(cmd.getVmId());
+        if (vm == null) {
+            vm = _instanceDao.findById(Long.parseLong(cmd.getVmId()));
+        }
+        if (vm == null) {
+            s_logger.error("Invalid vm id " + cmd.getVmId() + " sent from console access authentication");
+            return new ConsoleAccessAuthenticationAnswer(cmd, false);
+        }
+
+        if (vm.getHostId() == null) {
+            s_logger.warn("VM " + vmId + " lost host info, failed authentication request");
+            return new ConsoleAccessAuthenticationAnswer(cmd, false);
+        }
+
+        HostVO host = _hostDao.findById(vm.getHostId());
+        if (host == null) {
+            s_logger.warn("VM " + vmId + "'s host does not exist, fail authentication request");
+            return new ConsoleAccessAuthenticationAnswer(cmd, false);
+        }
+
+        String sid = cmd.getSid();
+        if (sid == null || !sid.equals(vm.getVncPassword())) {
+            s_logger.warn("sid " + sid + " in url does not match stored sid " + vm.getVncPassword());
+            return new ConsoleAccessAuthenticationAnswer(cmd, false);
+        }
+
+        if (cmd.isReauthenticating()) {
+            ConsoleAccessAuthenticationAnswer authenticationAnswer = new ConsoleAccessAuthenticationAnswer(cmd, true);
+            authenticationAnswer.setReauthenticating(true);
+
+            s_logger.info("Re-authentication request, ask host " + vm.getHostId() + " for new console info");
+            GetVncPortAnswer answer =
+                    (GetVncPortAnswer) _agentMgr.easySend(vm.getHostId(),
+                            new GetVncPortCommand(vm.getId(), vm.getInstanceName()));
+
+            if (answer != null && answer.getResult()) {
+                Ternary<String, String, String> parsedHostInfo = ConsoleProxyServlet.parseHostInfo(answer.getAddress());
+
+                if (parsedHostInfo.second() != null && parsedHostInfo.third() != null) {
+
+                    s_logger.info("Re-authentication result. vm: " + vm.getId() + ", tunnel url: "
+                            + parsedHostInfo.second() + ", tunnel session: " + parsedHostInfo.third());
+
+                    authenticationAnswer.setTunnelUrl(parsedHostInfo.second());
+                    authenticationAnswer.setTunnelSession(parsedHostInfo.third());
+                } else {
+                    s_logger.info("Re-authentication result. vm: " + vm.getId() + ", host address: "
+                            + parsedHostInfo.first() + ", port: " + answer.getPort());
+
+                    authenticationAnswer.setHost(parsedHostInfo.first());
+                    authenticationAnswer.setPort(answer.getPort());
+                }
+            } else {
+                s_logger.warn("Re-authentication request failed");
+
+                authenticationAnswer.setSuccess(false);
+            }
+
+            return authenticationAnswer;
+        }
+
+        return new ConsoleAccessAuthenticationAnswer(cmd, true);
+    }
+
 }