Github user jerrypeng commented on a diff in the pull request:

    https://github.com/apache/storm/pull/921#discussion_r46724663
  
    --- Diff: 
storm-core/src/jvm/backtype/storm/scheduler/resource/strategies/eviction/DefaultEvictionStrategy.java
 ---
    @@ -0,0 +1,111 @@
    +/**
    + * 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
    + * <p>
    + * http://www.apache.org/licenses/LICENSE-2.0
    + * <p>
    + * 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 backtype.storm.scheduler.resource.strategies.eviction;
    +
    +import backtype.storm.scheduler.Cluster;
    +import backtype.storm.scheduler.Topologies;
    +import backtype.storm.scheduler.TopologyDetails;
    +import backtype.storm.scheduler.WorkerSlot;
    +import backtype.storm.scheduler.resource.RAS_Nodes;
    +import backtype.storm.scheduler.resource.ResourceUtils;
    +import backtype.storm.scheduler.resource.User;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import java.util.Collection;
    +import java.util.Map;
    +
    +public class DefaultEvictionStrategy implements IEvictionStrategy {
    +    private static final Logger LOG = LoggerFactory
    +            .getLogger(DefaultEvictionStrategy.class);
    +
    +    private Topologies topologies;
    +    private Cluster cluster;
    +    private Map<String, User> userMap;
    +    private RAS_Nodes nodes;
    +
    +    @Override
    +    public void prepare(Topologies topologies, Cluster cluster, 
Map<String, User> userMap, RAS_Nodes nodes) {
    +        this.topologies = topologies;
    +        this.cluster = cluster;
    +        this.userMap = userMap;
    +        this.nodes = nodes;
    +    }
    +
    +    @Override
    +    public boolean makeSpaceForTopo(TopologyDetails td) {
    +        LOG.debug("attempting to make space for topo {} from user {}", 
td.getName(), td.getTopologySubmitter());
    +        User submitter = this.userMap.get(td.getTopologySubmitter());
    +        if (submitter.getCPUResourceGuaranteed() == null || 
submitter.getMemoryResourceGuaranteed() == null) {
    +            return false;
    +        }
    +        double cpuNeeded = td.getTotalRequestedCpu() / 
submitter.getCPUResourceGuaranteed();
    +        double memoryNeeded = (td.getTotalRequestedMemOffHeap() + 
td.getTotalRequestedMemOnHeap()) / submitter.getMemoryResourceGuaranteed();
    +
    +        User evictUser = this.findUserWithMostResourcesAboveGuarantee();
    +        //user has enough resource under his or her resource guarantee to 
schedule topology
    +        if ((1.0 - submitter.getCPUResourcePoolUtilization()) >= cpuNeeded 
&& (1.0 - submitter.getMemoryResourcePoolUtilization()) >= memoryNeeded) {
    +            if (evictUser != null) {
    +
    +                TopologyDetails topologyEvict = 
evictUser.getRunningTopologyWithLowestPriority();
    +                evictTopology(topologyEvict);
    +                return true;
    +            }
    +        } else {
    +            if (evictUser != null) {
    +                if ((evictUser.getResourcePoolAverageUtilization() - 1.0) 
> (cpuNeeded + (submitter.getResourcePoolAverageUtilization() - 1.0))) {
    +                    TopologyDetails topologyEvict = 
evictUser.getRunningTopologyWithLowestPriority();
    +                    evictTopology(topologyEvict);
    +                    return true;
    +                }
    +            }
    +        }
    +        //See if there is a lower priority topology that can be evicted 
from the current user
    +        for (TopologyDetails topo : submitter.getTopologiesRunning()) {
    +            //check to if there is a topology with a lower priority we can 
evict
    +            if (topo.getTopologyPriority() > td.getTopologyPriority()) {
    +                evictTopology(topo);
    +                return true;
    +            }
    +        }
    +        return false;
    +    }
    +
    +    private void evictTopology(TopologyDetails topologyEvict) {
    +        Collection<WorkerSlot> workersToEvict = 
this.cluster.getUsedSlotsByTopologyId(topologyEvict.getId());
    +        User submitter = 
this.userMap.get(topologyEvict.getTopologySubmitter());
    +
    +        LOG.info("Evicting Topology {} with workers: {} from user {}", 
topologyEvict.getName(), workersToEvict, topologyEvict.getTopologySubmitter());
    +        this.nodes.freeSlots(workersToEvict);
    +        submitter.moveTopoFromRunningToPending(topologyEvict, 
this.cluster);
    +    }
    +
    +    private User findUserWithMostResourcesAboveGuarantee() {
    --- End diff --
    
    will rename


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to