cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kous...@apache.org
Subject git commit: updated refs/heads/master to 4f5df54
Date Tue, 01 Jul 2014 09:56:33 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master f45c9f9d2 -> 4f5df54d5


Some fixes in the simulator
1. Fixed JSON response deserialization. While creating a mock a JSON can be passed which will
be deserialized into a response object and returned from agent layer.
For e.g. for a mock corresponding to StopCommand, a response like "{"com.cloud.agent.api.StopAnswer":{"result":false,"wait":0}}"
can be passed.
2. Ability to mock PingCommand (returned as part of getCurrentStatus() agent method). As a
part of this a mocked VM state report can be returned.
For e.g. {"com.cloud.agent.api.PingRoutingWithNwGroupsCommand":{"newGroupStates":{},"newStates":{},"_hostVmStateReport":{"v-2-VM":{"state":"PowerOn","host":"SimulatedAgent.e6df7732-69b2-429b-9b6a-3e24dddfa2e0"},"i-2-5-VM":{"state":"PowerOff","host":"SimulatedAgent.e6df7732-69b2-429b-9b6a-3e24dddfa2e0"}},"_gatewayAccessible":true,"_vnetAccessible":true,"hostType":"Routing","hostId":3,"contextMap":{},"wait":0}}


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

Branch: refs/heads/master
Commit: 4f5df54d5c809fbdcb5cbf57226a17bbd4957a67
Parents: f45c9f9
Author: Koushik Das <koushik@apache.org>
Authored: Tue Jul 1 14:54:28 2014 +0530
Committer: Koushik Das <koushik@apache.org>
Committed: Tue Jul 1 15:26:12 2014 +0530

----------------------------------------------------------------------
 .../agent/manager/SimulatorManagerImpl.java     | 18 ++++++---
 .../cloud/resource/AgentRoutingResource.java    | 40 +++++++++++++++++++-
 2 files changed, 51 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4f5df54d/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
index 6c12ecb..6fb5372 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/SimulatorManagerImpl.java
@@ -16,6 +16,7 @@
 // under the License.
 package com.cloud.agent.manager;
 
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -113,6 +114,7 @@ import com.cloud.api.commands.ConfigureSimulatorCmd;
 import com.cloud.api.commands.QuerySimulatorMockCmd;
 import com.cloud.agent.api.SecStorageFirewallCfgCommand;
 import com.cloud.resource.SimulatorStorageProcessor;
+import com.cloud.serializer.GsonHelper;
 import com.cloud.simulator.MockConfigurationVO;
 import com.cloud.simulator.MockHost;
 import com.cloud.simulator.MockVMVO;
@@ -128,11 +130,13 @@ import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.vm.VirtualMachine.State;
 import com.google.gson.Gson;
