mirror of https://github.com/apache/cloudstack.git
bug 11701: additional classes for VM sync detached from ping
This commit is contained in:
parent
438b01344d
commit
7f3a4c700c
|
|
@ -0,0 +1,54 @@
|
|||
/* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
public class ClusterSyncAnswer extends Answer {
|
||||
long _clusterId;
|
||||
HashMap<String, Pair<String, State>> _newStates;
|
||||
int _type = -1; // 0 for full, 1 for delta
|
||||
|
||||
public static final int FULL_SYNC=0;
|
||||
public static final int DELTA_SYNC=1;
|
||||
|
||||
public ClusterSyncAnswer() {
|
||||
}
|
||||
|
||||
public ClusterSyncAnswer(long clusterId, HashMap<String, Pair<String, State>> newStates, int type){
|
||||
_clusterId = clusterId;
|
||||
_newStates = newStates;
|
||||
_type = type;
|
||||
result = true;
|
||||
}
|
||||
|
||||
public long getClusterId() {
|
||||
return _clusterId;
|
||||
}
|
||||
|
||||
public HashMap<String, Pair<String, State>> getNewStates() {
|
||||
return _newStates;
|
||||
}
|
||||
|
||||
public boolean isFull(){
|
||||
return _type==0;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
/* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
|
||||
*
|
||||
* This software is licensed under the GNU General Public License v3 or later.
|
||||
*
|
||||
* It is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or any later version.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.cloud.agent.api;
|
||||
|
||||
|
||||
public class ClusterSyncCommand extends Command implements CronCommand {
|
||||
int _interval;
|
||||
int _skipSteps; // skip this many steps for full sync
|
||||
int _steps;
|
||||
|
||||
long _clusterId;
|
||||
|
||||
public ClusterSyncCommand() {
|
||||
}
|
||||
|
||||
public ClusterSyncCommand(int interval, int skipSteps, long clusterId){
|
||||
_interval = interval;
|
||||
_skipSteps = skipSteps;
|
||||
_clusterId = clusterId;
|
||||
_steps=0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInterval() {
|
||||
return _interval;
|
||||
}
|
||||
|
||||
public int getSkipSteps(){
|
||||
return _skipSteps;
|
||||
}
|
||||
|
||||
public void incrStep(){
|
||||
_steps++;
|
||||
if (_steps>=_skipSteps)_steps=0;
|
||||
}
|
||||
|
||||
public boolean isRightStep(){
|
||||
return (_steps==0);
|
||||
}
|
||||
|
||||
public long getClusterId() {
|
||||
return _clusterId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
package com.cloud.hypervisor.xen.resource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
|
||||
|
||||
public class XenServerPoolVms {
|
||||
private static final Logger s_logger = Logger.getLogger(XenServerPoolVms.class);
|
||||
HashMap<String/* clusterId */, HashMap<String/* vm name */, Pair<String/* host uuid */, State/* vm state */>>> _cluster_vms =
|
||||
new HashMap<String, HashMap<String, Pair<String, State>>>();
|
||||
|
||||
public HashMap<String, Pair<String, State>> getClusterVmState(String clusterId){
|
||||
HashMap<String, Pair<String, State>> _vms= _cluster_vms.get(clusterId);
|
||||
if (_vms==null) {
|
||||
HashMap<String, Pair<String, State>> vmStates = new HashMap<String, Pair<String, State>>();
|
||||
_cluster_vms.put(clusterId, vmStates);
|
||||
return vmStates;
|
||||
}
|
||||
else return _vms;
|
||||
}
|
||||
|
||||
public void clear(String clusterId){
|
||||
HashMap<String, Pair<String, State>> _vms= getClusterVmState(clusterId);
|
||||
synchronized (_vms) {
|
||||
_vms.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public State getState(String clusterId, String name){
|
||||
HashMap<String, Pair<String, State>> vms = getClusterVmState(clusterId);
|
||||
Pair<String, State> pv = vms.get(name);
|
||||
return pv.second();
|
||||
}
|
||||
|
||||
public void put(String clusterId, String hostUuid, String name, State state){
|
||||
HashMap<String, Pair<String, State>> vms= getClusterVmState(clusterId);
|
||||
synchronized (vms) {
|
||||
vms.put(name, new Pair<String, State>(hostUuid, state));
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(String clusterId, String hostUuid, String name){
|
||||
HashMap<String, Pair<String, State>> vms= getClusterVmState(clusterId);
|
||||
synchronized (vms) {
|
||||
vms.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void putAll(String clusterId, HashMap<String, Pair<String, State>> new_vms){
|
||||
HashMap<String, Pair<String, State>> vms= getClusterVmState(clusterId);
|
||||
synchronized (vms) {
|
||||
vms.putAll(new_vms);
|
||||
}
|
||||
}
|
||||
|
||||
public int size(String clusterId){
|
||||
HashMap<String, Pair<String, State>> vms= getClusterVmState(clusterId);
|
||||
return vms.size();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]){
|
||||
XenServerPoolVms vms = new XenServerPoolVms();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
StringBuilder sbuf = new StringBuilder("PoolVms=");
|
||||
for (HashMap<String/* vm name */, Pair<String/* host uuid */, State/* vm state */>> clusterVM: _cluster_vms.values()){
|
||||
for (String vmname: clusterVM.keySet()){
|
||||
sbuf.append(vmname).append("-").append(clusterVM.get(vmname).second()).append(",");
|
||||
}
|
||||
}
|
||||
return sbuf.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue