cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [12/39] git commit: updated refs/heads/master to 3e28747
Date Thu, 02 Apr 2015 18:22:53 GMT
Renaming files
  - Forgot to add "Citrix" before the new command wrappers


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

Branch: refs/heads/master
Commit: 9e41b8051e4a0f41e8867b2b311cf7762cf66ad8
Parents: 6b80c79
Author: wilderrodrigues <wrodrigues@schubergphilis.com>
Authored: Tue Mar 24 11:20:53 2015 +0100
Committer: wilderrodrigues <wrodrigues@schubergphilis.com>
Committed: Tue Mar 31 10:38:26 2015 +0200

----------------------------------------------------------------------
 .../wrapper/CheckHealthCommandWrapper.java      |  35 ----
 .../CitrixCheckHealthCommandWrapper.java        |  35 ++++
 .../CitrixGetHostStatsCommandWrapper.java       |  48 +++++
 .../CitrixGetVmDiskStatsCommandWrapper.java     |  34 ++++
 .../wrapper/CitrixGetVmStatsCommandWrapper.java |  82 +++++++++
 .../resource/wrapper/CitrixRequestWrapper.java  |  10 +-
 .../wrapper/CitrixStopCommandWrapper.java       | 173 +++++++++++++++++++
 .../wrapper/GetHostStatsCommandWrapper.java     |  48 -----
 .../wrapper/GetVmDiskStatsCommandWrapper.java   |  34 ----
 .../wrapper/GetVmStatsCommandWrapper.java       |  82 ---------
 .../resource/wrapper/StopCommandWrapper.java    | 173 -------------------
 11 files changed, 377 insertions(+), 377 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CheckHealthCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CheckHealthCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CheckHealthCommandWrapper.java