+import com.google.gson.stream.JsonReader;
 
 @Component
 @Local(value = {SimulatorManager.class})
 public class SimulatorManagerImpl extends ManagerBase implements SimulatorManager, PluggableService
{
     private static final Logger s_logger = Logger.getLogger(SimulatorManagerImpl.class);
+    private static final Gson s_gson = GsonHelper.getGson();
     @Inject
     MockVmManager _mockVmMgr;
     @Inject
@@ -252,16 +256,20 @@ public class SimulatorManagerImpl extends ManagerBase implements SimulatorManage
                 if (answer == null) {
                     String message = config.getJsonResponse();
                     if (message != null) {
-                        // json response looks like {"<AnswerType>":....}
-                        String answerType = message.split(":")[0].substring(1).replace("\"",
"");
-                        if (answerType != null) {
+                        // json response looks like {"<Type>":....}
+                        String objectType = message.split(":")[0].substring(2).replace("\"",
"");
+                        String objectData = message.substring(message.indexOf(':') + 1, message.length()
- 1);
+                        if (objectType != null) {
                             Class<?> clz = null;
                             try {
-                                clz = Class.forName(answerType);
+                                clz = Class.forName(objectType);
                             } catch (ClassNotFoundException e) {
                             }
                             if (clz != null) {
-                                answer = (Answer)new Gson().fromJson(message, clz);
+                                StringReader reader = new StringReader(objectData);
+                                JsonReader jsonReader = new JsonReader(reader);
+                                jsonReader.setLenient(true);
+                                answer = (Answer)s_gson.fromJson(jsonReader, clz);
                             }
                         }
                     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4f5df54d/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
index 4b5c9fd..2d75c6d 100644
--- a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
+++ b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java
@@ -16,6 +16,7 @@
 // under the License.
 package com.cloud.resource;
 
+import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -50,6 +51,7 @@ import com.cloud.host.Host;
 import com.cloud.host.Host.Type;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.network.Networks.RouterPrivateIpStrategy;
+import com.cloud.serializer.GsonHelper;
 import com.cloud.simulator.MockConfigurationVO;
 import com.cloud.simulator.MockVMVO;
 import com.cloud.storage.Storage.StorageResourceType;
@@ -58,9 +60,12 @@ import com.cloud.utils.Pair;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.vm.VirtualMachine.PowerState;
 import com.cloud.vm.VirtualMachine.State;
+import com.google.gson.Gson;
+import com.google.gson.stream.JsonReader;
 
 public class AgentRoutingResource extends AgentStorageResource {
     private static final Logger s_logger = Logger.getLogger(AgentRoutingResource.class);
+    private static final Gson s_gson = GsonHelper.getGson();
 
     protected Map<String, State> _vms = new HashMap<String, State>();
     private Map<String, Pair<Long, Long>> _runningVms = new HashMap<String,
Pair<Long, Long>>();
@@ -120,6 +125,29 @@ public class AgentRoutingResource extends AgentStorageResource {
                     }
                 }
             }
+
+            config = _simMgr.getMockConfigurationDao().findByNameBottomUP(agentHost.getDataCenterId(),
agentHost.getPodId(), agentHost.getClusterId(), agentHost.getId(), "PingRoutingWithNwGroupsCommand");
+            if (config != null) {
+                String message = config.getJsonResponse();
+                if (message != null) {
+                    // json response looks like {"<Type>":....}
+                    String objectType = message.split(":")[0].substring(2).replace("\"",
"");
+                    String objectData = message.substring(message.indexOf(':') + 1, message.length()
- 1);
+                    if (objectType != null) {
+                        Class<?> clz = null;
+                        try {
+                            clz = Class.forName(objectType);
+                        } catch (ClassNotFoundException e) {
+                        }
+                        if (clz != null) {
+                            StringReader reader = new StringReader(objectData);
+                            JsonReader jsonReader = new JsonReader(reader);
+                            jsonReader.setLenient(true);
+                            return (PingCommand)s_gson.fromJson(jsonReader, clz);
+                        }
+                    }
+                }
+            }
         } catch (Exception e) {
             txn.rollback();
         } finally {
@@ -303,8 +331,16 @@ public class AgentRoutingResource extends AgentStorageResource {
     protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport() {
         HashMap<String, HostVmStateReportEntry> report = new HashMap<String, HostVmStateReportEntry>();
 
-        for (String vmName : _runningVms.keySet()) {
-            report.put(vmName, new HostVmStateReportEntry(PowerState.PowerOn, agentHost.getName()));
+        Map<String, State> states = _simMgr.getVmStates(this.hostGuid);
+        for (String vmName : states.keySet()) {
+            State state = states.get(vmName);
+            if (state == State.Running) {
+                report.put(vmName, new HostVmStateReportEntry(PowerState.PowerOn, agentHost.getName()));
+            } else if (state == State.Stopped) {
+                report.put(vmName, new HostVmStateReportEntry(PowerState.PowerOff, agentHost.getName()));
+            } else {
+                report.put(vmName, new HostVmStateReportEntry(PowerState.PowerUnknown, agentHost.getName()));
+            }
         }
 
         return report;


Mime
View raw message