|
| 1 | +/** |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with this |
| 4 | + * work for additional information regarding copyright ownership. The ASF |
| 5 | + * licenses this file to you under the Apache License, Version 2.0 (the |
| 6 | + * "License"); you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + * License for the specific language governing permissions and limitations under |
| 15 | + * the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.hadoop.yarn.server.federation.policies.manager; |
| 19 | + |
| 20 | +import org.apache.hadoop.classification.VisibleForTesting; |
| 21 | +import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.HomeAMRMProxyPolicy; |
| 22 | +import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.LocalityMulticastAMRMProxyPolicy; |
| 23 | +import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo; |
| 24 | +import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyInitializationException; |
| 25 | +import org.apache.hadoop.yarn.server.federation.policies.router.LocalityRouterPolicy; |
| 26 | +import org.apache.hadoop.yarn.server.federation.policies.router.WeightedRandomRouterPolicy; |
| 27 | +import org.apache.hadoop.yarn.server.federation.store.records.SubClusterPolicyConfiguration; |
| 28 | + |
| 29 | +import java.nio.ByteBuffer; |
| 30 | + |
| 31 | +/** |
| 32 | + * Policy that allows operator to configure "weights" for routing. This picks a |
| 33 | + * {@link WeightedRandomRouterPolicy} for the router and a {@link |
| 34 | + * HomeAMRMProxyPolicy} for the amrmproxy as they are designed to |
| 35 | + * work together. |
| 36 | + */ |
| 37 | +public class WeightedHomePolicyManager extends AbstractPolicyManager { |
| 38 | + |
| 39 | + private WeightedPolicyInfo weightedPolicyInfo; |
| 40 | + |
| 41 | + public WeightedHomePolicyManager() { |
| 42 | + // this structurally hard-codes two compatible policies for Router and |
| 43 | + // AMRMProxy. |
| 44 | + routerFederationPolicy = WeightedRandomRouterPolicy.class; |
| 45 | + amrmProxyFederationPolicy = HomeAMRMProxyPolicy.class; |
| 46 | + weightedPolicyInfo = new WeightedPolicyInfo(); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public SubClusterPolicyConfiguration serializeConf() |
| 51 | + throws FederationPolicyInitializationException { |
| 52 | + ByteBuffer buf = weightedPolicyInfo.toByteBuffer(); |
| 53 | + return SubClusterPolicyConfiguration |
| 54 | + .newInstance(getQueue(), this.getClass().getCanonicalName(), buf); |
| 55 | + } |
| 56 | + |
| 57 | + @VisibleForTesting |
| 58 | + public WeightedPolicyInfo getWeightedPolicyInfo() { |
| 59 | + return weightedPolicyInfo; |
| 60 | + } |
| 61 | + |
| 62 | + @VisibleForTesting |
| 63 | + public void setWeightedPolicyInfo( |
| 64 | + WeightedPolicyInfo weightedPolicyInfo) { |
| 65 | + this.weightedPolicyInfo = weightedPolicyInfo; |
| 66 | + } |
| 67 | +} |
0 commit comments