mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
fix issues
This commit is contained in:
parent
0b0e2627d6
commit
f355359b23
@ -33,7 +33,7 @@ public class AutoScaleVmGroupVmMapDaoImpl extends GenericDaoBase<AutoScaleVmGrou
|
|||||||
public int remove(long vmGroupId, long vmId) {
|
public int remove(long vmGroupId, long vmId) {
|
||||||
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
|
SearchCriteria<AutoScaleVmGroupVmMapVO> sc = createSearchCriteria();
|
||||||
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
|
sc.addAnd("vmGroupId", SearchCriteria.Op.EQ, vmGroupId);
|
||||||
sc.addAnd("vmId", SearchCriteria.Op.EQ, vmId);
|
sc.addAnd("instanceId", SearchCriteria.Op.EQ, vmId);
|
||||||
return remove(sc);
|
return remove(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -186,16 +186,10 @@ def getuuid(vm_name):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
def get_vm_group_perfmon(args={}):
|
def get_vm_group_perfmon(args={}):
|
||||||
#Release code
|
|
||||||
login = XenAPI.xapi_local()
|
login = XenAPI.xapi_local()
|
||||||
login.login_with_password("","")
|
login.login_with_password("","")
|
||||||
average_cpu = 0
|
|
||||||
average_memory = 0
|
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
#test code
|
|
||||||
#login = XenAPI.Session(url)
|
|
||||||
#login.login_with_password(username, password)
|
|
||||||
total_vm = int(args['total_vm'])
|
total_vm = int(args['total_vm'])
|
||||||
total_counter = int(args['total_counter'])
|
total_counter = int(args['total_counter'])
|
||||||
now = int(time.time()) / 60
|
now = int(time.time()) / 60
|
||||||
@ -222,18 +216,19 @@ def get_vm_group_perfmon(args={}):
|
|||||||
vm_uuid = getuuid(vm_name)
|
vm_uuid = getuuid(vm_name)
|
||||||
#print "Got values for VM: " + str(vm_count) + " " + vm_uuid
|
#print "Got values for VM: " + str(vm_count) + " " + vm_uuid
|
||||||
for counter_count in xrange(1, total_counter + 1):
|
for counter_count in xrange(1, total_counter + 1):
|
||||||
|
#refresh average
|
||||||
|
average_cpu = 0
|
||||||
|
average_memory = 0
|
||||||
counter = args['counter' + str(counter_count)]
|
counter = args['counter' + str(counter_count)]
|
||||||
total_row = rrd_updates.get_nrows()
|
total_row = rrd_updates.get_nrows()
|
||||||
duration = int(args['duration' + str(counter_count)]) / 60
|
duration = int(args['duration' + str(counter_count)]) / 60
|
||||||
duration_diff = total_row - duration
|
duration_diff = total_row - duration
|
||||||
#print "param: " + counter
|
|
||||||
if counter == "cpu":
|
if counter == "cpu":
|
||||||
total_cpu = rrd_updates.get_total_cpu_core(vm_uuid)
|
total_cpu = rrd_updates.get_total_cpu_core(vm_uuid)
|
||||||
for row in xrange(duration_diff, total_row):
|
for row in xrange(duration_diff, total_row):
|
||||||
for cpu in xrange(0, total_cpu):
|
for cpu in xrange(0, total_cpu):
|
||||||
average_cpu += rrd_updates.get_vm_data(vm_uuid, "cpu" + str(cpu), row)
|
average_cpu += rrd_updates.get_vm_data(vm_uuid, "cpu" + str(cpu), row)
|
||||||
average_cpu /= (duration * total_cpu)
|
average_cpu /= (duration * total_cpu)
|
||||||
#print "Average CPU: " + str(average_cpu)
|
|
||||||
if result == "":
|
if result == "":
|
||||||
result += str(vm_count) + '.' + str(counter_count) + ':' + str(average_cpu)
|
result += str(vm_count) + '.' + str(counter_count) + ':' + str(average_cpu)
|
||||||
else:
|
else:
|
||||||
@ -242,7 +237,6 @@ def get_vm_group_perfmon(args={}):
|
|||||||
for row in xrange(duration_diff, total_row):
|
for row in xrange(duration_diff, total_row):
|
||||||
average_memory += rrd_updates.get_vm_data(vm_uuid, "memory_target", row) / 1048576 - rrd_updates.get_vm_data(vm_uuid, "memory_internal_free", row) / 1024
|
average_memory += rrd_updates.get_vm_data(vm_uuid, "memory_target", row) / 1048576 - rrd_updates.get_vm_data(vm_uuid, "memory_internal_free", row) / 1024
|
||||||
average_memory /= duration
|
average_memory /= duration
|
||||||
#print "Average Memory: " + str(average_memory)
|
|
||||||
if result == "":
|
if result == "":
|
||||||
result += str(vm_count) + '.' + str(counter_count) + ':' + str(average_memory)
|
result += str(vm_count) + '.' + str(counter_count) + ':' + str(average_memory)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -123,7 +124,7 @@ import com.google.gson.reflect.TypeToken;
|
|||||||
@Local(value = {AutoScaleService.class, AutoScaleManager.class})
|
@Local(value = {AutoScaleService.class, AutoScaleManager.class})
|
||||||
public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScaleManager, AutoScaleService {
|
public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScaleManager, AutoScaleService {
|
||||||
private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
|
private static final Logger s_logger = Logger.getLogger(AutoScaleManagerImpl.class);
|
||||||
private ScheduledExecutorService _executor = null;
|
private ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
EntityManager _entityMgr;
|
EntityManager _entityMgr;
|
||||||
@ -1423,6 +1424,20 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
|
|||||||
final long vmId = removeLBrule(asGroup);
|
final long vmId = removeLBrule(asGroup);
|
||||||
if (vmId != -1) {
|
if (vmId != -1) {
|
||||||
long profileId = asGroup.getProfileId();
|
long profileId = asGroup.getProfileId();
|
||||||
|
|
||||||
|
// update group-vm mapping
|
||||||
|
_autoScaleVmGroupVmMapDao.remove(groupId, vmId);
|
||||||
|
// update last_quiettime
|
||||||
|
List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao.listByVmGroupId(groupId);
|
||||||
|
for (AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
|
||||||
|
AutoScalePolicyVO vo = _autoScalePolicyDao.findById(GroupPolicyVO.getPolicyId());
|
||||||
|
if (vo.getAction().equals("scaledown")) {
|
||||||
|
vo.setLastQuiteTime(new Date());
|
||||||
|
_autoScalePolicyDao.persist(vo);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// get destroyvmgrace param
|
// get destroyvmgrace param
|
||||||
AutoScaleVmProfileVO asProfile = _autoScaleVmProfileDao.findById(profileId);
|
AutoScaleVmProfileVO asProfile = _autoScaleVmProfileDao.findById(profileId);
|
||||||
Integer destroyVmGracePeriod = asProfile.getDestroyVmGraceperiod();
|
Integer destroyVmGracePeriod = asProfile.getDestroyVmGraceperiod();
|
||||||
@ -1431,21 +1446,9 @@ public class AutoScaleManagerImpl<Type> extends ManagerBase implements AutoScale
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
// destroy vm
|
|
||||||
_userVmManager.destroyVm(vmId);
|
_userVmManager.destroyVm(vmId);
|
||||||
// update group-vm mapping
|
|
||||||
_autoScaleVmGroupVmMapDao.remove(groupId, vmId);
|
|
||||||
// update last_quiettime
|
|
||||||
List<AutoScaleVmGroupPolicyMapVO> GroupPolicyVOs = _autoScaleVmGroupPolicyMapDao
|
|
||||||
.listByVmGroupId(groupId);
|
|
||||||
for (AutoScaleVmGroupPolicyMapVO GroupPolicyVO : GroupPolicyVOs) {
|
|
||||||
AutoScalePolicyVO vo = _autoScalePolicyDao
|
|
||||||
.findById(GroupPolicyVO.getPolicyId());
|
|
||||||
if (vo.getAction().equals("scaledown")) {
|
|
||||||
vo.setLastQuiteTime(new Date());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (ResourceUnavailableException e) {
|
} catch (ResourceUnavailableException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (ConcurrentOperationException e) {
|
} catch (ConcurrentOperationException e) {
|
||||||
|
|||||||
@ -86,6 +86,8 @@ import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
|||||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||||
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
|
||||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.agent.AgentManager;
|
import com.cloud.agent.AgentManager;
|
||||||
import com.cloud.agent.api.Answer;
|
import com.cloud.agent.api.Answer;
|
||||||
@ -3362,9 +3364,12 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserVm destroyVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException {
|
|
||||||
Account caller = CallContext.current().getCallingAccount();
|
public UserVm destroyVm(long vmId) throws ResourceUnavailableException,
|
||||||
Long userId = CallContext.current().getCallingUserId();
|
ConcurrentOperationException {
|
||||||
|
// Account caller = CallContext.current().getCallingAccount();
|
||||||
|
// Long userId = CallContext.current().getCallingUserId();
|
||||||
|
Long userId = 2L;
|
||||||
|
|
||||||
// Verify input parameters
|
// Verify input parameters
|
||||||
UserVmVO vm = _vmDao.findById(vmId);
|
UserVmVO vm = _vmDao.findById(vmId);
|
||||||
@ -3378,8 +3383,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
_accountMgr.checkAccess(caller, null, true, vm);
|
|
||||||
_userDao.findById(userId);
|
// _accountMgr.checkAccess(caller, null, true, vm);
|
||||||
|
User userCaller = _userDao.findById(userId);
|
||||||
|
|
||||||
boolean status;
|
boolean status;
|
||||||
State vmState = vm.getState();
|
State vmState = vm.getState();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user