diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java index 7882b0e9feb..30c96ee5273 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java @@ -189,6 +189,7 @@ import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; import com.cloud.exception.InternalErrorException; import com.cloud.host.Host.Type; import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.hypervisor.xenserver.resource.wrapper.CitrixRequestWrapper; import com.cloud.network.Networks; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.IsolationType; @@ -426,33 +427,20 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe @Override public Answer executeRequest(final Command cmd) { + + final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance(); + try { + final Answer answer = wrapper.execute(cmd, this); + return answer; + } catch (final Exception e) { + // Ignore it for now. Just removing the command that have already been + // replaced by the new code. + } + final Class clazz = cmd.getClass(); - if (clazz == CreateCommand.class) { - return execute((CreateCommand)cmd); - } else if (cmd instanceof NetworkElementCommand) { + + if (cmd instanceof NetworkElementCommand) { return _vrResource.executeRequest((NetworkElementCommand)cmd); - } else if (clazz == CheckConsoleProxyLoadCommand.class) { - return execute((CheckConsoleProxyLoadCommand)cmd); - } else if (clazz == WatchConsoleProxyLoadCommand.class) { - return execute((WatchConsoleProxyLoadCommand)cmd); - } else if (clazz == ReadyCommand.class) { - return execute((ReadyCommand)cmd); - } else if (clazz == GetHostStatsCommand.class) { - return execute((GetHostStatsCommand)cmd); - } else if (clazz == GetVmStatsCommand.class) { - return execute((GetVmStatsCommand)cmd); - } else if (clazz == GetVmDiskStatsCommand.class) { - return execute((GetVmDiskStatsCommand)cmd); - } else if (clazz == CheckHealthCommand.class) { - return execute((CheckHealthCommand)cmd); - } else if (clazz == StopCommand.class) { - return execute((StopCommand)cmd); - } else if (clazz == RebootRouterCommand.class) { - return execute((RebootRouterCommand)cmd); - } else if (clazz == RebootCommand.class) { - return execute((RebootCommand)cmd); - } else if (clazz == CheckVirtualMachineCommand.class) { - return execute((CheckVirtualMachineCommand)cmd); } else if (clazz == PrepareForMigrationCommand.class) { return execute((PrepareForMigrationCommand)cmd); } else if (clazz == MigrateCommand.class) { @@ -2621,7 +2609,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe return vmStates; } - protected PowerState getVmState(final Connection conn, final String vmName) { + public PowerState getVmState(final Connection conn, final String vmName) { int retry = 3; while (retry-- > 0) { try { diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckVirtualMachineCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckVirtualMachineCommandWrapper.java new file mode 100644 index 00000000000..1ae20c1bcfb --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixCheckVirtualMachineCommandWrapper.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.CheckVirtualMachineAnswer; +import com.cloud.agent.api.CheckVirtualMachineCommand; +import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; +import com.cloud.resource.CommandWrapper; +import com.cloud.vm.VirtualMachine.PowerState; +import com.xensource.xenapi.Connection; + +public final class CitrixCheckVirtualMachineCommandWrapper extends CommandWrapper { + + private static final Logger s_logger = Logger.getLogger(CitrixCheckVirtualMachineCommandWrapper.class); + + @Override + public Answer execute(final CheckVirtualMachineCommand command, final CitrixResourceBase citrixResourceBase) { + final Connection conn = citrixResourceBase.getConnection(); + final String vmName = command.getVmName(); + final PowerState powerState = citrixResourceBase.getVmState(conn, vmName); + final Integer vncPort = null; + if (powerState == PowerState.PowerOn) { + s_logger.debug("3. The VM " + vmName + " is in Running state"); + } + + return new CheckVirtualMachineAnswer(command, powerState, vncPort); + } +} \ No newline at end of file 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 f83218bc7b5..77879f988ec 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 @@ -23,6 +23,7 @@ import java.util.Hashtable; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckHealthCommand; +import com.cloud.agent.api.CheckVirtualMachineCommand; import com.cloud.agent.api.Command; import com.cloud.agent.api.GetHostStatsCommand; import com.cloud.agent.api.GetVmDiskStatsCommand; @@ -67,6 +68,7 @@ public class CitrixRequestWrapper extends RequestWrapper { map.put(CheckHealthCommand.class, new CitrixCheckHealthCommandWrapper()); map.put(StopCommand.class, new CitrixStopCommandWrapper()); map.put(RebootCommand.class, new CitrixRebootCommandWrapper()); + map.put(CheckVirtualMachineCommand.class, new CitrixCheckVirtualMachineCommandWrapper()); } public static CitrixRequestWrapper getInstance() { diff --git a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java index 98023f76382..2237cf11aa1 100644 --- a/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java +++ b/plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRequestWrapperTest.java @@ -16,12 +16,14 @@ import org.mockito.runners.MockitoJUnitRunner; import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckHealthCommand; +import com.cloud.agent.api.CheckVirtualMachineCommand; import com.cloud.agent.api.Command; import com.cloud.agent.api.GetHostStatsCommand; import com.cloud.agent.api.GetVmDiskStatsCommand; import com.cloud.agent.api.GetVmStatsCommand; import com.cloud.agent.api.ReadyCommand; import com.cloud.agent.api.RebootAnswer; +import com.cloud.agent.api.RebootCommand; import com.cloud.agent.api.RebootRouterCommand; import com.cloud.agent.api.StopCommand; import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand; @@ -182,6 +184,32 @@ public class CitrixRequestWrapperTest { assertFalse(answer.getResult()); } + + @Test + public void testRebootCommand() { + final RebootCommand rebootCommand = new RebootCommand("Test"); + + final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance(); + assertNotNull(wrapper); + + final Answer answer = wrapper.execute(rebootCommand, citrixResourceBase); + + verify(citrixResourceBase, times(1)).getConnection(); + + assertFalse(answer.getResult()); + } + + @Test + public void testCheckVirtualMachineCommandCommand() { + final CheckVirtualMachineCommand statsCommand = new CheckVirtualMachineCommand("Test"); + + final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance(); + assertNotNull(wrapper); + + final Answer answer = wrapper.execute(statsCommand, citrixResourceBase); + + assertTrue(answer.getResult()); + } } class NotAValidCommand extends Command {