deleted file mode 100644
index fa2e0ca..0000000
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CheckHealthCommandWrapper.java
+++ /dev/null
@@ -1,35 +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.hypervisor.xenserver.resource.wrapper;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.CheckHealthAnswer;
-import com.cloud.agent.api.CheckHealthCommand;
-import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
-import com.cloud.resource.CommandWrapper;
-
-public final class CheckHealthCommandWrapper extends CommandWrapper<CheckHealthCommand,
Answer, CitrixResourceBase> {
-
-    @Override
-    public Answer execute(final CheckHealthCommand command, final CitrixResourceBase citrixResourceBase)
{
-        final boolean result = citrixResourceBase.pingXAPI();
-        return new CheckHealthAnswer(command, result);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckHealthCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckHealthCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckHealthCommandWrapper.java
new file mode 100644
index 0000000..f77e309
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckHealthCommandWrapper.java
@@ -0,0 +1,35 @@
+//
+// 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.hypervisor.xenserver.resource.wrapper;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CheckHealthAnswer;
+import com.cloud.agent.api.CheckHealthCommand;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+
+public final class CitrixCheckHealthCommandWrapper extends CommandWrapper<CheckHealthCommand,
Answer, CitrixResourceBase> {
+
+    @Override
+    public Answer execute(final CheckHealthCommand command, final CitrixResourceBase citrixResourceBase)
{
+        final boolean result = citrixResourceBase.pingXAPI();
+        return new CheckHealthAnswer(command, result);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetHostStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetHostStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetHostStatsCommandWrapper.java
new file mode 100644
index 0000000..21d9d3d
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetHostStatsCommandWrapper.java
@@ -0,0 +1,48 @@
+//
+// 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.hypervisor.xenserver.resource.wrapper;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.GetHostStatsAnswer;
+import com.cloud.agent.api.GetHostStatsCommand;
+import com.cloud.agent.api.HostStatsEntry;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.xensource.xenapi.Connection;
+
+public final class CitrixGetHostStatsCommandWrapper extends CommandWrapper<GetHostStatsCommand,
Answer, CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(CitrixGetHostStatsCommandWrapper.class);
+
+    @Override
+    public Answer execute(final GetHostStatsCommand command, final CitrixResourceBase citrixResourceBase)
{
+        final Connection conn = citrixResourceBase.getConnection();
+        try {
+            final HostStatsEntry hostStats = citrixResourceBase.getHostStats(conn, command,
command.getHostGuid(), command.getHostId());
+            return new GetHostStatsAnswer(command, hostStats);
+        } catch (final Exception e) {
+            final String msg = "Unable to get Host stats" + e.toString();
+            s_logger.warn(msg, e);
+            return new GetHostStatsAnswer(command, null);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmDiskStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmDiskStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmDiskStatsCommandWrapper.java
new file mode 100644
index 0000000..682d202
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmDiskStatsCommandWrapper.java
@@ -0,0 +1,34 @@
+//
+// 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.hypervisor.xenserver.resource.wrapper;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.GetVmDiskStatsAnswer;
+import com.cloud.agent.api.GetVmDiskStatsCommand;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+
+public final class CitrixGetVmDiskStatsCommandWrapper extends CommandWrapper<GetVmDiskStatsCommand,
Answer, CitrixResourceBase> {
+
+    @Override
+    public Answer execute(final GetVmDiskStatsCommand command, final CitrixResourceBase citrixResourceBase)
{
+        return new GetVmDiskStatsAnswer(command, null, null, null);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmStatsCommandWrapper.java
new file mode 100644
index 0000000..2b535ea
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixGetVmStatsCommandWrapper.java
@@ -0,0 +1,82 @@
+//
+// 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.hypervisor.xenserver.resource.wrapper;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.GetVmStatsAnswer;
+import com.cloud.agent.api.GetVmStatsCommand;
+import com.cloud.agent.api.VmStatsEntry;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VM;
+
+public final class CitrixGetVmStatsCommandWrapper extends CommandWrapper<GetVmStatsCommand,
Answer, CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(CitrixGetVmStatsCommandWrapper.class);
+
+    @Override
+    public Answer execute(final GetVmStatsCommand command, final CitrixResourceBase citrixResourceBase)
{
+        final Connection conn = citrixResourceBase.getConnection();
+        final List<String> vmNames = command.getVmNames();
+        final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String,
VmStatsEntry>();
+        if (vmNames.size() == 0) {
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        }
+        try {
+
+            // Determine the UUIDs of the requested VMs
+            final List<String> vmUUIDs = new ArrayList<String>();
+
+            for (final String vmName : vmNames) {
+                final VM vm = citrixResourceBase.getVM(conn, vmName);
+                vmUUIDs.add(vm.getUuid(conn));
+            }
+
+            final HashMap<String, VmStatsEntry> vmStatsUUIDMap = citrixResourceBase.getVmStats(conn,
command, vmUUIDs, command.getHostGuid());
+            if (vmStatsUUIDMap == null) {
+                return new GetVmStatsAnswer(command, vmStatsNameMap);
+            }
+
+            for (final Map.Entry<String,VmStatsEntry>entry : vmStatsUUIDMap.entrySet())
{
+                vmStatsNameMap.put(vmNames.get(vmUUIDs.indexOf(entry.getKey())), entry.getValue());
+            }
+
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        } catch (final XenAPIException e) {
+            final String msg = "Unable to get VM stats" + e.toString();
+            s_logger.warn(msg, e);
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        } catch (final XmlRpcException e) {
+            final String msg = "Unable to get VM stats" + e.getMessage();
+            s_logger.warn(msg, e);
+            return new GetVmStatsAnswer(command, vmStatsNameMap);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
index 5eb3882..5e3e6e4 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapper.java
@@ -60,11 +60,11 @@ public class CitrixRequestWrapper extends RequestWrapper {
         map.put(CheckConsoleProxyLoadCommand.class, new CitrixCheckConsoleProxyLoadCommandWrapper());
         map.put(WatchConsoleProxyLoadCommand.class, new CitrixWatchConsoleProxyLoadCommandWrapper());
         map.put(ReadyCommand.class, new CitrixReadyCommandWrapper());
-        map.put(GetHostStatsCommand.class, new GetHostStatsCommandWrapper());
-        map.put(GetVmStatsCommand.class, new GetVmStatsCommandWrapper());
-        map.put(GetVmDiskStatsCommand.class, new GetVmDiskStatsCommandWrapper());
-        map.put(CheckHealthCommand.class, new CheckHealthCommandWrapper());
-        map.put(StopCommand.class, new StopCommandWrapper());
+        map.put(GetHostStatsCommand.class, new CitrixGetHostStatsCommandWrapper());
+        map.put(GetVmStatsCommand.class, new CitrixGetVmStatsCommandWrapper());
+        map.put(GetVmDiskStatsCommand.class, new CitrixGetVmDiskStatsCommandWrapper());
+        map.put(CheckHealthCommand.class, new CitrixCheckHealthCommandWrapper());
+        map.put(StopCommand.class, new CitrixStopCommandWrapper());
     }
 
     public static CitrixRequestWrapper getInstance() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStopCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStopCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStopCommandWrapper.java
new file mode 100644
index 0000000..ce8517f
--- /dev/null
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStopCommandWrapper.java
@@ -0,0 +1,173 @@
+//
+// 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.hypervisor.xenserver.resource.wrapper;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.StopAnswer;
+import com.cloud.agent.api.StopCommand;
+import com.cloud.agent.api.VgpuTypesInfo;
+import com.cloud.agent.api.to.GPUDeviceTO;
+import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.utils.StringUtils;
+import com.xensource.xenapi.Connection;
+import com.xensource.xenapi.Network;
+import com.xensource.xenapi.SR;
+import com.xensource.xenapi.Types.VmPowerState;
+import com.xensource.xenapi.Types.XenAPIException;
+import com.xensource.xenapi.VGPU;
+import com.xensource.xenapi.VIF;
+import com.xensource.xenapi.VM;
+
+public final class CitrixStopCommandWrapper extends CommandWrapper<StopCommand, Answer,
CitrixResourceBase> {
+
+    private static final Logger s_logger = Logger.getLogger(CitrixStopCommandWrapper.class);
+
+    @Override
+    public Answer execute(final StopCommand command, final CitrixResourceBase citrixResourceBase)
{
+        final String vmName = command.getVmName();
+        String platformstring = null;
+        try {
+            final Connection conn = citrixResourceBase.getConnection();
+            final Set<VM> vms = VM.getByNameLabel(conn, vmName);
+            // stop vm which is running on this host or is in halted state
+            final Iterator<VM> iter = vms.iterator();
+            while (iter.hasNext()) {
+                final VM vm = iter.next();
+                final VM.Record vmr = vm.getRecord(conn);
+                if (vmr.powerState != VmPowerState.RUNNING) {
+                    continue;
+                }
+                if (citrixResourceBase.isRefNull(vmr.residentOn)) {
+                    continue;
+                }
+                if (vmr.residentOn.getUuid(conn).equals(citrixResourceBase.getHost().getUuid()))
{
+                    continue;
+                }
+                iter.remove();
+            }
+
+            if (vms.size() == 0) {
+                return new StopAnswer(command, "VM does not exist", true);
+            }
+            for (final VM vm : vms) {
+                final VM.Record vmr = vm.getRecord(conn);
+                platformstring = StringUtils.mapToString(vmr.platform);
+                if (vmr.isControlDomain) {
+                    final String msg = "Tring to Shutdown control domain";
+                    s_logger.warn(msg);
+                    return new StopAnswer(command, msg, false);
+                }
+
+                if (vmr.powerState == VmPowerState.RUNNING && !citrixResourceBase.isRefNull(vmr.residentOn)
&& !vmr.residentOn.getUuid(conn).equals(citrixResourceBase.getHost().getUuid())) {
+                    final String msg = "Stop Vm " + vmName + " failed due to this vm is not
running on this host: " + citrixResourceBase.getHost().getUuid() + " but host:" + vmr.residentOn.getUuid(conn);
+                    s_logger.warn(msg);
+                    return new StopAnswer(command, msg, platformstring, false);
+                }
+
+                if (command.checkBeforeCleanup() && vmr.powerState == VmPowerState.RUNNING)
{
+                    final String msg = "Vm " + vmName + " is running on host and checkBeforeCleanup
flag is set, so bailing out";
+                    s_logger.debug(msg);
+                    return new StopAnswer(command, msg, false);
+                }
+
+                s_logger.debug("9. The VM " + vmName + " is in Stopping state");
+
+                try {
+                    if (vmr.powerState == VmPowerState.RUNNING) {
+                        /* when stop a vm, set affinity to current xenserver */
+                        vm.setAffinity(conn, vm.getResidentOn(conn));
+
+                        if (citrixResourceBase.canBridgeFirewall()) {
+                            final String result = citrixResourceBase.callHostPlugin(conn,
"vmops", "destroy_network_rules_for_vm", "vmName", command.getVmName());
+                            if (result == null || result.isEmpty() || !Boolean.parseBoolean(result))
{
+                                s_logger.warn("Failed to remove  network rules for vm " +
command.getVmName());
+                            } else {
+                                s_logger.info("Removed  network rules for vm " + command.getVmName());
+                            }
+                        }
+                        citrixResourceBase.shutdownVM(conn, vm, vmName);
+                    }
+                } catch (final Exception e) {
+                    final String msg = "Catch exception " + e.getClass().getName() + " when
stop VM:" + command.getVmName() + " due to " + e.toString();
+                    s_logger.debug(msg);
+                    return new StopAnswer(command, msg, platformstring, false);
+                } finally {
+
+                    try {
+                        if (vm.getPowerState(conn) == VmPowerState.HALTED) {
+                            Set<VGPU> vGPUs = null;
+                            // Get updated GPU details
+                            try {
+                                vGPUs = vm.getVGPUs(conn);
+                            } catch (final XenAPIException e2) {
+                                s_logger.debug("VM " + vmName + " does not have GPU support.");
+                            }
+                            if (vGPUs != null && !vGPUs.isEmpty()) {
+                                final HashMap<String, HashMap<String, VgpuTypesInfo>>
groupDetails = citrixResourceBase.getGPUGroupDetails(conn);
+                                command.setGpuDevice(new GPUDeviceTO(null, null, groupDetails));
+                            }
+
+                            final Set<VIF> vifs = vm.getVIFs(conn);
+                            final List<Network> networks = new ArrayList<Network>();
+                            for (final VIF vif : vifs) {
+                                networks.add(vif.getNetwork(conn));
+                            }
+                            vm.destroy(conn);
+                            final SR sr = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName());
+                            citrixResourceBase.removeSR(conn, sr);
+                            // Disable any VLAN networks that aren't used
+                            // anymore
+                            for (final Network network : networks) {
+                                try {
+                                    if (network.getNameLabel(conn).startsWith("VLAN")) {
+                                        citrixResourceBase.disableVlanNetwork(conn, network);
+                                    }
+                                } catch (final Exception e) {
+                                    // network might be destroyed by other host
+                                }
+                            }
+                            return new StopAnswer(command, "Stop VM " + vmName + " Succeed",
platformstring, true);
+                        }
+                    } catch (final Exception e) {
+                        final String msg = "VM destroy failed in Stop " + vmName + " Command
due to " + e.getMessage();
+                        s_logger.warn(msg, e);
+                    } finally {
+                        s_logger.debug("10. The VM " + vmName + " is in Stopped state");
+                    }
+                }
+            }
+
+        } catch (final Exception e) {
+            final String msg = "Stop Vm " + vmName + " fail due to " + e.toString();
+            s_logger.warn(msg, e);
+            return new StopAnswer(command, msg, platformstring, false);
+        }
+        return new StopAnswer(command, "Stop VM failed", platformstring, false);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetHostStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetHostStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetHostStatsCommandWrapper.java
deleted file mode 100644
index d605367..0000000
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetHostStatsCommandWrapper.java
+++ /dev/null
@@ -1,48 +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.hypervisor.xenserver.resource.wrapper;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.GetHostStatsAnswer;
-import com.cloud.agent.api.GetHostStatsCommand;
-import com.cloud.agent.api.HostStatsEntry;
-import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
-import com.cloud.resource.CommandWrapper;
-import com.xensource.xenapi.Connection;
-
-public final class GetHostStatsCommandWrapper extends CommandWrapper<GetHostStatsCommand,
Answer, CitrixResourceBase> {
-
-    private static final Logger s_logger = Logger.getLogger(GetHostStatsCommandWrapper.class);
-
-    @Override
-    public Answer execute(final GetHostStatsCommand command, final CitrixResourceBase citrixResourceBase)
{
-        final Connection conn = citrixResourceBase.getConnection();
-        try {
-            final HostStatsEntry hostStats = citrixResourceBase.getHostStats(conn, command,
command.getHostGuid(), command.getHostId());
-            return new GetHostStatsAnswer(command, hostStats);
-        } catch (final Exception e) {
-            final String msg = "Unable to get Host stats" + e.toString();
-            s_logger.warn(msg, e);
-            return new GetHostStatsAnswer(command, null);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmDiskStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmDiskStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmDiskStatsCommandWrapper.java
deleted file mode 100644
index a403322..0000000
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmDiskStatsCommandWrapper.java
+++ /dev/null
@@ -1,34 +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.hypervisor.xenserver.resource.wrapper;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.GetVmDiskStatsAnswer;
-import com.cloud.agent.api.GetVmDiskStatsCommand;
-import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
-import com.cloud.resource.CommandWrapper;
-
-public final class GetVmDiskStatsCommandWrapper extends CommandWrapper<GetVmDiskStatsCommand,
Answer, CitrixResourceBase> {
-
-    @Override
-    public Answer execute(final GetVmDiskStatsCommand command, final CitrixResourceBase citrixResourceBase)
{
-        return new GetVmDiskStatsAnswer(command, null, null, null);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.java
deleted file mode 100644
index 1b4863a..0000000
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/GetVmStatsCommandWrapper.java
+++ /dev/null
@@ -1,82 +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.hypervisor.xenserver.resource.wrapper;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-import org.apache.xmlrpc.XmlRpcException;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.GetVmStatsAnswer;
-import com.cloud.agent.api.GetVmStatsCommand;
-import com.cloud.agent.api.VmStatsEntry;
-import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
-import com.cloud.resource.CommandWrapper;
-import com.xensource.xenapi.Connection;
-import com.xensource.xenapi.Types.XenAPIException;
-import com.xensource.xenapi.VM;
-
-public final class GetVmStatsCommandWrapper extends CommandWrapper<GetVmStatsCommand,
Answer, CitrixResourceBase> {
-
-    private static final Logger s_logger = Logger.getLogger(GetVmStatsCommandWrapper.class);
-
-    @Override
-    public Answer execute(final GetVmStatsCommand command, final CitrixResourceBase citrixResourceBase)
{
-        final Connection conn = citrixResourceBase.getConnection();
-        final List<String> vmNames = command.getVmNames();
-        final HashMap<String, VmStatsEntry> vmStatsNameMap = new HashMap<String,
VmStatsEntry>();
-        if (vmNames.size() == 0) {
-            return new GetVmStatsAnswer(command, vmStatsNameMap);
-        }
-        try {
-
-            // Determine the UUIDs of the requested VMs
-            final List<String> vmUUIDs = new ArrayList<String>();
-
-            for (final String vmName : vmNames) {
-                final VM vm = citrixResourceBase.getVM(conn, vmName);
-                vmUUIDs.add(vm.getUuid(conn));
-            }
-
-            final HashMap<String, VmStatsEntry> vmStatsUUIDMap = citrixResourceBase.getVmStats(conn,
command, vmUUIDs, command.getHostGuid());
-            if (vmStatsUUIDMap == null) {
-                return new GetVmStatsAnswer(command, vmStatsNameMap);
-            }
-
-            for (final Map.Entry<String,VmStatsEntry>entry : vmStatsUUIDMap.entrySet())
{
-                vmStatsNameMap.put(vmNames.get(vmUUIDs.indexOf(entry.getKey())), entry.getValue());
-            }
-
-            return new GetVmStatsAnswer(command, vmStatsNameMap);
-        } catch (final XenAPIException e) {
-            final String msg = "Unable to get VM stats" + e.toString();
-            s_logger.warn(msg, e);
-            return new GetVmStatsAnswer(command, vmStatsNameMap);
-        } catch (final XmlRpcException e) {
-            final String msg = "Unable to get VM stats" + e.getMessage();
-            s_logger.warn(msg, e);
-            return new GetVmStatsAnswer(command, vmStatsNameMap);
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/9e41b805/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/StopCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/StopCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/StopCommandWrapper.java
deleted file mode 100644
index bca90b5..0000000
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/StopCommandWrapper.java
+++ /dev/null
@@ -1,173 +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.hypervisor.xenserver.resource.wrapper;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.StopAnswer;
-import com.cloud.agent.api.StopCommand;
-import com.cloud.agent.api.VgpuTypesInfo;
-import com.cloud.agent.api.to.GPUDeviceTO;
-import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
-import com.cloud.resource.CommandWrapper;
-import com.cloud.utils.StringUtils;
-import com.xensource.xenapi.Connection;
-import com.xensource.xenapi.Network;
-import com.xensource.xenapi.SR;
-import com.xensource.xenapi.Types.VmPowerState;
-import com.xensource.xenapi.Types.XenAPIException;
-import com.xensource.xenapi.VGPU;
-import com.xensource.xenapi.VIF;
-import com.xensource.xenapi.VM;
-
-public final class StopCommandWrapper extends CommandWrapper<StopCommand, Answer, CitrixResourceBase>
{
-
-    private static final Logger s_logger = Logger.getLogger(StopCommandWrapper.class);
-
-    @Override
-    public Answer execute(final StopCommand command, final CitrixResourceBase citrixResourceBase)
{
-        final String vmName = command.getVmName();
-        String platformstring = null;
-        try {
-            final Connection conn = citrixResourceBase.getConnection();
-            final Set<VM> vms = VM.getByNameLabel(conn, vmName);
-            // stop vm which is running on this host or is in halted state
-            final Iterator<VM> iter = vms.iterator();
-            while (iter.hasNext()) {
-                final VM vm = iter.next();
-                final VM.Record vmr = vm.getRecord(conn);
-                if (vmr.powerState != VmPowerState.RUNNING) {
-                    continue;
-                }
-                if (citrixResourceBase.isRefNull(vmr.residentOn)) {
-                    continue;
-                }
-                if (vmr.residentOn.getUuid(conn).equals(citrixResourceBase.getHost().getUuid()))
{
-                    continue;
-                }
-                iter.remove();
-            }
-
-            if (vms.size() == 0) {
-                return new StopAnswer(command, "VM does not exist", true);
-            }
-            for (final VM vm : vms) {
-                final VM.Record vmr = vm.getRecord(conn);
-                platformstring = StringUtils.mapToString(vmr.platform);
-                if (vmr.isControlDomain) {
-                    final String msg = "Tring to Shutdown control domain";
-                    s_logger.warn(msg);
-                    return new StopAnswer(command, msg, false);
-                }
-
-                if (vmr.powerState == VmPowerState.RUNNING && !citrixResourceBase.isRefNull(vmr.residentOn)
&& !vmr.residentOn.getUuid(conn).equals(citrixResourceBase.getHost().getUuid())) {
-                    final String msg = "Stop Vm " + vmName + " failed due to this vm is not
running on this host: " + citrixResourceBase.getHost().getUuid() + " but host:" + vmr.residentOn.getUuid(conn);
-                    s_logger.warn(msg);
-                    return new StopAnswer(command, msg, platformstring, false);
-                }
-
-                if (command.checkBeforeCleanup() && vmr.powerState == VmPowerState.RUNNING)
{
-                    final String msg = "Vm " + vmName + " is running on host and checkBeforeCleanup
flag is set, so bailing out";
-                    s_logger.debug(msg);
-                    return new StopAnswer(command, msg, false);
-                }
-
-                s_logger.debug("9. The VM " + vmName + " is in Stopping state");
-
-                try {
-                    if (vmr.powerState == VmPowerState.RUNNING) {
-                        /* when stop a vm, set affinity to current xenserver */
-                        vm.setAffinity(conn, vm.getResidentOn(conn));
-
-                        if (citrixResourceBase.canBridgeFirewall()) {
-                            final String result = citrixResourceBase.callHostPlugin(conn,
"vmops", "destroy_network_rules_for_vm", "vmName", command.getVmName());
-                            if (result == null || result.isEmpty() || !Boolean.parseBoolean(result))
{
-                                s_logger.warn("Failed to remove  network rules for vm " +
command.getVmName());
-                            } else {
-                                s_logger.info("Removed  network rules for vm " + command.getVmName());
-                            }
-                        }
-                        citrixResourceBase.shutdownVM(conn, vm, vmName);
-                    }
-                } catch (final Exception e) {
-                    final String msg = "Catch exception " + e.getClass().getName() + " when
stop VM:" + command.getVmName() + " due to " + e.toString();
-                    s_logger.debug(msg);
-                    return new StopAnswer(command, msg, platformstring, false);
-                } finally {
-
-                    try {
-                        if (vm.getPowerState(conn) == VmPowerState.HALTED) {
-                            Set<VGPU> vGPUs = null;
-                            // Get updated GPU details
-                            try {
-                                vGPUs = vm.getVGPUs(conn);
-                            } catch (final XenAPIException e2) {
-                                s_logger.debug("VM " + vmName + " does not have GPU support.");
-                            }
-                            if (vGPUs != null && !vGPUs.isEmpty()) {
-                                final HashMap<String, HashMap<String, VgpuTypesInfo>>
groupDetails = citrixResourceBase.getGPUGroupDetails(conn);
-                                command.setGpuDevice(new GPUDeviceTO(null, null, groupDetails));
-                            }
-
-                            final Set<VIF> vifs = vm.getVIFs(conn);
-                            final List<Network> networks = new ArrayList<Network>();
-                            for (final VIF vif : vifs) {
-                                networks.add(vif.getNetwork(conn));
-                            }
-                            vm.destroy(conn);
-                            final SR sr = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName());
-                            citrixResourceBase.removeSR(conn, sr);
-                            // Disable any VLAN networks that aren't used
-                            // anymore
-                            for (final Network network : networks) {
-                                try {
-                                    if (network.getNameLabel(conn).startsWith("VLAN")) {
-                                        citrixResourceBase.disableVlanNetwork(conn, network);
-                                    }
-                                } catch (final Exception e) {
-                                    // network might be destroyed by other host
-                                }
-                            }
-                            return new StopAnswer(command, "Stop VM " + vmName + " Succeed",
platformstring, true);
-                        }
-                    } catch (final Exception e) {
-                        final String msg = "VM destroy failed in Stop " + vmName + " Command
due to " + e.getMessage();
-                        s_logger.warn(msg, e);
-                    } finally {
-                        s_logger.debug("10. The VM " + vmName + " is in Stopped state");
-                    }
-                }
-            }
-
-        } catch (final Exception e) {
-            final String msg = "Stop Vm " + vmName + " fail due to " + e.toString();
-            s_logger.warn(msg, e);
-            return new StopAnswer(command, msg, platformstring, false);
-        }
-        return new StopAnswer(command, "Stop VM failed", platformstring, false);
-    }
-}
\ No newline at end of file


Mime
View raw message