diff --git a/agent/src/com/cloud/agent/resource/DummyResource.java b/agent/src/com/cloud/agent/resource/DummyResource.java index 37a8b3d67e7..c7849830f0a 100755 --- a/agent/src/com/cloud/agent/resource/DummyResource.java +++ b/agent/src/com/cloud/agent/resource/DummyResource.java @@ -29,12 +29,12 @@ import com.cloud.agent.api.Answer; import com.cloud.agent.api.CheckNetworkAnswer; import com.cloud.agent.api.CheckNetworkCommand; import com.cloud.agent.api.Command; +import com.cloud.agent.api.HostVmStateReportEntry; import com.cloud.agent.api.PingCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; import com.cloud.agent.api.StartupStorageCommand; import com.cloud.agent.api.StoragePoolInfo; -import com.cloud.agent.api.StartupRoutingCommand.VmState; import com.cloud.host.Host; import com.cloud.host.Host.Type; import com.cloud.hypervisor.Hypervisor.HypervisorType; @@ -162,7 +162,7 @@ public class DummyResource implements ServerResource { @Override public StartupCommand[] initialize() { - Map changes = null; + Map changes = null; final List info = getHostInfo(); diff --git a/api/src/com/cloud/agent/api/CheckVirtualMachineAnswer.java b/api/src/com/cloud/agent/api/CheckVirtualMachineAnswer.java index 3f0ffdbcea1..cebdfd1bbe7 100644 --- a/api/src/com/cloud/agent/api/CheckVirtualMachineAnswer.java +++ b/api/src/com/cloud/agent/api/CheckVirtualMachineAnswer.java @@ -16,24 +16,24 @@ // under the License. package com.cloud.agent.api; -import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.PowerState; public class CheckVirtualMachineAnswer extends Answer { Integer vncPort; - State state; + PowerState state; protected CheckVirtualMachineAnswer() { } - public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, State state, Integer vncPort, String detail) { + public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, PowerState state, Integer vncPort, String detail) { super(cmd, true, detail); this.state = state; this.vncPort = vncPort; } - public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, State state, Integer vncPort) { + public CheckVirtualMachineAnswer(CheckVirtualMachineCommand cmd, PowerState state, Integer vncPort) { this(cmd, state, vncPort, null); } @@ -46,7 +46,7 @@ public class CheckVirtualMachineAnswer extends Answer { return vncPort; } - public State getState() { + public PowerState getState() { return state; } } diff --git a/api/src/com/cloud/agent/api/ClusterSyncAnswer.java b/api/src/com/cloud/agent/api/ClusterSyncAnswer.java index 99fee2a9dd1..44108fe9208 100644 --- a/api/src/com/cloud/agent/api/ClusterSyncAnswer.java +++ b/api/src/com/cloud/agent/api/ClusterSyncAnswer.java @@ -19,11 +19,11 @@ package com.cloud.agent.api; import java.util.HashMap; import com.cloud.utils.Pair; -import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.PowerState; public class ClusterSyncAnswer extends Answer { private long _clusterId; - private HashMap> _newStates; + private HashMap> _newStates; private boolean _isExecuted=false; // this is here because a cron command answer is being sent twice @@ -38,7 +38,7 @@ public class ClusterSyncAnswer extends Answer { } - public ClusterSyncAnswer(long clusterId, HashMap> newStates){ + public ClusterSyncAnswer(long clusterId, HashMap> newStates){ _clusterId = clusterId; _newStates = newStates; result = true; @@ -48,7 +48,7 @@ public class ClusterSyncAnswer extends Answer { return _clusterId; } - public HashMap> getNewStates() { + public HashMap> getNewStates() { return _newStates; } diff --git a/api/src/com/cloud/agent/api/HostVmStateReportEntry.java b/api/src/com/cloud/agent/api/HostVmStateReportEntry.java new file mode 100644 index 00000000000..7bcb50f361a --- /dev/null +++ b/api/src/com/cloud/agent/api/HostVmStateReportEntry.java @@ -0,0 +1,41 @@ +// 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.agent.api; + +import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.PowerState; + +public class HostVmStateReportEntry { + VirtualMachine.PowerState state; + String host; + + public HostVmStateReportEntry() { + } + + public HostVmStateReportEntry(PowerState state, String host) { + this.state = state; + this.host = host; + } + + public PowerState getState() { + return state; + } + + public String getHost() { + return host; + } +} diff --git a/api/src/com/cloud/agent/api/PingRoutingCommand.java b/api/src/com/cloud/agent/api/PingRoutingCommand.java index e25ac62786f..8b8b5542ac2 100755 --- a/api/src/com/cloud/agent/api/PingRoutingCommand.java +++ b/api/src/com/cloud/agent/api/PingRoutingCommand.java @@ -19,22 +19,22 @@ package com.cloud.agent.api; import java.util.Map; import com.cloud.host.Host; -import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.PowerState; public class PingRoutingCommand extends PingCommand { - Map newStates; + Map newStates; boolean _gatewayAccessible = true; boolean _vnetAccessible = true; protected PingRoutingCommand() { } - public PingRoutingCommand(Host.Type type, long id, Map states) { + public PingRoutingCommand(Host.Type type, long id, Map states) { super(type, id); this.newStates = states; } - public Map getNewStates() { + public Map getNewStates() { return newStates; } diff --git a/api/src/com/cloud/agent/api/PingRoutingWithNwGroupsCommand.java b/api/src/com/cloud/agent/api/PingRoutingWithNwGroupsCommand.java index 51226bc36c1..bb183bd5c72 100644 --- a/api/src/com/cloud/agent/api/PingRoutingWithNwGroupsCommand.java +++ b/api/src/com/cloud/agent/api/PingRoutingWithNwGroupsCommand.java @@ -21,7 +21,7 @@ import java.util.Map; import com.cloud.host.Host; import com.cloud.utils.Pair; -import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.PowerState; public class PingRoutingWithNwGroupsCommand extends PingRoutingCommand { @@ -31,7 +31,7 @@ public class PingRoutingWithNwGroupsCommand extends PingRoutingCommand { super(); } - public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map states, HashMap> nwGrpStates) { + public PingRoutingWithNwGroupsCommand(Host.Type type, long id, Map states, HashMap> nwGrpStates) { super(type, id, states); newGroupStates = nwGrpStates; } diff --git a/api/src/com/cloud/agent/api/PingRoutingWithOvsCommand.java b/api/src/com/cloud/agent/api/PingRoutingWithOvsCommand.java index d44987b20fd..f87bed8b5de 100644 --- a/api/src/com/cloud/agent/api/PingRoutingWithOvsCommand.java +++ b/api/src/com/cloud/agent/api/PingRoutingWithOvsCommand.java @@ -21,7 +21,7 @@ import java.util.Map; import com.cloud.host.Host; import com.cloud.utils.Pair; -import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.PowerState; public class PingRoutingWithOvsCommand extends PingRoutingCommand { List> states; @@ -31,7 +31,7 @@ public class PingRoutingWithOvsCommand extends PingRoutingCommand { } public PingRoutingWithOvsCommand(Host.Type type, long id, - Map states, List> ovsStates) { + Map states, List> ovsStates) { super(type, id, states); this.states = ovsStates; } diff --git a/api/src/com/cloud/agent/api/StartupRoutingCommand.java b/api/src/com/cloud/agent/api/StartupRoutingCommand.java index 5961ab0017e..31db26f375d 100755 --- a/api/src/com/cloud/agent/api/StartupRoutingCommand.java +++ b/api/src/com/cloud/agent/api/StartupRoutingCommand.java @@ -23,32 +23,16 @@ import com.cloud.host.Host; import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.network.Networks.RouterPrivateIpStrategy; import com.cloud.utils.Pair; -import com.cloud.vm.VirtualMachine.State; +import com.cloud.vm.VirtualMachine.PowerState; public class StartupRoutingCommand extends StartupCommand { - public static class VmState { - State state; - String host; - public VmState() { - } - public VmState(State state, String host) { - this.state = state; - this.host = host; - } - public State getState() { - return state; - } - public String getHost() { - return host; - } - } int cpus; long speed; long memory; long dom0MinMemory; boolean poolSync; - Map vms; - HashMap> _clusterVMStates; + Map vms; + HashMap> _clusterVMStates; String caps; String pool; HypervisorType hypervisorType; @@ -59,7 +43,6 @@ public class StartupRoutingCommand extends StartupCommand { super(Host.Type.Routing); hostDetails = new HashMap(); getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), RouterPrivateIpStrategy.DcGlobal.toString()); - } public StartupRoutingCommand(int cpus, @@ -69,8 +52,9 @@ public class StartupRoutingCommand extends StartupCommand { String caps, HypervisorType hypervisorType, RouterPrivateIpStrategy privIpStrategy, - Map vms) { - this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, vms); + Map vms) { + + this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, vms); getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString()); } @@ -81,9 +65,10 @@ public class StartupRoutingCommand extends StartupCommand { String caps, HypervisorType hypervisorType, RouterPrivateIpStrategy privIpStrategy) { -this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, new HashMap(), new HashMap()); -getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString()); -} + + this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, new HashMap(), new HashMap()); + getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStrategy.toString()); + } public StartupRoutingCommand(int cpus, long speed, @@ -92,7 +77,7 @@ getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStr final String caps, final HypervisorType hypervisorType, final Map hostDetails, - Map vms) { + Map vms) { super(Host.Type.Routing); this.cpus = cpus; this.speed = speed; @@ -107,29 +92,29 @@ getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStr public StartupRoutingCommand(int cpus2, long speed2, long memory2, long dom0MinMemory2, String caps2, HypervisorType hypervisorType2, - Map vms2) { + Map vms2) { this(cpus2, speed2, memory2, dom0MinMemory2, caps2, hypervisorType2, new HashMap(), vms2); } - public StartupRoutingCommand(int cpus, long speed, long memory, long dom0MinMemory, final String caps, final HypervisorType hypervisorType, final Map hostDetails, Map vms, String hypervisorVersion) { + public StartupRoutingCommand(int cpus, long speed, long memory, long dom0MinMemory, final String caps, final HypervisorType hypervisorType, final Map hostDetails, Map vms, String hypervisorVersion) { this(cpus, speed, memory, dom0MinMemory, caps, hypervisorType, hostDetails, vms); this.hypervisorVersion = hypervisorVersion; } - public void setChanges(Map vms) { + public void setChanges(Map vms) { this.vms = vms; } - public void setStateChanges(Map vms) { + public void setStateChanges(Map vms) { for( String vm_name : vms.keySet() ) { if( this.vms == null ) { - this.vms = new HashMap(); + this.vms = new HashMap(); } - this.vms.put(vm_name, new VmState(vms.get(vm_name), null)); + this.vms.put(vm_name, new HostVmStateReportEntry(vms.get(vm_name), null)); } } - public void setClusterVMStateChanges(HashMap> allStates){ + public void setClusterVMStateChanges(HashMap> allStates){ _clusterVMStates = allStates; } @@ -153,11 +138,11 @@ getHostDetails().put(RouterPrivateIpStrategy.class.getCanonicalName(), privIpStr return dom0MinMemory; } - public Map getVmStates() { + public Map getVmStates() { return vms; } - public HashMap> getClusterVMStateChanges() { + public HashMap> getClusterVMStateChanges() { return _clusterVMStates; } diff --git a/core/src/com/cloud/hypervisor/hyperv/resource/HypervResource.java b/core/src/com/cloud/hypervisor/hyperv/resource/HypervResource.java index 0f9b3dd9c6b..91ba4f68f48 100755 --- a/core/src/com/cloud/hypervisor/hyperv/resource/HypervResource.java +++ b/core/src/com/cloud/hypervisor/hyperv/resource/HypervResource.java @@ -109,6 +109,7 @@ import com.cloud.storage.template.TemplateInfo; import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.vm.DiskProfile; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.google.gson.Gson; @@ -900,8 +901,8 @@ public class HypervResource extends ServerResourceBase implements ServerResource return hypervHosts; } - protected HashMap sync() { - HashMap changes = new HashMap(); + protected HashMap sync() { + HashMap changes = new HashMap(); try { synchronized (_vms) { @@ -916,9 +917,9 @@ public class HypervResource extends ServerResourceBase implements ServerResource @Override public PingCommand getCurrentStatus(long id) { - HashMap newStates = sync(); + HashMap newStates = sync(); if (newStates == null) { - newStates = new HashMap(); + newStates = new HashMap(); } PingRoutingCommand cmd = new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id, newStates); return cmd; diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalResourceBase.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalResourceBase.java index 86e41fea070..20554e6b683 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalResourceBase.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BareMetalResourceBase.java @@ -76,6 +76,7 @@ import com.cloud.utils.script.Script2; import com.cloud.utils.script.Script2.ParamType; import com.cloud.vm.VMInstanceVO; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.VMInstanceDao; @@ -305,13 +306,13 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource } } - protected Map fullSync() { - Map states = new HashMap(); + protected Map fullSync() { + Map states = new HashMap(); if (hostId != null) { vmDao = ComponentContext.getComponent(VMInstanceDao.class); final List vms = vmDao.listByHostId(hostId); for (VMInstanceVO vm : vms) { - states.put(vm.getInstanceName(), vm.getState()); + states.put(vm.getInstanceName(), vm.getState() == State.Running ? PowerState.PowerOn : PowerState.PowerOff); } } /* @@ -402,7 +403,7 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource } protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) { - return new CheckVirtualMachineAnswer(cmd, State.Stopped, null); + return new CheckVirtualMachineAnswer(cmd, PowerState.PowerOff, null); } protected Answer execute(IpmiBootorResetCommand cmd) { @@ -554,8 +555,8 @@ public class BareMetalResourceBase extends ManagerBase implements ServerResource } } - protected HashMap deltaSync() { - final HashMap changes = new HashMap(); + protected HashMap deltaSync() { + final HashMap changes = new HashMap(); /* * Disable sync until we find a way that only tracks status but not does * action diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java index 4496d5d0e70..bd46dd296c9 100644 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpResourceBase.java @@ -44,6 +44,7 @@ import com.cloud.resource.ServerResource; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.trilead.ssh2.SCPClient; @@ -142,7 +143,7 @@ public class BaremetalDhcpResourceBase extends ManagerBase implements ServerReso @Override public PingCommand getCurrentStatus(long id) { //TODO: check server - return new PingRoutingCommand(getType(), id, new HashMap()); + return new PingRoutingCommand(getType(), id, new HashMap()); } protected ReadyAnswer execute(ReadyCommand cmd) { diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java index a27a6f26896..0fd1a0824af 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDhcpdResource.java @@ -36,6 +36,7 @@ import com.cloud.agent.api.PingRoutingCommand; import com.cloud.agent.api.routing.DhcpEntryCommand; import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.trilead.ssh2.SCPClient; @@ -105,7 +106,7 @@ public class BaremetalDhcpdResource extends BaremetalDhcpResourceBase { return null; } else { SSHCmdHelper.releaseSshConnection(sshConnection); - return new PingRoutingCommand(getType(), id, new HashMap()); + return new PingRoutingCommand(getType(), id, new HashMap()); } } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java index 6841c525107..18b81673858 100644 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalDnsmasqResource.java @@ -37,6 +37,7 @@ import com.cloud.agent.api.PingRoutingCommand; import com.cloud.agent.api.routing.DhcpEntryCommand; import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.trilead.ssh2.SCPClient; @@ -96,7 +97,7 @@ public class BaremetalDnsmasqResource extends BaremetalDhcpResourceBase { return null; } else { SSHCmdHelper.releaseSshConnection(sshConnection); - return new PingRoutingCommand(getType(), id, new HashMap()); + return new PingRoutingCommand(getType(), id, new HashMap()); } } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java index 7a7a5153e5c..32165890b32 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java @@ -35,6 +35,7 @@ import com.cloud.agent.api.routing.VmDataCommand; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.trilead.ssh2.SCPClient; @@ -106,7 +107,7 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase { return null; } else { SSHCmdHelper.releaseSshConnection(sshConnection); - return new PingRoutingCommand(getType(), id, new HashMap()); + return new PingRoutingCommand(getType(), id, new HashMap()); } } diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java index 2fb54154489..e907a58f910 100755 --- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java +++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalPingPxeResource.java @@ -40,6 +40,7 @@ import com.cloud.agent.api.baremetal.prepareCreateTemplateCommand; import com.cloud.agent.api.routing.VmDataCommand; import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.trilead.ssh2.SCPClient; @@ -142,7 +143,7 @@ public class BaremetalPingPxeResource extends BaremetalPxeResourceBase { return null; } else { SSHCmdHelper.releaseSshConnection(sshConnection); - return new PingRoutingCommand(getType(), id, new HashMap()); + return new PingRoutingCommand(getType(), id, new HashMap()); } } diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 362e0a53e53..d870e7bc72b 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -227,6 +227,7 @@ import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.Script; import com.cloud.vm.DiskProfile; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineName; @@ -352,21 +353,21 @@ ServerResource { protected int _timeout; protected int _cmdsTimeout; protected int _stopTimeout; - protected static HashMap s_statesTable; + protected static HashMap s_statesTable; static { - s_statesTable = new HashMap(); + s_statesTable = new HashMap(); s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTOFF, - State.Stopped); + PowerState.PowerOff); s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_PAUSED, - State.Running); + PowerState.PowerOn); s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_RUNNING, - State.Running); + PowerState.PowerOn); s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_BLOCKED, - State.Running); + PowerState.PowerOn); s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_NOSTATE, - State.Unknown); + PowerState.PowerUnknown); s_statesTable.put(DomainInfo.DomainState.VIR_DOMAIN_SHUTDOWN, - State.Stopping); + PowerState.PowerOff); } protected HashMap _vms = new HashMap(20); @@ -2533,19 +2534,19 @@ ServerResource { return new ReadyAnswer(cmd); } - protected State convertToState(DomainInfo.DomainState ps) { - final State state = s_statesTable.get(ps); - return state == null ? State.Unknown : state; + protected PowerState convertToState(DomainInfo.DomainState ps) { + final PowerState state = s_statesTable.get(ps); + return state == null ? PowerState.PowerUnknown : state; } - protected State getVmState(Connect conn, final String vmName) { + protected PowerState getVmState(Connect conn, final String vmName) { int retry = 3; Domain vms = null; while (retry-- > 0) { try { vms = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName .getBytes())); - State s = convertToState(vms.getInfo().state); + PowerState s = convertToState(vms.getInfo().state); return s; } catch (final LibvirtException e) { s_logger.warn("Can't get vm state " + vmName + e.getMessage() @@ -2560,15 +2561,15 @@ ServerResource { } } } - return State.Stopped; + return PowerState.PowerOff; } private Answer execute(CheckVirtualMachineCommand cmd) { try { Connect conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName()); - final State state = getVmState(conn, cmd.getVmName()); + final PowerState state = getVmState(conn, cmd.getVmName()); Integer vncPort = null; - if (state == State.Running) { + if (state == PowerState.PowerOn) { vncPort = getVncPort(conn, cmd.getVmName()); synchronized (_vms) { @@ -3584,7 +3585,7 @@ ServerResource { @Override public PingCommand getCurrentStatus(long id) { - final HashMap newStates = sync(); + final HashMap newStates = sync(); if (!_can_bridge_firewall) { return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id, @@ -3615,7 +3616,7 @@ ServerResource { @Override public StartupCommand[] initialize() { - Map changes = null; + Map changes = null; synchronized (_vms) { _vms.clear(); @@ -3663,7 +3664,16 @@ ServerResource { return new StartupCommand[] { cmd }; } } - + + protected HashMap sync() { + HashMap newStates = getAllVms(); + if(newStates != null) + return newStates; + + return new HashMap(); + } + +/* protected HashMap sync() { HashMap newStates; HashMap oldStates = null; @@ -3775,8 +3785,8 @@ ServerResource { return changes; } - - protected State getRealPowerState(String vm) { +*/ + protected PowerState getRealPowerState(String vm) { int i = 0; s_logger.trace("Checking on the HALTED State"); Domain dm = null; @@ -3809,7 +3819,7 @@ ServerResource { s_logger.trace("Ignoring InterruptedException.", e); } } - return State.Stopped; + return PowerState.PowerOff; } protected List getAllVmNames(Connect conn) { @@ -3852,8 +3862,8 @@ ServerResource { return la; } - private HashMap getAllVms() { - final HashMap vmStates = new HashMap(); + private HashMap getAllVms() { + final HashMap vmStates = new HashMap(); Connect conn = null; try { @@ -3873,8 +3883,8 @@ ServerResource { return vmStates; } - private HashMap getAllVms(Connect conn) { - final HashMap vmStates = new HashMap(); + private HashMap getAllVms(Connect conn) { + final HashMap vmStates = new HashMap(); String[] vms = null; int[] ids = null; @@ -3899,7 +3909,7 @@ ServerResource { DomainInfo.DomainState ps = dm.getInfo().state; - final State state = convertToState(ps); + final PowerState state = convertToState(ps); s_logger.trace("VM " + dm.getName() + ": powerstate = " + ps + "; vm state=" + state.toString()); @@ -3925,7 +3935,7 @@ ServerResource { .getBytes())); DomainInfo.DomainState ps = dm.getInfo().state; - final State state = convertToState(ps); + final PowerState state = convertToState(ps); String vmName = dm.getName(); s_logger.trace("VM " + vmName + ": powerstate = " + ps + "; vm state=" + state.toString()); diff --git a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java index a626e31f458..089d46d0a8e 100755 --- a/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java +++ b/plugins/hypervisors/ovm/src/com/cloud/ovm/hypervisor/OvmResourceBase.java @@ -123,6 +123,7 @@ import com.cloud.utils.script.Script; import com.cloud.utils.ssh.SSHCmdHelper; import com.cloud.vm.DiskProfile; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.trilead.ssh2.SCPClient; import com.xensource.xenapi.Types.XenAPIException; @@ -147,16 +148,16 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { static boolean _isHeartBeat = false; List _bridges = null; protected HashMap _vms = new HashMap(50); - static HashMap _stateMaps; + static HashMap _stateMaps; private final Map> _vmNetworkStats= new ConcurrentHashMap>(); private static String _ovsAgentPath = "/opt/ovs-agent-latest"; static { - _stateMaps = new HashMap(); - _stateMaps.put("RUNNING", State.Running); - _stateMaps.put("DOWN", State.Stopped); - _stateMaps.put("ERROR", State.Error); - _stateMaps.put("SUSPEND", State.Stopped); + _stateMaps = new HashMap(); + _stateMaps.put("RUNNING", PowerState.PowerOn); + _stateMaps.put("DOWN", PowerState.PowerOff); + _stateMaps.put("ERROR", PowerState.PowerUnknown); + _stateMaps.put("SUSPEND", PowerState.PowerOn); } @Override @@ -371,7 +372,7 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { try { StartupRoutingCommand cmd = new StartupRoutingCommand(); fillHostInfo(cmd); - Map changes = null; + Map changes = null; synchronized (_vms) { _vms.clear(); changes = sync(); @@ -389,7 +390,7 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { public PingCommand getCurrentStatus(long id) { try { OvmHost.ping(_conn); - HashMap newStates = sync(); + HashMap newStates = sync(); return new PingRoutingCommand(getType(), id, newStates); } catch (XmlRpcException e) { s_logger.debug("Check agent status failed", e); @@ -760,25 +761,37 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { } } - private State toState(String vmName, String s) { - State state = _stateMaps.get(s); + private PowerState toState(String vmName, String s) { + PowerState state = _stateMaps.get(s); if (state == null) { s_logger.debug("Unkown state " + s + " for " + vmName); - state = State.Unknown; + state = PowerState.PowerUnknown; } return state; } - protected HashMap getAllVms() throws XmlRpcException { - final HashMap vmStates = new HashMap(); + protected HashMap getAllVms() throws XmlRpcException { + final HashMap vmStates = new HashMap(); Map vms = OvmHost.getAllVms(_conn); for (final Map.Entry entry : vms.entrySet()) { - State state = toState(entry.getKey(), entry.getValue()); + PowerState state = toState(entry.getKey(), entry.getValue()); vmStates.put(entry.getKey(), state); } return vmStates; } + protected HashMap sync() { + try { + HashMap newStates = getAllVms(); + + if(newStates != null) + return newStates; + } catch(Exception e) { + } + return new HashMap(); + } + +/* protected HashMap sync() { HashMap newStates; HashMap oldStates = null; @@ -806,13 +819,6 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { s_logger.trace("VM " + vm + ": ovm has state " + newState + " and we have state " + (oldState != null ? oldState.toString() : "null")); } - /* - * TODO: what is migrating ??? if - * (vm.startsWith("migrating")) { - * s_logger.debug("Migrating from xen detected. Skipping"); - * continue; } - */ - if (oldState == null) { _vms.put(vm, newState); s_logger.debug("Detecting a new state but couldn't find a old state so adding it to the changes: " @@ -879,6 +885,7 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { return null; } } +*/ protected GetStorageStatsAnswer execute(final GetStorageStatsCommand cmd) { try { @@ -1001,14 +1008,14 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { try { Map res = OvmVm.register(_conn, vmName); Integer vncPort = Integer.parseInt(res.get("vncPort")); - HashMap states = getAllVms(); - State vmState = states.get(vmName); + HashMap states = getAllVms(); + PowerState vmState = states.get(vmName); if (vmState == null) { s_logger.warn("Check state of " + vmName + " return null in CheckVirtualMachineCommand"); - vmState = State.Stopped; + vmState = PowerState.PowerOff; } - if (vmState == State.Running) { + if (vmState == PowerState.PowerOn) { synchronized (_vms) { _vms.put(vmName, State.Running); } @@ -1017,7 +1024,7 @@ public class OvmResourceBase implements ServerResource, HypervisorResource { return new CheckVirtualMachineAnswer(cmd, vmState, vncPort); } catch (Exception e) { s_logger.debug("Check migration for " + vmName + " failed", e); - return new CheckVirtualMachineAnswer(cmd, State.Stopped, null); + return new CheckVirtualMachineAnswer(cmd, PowerState.PowerOff, null); } } diff --git a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java index c0ccbe43978..a83ffac7428 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java +++ b/plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java @@ -39,6 +39,7 @@ import com.cloud.utils.Ternary; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -334,7 +335,7 @@ public class MockVmManagerImpl extends ManagerBase implements MockVmManager { } txn.commit(); - return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort()); + return new CheckVirtualMachineAnswer(cmd, vm.getState() == State.Running ? PowerState.PowerOn : PowerState.PowerOff, vm.getVncPort()); } catch (Exception ex) { txn.rollback(); throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex); diff --git a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java index 46df50c2133..58840c8069e 100644 --- a/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java +++ b/plugins/hypervisors/simulator/src/com/cloud/resource/AgentRoutingResource.java @@ -53,6 +53,7 @@ import com.cloud.simulator.MockVMVO; import com.cloud.storage.Storage.StorageResourceType; import com.cloud.storage.template.TemplateInfo; import com.cloud.utils.Pair; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; public class AgentRoutingResource extends AgentStorageResource { @@ -112,17 +113,29 @@ public class AgentRoutingResource extends AgentStorageResource { _vms.putAll(_simMgr.getVmStates(hostGuid)); } } - final HashMap newStates = sync(); + final HashMap newStates = sync(); HashMap> nwGrpStates = _simMgr.syncNetworkGroups(hostGuid); return new PingRoutingWithNwGroupsCommand(getType(), id, newStates, nwGrpStates); } + private HashMap getVmStates() { + Map rawStates = _simMgr.getVmStates(this.hostGuid); + if(rawStates != null) { + HashMap states = new HashMap(); + for(Map.Entry entry : rawStates.entrySet()) { + states.put(entry.getKey(), entry.getValue() == State.Running ? PowerState.PowerOn : PowerState.PowerOff); + } + return states; + } + return new HashMap(); + } + @Override public StartupCommand[] initialize() { synchronized (_vms) { _vms.clear(); } - Map changes = _simMgr.getVmStates(this.hostGuid); + Map changes = getVmStates(); Map vmsMaps = _simMgr.getVms(this.hostGuid); totalCpu = agentHost.getCpuCount() * agentHost.getCpuSpeed(); totalMem = agentHost.getMemorySize(); @@ -251,8 +264,8 @@ public class AgentRoutingResource extends AgentStorageResource { protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) { final String vmName = cmd.getVmName(); CheckVirtualMachineAnswer result = (CheckVirtualMachineAnswer)_simMgr.simulate(cmd, hostGuid); - State state = result.getState(); - if (state == State.Running) { + PowerState state = result.getState(); + if (state == PowerState.PowerOn) { synchronized (_vms) { _vms.put(vmName, State.Running); } @@ -276,6 +289,11 @@ public class AgentRoutingResource extends AgentStorageResource { return info; } + protected HashMap sync() { + return this.getVmStates(); + } + +/* protected HashMap sync() { Map newStates; Map oldStates = null; @@ -342,7 +360,7 @@ public class AgentRoutingResource extends AgentStorageResource { return changes; } - +*/ private Answer execute(ShutdownCommand cmd) { this.stopped = true; return new Answer(cmd); diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index 634827b6468..9becd3f6d6e 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -223,6 +223,7 @@ import com.cloud.utils.net.NetUtils; import com.cloud.utils.ssh.SshHelper; import com.cloud.vm.DiskProfile; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.VirtualMachineName; import com.cloud.vm.VmDetailConstants; @@ -314,12 +315,12 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa protected volatile long _cmdSequence = 1; - protected static HashMap s_statesTable; + protected static HashMap s_statesTable; static { - s_statesTable = new HashMap(); - s_statesTable.put(VirtualMachinePowerState.POWERED_ON, State.Running); - s_statesTable.put(VirtualMachinePowerState.POWERED_OFF, State.Stopped); - s_statesTable.put(VirtualMachinePowerState.SUSPENDED, State.Stopped); + s_statesTable = new HashMap(); + s_statesTable.put(VirtualMachinePowerState.POWERED_ON, PowerState.PowerOn); + s_statesTable.put(VirtualMachinePowerState.POWERED_OFF, PowerState.PowerOff); + s_statesTable.put(VirtualMachinePowerState.SUSPENDED, PowerState.PowerOn); } public VmwareResource() { @@ -2082,7 +2083,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); if (vmMo != null) { s_logger.info("VM " + vmName + " already exists, tear down devices for reconfiguration"); - if (getVmState(vmMo) != State.Stopped) + if (getVmState(vmMo) != PowerState.PowerOff) vmMo.safePowerOff(_shutdown_waitMs); vmMo.tearDownDevices(new Class[] { VirtualDisk.class, VirtualEthernetCard.class }); vmMo.ensureScsiDeviceController(); @@ -2098,7 +2099,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa takeVmFromOtherHyperHost(hyperHost, vmName); - if (getVmState(vmMo) != State.Stopped) + if (getVmState(vmMo) != PowerState.PowerOff) vmMo.safePowerOff(_shutdown_waitMs); vmMo.tearDownDevices(new Class[] { VirtualDisk.class, VirtualEthernetCard.class }); vmMo.ensureScsiDeviceController(); @@ -2759,7 +2760,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa HashMap vmStatsMap = null; try { - HashMap newStates = getVmStates(); + HashMap newStates = getVmStates(); List requestedVmNames = cmd.getVmNames(); List vmNames = new ArrayList(); @@ -2833,7 +2834,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa try { vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, "0"); - if (getVmState(vmMo) != State.Stopped) { + if (getVmState(vmMo) != PowerState.PowerOff) { // before we stop VM, remove all possible snapshots on the VM to let // disk chain be collapsed @@ -2948,7 +2949,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } final String vmName = cmd.getVmName(); - State state = State.Unknown; + PowerState state = PowerState.PowerOff; Integer vncPort = null; VmwareContext context = getServiceContext(); @@ -2958,7 +2959,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); if (vmMo != null) { state = getVmState(vmMo); - if (state == State.Running) { + if (state == PowerState.PowerOn) { synchronized (_vms) { _vms.put(vmName, State.Running); } @@ -3719,7 +3720,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa List networks = vmMo.getNetworksWithDetails(); // tear down all devices first before we destroy the VM to avoid accidently delete disk backing files - if (getVmState(vmMo) != State.Stopped) + if (getVmState(vmMo) != PowerState.PowerOff) vmMo.safePowerOff(_shutdown_waitMs); vmMo.tearDownDevices(new Class[] { VirtualDisk.class, VirtualEthernetCard.class }); vmMo.destroy(); @@ -4074,7 +4075,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa @Override public PingCommand getCurrentStatus(long id) { - HashMap newStates = sync(); + HashMap newStates = sync(); if (newStates == null) { return null; } @@ -4180,7 +4181,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa StartupRoutingCommand cmd = new StartupRoutingCommand(); fillHostInfo(cmd); - Map changes = null; + Map changes = null; synchronized (_vms) { _vms.clear(); changes = sync(); @@ -4338,7 +4339,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa details.put("NativeHA", "true"); } } + + protected HashMap sync() { + try { + return this.getVmStates(); + } catch(Exception e) { + return new HashMap(); + } + } +/* protected HashMap sync() { HashMap changes = new HashMap(); HashMap oldStates = null; @@ -4388,10 +4398,6 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } else if (oldState != newState) { _vms.put(vm, newState); if (newState == State.Stopped) { - /* - * if (_vmsKilled.remove(vm)) { s_logger.debug("VM " + vm + " has been killed for storage. "); - * newState = State.Error; } - */ } changes.put(vm, newState); } @@ -4445,7 +4451,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } return changes; } - +*/ private boolean isVmInCluster(String vmName) throws Exception { VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); @@ -4610,11 +4616,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa } } - private HashMap getVmStates() throws Exception { + private HashMap getVmStates() throws Exception { VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext()); ObjectContent[] ocs = hyperHost.getVmPropertiesOnHyperHost(new String[] { "name", "runtime.powerState", "config.template" }); - HashMap newStates = new HashMap(); + HashMap newStates = new HashMap(); if (ocs != null && ocs.length > 0) { for (ObjectContent oc : ocs) { List objProps = oc.getPropSet(); @@ -4853,11 +4859,11 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa return connect(vmname, ipAddress, 3922); } - private static State convertState(VirtualMachinePowerState powerState) { + private static PowerState convertState(VirtualMachinePowerState powerState) { return s_statesTable.get(powerState); } - private static State getVmState(VirtualMachineMO vmMo) throws Exception { + private static PowerState getVmState(VirtualMachineMO vmMo) throws Exception { VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo(); return convertState(runtimeInfo.getPowerState()); } diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index c50f13ce7e5..4fcbb0f4dbd 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -244,6 +244,7 @@ import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.net.NetUtils; import com.cloud.vm.DiskProfile; import com.cloud.vm.VirtualMachine; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.snapshot.VMSnapshot; import com.trilead.ssh2.SCPClient; @@ -355,14 +356,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - protected static HashMap s_statesTable; + protected static HashMap s_statesTable; static { - s_statesTable = new HashMap(); - s_statesTable.put(Types.VmPowerState.HALTED, State.Stopped); - s_statesTable.put(Types.VmPowerState.PAUSED, State.Running); - s_statesTable.put(Types.VmPowerState.RUNNING, State.Running); - s_statesTable.put(Types.VmPowerState.SUSPENDED, State.Running); - s_statesTable.put(Types.VmPowerState.UNRECOGNIZED, State.Unknown); + s_statesTable = new HashMap(); + s_statesTable.put(Types.VmPowerState.HALTED, PowerState.PowerOff); + s_statesTable.put(Types.VmPowerState.PAUSED, PowerState.PowerOn); + s_statesTable.put(Types.VmPowerState.RUNNING, PowerState.PowerOn); + s_statesTable.put(Types.VmPowerState.SUSPENDED, PowerState.PowerOn); + s_statesTable.put(Types.VmPowerState.UNRECOGNIZED, PowerState.PowerUnknown); } public XsHost getHost() { @@ -2659,13 +2660,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe .valueOf(_pollingIntervalInSeconds), "startTime", startTime); } - protected State convertToState(Types.VmPowerState ps) { - final State state = s_statesTable.get(ps); - return state == null ? State.Unknown : state; + protected PowerState convertToState(Types.VmPowerState ps) { + final PowerState state = s_statesTable.get(ps); + return state == null ? PowerState.PowerUnknown : state; } - protected HashMap> getAllVms(Connection conn) { - final HashMap> vmStates = new HashMap>(); + protected HashMap> getAllVms(Connection conn) { + final HashMap> vmStates = new HashMap>(); Map vm_map = null; for (int i = 0; i < 2; i++) { try { @@ -2690,7 +2691,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } VmPowerState ps = record.powerState; - final State state = convertToState(ps); + final PowerState state = convertToState(ps); if (s_logger.isTraceEnabled()) { s_logger.trace("VM " + record.nameLabel + ": powerstate = " + ps + "; vm state=" + state.toString()); } @@ -2709,14 +2710,14 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe // TODO Auto-generated catch block e.printStackTrace(); } - vmStates.put(record.nameLabel, new Pair(host_uuid, state)); + vmStates.put(record.nameLabel, new Pair(host_uuid, state)); } } return vmStates; } - protected State getVmState(Connection conn, final String vmName) { + protected PowerState getVmState(Connection conn, final String vmName) { int retry = 3; while (retry-- > 0) { try { @@ -2753,15 +2754,15 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } } - return State.Stopped; + return PowerState.PowerOff; } protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) { Connection conn = getConnection(); final String vmName = cmd.getVmName(); - final State state = getVmState(conn, vmName); + final PowerState state = getVmState(conn, vmName); Integer vncPort = null; - if (state == State.Running) { + if (state == PowerState.PowerOn) { synchronized (_cluster.intern()) { s_vms.put(_cluster, _name, vmName, State.Running); } @@ -3102,7 +3103,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } - protected State getRealPowerState(Connection conn, String label) { + protected PowerState getRealPowerState(Connection conn, String label) { int i = 0; s_logger.trace("Checking on the HALTED State"); for (; i < 20; i++) { @@ -3131,7 +3132,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } catch (InterruptedException e) { } } - return State.Stopped; + return PowerState.PowerOff; } protected Pair getControlDomain(Connection conn) throws XenAPIException, XmlRpcException { @@ -4708,7 +4709,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe Host.Record hostr = poolr.master.getRecord(conn); if (_host.uuid.equals(hostr.uuid)) { - HashMap> allStates=fullClusterSync(conn); + HashMap> allStates=fullClusterSync(conn); cmd.setClusterVMStateChanges(allStates); } } catch (Throwable e) { @@ -7681,12 +7682,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe s_logger.warn("Check for master failed, failing the Cluster sync command"); return new Answer(cmd); } - HashMap> newStates = deltaClusterSync(conn); + // HashMap> newStates = deltaClusterSync(conn); + HashMap> newStates = new HashMap>(); return new ClusterSyncAnswer(cmd.getClusterId(), newStates); } - protected HashMap> fullClusterSync(Connection conn) { + protected HashMap> fullClusterSync(Connection conn) { synchronized (_cluster.intern()) { s_vms.clear(_cluster); } @@ -7698,13 +7700,13 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } String vm_name = record.nameLabel; VmPowerState ps = record.powerState; - final State state = convertToState(ps); + final PowerState state = convertToState(ps); Host host = record.residentOn; String host_uuid = null; if( ! isRefNull(host) ) { host_uuid = host.getUuid(conn); synchronized (_cluster.intern()) { - s_vms.put(_cluster, host_uuid, vm_name, state); + s_vms.put(_cluster, host_uuid, vm_name, state == PowerState.PowerOn ? State.Running : State.Stopped); } } if (s_logger.isTraceEnabled()) { @@ -7716,16 +7718,28 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe s_logger.warn(msg, e); throw new CloudRuntimeException(msg); } - return s_vms.getClusterVmState(_cluster); + + HashMap> states = new HashMap> (); + + HashMap> rawStates = s_vms.getClusterVmState(_cluster); + if(rawStates != null) { + for(Map.Entry> entry : rawStates.entrySet()) { + states.put(entry.getKey(), new Pair( + entry.getValue().first(), + entry.getValue().second() == State.Running ? PowerState.PowerOn : PowerState.PowerOff)); + } + } + + return states; } - +/* protected HashMap> deltaClusterSync(Connection conn) { final HashMap> changes = new HashMap>(); synchronized (_cluster.intern()) { - HashMap> newStates = getAllVms(conn); + HashMap> newStates = getAllVms(conn); if (newStates == null) { s_logger.warn("Unable to get the vm states so no state sync at this point."); return null; @@ -7791,10 +7805,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe s_logger.debug("14. The VM " + vm + " is in " + newState + " state was " + oldState.second()); s_vms.put(_cluster, host_uuid, vm, newState); if (newState == State.Stopped) { - /* - * if (s_vmsKilled.remove(vm)) { s_logger.debug("VM " + vm + " has been killed for storage. "); - * newState = State.Error; } - */ } changes.put(vm, new Pair(host_uuid, newState)); } @@ -7828,7 +7838,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe } return changes; } - +*/ /** * @param cmd * @return diff --git a/server/pom.xml b/server/pom.xml index a3971954475..36e4c08adda 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -98,6 +98,11 @@ cloud-framework-events ${project.version} + + org.apache.cloudstack + cloud-framework-ipc + ${project.version} + install diff --git a/server/src/com/cloud/ha/CheckOnAgentInvestigator.java b/server/src/com/cloud/ha/CheckOnAgentInvestigator.java index 29719105a15..e60aa273a16 100644 --- a/server/src/com/cloud/ha/CheckOnAgentInvestigator.java +++ b/server/src/com/cloud/ha/CheckOnAgentInvestigator.java @@ -30,6 +30,7 @@ import com.cloud.host.HostVO; import com.cloud.host.Status; import com.cloud.utils.component.AdapterBase; import com.cloud.vm.VMInstanceVO; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; @Local(value=Investigator.class) @@ -57,7 +58,7 @@ public class CheckOnAgentInvestigator extends AdapterBase implements Investigato } s_logger.debug("Agent responded with state " + answer.getState().toString()); - return answer.getState() == State.Running; + return answer.getState() == PowerState.PowerOn; } catch (AgentUnavailableException e) { s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage()); return null; diff --git a/server/src/com/cloud/hypervisor/kvm/discoverer/KvmDummyResourceBase.java b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmDummyResourceBase.java index 240ea6ce316..e930f6b62f7 100644 --- a/server/src/com/cloud/hypervisor/kvm/discoverer/KvmDummyResourceBase.java +++ b/server/src/com/cloud/hypervisor/kvm/discoverer/KvmDummyResourceBase.java @@ -23,10 +23,10 @@ import javax.naming.ConfigurationException; import com.cloud.agent.api.Answer; import com.cloud.agent.api.Command; +import com.cloud.agent.api.HostVmStateReportEntry; import com.cloud.agent.api.PingCommand; import com.cloud.agent.api.StartupCommand; import com.cloud.agent.api.StartupRoutingCommand; -import com.cloud.agent.api.StartupRoutingCommand.VmState; import com.cloud.host.Host.Type; import com.cloud.hypervisor.Hypervisor; import com.cloud.resource.ServerResource; @@ -46,7 +46,7 @@ public class KvmDummyResourceBase extends ServerResourceBase implements ServerRe @Override public StartupCommand[] initialize() { - StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.KVM, new HashMap(), new HashMap()); + StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.KVM, new HashMap(), new HashMap()); cmd.setDataCenter(_zoneId); cmd.setPod(_podId); cmd.setCluster(_clusterId); diff --git a/server/src/com/cloud/resource/DummyHostServerResource.java b/server/src/com/cloud/resource/DummyHostServerResource.java index 977dbbf6e19..dd5ea69d7c9 100644 --- a/server/src/com/cloud/resource/DummyHostServerResource.java +++ b/server/src/com/cloud/resource/DummyHostServerResource.java @@ -56,7 +56,7 @@ public class DummyHostServerResource extends ServerResourceBase { @Override public PingCommand getCurrentStatus(long id) { - HashMap newStates = new HashMap(); + HashMap newStates = new HashMap(); return new PingRoutingCommand(com.cloud.host.Host.Type.Routing, id, newStates); } diff --git a/server/src/com/cloud/vm/VirtualMachineManager.java b/server/src/com/cloud/vm/VirtualMachineManager.java index 4a30d97cc54..c98cc913dcd 100644 --- a/server/src/com/cloud/vm/VirtualMachineManager.java +++ b/server/src/com/cloud/vm/VirtualMachineManager.java @@ -17,6 +17,7 @@ package com.cloud.vm; import java.net.URI; +import java.util.Collection; import java.util.List; import java.util.Map; @@ -90,6 +91,8 @@ public interface VirtualMachineManager extends Manager { boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException; void registerGuru(VirtualMachine.Type type, VirtualMachineGuru guru); + + Collection> getRegisteredGurus(); boolean stateTransitTo(VMInstanceVO vm, VirtualMachine.Event e, Long hostId) throws NoTransitionException; diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 07d25e09067..7b849a95248 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -47,7 +47,6 @@ import org.apache.log4j.Logger; import com.cloud.agent.AgentManager; import com.cloud.agent.AgentManager.OnError; import com.cloud.agent.Listener; -import com.cloud.agent.api.StartupRoutingCommand.VmState; import com.cloud.agent.api.to.NicTO; import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.manager.Commands; @@ -132,6 +131,7 @@ import com.cloud.utils.fsm.NoTransitionException; import com.cloud.utils.fsm.StateMachine2; import com.cloud.vm.ItWorkVO.Step; import com.cloud.vm.VirtualMachine.Event; +import com.cloud.vm.VirtualMachine.PowerState; import com.cloud.vm.VirtualMachine.State; import com.cloud.vm.dao.NicDao; import com.cloud.vm.dao.UserVmDao; @@ -259,6 +259,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac _vmGurus.put(type, guru); } } + + @Override + public Collection> getRegisteredGurus() { + synchronized(_vmGurus) { + return _vmGurus.values(); + } + } @Override @DB @@ -1199,7 +1206,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac protected boolean checkVmOnHost(VirtualMachine vm, long hostId) throws AgentUnavailableException, OperationTimedoutException { CheckVirtualMachineAnswer answer = (CheckVirtualMachineAnswer) _agentMgr.send(hostId, new CheckVirtualMachineCommand(vm.getInstanceName())); - if (!answer.getResult() || answer.getState() == State.Stopped) { + if (!answer.getResult() || answer.getState() == PowerState.PowerOff) { return false; } @@ -1626,12 +1633,11 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public Command cleanup(String vmName) { return new StopCommand(vmName); } - +/* public Commands fullHostSync(final long hostId, StartupRoutingCommand startup) { Commands commands = new Commands(OnError.Continue); Map infos = convertToInfos(startup); - final List vms = _vmDao.listByHostId(hostId); s_logger.debug("Found " + vms.size() + " VMs for host " + hostId); for (VMInstanceVO vm : vms) { @@ -1718,8 +1724,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return commands; } - - public void deltaSync(Map> newStates) { Map states = convertToInfos(newStates); @@ -1754,7 +1758,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } } } - +*/ public void fullSync(final long clusterId, Map> newStates) { if (newStates==null)return; @@ -1924,15 +1928,16 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return map; } +/* protected Map convertToInfos(StartupRoutingCommand cmd) { - final Map states = cmd.getVmStates(); + final Map states = cmd.getVmStates(); final HashMap map = new HashMap(); if (states == null) { return map; } Collection> vmGurus = _vmGurus.values(); - for (Map.Entry entry : states.entrySet()) { + for (Map.Entry entry : states.entrySet()) { for (VirtualMachineGuru vmGuru : vmGurus) { String name = entry.getKey(); VMInstanceVO vm = vmGuru.findByName(name); @@ -1950,7 +1955,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return map; } - +*/ protected Map convertDeltaToInfos(final Map states) { final HashMap map = new HashMap(); @@ -2233,7 +2238,10 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (answer instanceof ClusterSyncAnswer) { ClusterSyncAnswer hs = (ClusterSyncAnswer) answer; if (!hs.isExceuted()){ + +/* TODO deltaSync(hs.getNewStates()); +*/ hs.setExecuted(); } } @@ -2258,6 +2266,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (cmd instanceof PingRoutingCommand) { PingRoutingCommand ping = (PingRoutingCommand) cmd; if (ping.getNewStates() != null && ping.getNewStates().size() > 0) { + +/* TODO Commands commands = deltaHostSync(agentId, ping.getNewStates()); if (commands.size() > 0) { try { @@ -2266,6 +2276,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac s_logger.warn("Agent is now unavailable", e); } } +*/ + } processed = true; } @@ -2304,11 +2316,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac if (agent.getHypervisorType() == HypervisorType.XenServer) { // only for Xen StartupRoutingCommand startup = (StartupRoutingCommand) cmd; + +/* TODO HashMap> allStates = startup.getClusterVMStateChanges(); if (allStates != null){ this.fullSync(clusterId, allStates); } - +*/ // initiate the cron job ClusterSyncCommand syncCmd = new ClusterSyncCommand(Integer.parseInt(Config.ClusterDeltaSyncInterval.getDefaultValue()), clusterId); try { @@ -2320,6 +2334,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } else { // for others KVM and VMWare StartupRoutingCommand startup = (StartupRoutingCommand) cmd; + +/* Commands commands = fullHostSync(agentId, startup); if (commands.size() > 0) { @@ -2345,7 +2361,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac throw new ConnectionException(true, "Unable to sync", e); } } - +*/ } } diff --git a/server/src/com/cloud/vm/VirtualMachinePowerStateSync.java b/server/src/com/cloud/vm/VirtualMachinePowerStateSync.java new file mode 100644 index 00000000000..ac1ddec06f9 --- /dev/null +++ b/server/src/com/cloud/vm/VirtualMachinePowerStateSync.java @@ -0,0 +1,26 @@ +// 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.vm; + +import java.util.Map; + +import com.cloud.agent.api.HostVmStateReportEntry; + +public interface VirtualMachinePowerStateSync { + void resetHostSyncState(long hostId); + void processHostVmStateReport(long hostId, Map report); +} diff --git a/server/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java b/server/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java new file mode 100644 index 00000000000..f5bedd65076 --- /dev/null +++ b/server/src/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java @@ -0,0 +1,91 @@ +// 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.vm; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import javax.inject.Inject; + +import org.apache.cloudstack.framework.messagebus.MessageBus; +import org.apache.cloudstack.framework.messagebus.PublishScope; +import org.apache.cloudstack.messagebus.SubjectConstants; +import org.apache.log4j.Logger; + +import com.cloud.agent.api.HostVmStateReportEntry; +import com.cloud.vm.dao.VMInstanceDao; + +public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStateSync { + private static final Logger s_logger = Logger.getLogger(VirtualMachinePowerStateSyncImpl.class); + + @Inject MessageBus _messageBus; + @Inject VMInstanceDao _instanceDao; + @Inject VirtualMachineManager _vmMgr; + + public VirtualMachinePowerStateSyncImpl() { + } + + @Override + public void resetHostSyncState(long hostId) { + s_logger.info("Reset VM power state sync for host: " + hostId); + _instanceDao.resetHostPowerStateTracking(hostId); + } + + @Override + public void processHostVmStateReport(long hostId, Map report) { + s_logger.info("Process host VM state report. host: " + hostId); + + Map translatedInfo = convertToInfos(report); + for(Map.Entry entry : translatedInfo.entrySet()) { + if(_instanceDao.updatePowerState(entry.getKey(), hostId, entry.getValue())) { + _messageBus.publish(null, SubjectConstants.VM_POWER_STATE, PublishScope.GLOBAL, entry.getKey()); + } + } + } + + protected Map convertToInfos(Map states) { + final HashMap map = new HashMap(); + if (states == null) { + return map; + } + + Collection> vmGurus = _vmMgr.getRegisteredGurus(); + + for (Map.Entry entry : states.entrySet()) { + for (VirtualMachineGuru vmGuru : vmGurus) { + String name = entry.getKey(); + VMInstanceVO vm = vmGuru.findByName(name); + if (vm != null) { + map.put(vm.getId(), entry.getValue().getState()); + break; + } + + Long id = vmGuru.convertToId(name); + if (id != null) { + vm = vmGuru.findById(id); + if(vm != null) { + map.put(id, entry.getValue().getState()); + break; + } + } + } + } + + return map; + } +} diff --git a/server/src/com/cloud/vm/dao/VMInstanceDao.java b/server/src/com/cloud/vm/dao/VMInstanceDao.java index 2a241263d2f..ba975856d7b 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDao.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDao.java @@ -116,7 +116,7 @@ public interface VMInstanceDao extends GenericDao, StateDao< */ List listDistinctHostNames(long networkId, VirtualMachine.Type... types); - void updatePowerState(long instanceId, long powerHostId, VirtualMachine.PowerState powerState); + boolean updatePowerState(long instanceId, long powerHostId, VirtualMachine.PowerState powerState); void resetVmPowerStateTracking(long instanceId); void resetHostPowerStateTracking(long hostId); } diff --git a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java index a3846ca98a9..254c9654a0d 100644 --- a/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java +++ b/server/src/com/cloud/vm/dao/VMInstanceDaoImpl.java @@ -29,7 +29,6 @@ import java.util.Map; import javax.annotation.PostConstruct; import javax.ejb.Local; import javax.inject.Inject; -import javax.persistence.Entity; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -630,7 +629,8 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem } @Override @DB - public void updatePowerState(long instanceId, long powerHostId, VirtualMachine.PowerState powerState) { + public boolean updatePowerState(long instanceId, long powerHostId, VirtualMachine.PowerState powerState) { + boolean needToUpdate = false; Transaction txn = Transaction.currentTxn(); txn.start(); @@ -642,20 +642,21 @@ public class VMInstanceDaoImpl extends GenericDaoBase implem instance.setPowerHostId(powerHostId); instance.setPowerStateUpdateCount(1); instance.setPowerStateUpdateTime(DateUtil.currentGMTTime()); - + needToUpdate = true; update(instanceId, instance); } else { // to reduce DB updates, consecutive same state update for more than 3 times if(instance.getPowerStateUpdateCount() < MAX_CONSECUTIVE_SAME_STATE_UPDATE_COUNT) { instance.setPowerStateUpdateCount(instance.getPowerStateUpdateCount() + 1); instance.setPowerStateUpdateTime(DateUtil.currentGMTTime()); - + needToUpdate = true; update(instanceId, instance); } } } txn.commit(); + return needToUpdate; } @Override @DB diff --git a/server/src/org/apache/cloudstack/messagebus/SubjectConstants.java b/server/src/org/apache/cloudstack/messagebus/SubjectConstants.java new file mode 100644 index 00000000000..16a9bee4cf4 --- /dev/null +++ b/server/src/org/apache/cloudstack/messagebus/SubjectConstants.java @@ -0,0 +1,21 @@ +// 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 org.apache.cloudstack.messagebus; + +public interface SubjectConstants { + public static final String VM_POWER_STATE = "vm.powerstate"; +} diff --git a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java b/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java deleted file mode 100755 index 4917e77cdef..00000000000 --- a/server/test/com/cloud/vm/MockVirtualMachineManagerImpl.java +++ /dev/null @@ -1,312 +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.vm; - -import java.net.URI; -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; -import javax.naming.ConfigurationException; - -import org.springframework.stereotype.Component; - -import com.cloud.agent.api.to.NicTO; -import com.cloud.agent.api.to.VirtualMachineTO; -import com.cloud.deploy.DeployDestination; -import com.cloud.deploy.DeploymentPlan; -import com.cloud.exception.AgentUnavailableException; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.InsufficientServerCapacityException; -import com.cloud.exception.ManagementServerException; -import com.cloud.exception.OperationTimedoutException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.exception.VirtualMachineMigrationException; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.Network; -import com.cloud.network.dao.NetworkVO; -import com.cloud.offering.ServiceOffering; -import com.cloud.service.ServiceOfferingVO; -import com.cloud.storage.DiskOfferingVO; -import com.cloud.storage.StoragePool; -import com.cloud.storage.VMTemplateVO; -import com.cloud.user.Account; -import com.cloud.user.User; -import com.cloud.utils.Pair; -import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.fsm.NoTransitionException; -import com.cloud.vm.VirtualMachine.Event; -import com.cloud.vm.VirtualMachine.Type; -import com.cloud.vm.VirtualMachineProfile.Param; - -@Component -@Local(value = VirtualMachineManager.class) -public class MockVirtualMachineManagerImpl extends ManagerBase implements VirtualMachineManager { - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - // TODO Auto-generated method stub - return false; - } - - @Override - public String getName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean stop(T vm, User caller, Account account) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - @Override - public void registerGuru(Type type, VirtualMachineGuru guru) { - // TODO Auto-generated method stub - - } - - @Override - public boolean stateTransitTo(VMInstanceVO vm, Event e, Long hostId) throws NoTransitionException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean advanceStop(T vm, boolean forced, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, - ConcurrentOperationException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean advanceExpunge(T vm, User caller, Account account) throws ResourceUnavailableException, OperationTimedoutException, ConcurrentOperationException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean remove(T vm, User caller, Account account) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean destroy(T vm, User caller, Account account) throws AgentUnavailableException, OperationTimedoutException, ConcurrentOperationException { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean migrateAway(Type type, long vmid, long hostId) throws InsufficientServerCapacityException, VirtualMachineMigrationException { - // TODO Auto-generated method stub - return false; - } - - @Override - public T migrate(T vm, long srcHostId, DeployDestination dest) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, - VirtualMachineMigrationException { - // TODO Auto-generated method stub - return null; - } - - @Override - public VMInstanceVO findByIdAndType(Type type, long vmId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering offering) { - // TODO Auto-generated method stub - return false; - } - - @Override - public T allocate(T vm, VMTemplateVO template, ServiceOfferingVO serviceOffering, Pair rootDiskOffering, - List> dataDiskOfferings, List> networks, Map params, DeploymentPlan plan, HypervisorType hyperType, Account owner) - throws InsufficientCapacityException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T allocate(T vm, VMTemplateVO template, ServiceOfferingVO serviceOffering, Long rootSize, Pair dataDiskOffering, - List> networks, DeploymentPlan plan, HypervisorType hyperType, Account owner) throws InsufficientCapacityException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T allocate(T vm, VMTemplateVO template, ServiceOfferingVO serviceOffering, List> networkProfiles, DeploymentPlan plan, - HypervisorType hyperType, Account owner) throws InsufficientCapacityException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T start(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T start(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, - ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T advanceStart(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, - ConcurrentOperationException, OperationTimedoutException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T advanceStart(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, - ResourceUnavailableException, ConcurrentOperationException, OperationTimedoutException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T reboot(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T advanceReboot(T vm, Map params, User caller, Account account) throws InsufficientCapacityException, ResourceUnavailableException, - ConcurrentOperationException, OperationTimedoutException { - // TODO Auto-generated method stub - return null; - } - - @Override - public T storageMigration(T vm, - StoragePool storagePoolId) { - // TODO Auto-generated method stub - return null; - } - - @Override - public VMInstanceVO findById(long vmId) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.vm.VirtualMachineManager#checkIfCanUpgrade(com.cloud.vm.VirtualMachine, long) - */ - @Override - public void checkIfCanUpgrade(VirtualMachine vmInstance, long newServiceOfferingId) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see com.cloud.vm.VirtualMachineManager#upgradeVmDb(long, long) - */ - @Override - public boolean upgradeVmDb(long vmId, long serviceOfferingId) { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.vm.VirtualMachineManager#toNicTO(com.cloud.vm.NicProfile, com.cloud.hypervisor.Hypervisor.HypervisorType) - */ - @Override - public NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.vm.VirtualMachineManager#toVmTO(com.cloud.vm.VirtualMachineProfile) - */ - @Override - public VirtualMachineTO toVmTO(VirtualMachineProfile profile) { - // TODO Auto-generated method stub - return null; - } - - @Override - public VMInstanceVO reConfigureVm(VMInstanceVO vm, ServiceOffering newServiceOffering, boolean sameHost) throws ResourceUnavailableException, ConcurrentOperationException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public VMInstanceVO findHostAndMigrate(VirtualMachine.Type vmType, VMInstanceVO vm, Long newSvcOfferingId) throws InsufficientCapacityException, - ConcurrentOperationException, ResourceUnavailableException, - VirtualMachineMigrationException, ManagementServerException{ - return null; - } - - @Override - public T migrateForScale(T vm, long srcHostId, DeployDestination dest, Long newSvcOfferingId) throws ResourceUnavailableException, ConcurrentOperationException, ManagementServerException, VirtualMachineMigrationException { - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - /* (non-Javadoc) - * @see com.cloud.vm.VirtualMachineManager#addVmToNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network, com.cloud.vm.NicProfile) - */ - @Override - public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.vm.VirtualMachineManager#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network, java.net.URI) - */ - @Override - public boolean removeNicFromVm(VirtualMachine vm, NicVO nic) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see com.cloud.vm.VirtualMachineManager#removeVmFromNetwork(com.cloud.vm.VirtualMachine, com.cloud.network.Network, java.net.URI) - */ - @Override - public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return false; - } - -}