| <?xml version='1.0' encoding='utf-8' ?> |
| <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| <!ENTITY % BOOK_ENTITIES SYSTEM "cloudstack.ent"> |
| %BOOK_ENTITIES; |
| ]> |
| |
| <!-- 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. |
| --> |
| |
| <chapter id="custom-hostallocator"> |
| <title>Implementing a custom HostAllocator</title> |
| <para>HostAllocators are written by extending com.cloud.agent.manager.allocator.HostAllocator interface.</para> |
| |
| <section> |
| <title>HostAllocator Interface</title> |
| <para>The interface defines the following two methods.</para> |
| |
| <programlisting> |
| <xi:include parse="text" href="extras/custom-hostallocator.java" xmlns:xi="http://www.w3.org/2001/XInclude" /> |
| </programlisting> |
| <para>A custom HostAllocator can be written by implementing the ‘allocateTo’ method</para> |
| |
| <section> |
| <title>Input Parameters for the method ‘HostAllocator :: allocateTo’</title> |
| |
| <para><emphasis role="italic">com.cloud.vm.VirtualMachineProfile vmProfile</emphasis></para> |
| <para>VirtualMachineProfile describes one virtual machine. This allows the adapters like Allocators to process the information in the virtual machine and make determinations on what the virtual machine profile should look like before it is actually started on the hypervisor.</para> |
| <para>HostAllocators can make use of the following information present in the VirtualMachineProfile:</para> |
| <itemizedlist> |
| <listitem> |
| <para>The ServiceOffering that specifies configuration like requested CPU speed, RAM etc necessary for the guest VM.</para> |
| </listitem> |
| <listitem> |
| <para>The VirtualMachineTemplate, the template to be used to start the VM.</para> |
| </listitem> |
| </itemizedlist> |
| |
| <para><emphasis role="italic">com.cloud.deploy.DeploymentPlan plan</emphasis></para> |
| <para>DeploymentPlan should specify:</para> |
| <itemizedlist> |
| <listitem> |
| <para>dataCenterId: The data center the VM should deploy in</para> |
| </listitem> |
| <listitem> |
| <para>podId: The pod the Vm should deploy in; null if no preference</para> |
| </listitem> |
| <listitem> |
| <para>clusterId: The cluster the VM should deploy in; null if no preference</para> |
| </listitem> |
| <listitem> |
| <para>poolId: The storage pool the VM should be created in; null if no preference</para> |
| </listitem> |
| </itemizedlist> |
| |
| <para><emphasis role="italic">com.cloud.host.Host.Type type</emphasis></para> |
| <para>Type of the Host needed for this guest VM. Currently com.cloud.host.Host.Type interface defines the following Host types:</para> |
| <itemizedlist> |
| <listitem> |
| <para>Storage</para> |
| </listitem> |
| <listitem> |
| <para>Routing</para> |
| </listitem> |
| <listitem> |
| <para>SecondaryStorage</para> |
| </listitem> |
| <listitem> |
| <para>ConsoleProxy</para> |
| </listitem> |
| <listitem> |
| <para>ExternalFirewall</para> |
| </listitem> |
| <listitem> |
| <para>ExternalLoadBalancer</para> |
| </listitem> |
| </itemizedlist> |
| |
| <para><emphasis role="italic">com.cloud.deploy.DeploymentPlanner.ExcludeList avoid</emphasis></para> |
| <para>The ExcludeList specifies what datacenters, pods, clusters, hosts, storagePools should not be considered for allocating this guest VM. HostAllocators should avoid the hosts that are mentioned in ExcludeList.hostIds.</para> |
| <itemizedlist> |
| <listitem> |
| <para>Set <replaceable>Long</replaceable> dcIds;</para> |
| </listitem> |
| <listitem> |
| <para>Set <replaceable>Long</replaceable> podIds;</para> |
| </listitem> |
| <listitem> |
| <para>Set <replaceable>Long</replaceable> clusterIds;</para> |
| </listitem> |
| <listitem> |
| <para>Set <replaceable>Long</replaceable> hostIds;</para> |
| </listitem> |
| <listitem> |
| <para>Set <replaceable>Long</replaceable> poolIds;</para> |
| </listitem> |
| </itemizedlist> |
| |
| <para><emphasis role="italic">int returnUpTo</emphasis></para> |
| <para>This specifies return up to that many available hosts for this guest VM.</para> |
| <para>To get all possible hosts, set this value to -1.</para> |
| </section> |
| |
| <section> |
| <title>Reference HostAllocator implementation</title> |
| <para>Refer com.cloud.agent.manager.allocator.impl.FirstFitAllocator that implements the HostAllocator interface. This allocator checks available hosts in the specified datacenter, Pod, Cluster and considering the given ServiceOffering requirements.</para> |
| <para>If returnUpTo = 1, this allocator would return the first Host that fits the requirements of the guest VM.</para> |
| </section> |
| |
| <section> |
| <title>Loading a custom HostAllocator</title> |
| <orderedlist> |
| <listitem> |
| <para>Write a custom HostAllocator class, implementing the interface described above.</para> |
| </listitem> |
| <listitem> |
| <para>Package the code into a JAR file and make the JAR available in the classpath of the Management Server/tomcat.</para> |
| </listitem> |
| <listitem> |
| <para>Modify the components.xml and components-premium.xml files found in /client/ tomcatconf as follows.</para> |
| </listitem> |
| <listitem> |
| <para>Search for ‘HostAllocator’ in these files.</para> |
| <programlisting> |
| <xi:include parse="text" href="extras/custom-hostallocator2.java" xmlns:xi="http://www.w3.org/2001/XInclude" /> |
| </programlisting> |
| </listitem> |
| <listitem> |
| <para>Replace the FirstFitAllocator with your class name. Optionally, you can change the name of the adapter as well.</para> |
| </listitem> |
| <listitem> |
| <para>Restart the Management Server.</para> |
| </listitem> |
| </orderedlist> |
| </section> |
| </section> |
| </chapter> |