http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/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 02f3774..8dabaf2 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 @@ -20,75 +20,12 @@ package com.cloud.hypervisor.xenserver.resource.wrapper; import java.util.Hashtable; +import java.util.Set; + +import org.reflections.Reflections; import com.cloud.agent.api.Answer; -import com.cloud.agent.api.AttachIsoCommand; -import com.cloud.agent.api.AttachVolumeCommand; -import com.cloud.agent.api.CheckHealthCommand; -import com.cloud.agent.api.CheckNetworkCommand; -import com.cloud.agent.api.CheckOnHostCommand; -import com.cloud.agent.api.CheckVirtualMachineCommand; -import com.cloud.agent.api.CleanupNetworkRulesCmd; -import com.cloud.agent.api.ClusterVMMetaDataSyncCommand; import com.cloud.agent.api.Command; -import com.cloud.agent.api.CreateStoragePoolCommand; -import com.cloud.agent.api.CreateVMSnapshotCommand; -import com.cloud.agent.api.DeleteStoragePoolCommand; -import com.cloud.agent.api.DeleteVMSnapshotCommand; -import com.cloud.agent.api.FenceCommand; -import com.cloud.agent.api.GetGPUStatsCommand; -import com.cloud.agent.api.GetHostStatsCommand; -import com.cloud.agent.api.GetStorageStatsCommand; -import com.cloud.agent.api.GetVmDiskStatsCommand; -import com.cloud.agent.api.GetVmStatsCommand; -import com.cloud.agent.api.GetVncPortCommand; -import com.cloud.agent.api.MaintainCommand; -import com.cloud.agent.api.MigrateCommand; -import com.cloud.agent.api.MigrateWithStorageCommand; -import com.cloud.agent.api.MigrateWithStorageCompleteCommand; -import com.cloud.agent.api.MigrateWithStorageReceiveCommand; -import com.cloud.agent.api.MigrateWithStorageSendCommand; -import com.cloud.agent.api.ModifySshKeysCommand; -import com.cloud.agent.api.ModifyStoragePoolCommand; -import com.cloud.agent.api.NetworkRulesSystemVmCommand; -import com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand; -import com.cloud.agent.api.NetworkUsageCommand; -import com.cloud.agent.api.OvsCreateGreTunnelCommand; -import com.cloud.agent.api.OvsCreateTunnelCommand; -import com.cloud.agent.api.OvsDeleteFlowCommand; -import com.cloud.agent.api.OvsDestroyBridgeCommand; -import com.cloud.agent.api.OvsDestroyTunnelCommand; -import com.cloud.agent.api.OvsFetchInterfaceCommand; -import com.cloud.agent.api.OvsSetTagAndFlowCommand; -import com.cloud.agent.api.OvsSetupBridgeCommand; -import com.cloud.agent.api.OvsVpcPhysicalTopologyConfigCommand; -import com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand; -import com.cloud.agent.api.PerformanceMonitorCommand; -import com.cloud.agent.api.PingTestCommand; -import com.cloud.agent.api.PlugNicCommand; -import com.cloud.agent.api.PrepareForMigrationCommand; -import com.cloud.agent.api.PvlanSetupCommand; -import com.cloud.agent.api.ReadyCommand; -import com.cloud.agent.api.RebootCommand; -import com.cloud.agent.api.RebootRouterCommand; -import com.cloud.agent.api.RevertToVMSnapshotCommand; -import com.cloud.agent.api.ScaleVmCommand; -import com.cloud.agent.api.SecurityGroupRulesCmd; -import com.cloud.agent.api.SetupCommand; -import com.cloud.agent.api.StartCommand; -import com.cloud.agent.api.StopCommand; -import com.cloud.agent.api.UnPlugNicCommand; -import com.cloud.agent.api.UpdateHostPasswordCommand; -import com.cloud.agent.api.UpgradeSnapshotCommand; -import com.cloud.agent.api.check.CheckSshCommand; -import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand; -import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand; -import com.cloud.agent.api.routing.NetworkElementCommand; -import com.cloud.agent.api.storage.CreateCommand; -import com.cloud.agent.api.storage.DestroyCommand; -import com.cloud.agent.api.storage.MigrateVolumeCommand; -import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; -import com.cloud.agent.api.storage.ResizeVolumeCommand; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.hypervisor.xenserver.resource.XcpServerResource; import com.cloud.hypervisor.xenserver.resource.XenServer56FP1Resource; @@ -107,103 +44,60 @@ public class CitrixRequestWrapper extends RequestWrapper { instance = new CitrixRequestWrapper(); } + Reflections baseWrappers = new Reflections("com.cloud.hypervisor.xenserver.resource.wrapper"); + @SuppressWarnings("rawtypes") + Set<Class<? extends CommandWrapper>> baseSet = baseWrappers.getSubTypesOf(CommandWrapper.class); + + Reflections xenServer56Wrappers = new Reflections("com.cloud.hypervisor.xenserver.resource.wrapper.xen56"); + @SuppressWarnings("rawtypes") + Set<Class<? extends CommandWrapper>> xenServer56Set = xenServer56Wrappers.getSubTypesOf(CommandWrapper.class); + + Reflections xenServer56P1Wrappers = new Reflections("com.cloud.hypervisor.xenserver.resource.wrapper.xen56p1"); + @SuppressWarnings("rawtypes") + Set<Class<? extends CommandWrapper>> xenServer56P1Set = xenServer56P1Wrappers.getSubTypesOf(CommandWrapper.class); + + Reflections xenServer610Wrappers = new Reflections("com.cloud.hypervisor.xenserver.resource.wrapper.xen610"); + @SuppressWarnings("rawtypes") + Set<Class<? extends CommandWrapper>> xenServer610Set = xenServer610Wrappers.getSubTypesOf(CommandWrapper.class); + + Reflections xenServer620SP1Wrappers = new Reflections("com.cloud.hypervisor.xenserver.resource.wrapper.xen620sp1"); + @SuppressWarnings("rawtypes") + Set<Class<? extends CommandWrapper>> xenServer620SP1Set = xenServer620SP1Wrappers.getSubTypesOf(CommandWrapper.class); + + Reflections xcpWrappers = new Reflections("com.cloud.hypervisor.xenserver.resource.wrapper.xcp"); + @SuppressWarnings("rawtypes") + Set<Class<? extends CommandWrapper>> xcpSet = xcpWrappers.getSubTypesOf(CommandWrapper.class); + private CitrixRequestWrapper() { init(); } @SuppressWarnings("rawtypes") private void init() { + + final Hashtable<Class<? extends Command>, CommandWrapper> citrixCommands = processAnnotations(baseSet); + final Hashtable<Class<? extends Command>, CommandWrapper> xenServer56Commands = processAnnotations(xenServer56Set); + final Hashtable<Class<? extends Command>, CommandWrapper> xenServer56P1Commands = processAnnotations(xenServer56P1Set); + final Hashtable<Class<? extends Command>, CommandWrapper> xenServer610Commands = processAnnotations(xenServer610Set); + final Hashtable<Class<? extends Command>, CommandWrapper> xenServer620SP1Commands = processAnnotations(xenServer620SP1Set); + final Hashtable<Class<? extends Command>, CommandWrapper> xcpServerResourceCommand = processAnnotations(xcpSet); + // CitrixResourceBase commands - final Hashtable<Class<? extends Command>, CommandWrapper> citrixCommands = new Hashtable<Class<? extends Command>, CommandWrapper>(); - citrixCommands.put(RebootRouterCommand.class, new CitrixRebootRouterCommandWrapper()); - citrixCommands.put(CreateCommand.class, new CitrixCreateCommandWrapper()); - citrixCommands.put(CheckConsoleProxyLoadCommand.class, new CitrixCheckConsoleProxyLoadCommandWrapper()); - citrixCommands.put(WatchConsoleProxyLoadCommand.class, new CitrixWatchConsoleProxyLoadCommandWrapper()); - citrixCommands.put(ReadyCommand.class, new CitrixReadyCommandWrapper()); - citrixCommands.put(GetHostStatsCommand.class, new CitrixGetHostStatsCommandWrapper()); - citrixCommands.put(GetVmStatsCommand.class, new CitrixGetVmStatsCommandWrapper()); - citrixCommands.put(GetVmDiskStatsCommand.class, new CitrixGetVmDiskStatsCommandWrapper()); - citrixCommands.put(CheckHealthCommand.class, new CitrixCheckHealthCommandWrapper()); - citrixCommands.put(StopCommand.class, new CitrixStopCommandWrapper()); - citrixCommands.put(RebootCommand.class, new CitrixRebootCommandWrapper()); - citrixCommands.put(CheckVirtualMachineCommand.class, new CitrixCheckVirtualMachineCommandWrapper()); - citrixCommands.put(PrepareForMigrationCommand.class, new CitrixPrepareForMigrationCommandWrapper()); - citrixCommands.put(MigrateCommand.class, new CitrixMigrateCommandWrapper()); - citrixCommands.put(DestroyCommand.class, new CitrixDestroyCommandWrapper()); - citrixCommands.put(CreateStoragePoolCommand.class, new CitrixCreateStoragePoolCommandWrapper()); - citrixCommands.put(ModifyStoragePoolCommand.class, new CitrixModifyStoragePoolCommandWrapper()); - citrixCommands.put(DeleteStoragePoolCommand.class, new CitrixDeleteStoragePoolCommandWrapper()); - citrixCommands.put(ResizeVolumeCommand.class, new CitrixResizeVolumeCommandWrapper()); - citrixCommands.put(AttachVolumeCommand.class, new CitrixAttachVolumeCommandWrapper()); - citrixCommands.put(AttachIsoCommand.class, new CitrixAttachIsoCommandWrapper()); - citrixCommands.put(UpgradeSnapshotCommand.class, new CitrixUpgradeSnapshotCommandWrapper()); - citrixCommands.put(GetStorageStatsCommand.class, new CitrixGetStorageStatsCommandWrapper()); - citrixCommands.put(PrimaryStorageDownloadCommand.class, new CitrixPrimaryStorageDownloadCommandWrapper()); - citrixCommands.put(GetVncPortCommand.class, new CitrixGetVncPortCommandWrapper()); - citrixCommands.put(SetupCommand.class, new CitrixSetupCommandWrapper()); - citrixCommands.put(MaintainCommand.class, new CitrixMaintainCommandWrapper()); - citrixCommands.put(PingTestCommand.class, new CitrixPingTestCommandWrapper()); - citrixCommands.put(CheckOnHostCommand.class, new CitrixCheckOnHostCommandWrapper()); - citrixCommands.put(ModifySshKeysCommand.class, new CitrixModifySshKeysCommandWrapper()); - citrixCommands.put(StartCommand.class, new CitrixStartCommandWrapper()); - citrixCommands.put(OvsSetTagAndFlowCommand.class, new CitrixOvsSetTagAndFlowCommandWrapper()); - citrixCommands.put(CheckSshCommand.class, new CitrixCheckSshCommandWrapper()); - citrixCommands.put(SecurityGroupRulesCmd.class, new CitrixSecurityGroupRulesCommandWrapper()); - citrixCommands.put(OvsFetchInterfaceCommand.class, new CitrixOvsFetchInterfaceCommandWrapper()); - citrixCommands.put(OvsCreateGreTunnelCommand.class, new CitrixOvsCreateGreTunnelCommandWrapper()); - citrixCommands.put(OvsDeleteFlowCommand.class, new CitrixOvsDeleteFlowCommandWrapper()); - citrixCommands.put(OvsVpcPhysicalTopologyConfigCommand.class, new CitrixOvsVpcPhysicalTopologyConfigCommandWrapper()); - citrixCommands.put(OvsVpcRoutingPolicyConfigCommand.class, new CitrixOvsVpcRoutingPolicyConfigCommandWrapper()); - citrixCommands.put(CleanupNetworkRulesCmd.class, new CitrixCleanupNetworkRulesCmdWrapper()); - citrixCommands.put(NetworkRulesSystemVmCommand.class, new CitrixNetworkRulesSystemVmCommandWrapper()); - citrixCommands.put(OvsCreateTunnelCommand.class, new CitrixOvsCreateTunnelCommandWrapper()); - citrixCommands.put(OvsSetupBridgeCommand.class, new CitrixOvsSetupBridgeCommandWrapper()); - citrixCommands.put(OvsDestroyBridgeCommand.class, new CitrixOvsDestroyBridgeCommandWrapper()); - citrixCommands.put(OvsDestroyTunnelCommand.class, new CitrixOvsDestroyTunnelCommandWrapper()); - citrixCommands.put(UpdateHostPasswordCommand.class, new CitrixUpdateHostPasswordCommandWrapper()); - citrixCommands.put(ClusterVMMetaDataSyncCommand.class, new CitrixClusterVMMetaDataSyncCommandWrapper()); - citrixCommands.put(CheckNetworkCommand.class, new CitrixCheckNetworkCommandWrapper()); - citrixCommands.put(PlugNicCommand.class, new CitrixPlugNicCommandWrapper()); - citrixCommands.put(UnPlugNicCommand.class, new CitrixUnPlugNicCommandWrapper()); - citrixCommands.put(CreateVMSnapshotCommand.class, new CitrixCreateVMSnapshotCommandWrapper()); - citrixCommands.put(DeleteVMSnapshotCommand.class, new CitrixDeleteVMSnapshotCommandWrapper()); - citrixCommands.put(RevertToVMSnapshotCommand.class, new CitrixRevertToVMSnapshotCommandWrapper()); - citrixCommands.put(NetworkRulesVmSecondaryIpCommand.class, new CitrixNetworkRulesVmSecondaryIpCommandWrapper()); - citrixCommands.put(ScaleVmCommand.class, new CitrixScaleVmCommandWrapper()); - citrixCommands.put(PvlanSetupCommand.class, new CitrixPvlanSetupCommandWrapper()); - citrixCommands.put(PerformanceMonitorCommand.class, new CitrixPerformanceMonitorCommandWrapper()); - citrixCommands.put(NetworkElementCommand.class, new CitrixNetworkElementCommandWrapper()); resources.put(CitrixResourceBase.class, citrixCommands); // XenServer56Resource commands - final Hashtable<Class<? extends Command>, CommandWrapper> xenServer56Commands = new Hashtable<Class<? extends Command>, CommandWrapper>(); - xenServer56Commands.put(CheckOnHostCommand.class, new XenServer56CheckOnHostCommandWrapper()); - xenServer56Commands.put(FenceCommand.class, new XenServer56FenceCommandWrapper()); - xenServer56Commands.put(NetworkUsageCommand.class, new XenServer56NetworkUsageCommandWrapper()); resources.put(XenServer56Resource.class, xenServer56Commands); // XenServer56FP1Resource commands - final Hashtable<Class<? extends Command>, CommandWrapper> xenServer56P1Commands = new Hashtable<Class<? extends Command>, CommandWrapper>(); - xenServer56P1Commands.put(FenceCommand.class, new XenServer56FP1FenceCommandWrapper()); resources.put(XenServer56FP1Resource.class, xenServer56P1Commands); // XenServer620SP1Resource commands - final Hashtable<Class<? extends Command>, CommandWrapper> xenServer620SP1Commands = new Hashtable<Class<? extends Command>, CommandWrapper>(); - xenServer620SP1Commands.put(GetGPUStatsCommand.class, new XenServer620SP1GetGPUStatsCommandWrapper()); resources.put(XenServer620SP1Resource.class, xenServer620SP1Commands); // XenServer610Resource commands - final Hashtable<Class<? extends Command>, CommandWrapper> xenServer610Commands = new Hashtable<Class<? extends Command>, CommandWrapper>(); - xenServer610Commands.put(MigrateWithStorageCommand.class, new XenServer610MigrateWithStorageCommandWrapper()); - xenServer610Commands.put(MigrateWithStorageReceiveCommand.class, new XenServer610MigrateWithStorageReceiveCommandWrapper()); - xenServer610Commands.put(MigrateWithStorageSendCommand.class, new XenServer610MigrateWithStorageSendCommandWrapper()); - xenServer610Commands.put(MigrateWithStorageCompleteCommand.class, new XenServer610MigrateWithStorageCompleteCommandWrapper()); - xenServer610Commands.put(MigrateVolumeCommand.class, new XenServer610MigrateVolumeCommandWrapper()); resources.put(XenServer610Resource.class, xenServer610Commands); // XcpServerResource commands - final Hashtable<Class<? extends Command>, CommandWrapper> xcpServerResourceCommand = new Hashtable<Class<? extends Command>, CommandWrapper>(); - xcpServerResourceCommand.put(NetworkUsageCommand.class, new XcpServerNetworkUsageCommandWrapper()); resources.put(XcpServerResource.class, xcpServerResourceCommand); }
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixResizeVolumeCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixResizeVolumeCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixResizeVolumeCommandWrapper.java index 62f9093..25f350f 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixResizeVolumeCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixResizeVolumeCommandWrapper.java @@ -26,9 +26,11 @@ import com.cloud.agent.api.storage.ResizeVolumeAnswer; import com.cloud.agent.api.storage.ResizeVolumeCommand; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Connection; import com.xensource.xenapi.VDI; +@ResourceWrapper(handles = ResizeVolumeCommand.class) public final class CitrixResizeVolumeCommandWrapper extends CommandWrapper<ResizeVolumeCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixResizeVolumeCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRevertToVMSnapshotCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRevertToVMSnapshotCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRevertToVMSnapshotCommandWrapper.java index a929132..def4df7 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRevertToVMSnapshotCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixRevertToVMSnapshotCommandWrapper.java @@ -32,6 +32,7 @@ import com.cloud.agent.api.RevertToVMSnapshotAnswer; import com.cloud.agent.api.RevertToVMSnapshotCommand; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.snapshot.VMSnapshot; import com.xensource.xenapi.Connection; @@ -40,6 +41,7 @@ import com.xensource.xenapi.VBD; import com.xensource.xenapi.VDI; import com.xensource.xenapi.VM; +@ResourceWrapper(handles = RevertToVMSnapshotCommand.class) public final class CitrixRevertToVMSnapshotCommandWrapper extends CommandWrapper<RevertToVMSnapshotCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixRevertToVMSnapshotCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixScaleVmCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixScaleVmCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixScaleVmCommandWrapper.java index 47a30f5..d21bcbd 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixScaleVmCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixScaleVmCommandWrapper.java @@ -31,6 +31,7 @@ import com.cloud.agent.api.ScaleVmCommand; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.cloud.utils.exception.CloudRuntimeException; import com.xensource.xenapi.Connection; import com.xensource.xenapi.Host; @@ -38,6 +39,7 @@ import com.xensource.xenapi.Types.VmPowerState; import com.xensource.xenapi.Types.XenAPIException; import com.xensource.xenapi.VM; +@ResourceWrapper(handles = ScaleVmCommand.class) public final class CitrixScaleVmCommandWrapper extends CommandWrapper<ScaleVmCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixScaleVmCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java index 0cf4a8a..793a564 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSecurityGroupRulesCommandWrapper.java @@ -26,8 +26,10 @@ import com.cloud.agent.api.SecurityGroupRuleAnswer; import com.cloud.agent.api.SecurityGroupRulesCmd; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Connection; +@ResourceWrapper(handles = SecurityGroupRulesCmd.class) public final class CitrixSecurityGroupRulesCommandWrapper extends CommandWrapper<SecurityGroupRulesCmd, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixSecurityGroupRulesCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSetupCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSetupCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSetupCommandWrapper.java index 3b24aa3..3ff0dfe 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSetupCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixSetupCommandWrapper.java @@ -30,6 +30,7 @@ import com.cloud.agent.api.SetupAnswer; import com.cloud.agent.api.SetupCommand; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.xensource.xenapi.Bond; @@ -41,6 +42,7 @@ import com.xensource.xenapi.Pool; import com.xensource.xenapi.Types; import com.xensource.xenapi.Types.XenAPIException; +@ResourceWrapper(handles = SetupCommand.class) public final class CitrixSetupCommandWrapper extends CommandWrapper<SetupCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixSetupCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStartCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStartCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStartCommandWrapper.java index ceaaf34..27f8474 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStartCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixStartCommandWrapper.java @@ -40,6 +40,7 @@ import com.cloud.network.Networks; import com.cloud.network.Networks.BroadcastDomainType; import com.cloud.network.Networks.IsolationType; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.cloud.vm.VirtualMachine; import com.xensource.xenapi.Connection; import com.xensource.xenapi.Host; @@ -47,6 +48,7 @@ import com.xensource.xenapi.Types.VmPowerState; import com.xensource.xenapi.VDI; import com.xensource.xenapi.VM; +@ResourceWrapper(handles = StartCommand.class) public final class CitrixStartCommandWrapper extends CommandWrapper<StartCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixStartCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/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 index ce8517f..8310cd8 100644 --- 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 @@ -34,6 +34,7 @@ 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.resource.ResourceWrapper; import com.cloud.utils.StringUtils; import com.xensource.xenapi.Connection; import com.xensource.xenapi.Network; @@ -44,6 +45,7 @@ import com.xensource.xenapi.VGPU; import com.xensource.xenapi.VIF; import com.xensource.xenapi.VM; +@ResourceWrapper(handles = StopCommand.class) public final class CitrixStopCommandWrapper extends CommandWrapper<StopCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixStopCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUnPlugNicCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUnPlugNicCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUnPlugNicCommandWrapper.java index 6250835..639cfb0 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUnPlugNicCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUnPlugNicCommandWrapper.java @@ -29,11 +29,13 @@ import com.cloud.agent.api.UnPlugNicCommand; import com.cloud.agent.api.to.NicTO; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Connection; import com.xensource.xenapi.Network; import com.xensource.xenapi.VIF; import com.xensource.xenapi.VM; +@ResourceWrapper(handles = UnPlugNicCommand.class) public final class CitrixUnPlugNicCommandWrapper extends CommandWrapper<UnPlugNicCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixUnPlugNicCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpdateHostPasswordCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpdateHostPasswordCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpdateHostPasswordCommandWrapper.java index f2f1fb5..c5654fd 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpdateHostPasswordCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpdateHostPasswordCommandWrapper.java @@ -23,7 +23,9 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.UpdateHostPasswordCommand; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +@ResourceWrapper(handles = UpdateHostPasswordCommand.class) public final class CitrixUpdateHostPasswordCommandWrapper extends CommandWrapper<UpdateHostPasswordCommand, Answer, CitrixResourceBase> { @Override http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpgradeSnapshotCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpgradeSnapshotCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpgradeSnapshotCommandWrapper.java index a7f3a50..c23ba1b 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpgradeSnapshotCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixUpgradeSnapshotCommandWrapper.java @@ -27,8 +27,10 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.UpgradeSnapshotCommand; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; import com.xensource.xenapi.Connection; +@ResourceWrapper(handles = UpgradeSnapshotCommand.class) public final class CitrixUpgradeSnapshotCommandWrapper extends CommandWrapper<UpgradeSnapshotCommand, Answer, CitrixResourceBase> { private static final Logger s_logger = Logger.getLogger(CitrixUpgradeSnapshotCommandWrapper.class); http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixWatchConsoleProxyLoadCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixWatchConsoleProxyLoadCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixWatchConsoleProxyLoadCommandWrapper.java index f188c20..74ca0dd 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixWatchConsoleProxyLoadCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/CitrixWatchConsoleProxyLoadCommandWrapper.java @@ -23,8 +23,10 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand; import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase; +import com.cloud.resource.ResourceWrapper; import com.cloud.resource.ServerResource; +@ResourceWrapper(handles = WatchConsoleProxyLoadCommand.class) public final class CitrixWatchConsoleProxyLoadCommandWrapper extends CitrixConsoleProxyLoadCommandWrapper<WatchConsoleProxyLoadCommand, Answer, CitrixResourceBase> { @Override http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XcpServerNetworkUsageCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XcpServerNetworkUsageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XcpServerNetworkUsageCommandWrapper.java deleted file mode 100644 index d22c608..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XcpServerNetworkUsageCommandWrapper.java +++ /dev/null @@ -1,52 +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.NetworkUsageAnswer; -import com.cloud.agent.api.NetworkUsageCommand; -import com.cloud.hypervisor.xenserver.resource.XcpServerResource; -import com.cloud.resource.CommandWrapper; -import com.xensource.xenapi.Connection; - -public final class XcpServerNetworkUsageCommandWrapper extends CommandWrapper<NetworkUsageCommand, Answer, XcpServerResource> { - - private static final Logger s_logger = Logger.getLogger(XcpServerNetworkUsageCommandWrapper.class); - - @Override - public Answer execute(final NetworkUsageCommand command, final XcpServerResource xcpServerResource) { - try { - final Connection conn = xcpServerResource.getConnection(); - if (command.getOption() != null && command.getOption().equals("create")) { - final String result = xcpServerResource.networkUsage(conn, command.getPrivateIP(), "create", null); - final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L); - return answer; - } - final long[] stats = xcpServerResource.getNetworkStats(conn, command.getPrivateIP()); - final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]); - return answer; - } catch (final Exception ex) { - s_logger.warn("Failed to get network usage stats due to ", ex); - return new NetworkUsageAnswer(command, ex); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56CheckOnHostCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56CheckOnHostCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56CheckOnHostCommandWrapper.java deleted file mode 100644 index 972936e..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56CheckOnHostCommandWrapper.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.CheckOnHostAnswer; -import com.cloud.agent.api.CheckOnHostCommand; -import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; -import com.cloud.resource.CommandWrapper; - -public final class XenServer56CheckOnHostCommandWrapper extends CommandWrapper<CheckOnHostCommand, Answer, XenServer56Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer56CheckOnHostCommandWrapper.class); - - @Override - public Answer execute(final CheckOnHostCommand command, final XenServer56Resource xenServer56) { - final Boolean alive = xenServer56.checkHeartbeat(command.getHost().getGuid()); - String msg = ""; - if (alive == null) { - msg = " cannot determine "; - } else if ( alive == true) { - msg = "Heart beat is still going"; - } else { - msg = "Heart beat is gone so dead."; - } - s_logger.debug(msg); - return new CheckOnHostAnswer(command, alive, msg); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FP1FenceCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FP1FenceCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FP1FenceCommandWrapper.java deleted file mode 100644 index b169636..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FP1FenceCommandWrapper.java +++ /dev/null @@ -1,92 +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.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.log4j.Logger; -import org.apache.xmlrpc.XmlRpcException; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.FenceAnswer; -import com.cloud.agent.api.FenceCommand; -import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; -import com.cloud.resource.CommandWrapper; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Types.XenAPIException; -import com.xensource.xenapi.VBD; -import com.xensource.xenapi.VDI; -import com.xensource.xenapi.VM; - -public final class XenServer56FP1FenceCommandWrapper extends CommandWrapper<FenceCommand, Answer, XenServer56Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer56FP1FenceCommandWrapper.class); - - @Override - public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) { - final Connection conn = xenServer56.getConnection(); - try { - final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid()); - if ( alive == null ) { - s_logger.debug("Failed to check heartbeat, so unable to fence"); - return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence"); - } - if ( alive ) { - s_logger.debug("Heart beat is still going so unable to fence"); - return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence"); - } - final Set<VM> vms = VM.getByNameLabel(conn, command.getVmName()); - for (final VM vm : vms) { - final Set<VDI> vdis = new HashSet<VDI>(); - final Set<VBD> vbds = vm.getVBDs(conn); - for (final VBD vbd : vbds) { - final VDI vdi = vbd.getVDI(conn); - if (!xenServer56.isRefNull(vdi)) { - vdis.add(vdi); - } - } - s_logger.info("Fence command for VM " + command.getVmName()); - vm.powerStateReset(conn); - vm.destroy(conn); - for (final VDI vdi : vdis) { - final Map<String, String> smConfig = vdi.getSmConfig(conn); - for (final String key : smConfig.keySet()) { - if (key.startsWith("host_")) { - vdi.removeFromSmConfig(conn, key); - break; - } - } - } - } - return new FenceAnswer(command); - } catch (final XmlRpcException e) { - s_logger.warn("Unable to fence", e); - return new FenceAnswer(command, false, e.getMessage()); - } catch (final XenAPIException e) { - s_logger.warn("Unable to fence", e); - return new FenceAnswer(command, false, e.getMessage()); - } catch (final Exception e) { - s_logger.warn("Unable to fence", e); - return new FenceAnswer(command, false, e.getMessage()); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FenceCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FenceCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FenceCommandWrapper.java deleted file mode 100644 index ece3329..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56FenceCommandWrapper.java +++ /dev/null @@ -1,71 +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.Set; - -import org.apache.log4j.Logger; -import org.apache.xmlrpc.XmlRpcException; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.FenceAnswer; -import com.cloud.agent.api.FenceCommand; -import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; -import com.cloud.resource.CommandWrapper; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Types.XenAPIException; -import com.xensource.xenapi.VM; - -public final class XenServer56FenceCommandWrapper extends CommandWrapper<FenceCommand, Answer, XenServer56Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer56FenceCommandWrapper.class); - - @Override - public Answer execute(final FenceCommand command, final XenServer56Resource xenServer56) { - final Connection conn = xenServer56.getConnection(); - try { - final Boolean alive = xenServer56.checkHeartbeat(command.getHostGuid()); - if (alive == null) { - s_logger.debug("Failed to check heartbeat, so unable to fence"); - return new FenceAnswer(command, false, "Failed to check heartbeat, so unable to fence"); - } - if (alive) { - s_logger.debug("Heart beat is still going so unable to fence"); - return new FenceAnswer(command, false, "Heartbeat is still going on unable to fence"); - } - final Set<VM> vms = VM.getByNameLabel(conn, command.getVmName()); - for (final VM vm : vms) { - s_logger.info("Fence command for VM " + command.getVmName()); - vm.powerStateReset(conn); - vm.destroy(conn); - } - return new FenceAnswer(command); - } catch (final XmlRpcException e) { - s_logger.warn("Unable to fence", e); - return new FenceAnswer(command, false, e.getMessage()); - } catch (final XenAPIException e) { - s_logger.warn("Unable to fence", e); - return new FenceAnswer(command, false, e.getMessage()); - } catch (final Exception e) { - s_logger.warn("Unable to fence", e); - return new FenceAnswer(command, false, e.getMessage()); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56NetworkUsageCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56NetworkUsageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56NetworkUsageCommandWrapper.java deleted file mode 100644 index 9132aa1..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer56NetworkUsageCommandWrapper.java +++ /dev/null @@ -1,103 +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.xensource.xenapi.Connection; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.NetworkUsageAnswer; -import com.cloud.agent.api.NetworkUsageCommand; -import com.cloud.hypervisor.xenserver.resource.XenServer56Resource; -import com.cloud.resource.CommandWrapper; -import com.cloud.utils.ExecutionResult; - -public final class XenServer56NetworkUsageCommandWrapper extends CommandWrapper<NetworkUsageCommand, Answer, XenServer56Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer56NetworkUsageCommandWrapper.class); - - @Override - public Answer execute(final NetworkUsageCommand command, final XenServer56Resource xenServer56) { - if (command.isForVpc()) { - return executeNetworkUsage(command, xenServer56); - } - try { - final Connection conn = xenServer56.getConnection(); - if (command.getOption() != null && command.getOption().equals("create")) { - final String result = xenServer56.networkUsage(conn, command.getPrivateIP(), "create", null); - final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L); - return answer; - } - final long[] stats = xenServer56.getNetworkStats(conn, command.getPrivateIP()); - final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]); - return answer; - } catch (final Exception ex) { - s_logger.warn("Failed to get network usage stats due to ", ex); - return new NetworkUsageAnswer(command, ex); - } - } - - protected NetworkUsageAnswer executeNetworkUsage(final NetworkUsageCommand command, final XenServer56Resource xenServer56) { - try { - final String option = command.getOption(); - final String publicIp = command.getGatewayIP(); - - String args = " -l " + publicIp + " "; - if (option.equals("get")) { - args += "-g"; - } else if (option.equals("create")) { - args += "-c"; - final String vpcCIDR = command.getVpcCIDR(); - args += " -v " + vpcCIDR; - } else if (option.equals("reset")) { - args += "-r"; - } else if (option.equals("vpn")) { - args += "-n"; - } else if (option.equals("remove")) { - args += "-d"; - } else { - return new NetworkUsageAnswer(command, "success", 0L, 0L); - } - - final ExecutionResult result = xenServer56.executeInVR(command.getPrivateIP(), "vpc_netusage.sh", args); - final String detail = result.getDetails(); - if (!result.isSuccess()) { - throw new Exception(" vpc network usage plugin call failed "); - } - if (option.equals("get") || option.equals("vpn")) { - final long[] stats = new long[2]; - if (detail != null) { - final String[] splitResult = detail.split(":"); - int i = 0; - while (i < splitResult.length - 1) { - stats[0] += Long.parseLong(splitResult[i++]); - stats[1] += Long.parseLong(splitResult[i++]); - } - return new NetworkUsageAnswer(command, "success", stats[0], stats[1]); - } - } - return new NetworkUsageAnswer(command, "success", 0L, 0L); - } catch (final Exception ex) { - s_logger.warn("Failed to get network usage stats due to ", ex); - return new NetworkUsageAnswer(command, ex); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateVolumeCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateVolumeCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateVolumeCommandWrapper.java deleted file mode 100644 index 284ec89..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateVolumeCommandWrapper.java +++ /dev/null @@ -1,71 +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.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.storage.MigrateVolumeAnswer; -import com.cloud.agent.api.storage.MigrateVolumeCommand; -import com.cloud.agent.api.to.StorageFilerTO; -import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; -import com.cloud.resource.CommandWrapper; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.SR; -import com.xensource.xenapi.Task; -import com.xensource.xenapi.Types; -import com.xensource.xenapi.VDI; - -public final class XenServer610MigrateVolumeCommandWrapper extends CommandWrapper<MigrateVolumeCommand, Answer, XenServer610Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateVolumeCommandWrapper.class); - - @Override - public Answer execute(final MigrateVolumeCommand command, final XenServer610Resource xenServer610Resource) { - final Connection connection = xenServer610Resource.getConnection(); - final String volumeUUID = command.getVolumePath(); - final StorageFilerTO poolTO = command.getPool(); - - try { - String uuid = poolTO.getUuid(); - final SR destinationPool = xenServer610Resource.getStorageRepository(connection, uuid); - final VDI srcVolume = xenServer610Resource.getVDIbyUuid(connection, volumeUUID); - final Map<String, String> other = new HashMap<String, String>(); - other.put("live", "true"); - - // Live migrate the vdi across pool. - final Task task = srcVolume.poolMigrateAsync(connection, destinationPool, other); - final long timeout = xenServer610Resource.getMigrateWait() * 1000L; - xenServer610Resource.waitForTask(connection, task, 1000, timeout); - xenServer610Resource.checkForSuccess(connection, task); - - final VDI dvdi = Types.toVDI(task, connection); - - return new MigrateVolumeAnswer(command, true, null, dvdi.getUuid(connection)); - } catch (final Exception e) { - final String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString(); - s_logger.error(msg, e); - return new MigrateVolumeAnswer(command, false, msg, null); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCommandWrapper.java deleted file mode 100644 index 970ed10..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCommandWrapper.java +++ /dev/null @@ -1,137 +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.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.MigrateWithStorageAnswer; -import com.cloud.agent.api.MigrateWithStorageCommand; -import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.StorageFilerTO; -import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.agent.api.to.VolumeTO; -import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; -import com.cloud.hypervisor.xenserver.resource.XsHost; -import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork; -import com.cloud.network.Networks.TrafficType; -import com.cloud.resource.CommandWrapper; -import com.cloud.utils.exception.CloudRuntimeException; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Host; -import com.xensource.xenapi.Network; -import com.xensource.xenapi.SR; -import com.xensource.xenapi.Task; -import com.xensource.xenapi.Types; -import com.xensource.xenapi.VDI; -import com.xensource.xenapi.VIF; -import com.xensource.xenapi.VM; - -public final class XenServer610MigrateWithStorageCommandWrapper extends CommandWrapper<MigrateWithStorageCommand, Answer, XenServer610Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageCommandWrapper.class); - - @Override - public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) { - final Connection connection = xenServer610Resource.getConnection(); - final VirtualMachineTO vmSpec = command.getVirtualMachine(); - final Map<VolumeTO, StorageFilerTO> volumeToFiler = command.getVolumeToFiler(); - final String vmName = vmSpec.getName(); - Task task = null; - - final XsHost xsHost = xenServer610Resource.getHost(); - final String uuid = xsHost.getUuid(); - try { - xenServer610Resource.prepareISO(connection, vmName); - - // Get the list of networks and recreate VLAN, if required. - for (final NicTO nicTo : vmSpec.getNics()) { - xenServer610Resource.getNetwork(connection, nicTo); - } - - final Map<String, String> other = new HashMap<String, String>(); - other.put("live", "true"); - - final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null); - final Network networkForSm = nativeNetworkForTraffic.getNetwork(); - - // Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map. - final Map<VIF, Network> vifMap = new HashMap<VIF, Network>(); - final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>(); - for (final Map.Entry<VolumeTO, StorageFilerTO> entry : volumeToFiler.entrySet()) { - final VolumeTO volume = entry.getKey(); - final StorageFilerTO sotrageFiler = entry.getValue(); - vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, sotrageFiler.getUuid())); - } - - // Get the vm to migrate. - final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName()); - final VM vmToMigrate = vms.iterator().next(); - - // Check migration with storage is possible. - final Host host = Host.getByUuid(connection, uuid); - final Map<String, String> token = host.migrateReceive(connection, networkForSm, other); - task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other); - try { - // poll every 1 seconds - final long timeout = xenServer610Resource.getMigrateWait() * 1000L; - xenServer610Resource.waitForTask(connection, task, 1000, timeout); - xenServer610Resource.checkForSuccess(connection, task); - } catch (final Types.HandleInvalid e) { - s_logger.error("Error while checking if vm " + vmName + " can be migrated to the destination host " + host, e); - throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated to the " + "destination host " + host, e); - } - - // Migrate now. - task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other); - try { - // poll every 1 seconds. - final long timeout = xenServer610Resource.getMigrateWait() * 1000L; - xenServer610Resource.waitForTask(connection, task, 1000, timeout); - xenServer610Resource.checkForSuccess(connection, task); - } catch (final Types.HandleInvalid e) { - s_logger.error("Error while migrating vm " + vmName + " to the destination host " + host, e); - throw new CloudRuntimeException("Error while migrating vm " + vmName + " to the destination host " + host, e); - } - - // Volume paths would have changed. Return that information. - final List<VolumeObjectTO> volumeToList = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, vmToMigrate, vmSpec.getDisks()); - vmToMigrate.setAffinity(connection, host); - return new MigrateWithStorageAnswer(command, volumeToList); - } catch (final Exception e) { - s_logger.warn("Catch Exception " + e.getClass().getName() + ". Storage motion failed due to " + e.toString(), e); - return new MigrateWithStorageAnswer(command, e); - } finally { - if (task != null) { - try { - task.destroy(connection); - } catch (final Exception e) { - s_logger.debug("Unable to destroy task " + task.toString() + " on host " + uuid + " due to " + e.toString()); - } - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCompleteCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCompleteCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCompleteCommandWrapper.java deleted file mode 100644 index e993b96..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageCompleteCommandWrapper.java +++ /dev/null @@ -1,81 +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.List; -import java.util.Set; - -import org.apache.cloudstack.storage.to.VolumeObjectTO; -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.MigrateWithStorageCompleteAnswer; -import com.cloud.agent.api.MigrateWithStorageCompleteCommand; -import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; -import com.cloud.hypervisor.xenserver.resource.XsHost; -import com.cloud.resource.CommandWrapper; -import com.cloud.utils.exception.CloudRuntimeException; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Host; -import com.xensource.xenapi.VM; - -public final class XenServer610MigrateWithStorageCompleteCommandWrapper extends CommandWrapper<MigrateWithStorageCompleteCommand, Answer, XenServer610Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageCompleteCommandWrapper.class); - - @Override - public Answer execute(final MigrateWithStorageCompleteCommand command, final XenServer610Resource xenServer610Resource) { - final Connection connection = xenServer610Resource.getConnection(); - final VirtualMachineTO vmSpec = command.getVirtualMachine(); - - final String name = vmSpec.getName(); - try { - final XsHost xsHost = xenServer610Resource.getHost(); - final String uuid = xsHost.getUuid(); - - final Set<VM> vms = VM.getByNameLabel(connection, name); - // Check if VMs can be found by label. - if (vms == null) { - throw new CloudRuntimeException("Couldn't find VMs by label " + name + " on the destination host."); - } - final VM migratedVm = vms.iterator().next(); - - // Check the vm is present on the new host. - if (migratedVm == null) { - throw new CloudRuntimeException("Couldn't find the migrated vm " + name + " on the destination host."); - } - - final Host host = Host.getByUuid(connection, uuid); - migratedVm.setAffinity(connection, host); - - // Volume paths would have changed. Return that information. - final List<VolumeObjectTO> volumeToSet = xenServer610Resource.getUpdatedVolumePathsOfMigratedVm(connection, migratedVm, vmSpec.getDisks()); - - return new MigrateWithStorageCompleteAnswer(command, volumeToSet); - } catch (final CloudRuntimeException e) { - s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); - return new MigrateWithStorageCompleteAnswer(command, e); - } catch (final Exception e) { - s_logger.error("Migration of vm " + name + " with storage failed due to " + e.toString(), e); - return new MigrateWithStorageCompleteAnswer(command, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageReceiveCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageReceiveCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageReceiveCommandWrapper.java deleted file mode 100644 index 57f5851..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageReceiveCommandWrapper.java +++ /dev/null @@ -1,91 +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.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.MigrateWithStorageReceiveAnswer; -import com.cloud.agent.api.MigrateWithStorageReceiveCommand; -import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.StorageFilerTO; -import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.agent.api.to.VolumeTO; -import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; -import com.cloud.hypervisor.xenserver.resource.XsHost; -import com.cloud.hypervisor.xenserver.resource.XsLocalNetwork; -import com.cloud.network.Networks.TrafficType; -import com.cloud.resource.CommandWrapper; -import com.cloud.utils.exception.CloudRuntimeException; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Host; -import com.xensource.xenapi.Network; -import com.xensource.xenapi.SR; - -public final class XenServer610MigrateWithStorageReceiveCommandWrapper extends CommandWrapper<MigrateWithStorageReceiveCommand, Answer, XenServer610Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageReceiveCommandWrapper.class); - - @Override - public Answer execute(final MigrateWithStorageReceiveCommand command, final XenServer610Resource xenServer610Resource) { - final Connection connection = xenServer610Resource.getConnection(); - final VirtualMachineTO vmSpec = command.getVirtualMachine(); - final Map<VolumeTO, StorageFilerTO> volumeToFiler = command.getVolumeToFiler(); - - try { - // Get a map of all the SRs to which the vdis will be migrated. - final Map<VolumeTO, Object> volumeToSr = new HashMap<VolumeTO, Object>(); - for (final Map.Entry<VolumeTO, StorageFilerTO> entry : volumeToFiler.entrySet()) { - final StorageFilerTO storageFiler = entry.getValue(); - final SR sr = xenServer610Resource.getStorageRepository(connection, storageFiler.getUuid()); - volumeToSr.put(entry.getKey(), sr); - } - - // Get the list of networks to which the vifs will attach. - final Map<NicTO, Object> nicToNetwork = new HashMap<NicTO, Object>(); - for (final NicTO nicTo : vmSpec.getNics()) { - final Network network = xenServer610Resource.getNetwork(connection, nicTo); - nicToNetwork.put(nicTo, network); - } - - final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null); - final Network network = nativeNetworkForTraffic.getNetwork(); - final XsHost xsHost = xenServer610Resource.getHost(); - final String uuid = xsHost.getUuid(); - - final Map<String, String> other = new HashMap<String, String>(); - other.put("live", "true"); - - final Host host = Host.getByUuid(connection, uuid); - final Map<String, String> token = host.migrateReceive(connection, network, other); - - return new MigrateWithStorageReceiveAnswer(command, volumeToSr, nicToNetwork, token); - } catch (final CloudRuntimeException e) { - s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); - return new MigrateWithStorageReceiveAnswer(command, e); - } catch (final Exception e) { - s_logger.error("Migration of vm " + vmSpec.getName() + " with storage failed due to " + e.toString(), e); - return new MigrateWithStorageReceiveAnswer(command, e); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageSendCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageSendCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageSendCommandWrapper.java deleted file mode 100644 index 267f528..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer610MigrateWithStorageSendCommandWrapper.java +++ /dev/null @@ -1,143 +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.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.MigrateWithStorageSendAnswer; -import com.cloud.agent.api.MigrateWithStorageSendCommand; -import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.agent.api.to.VolumeTO; -import com.cloud.hypervisor.xenserver.resource.XenServer610Resource; -import com.cloud.resource.CommandWrapper; -import com.cloud.utils.exception.CloudRuntimeException; -import com.xensource.xenapi.Connection; -import com.xensource.xenapi.Network; -import com.xensource.xenapi.SR; -import com.xensource.xenapi.Task; -import com.xensource.xenapi.Types; -import com.xensource.xenapi.VDI; -import com.xensource.xenapi.VIF; -import com.xensource.xenapi.VM; - -public final class XenServer610MigrateWithStorageSendCommandWrapper extends CommandWrapper<MigrateWithStorageSendCommand, Answer, XenServer610Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer610MigrateWithStorageSendCommandWrapper.class); - - @Override - public Answer execute(final MigrateWithStorageSendCommand command, final XenServer610Resource xenServer610Resource) { - final Connection connection = xenServer610Resource.getConnection(); - - final VirtualMachineTO vmSpec = command.getVirtualMachine(); - final Map<VolumeTO, Object> volumeToSr = command.getVolumeToSr(); - final Map<NicTO, Object> nicToNetwork = command.getNicToNetwork(); - final Map<String, String> token = command.getToken(); - final String vmName = vmSpec.getName(); - - Task task = null; - try { - - final Map<String, String> other = new HashMap<String, String>(); - other.put("live", "true"); - - // Create the vdi map which tells what volumes of the vm need to go - // on which sr on the destination. - final Map<VDI, SR> vdiMap = new HashMap<VDI, SR>(); - for (final Map.Entry<VolumeTO, Object> entry : volumeToSr.entrySet()) { - final Object srObj = entry.getValue(); - if (srObj instanceof SR) { - final SR sr = (SR) srObj; - final VolumeTO volume = entry.getKey(); - final VDI vdi = xenServer610Resource.getVDIbyUuid(connection, volume.getPath()); - vdiMap.put(vdi, sr); - } else { - throw new CloudRuntimeException("The object " + srObj + " passed is not of type SR."); - } - } - - final Set<VM> vms = VM.getByNameLabel(connection, vmSpec.getName()); - VM vmToMigrate = null; - if (vms != null) { - vmToMigrate = vms.iterator().next(); - } - - // Create the vif map. - final Map<VIF, Network> vifMap = new HashMap<VIF, Network>(); - for (final Map.Entry<NicTO, Object> entry : nicToNetwork.entrySet()) { - Object networkObj = entry.getValue(); - if (networkObj instanceof Network) { - final Network network = (Network) networkObj; - NicTO nic = entry.getKey(); - final VIF vif = xenServer610Resource.getVifByMac(connection, vmToMigrate, nic.getMac()); - vifMap.put(vif, network); - } else { - throw new CloudRuntimeException("The object " + networkObj + " passed is not of type Network."); - } - } - - // Check migration with storage is possible. - task = vmToMigrate.assertCanMigrateAsync(connection, token, true, vdiMap, vifMap, other); - try { - // poll every 1 seconds. - final long timeout = xenServer610Resource.getMigrateWait() * 1000L; - xenServer610Resource.waitForTask(connection, task, 1000, timeout); - xenServer610Resource.checkForSuccess(connection, task); - } catch (final Types.HandleInvalid e) { - s_logger.error("Error while checking if vm " + vmName + " can be migrated.", e); - throw new CloudRuntimeException("Error while checking if vm " + vmName + " can be migrated.", e); - } - - // Migrate now. - task = vmToMigrate.migrateSendAsync(connection, token, true, vdiMap, vifMap, other); - try { - // poll every 1 seconds. - final long timeout = xenServer610Resource.getMigrateWait() * 1000L; - xenServer610Resource.waitForTask(connection, task, 1000, timeout); - xenServer610Resource.checkForSuccess(connection, task); - } catch (final Types.HandleInvalid e) { - s_logger.error("Error while migrating vm " + vmName, e); - throw new CloudRuntimeException("Error while migrating vm " + vmName, e); - } - - final Set<VolumeTO> volumeToSet = null; - return new MigrateWithStorageSendAnswer(command, volumeToSet); - } catch (final CloudRuntimeException e) { - s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); - return new MigrateWithStorageSendAnswer(command, e); - } catch (final Exception e) { - s_logger.error("Migration of vm " + vmName + " with storage failed due to " + e.toString(), e); - return new MigrateWithStorageSendAnswer(command, e); - } finally { - if (task != null) { - try { - task.destroy(connection); - } catch (final Exception e) { - s_logger.debug("Unable to destroy task " + task.toString() + " on host " + xenServer610Resource.getHost().getUuid() + " due to " + e.toString()); - } - } - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer620SP1GetGPUStatsCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer620SP1GetGPUStatsCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer620SP1GetGPUStatsCommandWrapper.java deleted file mode 100644 index e177256..0000000 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/XenServer620SP1GetGPUStatsCommandWrapper.java +++ /dev/null @@ -1,51 +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.HashMap; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.GetGPUStatsAnswer; -import com.cloud.agent.api.GetGPUStatsCommand; -import com.cloud.agent.api.VgpuTypesInfo; -import com.cloud.hypervisor.xenserver.resource.XenServer620SP1Resource; -import com.cloud.resource.CommandWrapper; -import com.xensource.xenapi.Connection; - -public final class XenServer620SP1GetGPUStatsCommandWrapper extends CommandWrapper<GetGPUStatsCommand, Answer, XenServer620SP1Resource> { - - private static final Logger s_logger = Logger.getLogger(XenServer620SP1GetGPUStatsCommandWrapper.class); - - @Override - public Answer execute(final GetGPUStatsCommand command, final XenServer620SP1Resource xenServer620SP1Resource) { - final Connection conn = xenServer620SP1Resource.getConnection(); - HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = new HashMap<String, HashMap<String, VgpuTypesInfo>>(); - try { - groupDetails = xenServer620SP1Resource.getGPUGroupDetails(conn); - } catch (final Exception e) { - final String msg = "Unable to get GPU stats" + e.toString(); - s_logger.warn(msg, e); - return new GetGPUStatsAnswer(command, false, msg); - } - return new GetGPUStatsAnswer(command, groupDetails); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cloudstack/blob/7ff1a81c/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java ---------------------------------------------------------------------- diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java new file mode 100644 index 0000000..e034021 --- /dev/null +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xcp/XcpServerNetworkUsageCommandWrapper.java @@ -0,0 +1,54 @@ +// +// 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.xcp; + +import org.apache.log4j.Logger; + +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.NetworkUsageAnswer; +import com.cloud.agent.api.NetworkUsageCommand; +import com.cloud.hypervisor.xenserver.resource.XcpServerResource; +import com.cloud.resource.CommandWrapper; +import com.cloud.resource.ResourceWrapper; +import com.xensource.xenapi.Connection; + +@ResourceWrapper(handles = NetworkUsageCommand.class) +public final class XcpServerNetworkUsageCommandWrapper extends CommandWrapper<NetworkUsageCommand, Answer, XcpServerResource> { + + private static final Logger s_logger = Logger.getLogger(XcpServerNetworkUsageCommandWrapper.class); + + @Override + public Answer execute(final NetworkUsageCommand command, final XcpServerResource xcpServerResource) { + try { + final Connection conn = xcpServerResource.getConnection(); + if (command.getOption() != null && command.getOption().equals("create")) { + final String result = xcpServerResource.networkUsage(conn, command.getPrivateIP(), "create", null); + final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, result, 0L, 0L); + return answer; + } + final long[] stats = xcpServerResource.getNetworkStats(conn, command.getPrivateIP()); + final NetworkUsageAnswer answer = new NetworkUsageAnswer(command, "", stats[0], stats[1]); + return answer; + } catch (final Exception ex) { + s_logger.warn("Failed to get network usage stats due to ", ex); + return new NetworkUsageAnswer(command, ex); + } + } +} \ No newline at end of file
