cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] rhtyd commented on a change in pull request #2309: CLOUDSTACK-10132: Multiple Management Servers Support for agents
Date Thu, 01 Jan 1970 00:00:00 GMT
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_r151065113
 
 

 ##########
 File path: server/src/org/apache/cloudstack/agent/mslb/AgentMSLBServiceImpl.java
 ##########
 @@ -0,0 +1,128 @@
+// 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.host.Host;
+import com.cloud.host.HostVO;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.resource.ResourceManager;
+import com.cloud.resource.ResourceState;
+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(Long hostId, Long dcId) {
+
+        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()));
+        }
+
+        List<Long> orderedHostIds = getOrderedRunningHostIds(dcId);
+        List<String> msList = Arrays.asList(msServerAddresses.replace(" ", "").split(","));
+        AgentMSLBAlgorithm algorithm = getAgentMSLBAlgorithm();
+        return algorithm.getMSList(msList, orderedHostIds, hostId);
+    }
+
+    protected List<Long> getOrderedRunningHostIds(Long dcId) {
+        List<HostVO> hosts = resourceManager.listAllHostsInOneZoneByType(Host.Type.Routing,
dcId);
+        if (hosts != null) {
+            return hosts.stream()
+                    .filter(x -> x.getHypervisorType().equals(Hypervisor.HypervisorType.KVM)
&&
 
 Review comment:
   This should not be restricted just for KVM, but for any connected (indirect) agent.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message