YARN-5872. Add AlwayReject policies for router and amrmproxy. (Carlo Curino via Subru).
This commit is contained in:
parent
e0f0e7afed
commit
db26bade05
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
* 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.hadoop.yarn.server.federation.policies.amrmproxy;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse;
|
||||||
|
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
||||||
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyInitializationContext;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyInitializationContextValidator;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyInitializationException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An implementation of the {@link FederationAMRMProxyPolicy} that simply
|
||||||
|
* rejects all requests. Useful to prevent apps from accessing any sub-cluster.
|
||||||
|
*/
|
||||||
|
public class RejectAMRMProxyPolicy extends AbstractAMRMProxyPolicy {
|
||||||
|
|
||||||
|
private Set<SubClusterId> knownClusterIds = new HashSet<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reinitialize(FederationPolicyInitializationContext policyContext)
|
||||||
|
throws FederationPolicyInitializationException {
|
||||||
|
// overrides initialize to avoid weight checks that do no apply for
|
||||||
|
// this policy.
|
||||||
|
FederationPolicyInitializationContextValidator.validate(policyContext,
|
||||||
|
this.getClass().getCanonicalName());
|
||||||
|
setPolicyContext(policyContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<SubClusterId, List<ResourceRequest>> splitResourceRequests(
|
||||||
|
List<ResourceRequest> resourceRequests) throws YarnException {
|
||||||
|
throw new FederationPolicyException("The policy configured for this queue "
|
||||||
|
+ "rejects all routing requests by construction.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void notifyOfResponse(SubClusterId subClusterId,
|
||||||
|
AllocateResponse response) throws YarnException {
|
||||||
|
// This might be invoked for applications started with a previous policy,
|
||||||
|
// do nothing for this policy.
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
* 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.hadoop.yarn.server.federation.policies.manager;
|
||||||
|
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.RejectAMRMProxyPolicy;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.router.RejectRouterPolicy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a simple implementation of a {@code
|
||||||
|
* FederationPolicyManager}.
|
||||||
|
*
|
||||||
|
* This policy rejects all reuqests for both router and amrmproxy routing. This
|
||||||
|
* is to be used to prevent applications in a specific queue (or if used as
|
||||||
|
* default for non-configured queues) from accessing cluster resources.
|
||||||
|
*/
|
||||||
|
public class RejectAllPolicyManager extends AbstractPolicyManager {
|
||||||
|
|
||||||
|
public RejectAllPolicyManager() {
|
||||||
|
// this structurally hard-codes two compatible policies for Router and
|
||||||
|
// AMRMProxy.
|
||||||
|
routerFederationPolicy = RejectRouterPolicy.class;
|
||||||
|
amrmProxyFederationPolicy = RejectAMRMProxyPolicy.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
* 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.hadoop.yarn.server.federation.policies.router;
|
||||||
|
|
||||||
|
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
|
||||||
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyInitializationContext;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.FederationPolicyInitializationContextValidator;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyInitializationException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This {@link FederationRouterPolicy} simply rejects all incoming requests.
|
||||||
|
* This is useful to prevent applications running in a queue to be run
|
||||||
|
* anywhere in the federated cluster.
|
||||||
|
*/
|
||||||
|
public class RejectRouterPolicy extends AbstractRouterPolicy {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reinitialize(
|
||||||
|
FederationPolicyInitializationContext federationPolicyContext)
|
||||||
|
throws FederationPolicyInitializationException {
|
||||||
|
FederationPolicyInitializationContextValidator
|
||||||
|
.validate(federationPolicyContext, this.getClass().getCanonicalName());
|
||||||
|
setPolicyContext(federationPolicyContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The policy always reject requests.
|
||||||
|
*
|
||||||
|
* @param appSubmissionContext the context for the app being submitted.
|
||||||
|
*
|
||||||
|
* @return (never).
|
||||||
|
*
|
||||||
|
* @throws YarnException (always) to prevent applications in this queue to
|
||||||
|
* be run anywhere in the federated cluster.
|
||||||
|
*/
|
||||||
|
public SubClusterId getHomeSubcluster(
|
||||||
|
ApplicationSubmissionContext appSubmissionContext) throws YarnException {
|
||||||
|
|
||||||
|
// run standard validation, as error might differ
|
||||||
|
validate(appSubmissionContext);
|
||||||
|
|
||||||
|
throw new FederationPolicyException("The policy configured for this queue"
|
||||||
|
+ " (" + appSubmissionContext.getQueue() + ") reject all routing "
|
||||||
|
+ "requests by construction. Application " + appSubmissionContext
|
||||||
|
.getApplicationId() + " cannot be routed to any RM.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
* 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.hadoop.yarn.server.federation.policies.amrmproxy;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.hadoop.yarn.api.records.ResourceRequest;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.BaseFederationPoliciesTest;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.dao.WeightedPolicyInfo;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterId;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterIdInfo;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterInfo;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.store.records.SubClusterState;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.utils.FederationPoliciesTestUtil;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple test class for the {@link RejectAMRMProxyPolicy}.
|
||||||
|
*/
|
||||||
|
public class TestRejectAMRMProxyPolicy
|
||||||
|
extends BaseFederationPoliciesTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
setPolicy(new RejectAMRMProxyPolicy());
|
||||||
|
// needed for base test to work
|
||||||
|
setPolicyInfo(mock(WeightedPolicyInfo.class));
|
||||||
|
|
||||||
|
for (int i = 1; i <= 2; i++) {
|
||||||
|
SubClusterIdInfo sc = new SubClusterIdInfo("sc" + i);
|
||||||
|
SubClusterInfo sci = mock(SubClusterInfo.class);
|
||||||
|
when(sci.getState()).thenReturn(SubClusterState.SC_RUNNING);
|
||||||
|
when(sci.getSubClusterId()).thenReturn(sc.toId());
|
||||||
|
getActiveSubclusters().put(sc.toId(), sci);
|
||||||
|
}
|
||||||
|
|
||||||
|
FederationPoliciesTestUtil.initializePolicyContext(getPolicy(),
|
||||||
|
mock(WeightedPolicyInfo.class), getActiveSubclusters());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test (expected = FederationPolicyException.class)
|
||||||
|
public void testSplitAllocateRequest() throws Exception {
|
||||||
|
// verify the request is broadcasted to all subclusters
|
||||||
|
String[] hosts = new String[] {"host1", "host2" };
|
||||||
|
List<ResourceRequest> resourceRequests = FederationPoliciesTestUtil
|
||||||
|
.createResourceRequests(hosts, 2 * 1024, 2, 1, 3, null, false);
|
||||||
|
|
||||||
|
Map<SubClusterId, List<ResourceRequest>> response =
|
||||||
|
((FederationAMRMProxyPolicy) getPolicy())
|
||||||
|
.splitResourceRequests(resourceRequests);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/**
|
||||||
|
* 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.hadoop.yarn.server.federation.policies.manager;
|
||||||
|
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.amrmproxy.RejectAMRMProxyPolicy;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.router.RejectRouterPolicy;
|
||||||
|
import org.junit.Before;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple test of {@link RejectAllPolicyManager}.
|
||||||
|
*/
|
||||||
|
public class TestRejectAllPolicyManager extends BasePolicyManagerTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
// config policy
|
||||||
|
wfp = new RejectAllPolicyManager();
|
||||||
|
wfp.setQueue("queue1");
|
||||||
|
|
||||||
|
// set expected params that the base test class will use for tests
|
||||||
|
expectedPolicyManager = RejectAllPolicyManager.class;
|
||||||
|
expectedAMRMProxyPolicy = RejectAMRMProxyPolicy.class;
|
||||||
|
expectedRouterPolicy = RejectRouterPolicy.class;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,63 @@
|
||||||
|
/**
|
||||||
|
* 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.hadoop.yarn.server.federation.policies.router;
|
||||||
|
|
||||||
|
import org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext;
|
||||||
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.policies.exceptions.FederationPolicyException;
|
||||||
|
import org.apache.hadoop.yarn.server.federation.utils.FederationPoliciesTestUtil;
|
||||||
|
import org.apache.hadoop.yarn.util.resource.Resources;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple test class for the {@link RejectRouterPolicy}. Tests that one of the
|
||||||
|
* active subcluster is chosen.
|
||||||
|
*/
|
||||||
|
public class TestRejectRouterPolicy extends BaseRouterPoliciesTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
setPolicy(new RejectRouterPolicy());
|
||||||
|
|
||||||
|
// setting up the active sub-clusters for this test
|
||||||
|
setMockActiveSubclusters(2);
|
||||||
|
|
||||||
|
// initialize policy with context
|
||||||
|
FederationPoliciesTestUtil.initializePolicyContext(getPolicy(),
|
||||||
|
getPolicyInfo(), getActiveSubclusters());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = FederationPolicyException.class)
|
||||||
|
public void testNoClusterIsChosen() throws YarnException {
|
||||||
|
((FederationRouterPolicy) getPolicy())
|
||||||
|
.getHomeSubcluster(getApplicationSubmissionContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Test(expected = FederationPolicyException.class)
|
||||||
|
public void testNullQueueRouting() throws YarnException {
|
||||||
|
FederationRouterPolicy localPolicy = (FederationRouterPolicy) getPolicy();
|
||||||
|
ApplicationSubmissionContext applicationSubmissionContext =
|
||||||
|
ApplicationSubmissionContext.newInstance(null, null, null, null, null,
|
||||||
|
false, false, 0, Resources.none(), null, false, null, null);
|
||||||
|
localPolicy.getHomeSubcluster(applicationSubmissionContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue