|
16 | 16 | // under the License.
|
17 | 17 | package com.cloud.agent.manager;
|
18 | 18 |
|
19 |
| -import java.lang.reflect.Constructor; |
20 |
| -import java.lang.reflect.InvocationTargetException; |
21 |
| -import java.nio.channels.ClosedChannelException; |
22 |
| -import java.util.ArrayList; |
23 |
| -import java.util.Arrays; |
24 |
| -import java.util.Date; |
25 |
| -import java.util.HashMap; |
26 |
| -import java.util.List; |
27 |
| -import java.util.Map; |
28 |
| -import java.util.concurrent.ConcurrentHashMap; |
29 |
| -import java.util.concurrent.ExecutorService; |
30 |
| -import java.util.concurrent.LinkedBlockingQueue; |
31 |
| -import java.util.concurrent.ScheduledExecutorService; |
32 |
| -import java.util.concurrent.ScheduledThreadPoolExecutor; |
33 |
| -import java.util.concurrent.ThreadPoolExecutor; |
34 |
| -import java.util.concurrent.TimeUnit; |
35 |
| -import java.util.concurrent.locks.Lock; |
36 |
| -import java.util.concurrent.locks.ReentrantLock; |
37 |
| - |
38 |
| -import javax.inject.Inject; |
39 |
| -import javax.naming.ConfigurationException; |
40 |
| - |
41 |
| -import com.cloud.configuration.Config; |
42 |
| -import com.cloud.utils.NumbersUtil; |
43 |
| -import org.apache.cloudstack.agent.lb.IndirectAgentLB; |
44 |
| -import org.apache.cloudstack.ca.CAManager; |
45 |
| -import org.apache.cloudstack.framework.config.ConfigKey; |
46 |
| -import org.apache.cloudstack.framework.config.Configurable; |
47 |
| -import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
48 |
| -import org.apache.cloudstack.framework.jobs.AsyncJob; |
49 |
| -import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext; |
50 |
| -import org.apache.cloudstack.managed.context.ManagedContextRunnable; |
51 |
| -import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao; |
52 |
| -import org.apache.cloudstack.utils.identity.ManagementServerNode; |
53 |
| -import org.apache.log4j.Logger; |
54 |
| -import org.apache.log4j.MDC; |
55 |
| - |
56 | 19 | import com.cloud.agent.AgentManager;
|
57 | 20 | import com.cloud.agent.Listener;
|
58 | 21 | import com.cloud.agent.StartupCommandProcessor;
|
|
78 | 41 | import com.cloud.agent.transport.Request;
|
79 | 42 | import com.cloud.agent.transport.Response;
|
80 | 43 | import com.cloud.alert.AlertManager;
|
| 44 | +import com.cloud.capacity.Capacity; |
| 45 | +import com.cloud.capacity.CapacityVO; |
| 46 | +import com.cloud.capacity.dao.CapacityDao; |
| 47 | +import com.cloud.configuration.Config; |
81 | 48 | import com.cloud.configuration.ManagementServiceConfiguration;
|
82 | 49 | import com.cloud.dc.ClusterVO;
|
83 | 50 | import com.cloud.dc.DataCenterVO;
|
|
101 | 68 | import com.cloud.resource.ResourceManager;
|
102 | 69 | import com.cloud.resource.ResourceState;
|
103 | 70 | import com.cloud.resource.ServerResource;
|
| 71 | +import com.cloud.utils.NumbersUtil; |
104 | 72 | import com.cloud.utils.Pair;
|
105 | 73 | import com.cloud.utils.component.ManagerBase;
|
106 | 74 | import com.cloud.utils.concurrency.NamedThreadFactory;
|
|
120 | 88 | import com.cloud.utils.nio.NioServer;
|
121 | 89 | import com.cloud.utils.nio.Task;
|
122 | 90 | import com.cloud.utils.time.InaccurateClock;
|
| 91 | +import org.apache.cloudstack.agent.lb.IndirectAgentLB; |
| 92 | +import org.apache.cloudstack.ca.CAManager; |
| 93 | +import org.apache.cloudstack.framework.config.ConfigKey; |
| 94 | +import org.apache.cloudstack.framework.config.Configurable; |
| 95 | +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
| 96 | +import org.apache.cloudstack.framework.jobs.AsyncJob; |
| 97 | +import org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext; |
| 98 | +import org.apache.cloudstack.managed.context.ManagedContextRunnable; |
| 99 | +import org.apache.cloudstack.outofbandmanagement.dao.OutOfBandManagementDao; |
| 100 | +import org.apache.cloudstack.utils.identity.ManagementServerNode; |
123 | 101 | import org.apache.commons.lang3.StringUtils;
|
| 102 | +import org.apache.log4j.Logger; |
| 103 | +import org.apache.log4j.MDC; |
| 104 | + |
| 105 | +import javax.inject.Inject; |
| 106 | +import javax.naming.ConfigurationException; |
| 107 | +import java.lang.reflect.Constructor; |
| 108 | +import java.lang.reflect.InvocationTargetException; |
| 109 | +import java.nio.channels.ClosedChannelException; |
| 110 | +import java.util.ArrayList; |
| 111 | +import java.util.Arrays; |
| 112 | +import java.util.Date; |
| 113 | +import java.util.HashMap; |
| 114 | +import java.util.List; |
| 115 | +import java.util.Map; |
| 116 | +import java.util.concurrent.ConcurrentHashMap; |
| 117 | +import java.util.concurrent.ExecutorService; |
| 118 | +import java.util.concurrent.LinkedBlockingQueue; |
| 119 | +import java.util.concurrent.ScheduledExecutorService; |
| 120 | +import java.util.concurrent.ScheduledThreadPoolExecutor; |
| 121 | +import java.util.concurrent.ThreadPoolExecutor; |
| 122 | +import java.util.concurrent.TimeUnit; |
| 123 | +import java.util.concurrent.locks.Lock; |
| 124 | +import java.util.concurrent.locks.ReentrantLock; |
| 125 | + |
| 126 | +import static com.cloud.configuration.ConfigurationManagerImpl.HOST_RESERVED_MEM_MB; |
| 127 | +import static com.cloud.configuration.ConfigurationManagerImpl.HOST_RESERVED_MEM_MB_STRING; |
124 | 128 |
|
125 | 129 | /**
|
126 | 130 | * Implementation of the Agent Manager. This class controls the connection to the agents.
|
@@ -169,6 +173,8 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
|
169 | 173 |
|
170 | 174 | @Inject
|
171 | 175 | protected IndirectAgentLB indirectAgentLB;
|
| 176 | + @Inject |
| 177 | + CapacityDao _capacityDao; |
172 | 178 |
|
173 | 179 | protected int _retry = 2;
|
174 | 180 |
|
@@ -1783,6 +1789,7 @@ public void processConnect(final Host host, final StartupCommand cmd, final bool
|
1783 | 1789 | Map<String, String> params = new HashMap<String, String>();
|
1784 | 1790 | params.put(Config.RouterAggregationCommandEachTimeout.toString(), _configDao.getValue(Config.RouterAggregationCommandEachTimeout.toString()));
|
1785 | 1791 | params.put(Config.MigrateWait.toString(), _configDao.getValue(Config.MigrateWait.toString()));
|
| 1792 | + params.put(HOST_RESERVED_MEM_MB_STRING, _configDao.getValue(HOST_RESERVED_MEM_MB_STRING)); |
1786 | 1793 |
|
1787 | 1794 | try {
|
1788 | 1795 | SetHostParamsCommand cmds = new SetHostParamsCommand(params);
|
@@ -1862,4 +1869,50 @@ public void propagateChangeToAgents(Map<String, String> params) {
|
1862 | 1869 | sendCommandToAgents(hostsPerZone, params);
|
1863 | 1870 | }
|
1864 | 1871 | }
|
| 1872 | + |
| 1873 | + @Override |
| 1874 | + public void updateCapacityOfHosts() { |
| 1875 | + Map<Long, List<Long>> hostsByZone = new HashMap<>(); |
| 1876 | + Map<String, String> params = new HashMap<>(); |
| 1877 | + boolean status = true; |
| 1878 | + List<HostVO> allHosts = _resourceMgr.listAllHostsInAllZonesByType(Host.Type.Routing); |
| 1879 | + if (allHosts == null) { |
| 1880 | + return; |
| 1881 | + } |
| 1882 | + |
| 1883 | + String value = HOST_RESERVED_MEM_MB.value().toString(); |
| 1884 | + params.put(HOST_RESERVED_MEM_MB.key(), value); |
| 1885 | + for (HostVO host : allHosts) { |
| 1886 | + Long zoneId = host.getDataCenterId(); |
| 1887 | + try { |
| 1888 | + // Update the "ram" for all hosts |
| 1889 | + long updatedHostRam = (host.getTotalMemory() + host.getDom0MinMemory()) - (Integer.parseInt(value) * 1024L * 1024L); |
| 1890 | + if (updatedHostRam > 0) { |
| 1891 | + host.setTotalMemory(updatedHostRam); |
| 1892 | + // Update "dom0_memory" in host table |
| 1893 | + host.setDom0MinMemory(Integer.parseInt(value) * 1024L * 1024L); |
| 1894 | + _hostDao.update(host.getId(), host); |
| 1895 | + |
| 1896 | + // Update the "total_capacity" for all hosts in op_host_capacity |
| 1897 | + CapacityVO memCap = _capacityDao.findByHostIdType(host.getId(), Capacity.CAPACITY_TYPE_MEMORY); |
| 1898 | + memCap.setTotalCapacity(host.getTotalMemory()); |
| 1899 | + _capacityDao.update(memCap.getId(), memCap); |
| 1900 | + } else { |
| 1901 | + status = false; |
| 1902 | + } |
| 1903 | + } catch (Exception e) { |
| 1904 | + s_logger.error("Unable to update the reserved memory capacity for host id " + host.getId() + " : " + e.getMessage()); |
| 1905 | + status = false; |
| 1906 | + continue; |
| 1907 | + } |
| 1908 | + |
| 1909 | + List<Long> hostIds = hostsByZone.getOrDefault(zoneId, new ArrayList<>()); |
| 1910 | + hostIds.add(host.getId()); |
| 1911 | + hostsByZone.put(zoneId, hostIds); |
| 1912 | + } |
| 1913 | + |
| 1914 | + if (status) { |
| 1915 | + sendCommandToAgents(hostsByZone, params); |
| 1916 | + } |
| 1917 | + } |
1865 | 1918 | }
|
0 commit comments