You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mu...@apache.org on 2012/06/26 03:44:46 UTC
git commit: moving out random host allocator to
plugins/host-allocators/random/
Updated Branches:
refs/heads/master 621f2447b -> 974ad65b0
moving out random host allocator to plugins/host-allocators/random/
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/974ad65b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/974ad65b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/974ad65b
Branch: refs/heads/master
Commit: 974ad65b01cbe687b43f288cbdd1bebb1c394671
Parents: 621f244
Author: Murali reddy <Mu...@citrix.com>
Authored: Mon Jun 25 18:47:47 2012 -0700
Committer: Murali reddy <Mu...@citrix.com>
Committed: Mon Jun 25 18:47:47 2012 -0700
----------------------------------------------------------------------
build/build-cloud.xml | 10 +-
plugins/host-allocators/random/.classpath | 10 +
plugins/host-allocators/random/.project | 17 ++
plugins/host-allocators/random/build.xml | 128 +++++++++++++
.../manager/allocator/impl/RandomAllocator.java | 142 +++++++++++++++
.../manager/allocator/impl/RandomAllocator.java | 142 ---------------
6 files changed, 305 insertions(+), 144 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/974ad65b/build/build-cloud.xml
----------------------------------------------------------------------
diff --git a/build/build-cloud.xml b/build/build-cloud.xml
index 68962ff..0fdc4f3 100755
--- a/build/build-cloud.xml
+++ b/build/build-cloud.xml
@@ -479,7 +479,7 @@
<target name="build-servers" depends="-init, build-server" />
- <target name="build-opensource" depends="-init, build-server, build-agent, build-scripts, build-ui, build-console-proxy, build-ovm, package-oss-systemvm-iso, build-netscaler, build-f5, build-srx, build-dp-user-dispersing, build-dp-user-concentrated-pod">
+ <target name="build-opensource" depends="-init, build-server, build-agent, build-scripts, build-ui, build-console-proxy, build-ovm, package-oss-systemvm-iso, build-netscaler, build-f5, build-srx, build-dp-user-dispersing, build-dp-user-concentrated-pod, build-host-allocator-random">
<copy overwrite="true" todir="${dist.dir}">
<fileset dir="${base.dir}/build/deploy/">
<include name="deploy-agent.sh" />
@@ -586,7 +586,7 @@
<delete dir="${unittest.dir}"/>
</target>
- <target name="compile-all" description="Compile all of the jars" depends="compile-utils, compile-api, compile-core, compile-server, compile-ovm, compile-netscaler, compile-f5, compile-srx"/>
+ <target name="compile-all" description="Compile all of the jars" depends="compile-utils, compile-api, compile-core, compile-server, compile-ovm, compile-netscaler, compile-f5, compile-srx, compile-dp-user-dispersing, compile-dp-user-concentrated-pod, compile-host-allocator-random"/>
<target name="clean-all" depends="clean, clean-awsapi" description="Clean all of the generated files, including dependency cache and javadoc">
<delete dir="${target.dir}" />
@@ -610,6 +610,12 @@
</target>
<target name="build-dp-user-concentrated-pod" depends="compile-dp-user-concentrated-pod" />
+ <!-- =====================compile-host-allocator-random.jar ===================== -->
+ <target name="compile-host-allocator-random" depends="-init, compile-server" description="Compile ">
+ <ant antfile="${base.dir}/plugins/host-allocators/random/build.xml" target="build"/>
+ </target>
+ <target name="build-host-allocator-random" depends="compile-host-allocator-random" />
+
<!-- ===================== Cloud-Plugin-Netscaler.Jar ===================== -->
<target name="compile-netscaler" depends="-init, compile-server" description="Compile NetScaler plugin">
<ant antfile="${base.dir}/plugins/network-elements/netscaler/build.xml" target="build"/>
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/974ad65b/plugins/host-allocators/random/.classpath
----------------------------------------------------------------------
diff --git a/plugins/host-allocators/random/.classpath b/plugins/host-allocators/random/.classpath
new file mode 100755
index 0000000..e39771a
--- /dev/null
+++ b/plugins/host-allocators/random/.classpath
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/api"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/core"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/server"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/utils"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/974ad65b/plugins/host-allocators/random/.project
----------------------------------------------------------------------
diff --git a/plugins/host-allocators/random/.project b/plugins/host-allocators/random/.project
new file mode 100755
index 0000000..d33268d
--- /dev/null
+++ b/plugins/host-allocators/random/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>random-host-allocator</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/974ad65b/plugins/host-allocators/random/build.xml
----------------------------------------------------------------------
diff --git a/plugins/host-allocators/random/build.xml b/plugins/host-allocators/random/build.xml
new file mode 100755
index 0000000..6cb8fd8
--- /dev/null
+++ b/plugins/host-allocators/random/build.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+
+<project name="Cloud Stack Random Host Allocator" default="help" basedir=".">
+ <description>
+ Cloud Stack ant build file
+ </description>
+
+ <dirname property="host-allocator-random.base.dir" file="${ant.file.Cloud Stack Random Host Allocator}/"/>
+ <!-- This directory must be set -->
+ <property name="top.dir" location="${host-allocator-random.base.dir}/../../.."/>
+ <property name="build.dir" location="${top.dir}/build"/>
+
+ <echo message="build.dir=${build.dir}; top.dir=${top.dir}; host-allocator-random.base.dir=${host-allocator-random.base.dir}"/>
+
+ <!-- Import anything that the user wants to set-->
+ <!-- Import properties files and environment variables here -->
+
+ <property environment="env" />
+
+ <condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
+ <available file="${build.dir}/override/build-cloud.properties" />
+ </condition>
+
+ <condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
+ <available file="${build.dir}/override/cloud.properties" />
+ </condition>
+
+ <condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
+ <available file="${build.dir}/override/replace.properties" />
+ </condition>
+
+ <echo message="Using build parameters from ${build-cloud.properties.file}" />
+ <property file="${build-cloud.properties.file}" />
+
+ <echo message="Using company info from ${cloud.properties.file}" />
+ <property file="${cloud.properties.file}" />
+
+ <echo message="Using override file from ${override.file}" />
+ <property file="${override.file}" />
+
+ <property file="${build.dir}/build.number" />
+
+ <!-- In case these didn't get defined in the build-cloud.properties -->
+ <property name="branding.name" value="default" />
+ <property name="deprecation" value="off" />
+ <property name="target.compat.version" value="1.6" />
+ <property name="source.compat.version" value="1.6" />
+ <property name="debug" value="true" />
+ <property name="debuglevel" value="lines,source"/>
+
+ <echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
+ <!-- directories for build and distribution -->
+ <property name="target.dir" location="${top.dir}/target" />
+ <property name="classes.dir" location="${target.dir}/classes" />
+ <property name="jar.dir" location="${target.dir}/jar" />
+ <property name="dep.cache.dir" location="${target.dir}/dep-cache" />
+ <property name="build.log" location="${target.dir}/ant_verbose.txt" />
+
+ <property name="deps.dir" location="${top.dir}/deps" />
+
+ <property name="host-allocator-random.jar" value="cloud-host-allocator-random.jar" />
+ <property name="host-allocator-random-scripts.dir" location="${host-allocator-random.base.dir}/scripts" />
+
+ <import file="${build.dir}/build-common.xml"/>
+
+ <echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
+
+ <!-- This section needs to be replaced by some kind of dependency library-->
+ <path id="deps.classpath">
+ <!--filelist files="${deps.classpath}" /-->
+ <fileset dir="${deps.dir}" erroronmissingdir="false">
+ <include name="*.jar" />
+ </fileset>
+ </path>
+
+ <path id="cloudstack.classpath">
+ <fileset dir="${jar.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <path id="host-allocator-random.classpath">
+ <path refid="deps.classpath"/>
+ <path refid="cloudstack.classpath"/>
+ </path>
+
+ <!-- This section needs to be replaced by some kind of dependency library-->
+
+
+ <target name="init" description="Initialize binaries directory">
+ <mkdir dir="${classes.dir}/${host-allocator-random.jar}"/>
+ <mkdir dir="${jar.dir}"/>
+ </target>
+
+ <target name="compile-host-allocator-random" depends="init" description="Compile host-allocator-random">
+ <compile-java jar.name="${host-allocator-random.jar}" top.dir="${host-allocator-random.base.dir}" classpath="host-allocator-random.classpath" />
+ </target>
+
+ <target name="help" description="help">
+ <echo level="info" message="This is the build file for host-allocator-random"/>
+ <echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
+ </target>
+
+ <target name="clean-host-allocator-random">
+ <delete dir="${classes.dir}/${host-allocator-random.jar}"/>
+ </target>
+
+ <target name="build" depends="compile-host-allocator-random"/>
+ <target name="clean" depends="clean-host-allocator-random"/>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/974ad65b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
----------------------------------------------------------------------
diff --git a/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
new file mode 100755
index 0000000..3ca2da1
--- /dev/null
+++ b/plugins/host-allocators/random/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
@@ -0,0 +1,142 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License. Citrix Systems, Inc.
+// reserves all rights not expressly granted by 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.
+//
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.agent.manager.allocator.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.manager.allocator.HostAllocator;
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.host.Host;
+import com.cloud.host.Host.Type;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.resource.ResourceManager;
+import com.cloud.utils.component.ComponentLocator;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+
+@Local(value=HostAllocator.class)
+public class RandomAllocator implements HostAllocator {
+ private static final Logger s_logger = Logger.getLogger(RandomAllocator.class);
+ private String _name;
+ private HostDao _hostDao;
+ private ResourceManager _resourceMgr;
+
+ @Override
+ public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
+ ExcludeList avoid, int returnUpTo) {
+ return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true);
+ }
+
+ @Override
+ public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
+ ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
+
+ long dcId = plan.getDataCenterId();
+ Long podId = plan.getPodId();
+ Long clusterId = plan.getClusterId();
+ ServiceOffering offering = vmProfile.getServiceOffering();
+
+ List<Host> suitableHosts = new ArrayList<Host>();
+
+ if (type == Host.Type.Storage) {
+ return suitableHosts;
+ }
+
+ String hostTag = offering.getHostTag();
+ if(hostTag != null){
+ s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId + " having host tag:" + hostTag);
+ }else{
+ s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
+ }
+
+ // list all computing hosts, regardless of whether they support routing...it's random after all
+ List<? extends Host> hosts = new ArrayList<HostVO>();
+ if(hostTag != null){
+ hosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag);
+ }else{
+ hosts = _resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId);
+ }
+
+ s_logger.debug("Random Allocator found " + hosts.size() + " hosts");
+
+ if (hosts.size() == 0) {
+ return suitableHosts;
+ }
+
+
+ Collections.shuffle(hosts);
+ for (Host host : hosts) {
+ if(suitableHosts.size() == returnUpTo){
+ break;
+ }
+
+ if (!avoid.shouldAvoid(host)) {
+ suitableHosts.add(host);
+ }else{
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() +" is in avoid set, skipping this and trying other available hosts");
+ }
+ }
+ }
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Random Host Allocator returning "+suitableHosts.size() +" suitable hosts");
+ }
+ return suitableHosts;
+ }
+
+ @Override
+ public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering offering) {
+ // currently we do no special checks to rule out a VM being upgradable to an offering, so
+ // return true
+ return true;
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) {
+ ComponentLocator locator = ComponentLocator.getCurrentLocator();
+ _hostDao = locator.getDao(HostDao.class);
+ _resourceMgr = locator.getManager(ResourceManager.class);
+ if (_hostDao == null) {
+ s_logger.error("Unable to get host dao.");
+ return false;
+ }
+ _name=name;
+
+ return true;
+ }
+
+ @Override
+ public String getName() {
+ return _name;
+ }
+
+ @Override
+ public boolean start() {
+ return true;
+ }
+
+ @Override
+ public boolean stop() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/974ad65b/server/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
deleted file mode 100755
index 3ca2da1..0000000
--- a/server/src/com/cloud/agent/manager/allocator/impl/RandomAllocator.java
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.agent.manager.allocator.impl;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.manager.allocator.HostAllocator;
-import com.cloud.deploy.DeploymentPlan;
-import com.cloud.deploy.DeploymentPlanner.ExcludeList;
-import com.cloud.host.Host;
-import com.cloud.host.Host.Type;
-import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
-import com.cloud.offering.ServiceOffering;
-import com.cloud.resource.ResourceManager;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Local(value=HostAllocator.class)
-public class RandomAllocator implements HostAllocator {
- private static final Logger s_logger = Logger.getLogger(RandomAllocator.class);
- private String _name;
- private HostDao _hostDao;
- private ResourceManager _resourceMgr;
-
- @Override
- public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
- ExcludeList avoid, int returnUpTo) {
- return allocateTo(vmProfile, plan, type, avoid, returnUpTo, true);
- }
-
- @Override
- public List<Host> allocateTo(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, Type type,
- ExcludeList avoid, int returnUpTo, boolean considerReservedCapacity) {
-
- long dcId = plan.getDataCenterId();
- Long podId = plan.getPodId();
- Long clusterId = plan.getClusterId();
- ServiceOffering offering = vmProfile.getServiceOffering();
-
- List<Host> suitableHosts = new ArrayList<Host>();
-
- if (type == Host.Type.Storage) {
- return suitableHosts;
- }
-
- String hostTag = offering.getHostTag();
- if(hostTag != null){
- s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId + " having host tag:" + hostTag);
- }else{
- s_logger.debug("Looking for hosts in dc: " + dcId + " pod:" + podId + " cluster:" + clusterId);
- }
-
- // list all computing hosts, regardless of whether they support routing...it's random after all
- List<? extends Host> hosts = new ArrayList<HostVO>();
- if(hostTag != null){
- hosts = _hostDao.listByHostTag(type, clusterId, podId, dcId, hostTag);
- }else{
- hosts = _resourceMgr.listAllUpAndEnabledHosts(type, clusterId, podId, dcId);
- }
-
- s_logger.debug("Random Allocator found " + hosts.size() + " hosts");
-
- if (hosts.size() == 0) {
- return suitableHosts;
- }
-
-
- Collections.shuffle(hosts);
- for (Host host : hosts) {
- if(suitableHosts.size() == returnUpTo){
- break;
- }
-
- if (!avoid.shouldAvoid(host)) {
- suitableHosts.add(host);
- }else{
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Host name: " + host.getName() + ", hostId: "+ host.getId() +" is in avoid set, skipping this and trying other available hosts");
- }
- }
- }
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Random Host Allocator returning "+suitableHosts.size() +" suitable hosts");
- }
- return suitableHosts;
- }
-
- @Override
- public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering offering) {
- // currently we do no special checks to rule out a VM being upgradable to an offering, so
- // return true
- return true;
- }
-
- @Override
- public boolean configure(String name, Map<String, Object> params) {
- ComponentLocator locator = ComponentLocator.getCurrentLocator();
- _hostDao = locator.getDao(HostDao.class);
- _resourceMgr = locator.getManager(ResourceManager.class);
- if (_hostDao == null) {
- s_logger.error("Unable to get host dao.");
- return false;
- }
- _name=name;
-
- return true;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- @Override
- public boolean start() {
- return true;
- }
-
- @Override
- public boolean stop() {
- return true;
- }
-}