From 5e23f00b1ab53daaeb5ad85943a8b04567d12ac5 Mon Sep 17 00:00:00 2001 From: tuna Date: Tue, 10 Dec 2013 10:21:09 +0700 Subject: [PATCH] add Apache Licensed and add check native --- .../agent/api/PerformanceMonitorAnswer.java | 16 +++++++++ .../agent/api/PerformanceMonitorCommand.java | 16 +++++++++ .../network/as/AutoScaleVmGroupVmMapVO.java | 16 +++++++++ .../as/dao/AutoScaleVmGroupVmMapDao.java | 16 +++++++++ .../as/dao/AutoScaleVmGroupVmMapDaoImpl.java | 16 +++++++++ scripts/vm/hypervisor/xenserver/perfmon.py | 16 +++++++++ .../src/com/cloud/server/StatsCollector.java | 36 +++++++++++++++---- setup/db/db/schema-40to410.sql | 4 +-- 8 files changed, 128 insertions(+), 8 deletions(-) diff --git a/core/src/com/cloud/agent/api/PerformanceMonitorAnswer.java b/core/src/com/cloud/agent/api/PerformanceMonitorAnswer.java index 931e2377002..10f4185719d 100644 --- a/core/src/com/cloud/agent/api/PerformanceMonitorAnswer.java +++ b/core/src/com/cloud/agent/api/PerformanceMonitorAnswer.java @@ -1,3 +1,19 @@ +// 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; public class PerformanceMonitorAnswer extends Answer { diff --git a/core/src/com/cloud/agent/api/PerformanceMonitorCommand.java b/core/src/com/cloud/agent/api/PerformanceMonitorCommand.java index 41a794543d8..882d7b18763 100644 --- a/core/src/com/cloud/agent/api/PerformanceMonitorCommand.java +++ b/core/src/com/cloud/agent/api/PerformanceMonitorCommand.java @@ -1,3 +1,19 @@ +// 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 java.util.HashMap; diff --git a/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVmMapVO.java b/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVmMapVO.java index 30a89f36c72..d70f9bfba37 100644 --- a/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVmMapVO.java +++ b/engine/schema/src/com/cloud/network/as/AutoScaleVmGroupVmMapVO.java @@ -1,3 +1,19 @@ +// 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.network.as; import javax.persistence.Column; diff --git a/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java b/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java index 1a080adb163..b7234e7a64c 100644 --- a/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java +++ b/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDao.java @@ -1,3 +1,19 @@ +// 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.network.as.dao; import java.util.List; diff --git a/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java b/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java index f7b354a4f10..494092d65d5 100644 --- a/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java +++ b/engine/schema/src/com/cloud/network/as/dao/AutoScaleVmGroupVmMapDaoImpl.java @@ -1,3 +1,19 @@ +// 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.network.as.dao; import java.util.List; diff --git a/scripts/vm/hypervisor/xenserver/perfmon.py b/scripts/vm/hypervisor/xenserver/perfmon.py index 9db2958106b..eb14e32aa54 100755 --- a/scripts/vm/hypervisor/xenserver/perfmon.py +++ b/scripts/vm/hypervisor/xenserver/perfmon.py @@ -1,4 +1,20 @@ #!/usr/bin/python +# 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. import pprint import XenAPI diff --git a/server/src/com/cloud/server/StatsCollector.java b/server/src/com/cloud/server/StatsCollector.java index 33597e00ef8..82f774fcbe6 100755 --- a/server/src/com/cloud/server/StatsCollector.java +++ b/server/src/com/cloud/server/StatsCollector.java @@ -623,7 +623,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc List asGroups = _asGroupDao.listAll(); for (AutoScaleVmGroupVO asGroup : asGroups) { // check group state - if (asGroup.getState().equals("enabled")) { + if ((asGroup.getState().equals("enabled")) && (is_native(asGroup.getId()))) { // check minimum vm of group Integer currentVM = _asGroupVmDao.countByGroup(asGroup.getId()); if (currentVM < asGroup.getMinMembers()) { @@ -733,7 +733,7 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc } } - String scaleAction = getAutoscaleAction(avgCounter, asGroup.getId(), currentVM); + String scaleAction = getAutoscaleAction(avgCounter, asGroup.getId(), currentVM, params); if (scaleAction != null) { s_logger.debug("[AutoScale] Doing scale action: " + scaleAction + " for group " + asGroup.getId()); if (scaleAction.equals("scaleup")) { @@ -758,7 +758,21 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc } - private String getAutoscaleAction(HashMap avgCounter, long groupId, long currentVM) { + private boolean is_native(long groupId) { + List vos = _asGroupPolicyDao.listByVmGroupId(groupId); + for (AutoScaleVmGroupPolicyMapVO vo : vos) { + List ConditionPolicies = _asConditionMapDao.findByPolicyId(vo.getPolicyId()); + for (AutoScalePolicyConditionMapVO ConditionPolicy : ConditionPolicies) { + ConditionVO condition = _asConditionDao.findById(ConditionPolicy.getConditionId()); + CounterVO counter = _asCounterDao.findById(condition.getCounterid()); + if (counter.getSource() == Counter.Source.cpu || counter.getSource() == Counter.Source.memory) + return true; + } + } + return false; + } + + private String getAutoscaleAction(HashMap avgCounter, long groupId, long currentVM, Map params) { List listMap = _asGroupPolicyDao.listByVmGroupId(groupId); if ( (listMap == null) || (listMap.size() == 0) ) @@ -785,9 +799,19 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc for (ConditionVO conditionVO : lstConditions) { long thresholdValue = conditionVO.getThreshold(); Double thresholdPercent = (double)thresholdValue / 100; - Double sum = avgCounter.get(conditionVO.getCounterid()); - Double avg = sum/ currentVM; - + CounterVO counterVO = _asCounterDao.findById(conditionVO.getCounterid()); +// Double sum = avgCounter.get(conditionVO.getCounterid()); + long counter_count=1; + do { + String counter_param = params.get("counter" + String.valueOf(counter_count)); + Counter.Source counter_source = counterVO.getSource(); + if (counter_param.equals(counter_source.toString())) + break; + counter_count++; + } while (1==1); + + Double sum = avgCounter.get(counter_count); + Double avg = sum / currentVM; Operator op = conditionVO.getRelationalOperator(); boolean bConditionCheck = ((op == com.cloud.network.as.Condition.Operator.EQ) && (thresholdPercent == avg)) || ((op == com.cloud.network.as.Condition.Operator.GE) && (avg >= thresholdPercent)) diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql index ca1edb1593b..65fb350bf19 100644 --- a/setup/db/db/schema-40to410.sql +++ b/setup/db/db/schema-40to410.sql @@ -417,8 +417,8 @@ INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (1, INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (2, UUID(), 'snmp','Linux System CPU - percentage', '1.3.6.1.4.1.2021.11.10.0', now()); INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (3, UUID(), 'snmp','Linux CPU Idle - percentage', '1.3.6.1.4.1.2021.11.11.0', now()); INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (100, UUID(), 'netscaler','Response Time - microseconds', 'RESPTIME', now()); -INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (4, UUID(), 'cpu','Linux User CPU - percentage', '1.3.6.1.4.1.2021.11.9.1', now()); -INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (5, UUID(), 'memory','Linux User RAM - percentage', '1.3.6.1.4.1.2021.11.10.1', now()); +INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (4, UUID(), 'cpu','Linux User CPU - percentage - native', '1.3.6.1.4.1.2021.11.9.1', now()); +INSERT INTO `cloud`.`counter` (id, uuid, source, name, value,created) VALUES (5, UUID(), 'memory','Linux User RAM - percentage - native', '1.3.6.1.4.1.2021.11.10.1', now()); CREATE TABLE `cloud`.`user_ipv6_address` ( `id` bigint unsigned NOT NULL UNIQUE auto_increment,