[ https://issues.apache.org/jira/browse/CLOUDSTACK-10132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16249211#comment-16249211 ]
ASF GitHub Bot commented on CLOUDSTACK-10132: --------------------------------------------- rhtyd commented on a change in pull request #2309: CLOUDSTACK-10132: Multiple Management Servers Support for agents URL: https://github.com/apache/cloudstack/pull/2309#discussion_r150465994 ########## File path: server/src/org/apache/cloudstack/agent/mslb/AgentMSLBServiceImpl.java ########## @@ -0,0 +1,137 @@ +// 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 org.apache.cloudstack.agent.mslb; + +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.ReadyCommand; +import com.cloud.host.HostVO; +import com.cloud.host.Status; +import com.cloud.hypervisor.Hypervisor; +import com.cloud.resource.ResourceManager; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import java.util.stream.Collectors; +import javax.inject.Inject; +import javax.naming.ConfigurationException; + +import org.apache.cloudstack.agent.mslb.algorithm.AgentMSLBRoundRobinAlgorithm; +import org.apache.cloudstack.agent.mslb.algorithm.AgentMSLBShuffleAlgorithm; +import org.apache.cloudstack.agent.mslb.algorithm.AgentMSLBStaticAlgorithm; +import org.apache.cloudstack.config.ApiServiceConfiguration; +import org.apache.cloudstack.framework.config.ConfigKey; +import org.apache.cloudstack.framework.config.Configurable; +import org.apache.log4j.Logger; + +import com.cloud.utils.component.ComponentLifecycleBase; +import com.cloud.utils.exception.CloudRuntimeException; +import com.google.common.base.Strings; + +public class AgentMSLBServiceImpl extends ComponentLifecycleBase implements AgentMSLB, Configurable { + public static final Logger LOG = Logger.getLogger(AgentMSLBServiceImpl.class); + + public static final ConfigKey<String> ConnectedAgentLBAlgorithm = new ConfigKey<>("Advanced", String.class, + "connected.agent.mslb.algorithm", "static", + "The algorithm to applied on the provided 'host' management server list that is sent to indirect agents. Allowed values are: static, roundrobin and shuffle.", + true, ConfigKey.Scope.Global); + + private static Map<String, AgentMSLBAlgorithm> algorithmMap = new HashMap<>(); + + @Inject + ResourceManager resourceManager; + @Inject + AgentManager agentManager; + + @Override + public List<String> getManagementServerList() { + final String msServerAddresses = ApiServiceConfiguration.ManagementServerAddresses.value(); + if (Strings.isNullOrEmpty(msServerAddresses)) { + throw new CloudRuntimeException(String.format("No management server addresses are defined in '%s' setting", + ApiServiceConfiguration.ManagementServerAddresses.key())); + } + + return getAgentMSLBAlgorithm().getMSList(Arrays.asList(msServerAddresses.replace(" ", "").split(","))); + } + + protected List<HostVO> getOrderedRunningIndirectAgentIds() { + List<HostVO> hosts = resourceManager.findDirectlyConnectedHosts(); + if (hosts != null) { + return hosts.stream() + .filter(x -> x.getState().equals(Status.Up) && x.getHypervisorType().equals(Hypervisor.HypervisorType.KVM)) + .sorted((x,y) -> Long.compare(x.getId(), y.getId())) + .collect(Collectors.toList()); + } + return null; + } + + @Override + public void propagateManagementServerListToAgents() { + List<HostVO> hosts = getOrderedRunningIndirectAgentIds(); + if (hosts != null) { + for (HostVO h : hosts) { Review comment: @nvazquez I don't think it's a good idea, `resource claim and ownership` is not within the scope of this feature. This method will send command/answers to all the hosts (even those not managed by the `this` management server) and may cause disconnections. In case of multiple management servers, this will cause all the management servers to send multiple requests to all the agents. (note, when you do agent.send(), if the agent is not connected to `this` management server, it will use clustered mgmt server impl to send the request to the forwarding agent which is via other mgmt servers). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Multiple Management Servers Support for agents > ---------------------------------------------- > > Key: CLOUDSTACK-10132 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10132 > Project: CloudStack > Issue Type: Improvement > Security Level: Public(Anyone can view this level - this is the > default.) > Affects Versions: 4.11.0.0 > Reporter: Nicolas Vazquez > Assignee: Nicolas Vazquez > > Multiple Management Servers Support for agents -- This message was sent by Atlassian JIRA (v6.4.14#64029)