Github user Ethanlm commented on a diff in the pull request:
https://github.com/apache/storm/pull/2385#discussion_r147755614
--- Diff:
storm-server/src/main/java/org/apache/storm/scheduler/resource/strategies/scheduling/GenericResourceAwareStrategy.java
---
@@ -0,0 +1,194 @@
+/*
+ * 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.storm.scheduler.resource.strategies.scheduling;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+
+import org.apache.storm.Config;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.Component;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.resource.ResourceUtils;
+import org.apache.storm.scheduler.resource.SchedulingResult;
+import org.apache.storm.scheduler.resource.SchedulingStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class GenericResourceAwareStrategy extends
BaseResourceAwareStrategy implements IStrategy {
+ private static final Logger LOG =
LoggerFactory.getLogger(GenericResourceAwareStrategy.class);
+
+ @Override
+ public SchedulingResult schedule(Cluster cluster, TopologyDetails td) {
+ prepare(cluster);
+ if (nodes.getNodes().size() <= 0) {
+ LOG.warn("No available nodes to schedule tasks on!");
+ return SchedulingResult.failure(
+ SchedulingStatus.FAIL_NOT_ENOUGH_RESOURCES, "No
available nodes to schedule tasks on!");
+ }
+ Collection<ExecutorDetails> unassignedExecutors =
+ new HashSet<>(this.cluster.getUnassignedExecutors(td));
+ LOG.info("ExecutorsNeedScheduling: {}", unassignedExecutors);
+ Collection<ExecutorDetails> scheduledTasks = new ArrayList<>();
+ List<Component> spouts = this.getSpouts(td);
+
+ if (spouts.size() == 0) {
+ LOG.error("Cannot find a Spout!");
+ return SchedulingResult.failure(
+ SchedulingStatus.FAIL_INVALID_TOPOLOGY, "Cannot find a
Spout!");
+ }
+
+ //order executors to be scheduled
+ List<ExecutorDetails> orderedExecutors = this.orderExecutors(td,
unassignedExecutors);
+ LOG.info("orderedExecutors");
+ LOG.info(orderedExecutors. toString());
+ Collection<ExecutorDetails> executorsNotScheduled = new
HashSet<>(unassignedExecutors);
+ List<String> favoredNodes = (List<String>)
td.getConf().get(Config.TOPOLOGY_SCHEDULER_FAVORED_NODES);
+ List<String> unFavoredNodes = (List<String>)
td.getConf().get(Config.TOPOLOGY_SCHEDULER_UNFAVORED_NODES);
+
+ for (ExecutorDetails exec : orderedExecutors) {
+ LOG.debug(
+ "Attempting to schedule: {} of component {}[ REQ {} ]",
+ exec,
+ td.getExecutorToComponent().get(exec),
+ td.getTaskResourceReqList(exec));
+ final List<ObjectResources> sortedNodes =
this.sortAllNodes(td, exec, favoredNodes, unFavoredNodes);
+ LOG.info("sortedNodes");
+ LOG.info(sortedNodes.toString());
+
+ scheduleExecutor(exec, td, scheduledTasks, sortedNodes);
+ }
+
+ executorsNotScheduled.removeAll(scheduledTasks);
+ LOG.error("/* Scheduling left over task (most likely sys tasks)
*/");
+ // schedule left over system tasks
+ for (ExecutorDetails exec : executorsNotScheduled) {
+ final List<ObjectResources> sortedNodes =
this.sortAllNodes(td, exec, favoredNodes, unFavoredNodes);
+ LOG.info("sortedNodes");
+ LOG.info(sortedNodes.toString());
--- End diff --
same here
---