Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B94FF200D1F for ; Fri, 13 Oct 2017 20:21:12 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B7BAF1609E9; Fri, 13 Oct 2017 18:21:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B47C2160BE6 for ; Fri, 13 Oct 2017 20:21:10 +0200 (CEST) Received: (qmail 5433 invoked by uid 500); 13 Oct 2017 18:21:09 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 5041 invoked by uid 99); 13 Oct 2017 18:21:09 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Oct 2017 18:21:09 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 791B0DFCBC; Fri, 13 Oct 2017 18:21:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jianhe@apache.org To: common-commits@hadoop.apache.org Date: Fri, 13 Oct 2017 18:21:11 -0000 Message-Id: <5b35831077f14a189399d06e63227467@git.apache.org> In-Reply-To: <16cfa6f3e00a40809f6ac26e512c7005@git.apache.org> References: <16cfa6f3e00a40809f6ac26e512c7005@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/93] [abbrv] hadoop git commit: YARN-7050. Post cleanup after YARN-6903, removal of org.apache.slider package. Contributed by Jian He archived-at: Fri, 13 Oct 2017 18:21:12 -0000 http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryFindNodesForNewInstances.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryFindNodesForNewInstances.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryFindNodesForNewInstances.java deleted file mode 100644 index ece65ba..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryFindNodesForNewInstances.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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.slider.server.appmaster.model.history; - -import org.apache.slider.core.exceptions.BadConfigException; -import org.apache.slider.server.appmaster.model.mock.BaseMockAppStateTest; -import org.apache.slider.server.appmaster.model.mock.MockFactory; -import org.apache.slider.server.appmaster.model.mock.MockRoleHistory; -import org.apache.slider.server.appmaster.state.ContainerOutcome; -import org.apache.slider.server.appmaster.state.NodeEntry; -import org.apache.slider.server.appmaster.state.NodeInstance; -import org.apache.slider.server.appmaster.state.RoleHistory; -import org.apache.slider.server.appmaster.state.RoleStatus; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Testing finding nodes for new instances. - * - * This stresses the non-AA codepath - */ -public class TestRoleHistoryFindNodesForNewInstances extends - BaseMockAppStateTest { - private static final Logger LOG = - LoggerFactory.getLogger(TestRoleHistoryFindNodesForNewInstances.class); - - public TestRoleHistoryFindNodesForNewInstances() throws BadConfigException { - } - - @Override - public String getTestName() { - return "TestFindNodesForNewInstances"; - } - - private NodeInstance age1Active4; - private NodeInstance age2Active2; - private NodeInstance age3Active0; - private NodeInstance age4Active1; - private NodeInstance age2Active0; - - private RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - - private RoleStatus roleStat; - private RoleStatus roleStat2; - - @Override - public void setup() throws Exception { - super.setup(); - - age1Active4 = nodeInstance(1, 4, 0, 0); - age2Active2 = nodeInstance(2, 2, 0, 1); - age3Active0 = nodeInstance(3, 0, 0, 0); - age4Active1 = nodeInstance(4, 1, 0, 0); - age2Active0 = nodeInstance(2, 0, 0, 0); - - roleHistory.insert(Arrays.asList(age2Active2, age2Active0, age4Active1, - age1Active4, age3Active0)); - roleHistory.buildRecentNodeLists(); - - roleStat = getRole0Status(); - roleStat2 = getRole2Status(); - } - - public List findNodes(int count) { - return findNodes(count, roleStat); - } - - public List findNodes(int count, RoleStatus roleStatus) { - List found = new ArrayList<>(); - for (int i = 0; i < count; i++) { - NodeInstance f = roleHistory.findRecentNodeForNewInstance(roleStatus); - if (f != null) { - found.add(f); - } - } - return found; - } - - //@Test - public void testFind1NodeR0() throws Throwable { - NodeInstance found = roleHistory.findRecentNodeForNewInstance(roleStat); - LOG.info("found: {}", found); - assertTrue(Arrays.asList(age3Active0).contains(found)); - } - - //@Test - public void testFind2NodeR0() throws Throwable { - NodeInstance found = roleHistory.findRecentNodeForNewInstance(roleStat); - LOG.info("found: {}", found); - assertTrue(Arrays.asList(age2Active0, age3Active0).contains(found)); - NodeInstance found2 = roleHistory.findRecentNodeForNewInstance(roleStat); - LOG.info("found: {}", found2); - assertTrue(Arrays.asList(age2Active0, age3Active0).contains(found2)); - assertNotEquals(found, found2); - } - - //@Test - public void testFind3NodeR0ReturnsNull() throws Throwable { - assertEquals(2, findNodes(2).size()); - NodeInstance found = roleHistory.findRecentNodeForNewInstance(roleStat); - assertNull(found); - } - - //@Test - public void testFindNodesOneEntry() throws Throwable { - List foundNodes = findNodes(4, roleStat2); - assertEquals(0, foundNodes.size()); - } - - //@Test - public void testFindNodesIndependent() throws Throwable { - assertEquals(2, findNodes(2).size()); - roleHistory.dump(); - assertEquals(0, findNodes(3, roleStat2).size()); - } - - //@Test - public void testFindNodesFallsBackWhenUsed() throws Throwable { - // mark age2 and active 0 as busy, expect a null back - age2Active0.get(getRole0Status().getKey()).onStartCompleted(); - assertNotEquals(0, age2Active0.getActiveRoleInstances(getRole0Status() - .getKey())); - age3Active0.get(getRole0Status().getKey()).onStartCompleted(); - assertNotEquals(0, age3Active0.getActiveRoleInstances(getRole0Status() - .getKey())); - NodeInstance found = roleHistory.findRecentNodeForNewInstance(roleStat); - if (found != null) { - LOG.info(found.toFullString()); - } - assertNull(found); - } - //@Test - public void testFindNodesSkipsFailingNode() throws Throwable { - // mark age2 and active 0 as busy, expect a null back - - NodeEntry entry0 = age2Active0.get(getRole0Status().getKey()); - entry0.containerCompleted( - false, - ContainerOutcome.Failed); - assertTrue(entry0.getFailed() > 0); - assertTrue(entry0.getFailedRecently() > 0); - entry0.containerCompleted( - false, - ContainerOutcome.Failed); - assertFalse(age2Active0.exceedsFailureThreshold(roleStat)); - // set failure to 1 - roleStat.getProviderRole().nodeFailureThreshold = 1; - // threshold is now exceeded - assertTrue(age2Active0.exceedsFailureThreshold(roleStat)); - - // get the role & expect age3 to be picked up, even though it is older - NodeInstance found = roleHistory.findRecentNodeForNewInstance(roleStat); - assertEquals(age3Active0, found); - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryNIComparators.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryNIComparators.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryNIComparators.java deleted file mode 100644 index 4d4cf62..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryNIComparators.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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.slider.server.appmaster.model.history; - -import org.apache.slider.server.appmaster.model.mock.BaseMockAppStateTest; -import org.apache.slider.server.appmaster.model.mock.MockFactory; -import org.apache.slider.server.appmaster.state.NodeInstance; -import org.apache.slider.server.appmaster.state.RoleStatus; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * Unit test to verify the comparators sort as expected. - */ -public class TestRoleHistoryNIComparators extends BaseMockAppStateTest { - - private NodeInstance age1Active4; - private NodeInstance age2Active2; - private NodeInstance age3Active0; - private NodeInstance age4Active1; - private NodeInstance empty = new NodeInstance("empty", MockFactory - .ROLE_COUNT); - private NodeInstance age6failing; - private NodeInstance age1failing; - - private List nodes; - private List nodesPlusEmpty; - private List allnodes; - - private RoleStatus role0Status; - - @Override - public void setup() throws Exception { - super.setup(); - - role0Status = getRole0Status(); - - age1Active4 = nodeInstance(1001, 4, 0, 0); - age2Active2 = nodeInstance(1002, 2, 0, 0); - age3Active0 = nodeInstance(1003, 0, 0, 0); - age4Active1 = nodeInstance(1004, 1, 0, 0); - age6failing = nodeInstance(1006, 0, 0, 0); - age1failing = nodeInstance(1001, 0, 0, 0); - - age6failing.get(role0Status.getKey()).setFailedRecently(2); - age1failing.get(role0Status.getKey()).setFailedRecently(1); - - nodes = Arrays.asList(age2Active2, age4Active1, age1Active4, age3Active0); - nodesPlusEmpty = Arrays.asList(age2Active2, age4Active1, age1Active4, - age3Active0, empty); - allnodes = Arrays.asList(age6failing, age2Active2, age4Active1, - age1Active4, age3Active0, age1failing); - } - - @Override - public String getTestName() { - return "TestNIComparators"; - } - - //@Test - public void testPreferred() throws Throwable { - Collections.sort(nodes, new NodeInstance.Preferred(role0Status.getKey())); - assertListEquals(nodes, Arrays.asList(age4Active1, age3Active0, - age2Active2, age1Active4)); - } - - /** - * The preferred sort still includes failures; up to next phase in process - * to handle that. - * @throws Throwable - */ - //@Test - public void testPreferredWithFailures() throws Throwable { - Collections.sort(allnodes, new NodeInstance.Preferred(role0Status - .getKey())); - assertEquals(allnodes.get(0), age6failing); - assertEquals(allnodes.get(1), age4Active1); - } - - //@Test - public void testPreferredComparatorDowngradesFailures() throws Throwable { - NodeInstance.Preferred preferred = new NodeInstance.Preferred(role0Status - .getKey()); - assertEquals(-1, preferred.compare(age6failing, age1failing)); - assertEquals(1, preferred.compare(age1failing, age6failing)); - } - - //@Test - public void testNewerThanNoRole() throws Throwable { - Collections.sort(nodesPlusEmpty, new NodeInstance.Preferred(role0Status - .getKey())); - assertListEquals(nodesPlusEmpty, Arrays.asList(age4Active1, age3Active0, - age2Active2, age1Active4, empty)); - } - - //@Test - public void testMoreActiveThan() throws Throwable { - - Collections.sort(nodes, new NodeInstance.MoreActiveThan(role0Status - .getKey())); - assertListEquals(nodes, Arrays.asList(age1Active4, age2Active2, - age4Active1, age3Active0)); - } - - //@Test - public void testMoreActiveThanEmpty() throws Throwable { - - Collections.sort(nodesPlusEmpty, new NodeInstance.MoreActiveThan( - role0Status.getKey())); - assertListEquals(nodesPlusEmpty, Arrays.asList(age1Active4, age2Active2, - age4Active1, age3Active0, empty)); - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryOutstandingRequestTracker.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryOutstandingRequestTracker.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryOutstandingRequestTracker.java deleted file mode 100644 index c1fc28f..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryOutstandingRequestTracker.java +++ /dev/null @@ -1,385 +0,0 @@ -/* - * 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.slider.server.appmaster.model.history; - -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest; -import org.apache.hadoop.yarn.util.resource.Resources; -import org.apache.slider.api.ResourceKeys; -import org.apache.slider.api.resource.Application; -import org.apache.slider.api.resource.Component; -import org.apache.slider.common.tools.SliderUtils; -import org.apache.slider.providers.PlacementPolicy; -import org.apache.slider.providers.ProviderRole; -import org.apache.slider.server.appmaster.model.mock.BaseMockAppStateTest; -import org.apache.slider.server.appmaster.model.mock.MockAppState; -import org.apache.slider.server.appmaster.model.mock.MockContainer; -import org.apache.slider.server.appmaster.model.mock.MockNodeId; -import org.apache.slider.server.appmaster.model.mock.MockPriority; -import org.apache.slider.server.appmaster.model.mock.MockResource; -import org.apache.slider.server.appmaster.operations.AbstractRMOperation; -import org.apache.slider.server.appmaster.operations.CancelSingleRequest; -import org.apache.slider.server.appmaster.operations.ContainerRequestOperation; -import org.apache.slider.server.appmaster.state.ContainerAllocationOutcome; -import org.apache.slider.server.appmaster.state.ContainerAllocationResults; -import org.apache.slider.server.appmaster.state.ContainerPriority; -import org.apache.slider.server.appmaster.state.NodeInstance; -import org.apache.slider.server.appmaster.state.OutstandingRequest; -import org.apache.slider.server.appmaster.state.OutstandingRequestTracker; -import org.apache.slider.server.appmaster.state.RoleStatus; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Test outstanding request tracker. - */ -public class TestRoleHistoryOutstandingRequestTracker extends - BaseMockAppStateTest { - private static final Logger LOG = - LoggerFactory.getLogger(TestRoleHistoryOutstandingRequestTracker.class); - - public static final String WORKERS_LABEL = "workers"; - private NodeInstance host1 = new NodeInstance("host1", 3); - private NodeInstance host2 = new NodeInstance("host2", 3); - private MockResource resource = factory.newResource(48, 1); - - private OutstandingRequestTracker tracker = new OutstandingRequestTracker(); - - public static final String WORKER = "worker"; - - @Override - public Application buildApplication() { - Application application = super.buildApplication(); - Component component = new Component().name("worker").numberOfContainers(0L); - component.getConfiguration().setProperty(ResourceKeys.YARN_LABEL_EXPRESSION, - WORKERS_LABEL); - application.getComponents().add(component); - return application; - } - - //@Test - public void testAddRetrieveEntry() throws Throwable { - OutstandingRequest request = tracker.newRequest(host1, 0); - assertEquals(tracker.lookupPlacedRequest(0, "host1"), request); - assertEquals(tracker.removePlacedRequest(request), request); - assertNull(tracker.lookupPlacedRequest(0, "host1")); - } - - //@Test - public void testAddCompleteEntry() throws Throwable { - OutstandingRequest req1 = tracker.newRequest(host1, 0); - req1.buildContainerRequest(resource, getRole0Status(), 0); - - tracker.newRequest(host2, 0).buildContainerRequest(resource, - getRole0Status(), 0); - tracker.newRequest(host1, 1).buildContainerRequest(resource, - getRole0Status(), 0); - - ContainerAllocationResults allocation = tracker.onContainerAllocated(1, - "host1", null); - assertEquals(allocation.outcome, ContainerAllocationOutcome.Placed); - assertTrue(allocation.operations.get(0) instanceof CancelSingleRequest); - - assertNull(tracker.lookupPlacedRequest(1, "host1")); - assertNotNull(tracker.lookupPlacedRequest(0, "host1")); - } - - //@Test - public void testResetOpenRequests() throws Throwable { - OutstandingRequest req1 = tracker.newRequest(null, 0); - assertFalse(req1.isLocated()); - tracker.newRequest(host1, 0); - List openRequests = tracker.listOpenRequests(); - assertEquals(1, openRequests.size()); - tracker.resetOutstandingRequests(0); - assertTrue(tracker.listOpenRequests().isEmpty()); - assertTrue(tracker.listPlacedRequests().isEmpty()); - } - - //@Test - public void testRemoveOpenRequestUnissued() throws Throwable { - OutstandingRequest req1 = tracker.newRequest(null, 0); - req1.buildContainerRequest(resource, getRole0Status(), 0); - assertEquals(1, tracker.listOpenRequests().size()); - MockContainer c1 = factory.newContainer(null, new MockPriority(0)); - c1.setResource(resource); - - ContainerAllocationResults allocation = - tracker.onContainerAllocated(0, "host1", c1); - ContainerAllocationOutcome outcome = allocation.outcome; - assertEquals(outcome, ContainerAllocationOutcome.Unallocated); - assertTrue(allocation.operations.isEmpty()); - assertEquals(1, tracker.listOpenRequests().size()); - } - - //@Test - public void testIssuedOpenRequest() throws Throwable { - OutstandingRequest req1 = tracker.newRequest(null, 0); - req1.buildContainerRequest(resource, getRole0Status(), 0); - assertEquals(1, tracker.listOpenRequests().size()); - - int pri = ContainerPriority.buildPriority(0, false); - assertTrue(pri > 0); - MockNodeId nodeId = factory.newNodeId("hostname-1"); - MockContainer c1 = factory.newContainer(nodeId, new MockPriority(pri)); - - c1.setResource(resource); - - ContainerRequest issued = req1.getIssuedRequest(); - assertEquals(issued.getCapability(), resource); - assertEquals(issued.getPriority().getPriority(), c1.getPriority() - .getPriority()); - assertTrue(req1.resourceRequirementsMatch(resource)); - - ContainerAllocationResults allocation = - tracker.onContainerAllocated(0, nodeId.getHost(), c1); - assertEquals(0, tracker.listOpenRequests().size()); - assertTrue(allocation.operations.get(0) instanceof CancelSingleRequest); - - assertEquals(allocation.outcome, ContainerAllocationOutcome.Open); - assertEquals(allocation.origin, req1); - } - - //@Test - public void testResetEntries() throws Throwable { - tracker.newRequest(host1, 0); - tracker.newRequest(host2, 0); - tracker.newRequest(host1, 1); - List canceled = tracker.resetOutstandingRequests(0); - assertEquals(2, canceled.size()); - assertTrue(canceled.contains(host1)); - assertTrue(canceled.contains(host2)); - assertNotNull(tracker.lookupPlacedRequest(1, "host1")); - assertNull(tracker.lookupPlacedRequest(0, "host1")); - canceled = tracker.resetOutstandingRequests(0); - assertEquals(0, canceled.size()); - assertEquals(1, tracker.resetOutstandingRequests(1).size()); - } - - //@Test - public void testEscalation() throws Throwable { - // first request: default placement - assertEquals(getRole0Status().getPlacementPolicy(), PlacementPolicy - .DEFAULT); - Resource res0 = newResource(getRole0Status()); - OutstandingRequest outstanding0 = tracker.newRequest(host1, - getRole0Status().getKey()); - ContainerRequest initialRequest = - outstanding0.buildContainerRequest(res0, getRole0Status(), 0); - assertNotNull(outstanding0.getIssuedRequest()); - assertTrue(outstanding0.isLocated()); - assertFalse(outstanding0.isEscalated()); - assertFalse(initialRequest.getRelaxLocality()); - assertEquals(1, tracker.listPlacedRequests().size()); - - // second. This one doesn't get launched. This is to verify that the - // escalation process skips entries which are in the list but have not - // been issued, which can be a race condition between request issuance & - // escalation. - // (not one observed outside test authoring, but retained for completeness) - Resource res2 = newResource(getRole2Status()); - OutstandingRequest outstanding2 = tracker.newRequest(host1, - getRole2Status().getKey()); - - // simulate some time escalation of role 1 MUST now be triggered - long interval = getRole0Status().getPlacementTimeoutSeconds() * 1000 + 500; - long now = interval; - final List escalations = tracker - .escalateOutstandingRequests(now); - - assertTrue(outstanding0.isEscalated()); - assertFalse(outstanding2.isEscalated()); - - // two entries - assertEquals(2, escalations.size()); - AbstractRMOperation e1 = escalations.get(0); - assertTrue(e1 instanceof CancelSingleRequest); - final CancelSingleRequest cancel = (CancelSingleRequest) e1; - assertEquals(initialRequest, cancel.getRequest()); - AbstractRMOperation e2 = escalations.get(1); - assertTrue(e2 instanceof ContainerRequestOperation); - ContainerRequestOperation escRequest = (ContainerRequestOperation) e2; - assertTrue(escRequest.getRequest().getRelaxLocality()); - - // build that second request from an anti-affine entry - // these get placed as well - now += interval; - ContainerRequest containerReq2 = - outstanding2.buildContainerRequest(res2, getRole2Status(), now); - // escalate a little bit more - final List escalations2 = tracker - .escalateOutstandingRequests(now); - // and expect no new entries - assertEquals(0, escalations2.size()); - - // go past the role2 timeout - now += getRole2Status().getPlacementTimeoutSeconds() * 1000 + 500; - // escalate a little bit more - final List escalations3 = tracker - .escalateOutstandingRequests(now); - // and expect another escalation - assertEquals(2, escalations3.size()); - assertTrue(outstanding2.isEscalated()); - - // finally add a strict entry to the mix - Resource res3 = newResource(getRole1Status()); - OutstandingRequest outstanding3 = tracker.newRequest(host1, - getRole1Status().getKey()); - - final ProviderRole providerRole1 = getRole1Status().getProviderRole(); - assertEquals(providerRole1.placementPolicy, PlacementPolicy.STRICT); - now += interval; - assertFalse(outstanding3.mayEscalate()); - final List escalations4 = tracker - .escalateOutstandingRequests(now); - assertTrue(escalations4.isEmpty()); - - } - - /** - * If the placement does include a label, the initial request must - * not include it. - * The escalation request will contain the label, while - * leaving out the node list. - * retains the node list, but sets relaxLocality==true - * @throws Throwable - */ - //@Test - public void testRequestLabelledPlacement() throws Throwable { - NodeInstance ni = new NodeInstance("host1", 0); - OutstandingRequest req1 = tracker.newRequest(ni, 0); - Resource res0 = factory.newResource(48, 1); - - RoleStatus workerRole = lookupRole(WORKER); - // initial request - ContainerRequest yarnRequest = - req1.buildContainerRequest(res0, workerRole, 0); - assertEquals(req1.label, WORKERS_LABEL); - - assertNull(yarnRequest.getNodeLabelExpression()); - assertFalse(yarnRequest.getRelaxLocality()); - // escalation - ContainerRequest yarnRequest2 = req1.escalate(); - assertNull(yarnRequest2.getNodes()); - assertTrue(yarnRequest2.getRelaxLocality()); - assertEquals(yarnRequest2.getNodeLabelExpression(), WORKERS_LABEL); - } - - /** - * If the placement doesnt include a label, then the escalation request - * retains the node list, but sets relaxLocality==true. - * @throws Throwable - */ - //@Test - public void testRequestUnlabelledPlacement() throws Throwable { - NodeInstance ni = new NodeInstance("host1", 0); - OutstandingRequest req1 = tracker.newRequest(ni, 0); - Resource res0 = factory.newResource(48, 1); - - // initial request - ContainerRequest yarnRequest = req1.buildContainerRequest(res0, - getRole0Status(), 0); - assertNotNull(yarnRequest.getNodes()); - assertTrue(SliderUtils.isUnset(yarnRequest.getNodeLabelExpression())); - assertFalse(yarnRequest.getRelaxLocality()); - ContainerRequest yarnRequest2 = req1.escalate(); - assertNotNull(yarnRequest2.getNodes()); - assertTrue(yarnRequest2.getRelaxLocality()); - } - - //@Test(expected = IllegalArgumentException.class) - public void testAARequestNoNodes() throws Throwable { - tracker.newAARequest(getRole0Status().getKey(), new ArrayList<>(), ""); - } - - //@Test - public void testAARequest() throws Throwable { - int role0 = getRole0Status().getKey(); - OutstandingRequest request = tracker.newAARequest(role0, Arrays - .asList(host1), ""); - assertEquals(host1.hostname, request.hostname); - assertFalse(request.isLocated()); - } - - //@Test - public void testAARequestPair() throws Throwable { - int role0 = getRole0Status().getKey(); - OutstandingRequest request = tracker.newAARequest(role0, Arrays.asList( - host1, host2), ""); - assertEquals(host1.hostname, request.hostname); - assertFalse(request.isLocated()); - ContainerRequest yarnRequest = request.buildContainerRequest( - getRole0Status().copyResourceRequirements(new MockResource(0, 0)), - getRole0Status(), - 0); - assertFalse(yarnRequest.getRelaxLocality()); - assertFalse(request.mayEscalate()); - - assertEquals(2, yarnRequest.getNodes().size()); - } - - //@Test - public void testBuildResourceRequirements() throws Throwable { - // Store original values - Application application = appState.getClusterStatus(); - Component role0 = application.getComponent(getRole0Status().getName()); - String origMem = role0.getResource().getMemory(); - Integer origVcores = role0.getResource().getCpus(); - - // Resource values to be used for this test - int testMem = 32768; - int testVcores = 2; - role0.resource(new org.apache.slider.api.resource.Resource().memory(Integer - .toString(testMem)).cpus(testVcores)); - - // Test normalization disabled - LOG.info("Test normalization: disabled"); - role0.getConfiguration().setProperty( - ResourceKeys.YARN_RESOURCE_NORMALIZATION_ENABLED, "false"); - MockResource requestedRes = new MockResource(testMem, testVcores); - MockResource expectedRes = new MockResource(testMem, testVcores); - LOG.info("Resource requested: {}", requestedRes); - Resource resFinal = appState.buildResourceRequirements(getRole0Status()); - LOG.info("Resource actual: {}", resFinal); - assertTrue(Resources.equals(expectedRes, resFinal)); - - // Test normalization enabled - LOG.info("Test normalization: enabled"); - role0.getConfiguration().setProperty( - ResourceKeys.YARN_RESOURCE_NORMALIZATION_ENABLED, "true"); - expectedRes = new MockResource(MockAppState.RM_MAX_RAM, testVcores); - LOG.info("Resource requested: {}", requestedRes); - resFinal = appState.buildResourceRequirements(getRole0Status()); - LOG.info("Resource actual: {}", resFinal); - assertTrue(Resources.equals(expectedRes, resFinal)); - - // revert resource configuration to original value - role0.resource(new org.apache.slider.api.resource.Resource().memory(origMem) - .cpus(origVcores)); - } - - public Resource newResource(RoleStatus r) { - return appState.buildResourceRequirements(r); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRW.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRW.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRW.java deleted file mode 100644 index e3770a5..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRW.java +++ /dev/null @@ -1,371 +0,0 @@ -/* - * 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.slider.server.appmaster.model.history; - -import org.apache.hadoop.fs.FSDataOutputStream; -import org.apache.hadoop.fs.Path; -import org.apache.slider.api.ResourceKeys; -import org.apache.slider.providers.PlacementPolicy; -import org.apache.slider.providers.ProviderRole; -import org.apache.slider.server.appmaster.model.mock.BaseMockAppStateTest; -import org.apache.slider.server.appmaster.model.mock.MockFactory; -import org.apache.slider.server.appmaster.model.mock.MockRoleHistory; -import org.apache.slider.server.appmaster.state.NodeEntry; -import org.apache.slider.server.appmaster.state.NodeInstance; -import org.apache.slider.server.appmaster.state.RoleHistory; -import org.apache.slider.server.appmaster.state.RoleStatus; -import org.apache.slider.server.avro.LoadedRoleHistory; -import org.apache.slider.server.avro.RoleHistoryWriter; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * Test fole history reading and writing. - */ -public class TestRoleHistoryRW extends BaseMockAppStateTest { - private static final Logger LOG = - LoggerFactory.getLogger(TestRoleHistoryRW.class); - - private static long time = System.currentTimeMillis(); - public static final String HISTORY_V1_6_ROLE = - "org/apache/slider/server/avro/history-v01-6-role.json"; - public static final String HISTORY_V1_3_ROLE = - "org/apache/slider/server/avro/history-v01-3-role.json"; - public static final String HISTORY_V1B_1_ROLE = - "org/apache/slider/server/avro/history_v01b_1_role.json"; - - private RoleStatus role0Status; - private RoleStatus role1Status; - - static final ProviderRole PROVIDER_ROLE3 = new ProviderRole( - "role3", - 3, - PlacementPolicy.STRICT, - 3, - 3, - ResourceKeys.DEF_YARN_LABEL_EXPRESSION); - - @Override - public String getTestName() { - return "TestHistoryRW"; - } - - @Override - public void setup() throws Exception { - super.setup(); - role0Status = getRole0Status(); - role1Status = getRole1Status(); - } - - //@Test - public void testWriteReadEmpty() throws Throwable { - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - roleHistory.onStart(fs, historyPath); - Path history = roleHistory.saveHistory(time++); - assertTrue(fs.getFileStatus(history).isFile()); - RoleHistoryWriter historyWriter = new RoleHistoryWriter(); - historyWriter.read(fs, history); - } - - //@Test - public void testWriteReadData() throws Throwable { - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - assertFalse(roleHistory.onStart(fs, historyPath)); - String addr = "localhost"; - NodeInstance instance = roleHistory.getOrCreateNodeInstance(addr); - NodeEntry ne1 = instance.getOrCreate(0); - ne1.setLastUsed(0xf00d); - - Path history = roleHistory.saveHistory(time++); - assertTrue(fs.getFileStatus(history).isFile()); - RoleHistoryWriter historyWriter = new RoleHistoryWriter(); - RoleHistory rh2 = new MockRoleHistory(MockFactory.ROLES); - - - LoadedRoleHistory loadedRoleHistory = historyWriter.read(fs, history); - assertTrue(0 < loadedRoleHistory.size()); - rh2.rebuild(loadedRoleHistory); - NodeInstance ni2 = rh2.getExistingNodeInstance(addr); - assertNotNull(ni2); - NodeEntry ne2 = ni2.get(0); - assertNotNull(ne2); - assertEquals(ne2.getLastUsed(), ne1.getLastUsed()); - } - - //@Test - public void testWriteReadActiveData() throws Throwable { - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - roleHistory.onStart(fs, historyPath); - String addr = "localhost"; - String addr2 = "rack1server5"; - NodeInstance localhost = roleHistory.getOrCreateNodeInstance(addr); - NodeEntry orig1 = localhost.getOrCreate(role0Status.getKey()); - orig1.setLastUsed(0x10); - NodeInstance rack1server5 = roleHistory.getOrCreateNodeInstance(addr2); - NodeEntry orig2 = rack1server5.getOrCreate(role1Status.getKey()); - orig2.setLive(3); - assertFalse(orig2.isAvailable()); - NodeEntry orig3 = localhost.getOrCreate(role1Status.getKey()); - orig3.setLastUsed(0x20); - orig3.setLive(1); - assertFalse(orig3.isAvailable()); - orig3.release(); - assertTrue(orig3.isAvailable()); - roleHistory.dump(); - - long savetime = 0x0001000; - Path history = roleHistory.saveHistory(savetime); - assertTrue(fs.getFileStatus(history).isFile()); - describe("Loaded"); - LOG.info("testWriteReadActiveData in {}", history); - RoleHistoryWriter historyWriter = new RoleHistoryWriter(); - RoleHistory rh2 = new MockRoleHistory(MockFactory.ROLES); - LoadedRoleHistory loadedRoleHistory = historyWriter.read(fs, history); - assertEquals(3, loadedRoleHistory.size()); - rh2.rebuild(loadedRoleHistory); - rh2.dump(); - - assertEquals(2, rh2.getClusterSize()); - NodeInstance ni2 = rh2.getExistingNodeInstance(addr); - assertNotNull(ni2); - NodeEntry loadedNE = ni2.get(role0Status.getKey()); - assertEquals(loadedNE.getLastUsed(), orig1.getLastUsed()); - NodeInstance ni2b = rh2.getExistingNodeInstance(addr2); - assertNotNull(ni2b); - NodeEntry loadedNE2 = ni2b.get(role1Status.getKey()); - assertNotNull(loadedNE2); - assertEquals(loadedNE2.getLastUsed(), savetime); - assertEquals(rh2.getThawedDataTime(), savetime); - - // now start it - rh2.buildRecentNodeLists(); - describe("starting"); - rh2.dump(); - List available0 = rh2.cloneRecentNodeList(role0Status - .getKey()); - assertEquals(1, available0.size()); - - NodeInstance entry = available0.get(0); - assertEquals(entry.hostname, "localhost"); - assertEquals(entry, localhost); - List available1 = rh2.cloneRecentNodeList(role1Status - .getKey()); - assertEquals(2, available1.size()); - //and verify that even if last used was set, the save time is picked up - assertEquals(entry.get(role1Status.getKey()).getLastUsed(), roleHistory - .getSaveTime()); - - } - - //@Test - public void testWriteThaw() throws Throwable { - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - assertFalse(roleHistory.onStart(fs, historyPath)); - String addr = "localhost"; - NodeInstance instance = roleHistory.getOrCreateNodeInstance(addr); - NodeEntry ne1 = instance.getOrCreate(0); - ne1.setLastUsed(0xf00d); - - Path history = roleHistory.saveHistory(time++); - long savetime =roleHistory.getSaveTime(); - assertTrue(fs.getFileStatus(history).isFile()); - RoleHistory rh2 = new MockRoleHistory(MockFactory.ROLES); - assertTrue(rh2.onStart(fs, historyPath)); - NodeInstance ni2 = rh2.getExistingNodeInstance(addr); - assertNotNull(ni2); - NodeEntry ne2 = ni2.get(0); - assertNotNull(ne2); - assertEquals(ne2.getLastUsed(), ne1.getLastUsed()); - assertEquals(rh2.getThawedDataTime(), savetime); - } - - - //@Test - public void testPurgeOlderEntries() throws Throwable { - RoleHistoryWriter historyWriter = new RoleHistoryWriter(); - time = 1; - Path file1 = touch(historyWriter, time++); - Path file2 = touch(historyWriter, time++); - Path file3 = touch(historyWriter, time++); - Path file4 = touch(historyWriter, time++); - Path file5 = touch(historyWriter, time++); - Path file6 = touch(historyWriter, time++); - - assertEquals(0, historyWriter.purgeOlderHistoryEntries(fs, file1)); - assertEquals(1, historyWriter.purgeOlderHistoryEntries(fs, file2)); - assertEquals(0, historyWriter.purgeOlderHistoryEntries(fs, file2)); - assertEquals(3, historyWriter.purgeOlderHistoryEntries(fs, file5)); - assertEquals(1, historyWriter.purgeOlderHistoryEntries(fs, file6)); - try { - // make an impossible assertion that will fail if the method - // actually completes - assertEquals(-1, historyWriter.purgeOlderHistoryEntries(fs, file1)); - } catch (FileNotFoundException ignored) { - // expected - } - - } - - public Path touch(RoleHistoryWriter historyWriter, long timeMs) - throws IOException { - Path path = historyWriter.createHistoryFilename(historyPath, timeMs); - FSDataOutputStream out = fs.create(path); - out.close(); - return path; - } - - //@Test - public void testSkipEmptyFileOnRead() throws Throwable { - describe("verify that empty histories are skipped on read; old histories " + - "purged"); - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - roleHistory.onStart(fs, historyPath); - time = 0; - Path oldhistory = roleHistory.saveHistory(time++); - - String addr = "localhost"; - NodeInstance instance = roleHistory.getOrCreateNodeInstance(addr); - NodeEntry ne1 = instance.getOrCreate(0); - ne1.setLastUsed(0xf00d); - - Path goodhistory = roleHistory.saveHistory(time++); - - RoleHistoryWriter historyWriter = new RoleHistoryWriter(); - Path touched = touch(historyWriter, time++); - - RoleHistory rh2 = new MockRoleHistory(MockFactory.ROLES); - assertTrue(rh2.onStart(fs, historyPath)); - NodeInstance ni2 = rh2.getExistingNodeInstance(addr); - assertNotNull(ni2); - - //and assert the older file got purged - assertFalse(fs.exists(oldhistory)); - assertTrue(fs.exists(goodhistory)); - assertTrue(fs.exists(touched)); - } - - //@Test - public void testSkipBrokenFileOnRead() throws Throwable { - describe("verify that empty histories are skipped on read; old histories " + - "purged"); - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - roleHistory.onStart(fs, historyPath); - time = 0; - Path oldhistory = roleHistory.saveHistory(time++); - - String addr = "localhost"; - NodeInstance instance = roleHistory.getOrCreateNodeInstance(addr); - NodeEntry ne1 = instance.getOrCreate(0); - ne1.setLastUsed(0xf00d); - - Path goodhistory = roleHistory.saveHistory(time++); - - RoleHistoryWriter historyWriter = new RoleHistoryWriter(); - Path badfile = historyWriter.createHistoryFilename(historyPath, time++); - FSDataOutputStream out = fs.create(badfile); - out.writeBytes("{broken:true}"); - out.close(); - - RoleHistory rh2 = new MockRoleHistory(MockFactory.ROLES); - describe("IGNORE STACK TRACE BELOW"); - - assertTrue(rh2.onStart(fs, historyPath)); - - describe("IGNORE STACK TRACE ABOVE"); - NodeInstance ni2 = rh2.getExistingNodeInstance(addr); - assertNotNull(ni2); - - //and assert the older file got purged - assertFalse(fs.exists(oldhistory)); - assertTrue(fs.exists(goodhistory)); - assertTrue(fs.exists(badfile)); - } - - /** - * Test that a v1 JSON file can be read. Here the number of roles - * matches the current state. - * @throws Throwable - */ - //@Test - public void testReloadDataV13Role() throws Throwable { - String source = HISTORY_V1_3_ROLE; - RoleHistoryWriter writer = new RoleHistoryWriter(); - - LoadedRoleHistory loadedRoleHistory = writer.read(source); - assertEquals(4, loadedRoleHistory.size()); - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - assertEquals(0, roleHistory.rebuild(loadedRoleHistory)); - } - - /** - * Test that a v1 JSON file can be read. Here more roles than expected - * @throws Throwable - */ - //@Test - public void testReloadDataV16Role() throws Throwable { - String source = HISTORY_V1_6_ROLE; - RoleHistoryWriter writer = new RoleHistoryWriter(); - - LoadedRoleHistory loadedRoleHistory = writer.read(source); - assertEquals(6, loadedRoleHistory.size()); - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - assertEquals(3, roleHistory.rebuild(loadedRoleHistory)); - } - - /** - * Test that a v1 JSON file can be read. Here the number of roles - * is less than the current state. - * @throws Throwable - */ - //@Test - public void testReloadLessRoles() throws Throwable { - String source = HISTORY_V1_3_ROLE; - RoleHistoryWriter writer = new RoleHistoryWriter(); - - LoadedRoleHistory loadedRoleHistory = writer.read(source); - assertEquals(4, loadedRoleHistory.size()); - List expandedRoles = new ArrayList(MockFactory.ROLES); - expandedRoles.add(PROVIDER_ROLE3); - RoleHistory roleHistory = new MockRoleHistory(expandedRoles); - assertEquals(0, roleHistory.rebuild(loadedRoleHistory)); - } - - /** - * Test that a v1b JSON file can be read. Here more roles than expected - * @throws Throwable - */ - //@Test - public void testReloadDataV1B1Role() throws Throwable { - String source = HISTORY_V1B_1_ROLE; - RoleHistoryWriter writer = new RoleHistoryWriter(); - - LoadedRoleHistory loadedRoleHistory = writer.read(source); - assertEquals(1, loadedRoleHistory.size()); - assertEquals(2, loadedRoleHistory.roleMap.size()); - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - assertEquals(0, roleHistory.rebuild(loadedRoleHistory)); - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRWOrdering.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRWOrdering.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRWOrdering.java deleted file mode 100644 index 033b509..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRWOrdering.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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.slider.server.appmaster.model.history; - -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.yarn.service.conf.SliderKeys; -import org.apache.slider.server.appmaster.model.mock.BaseMockAppStateTest; -import org.apache.slider.server.appmaster.model.mock.MockFactory; -import org.apache.slider.server.appmaster.model.mock.MockRoleHistory; -import org.apache.slider.server.appmaster.state.NodeEntry; -import org.apache.slider.server.appmaster.state.NodeInstance; -import org.apache.slider.server.appmaster.state.RoleHistory; -import org.apache.slider.server.avro.NewerFilesFirst; -import org.apache.slider.server.avro.RoleHistoryWriter; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Test role history rw ordering. - */ -public class TestRoleHistoryRWOrdering extends BaseMockAppStateTest { - private static final Logger LOG = - LoggerFactory.getLogger(TestRoleHistoryRWOrdering.class); - - private List paths = pathlist( - Arrays.asList( - "hdfs://localhost/history-0406c.json", - "hdfs://localhost/history-5fffa.json", - "hdfs://localhost/history-0001a.json", - "hdfs://localhost/history-0001f.json" - ) - ); - private Path h0406c = paths.get(0); - private Path h5fffa = paths.get(1); - private Path h0001a = paths.get(3); - - public TestRoleHistoryRWOrdering() throws URISyntaxException { - } - - List pathlist(List pathnames) throws URISyntaxException { - List pathList = new ArrayList<>(); - for (String p : pathnames) { - pathList.add(new Path(new URI(p))); - } - return pathList; - } - - @Override - public String getTestName() { - return "TestHistoryRWOrdering"; - } - - /** - * This tests regexp pattern matching. It uses the current time so isn't - * repeatable -but it does test a wider range of values in the process - * @throws Throwable - */ - //@Test - public void testPatternRoundTrip() throws Throwable { - describe("test pattern matching of names"); - long value=System.currentTimeMillis(); - String name = String.format(SliderKeys.HISTORY_FILENAME_CREATION_PATTERN, - value); - String matchpattern = SliderKeys.HISTORY_FILENAME_MATCH_PATTERN; - Pattern pattern = Pattern.compile(matchpattern); - Matcher matcher = pattern.matcher(name); - if (!matcher.find()) { - throw new Exception("No match for pattern $matchpattern in $name"); - } - } - - //@Test - public void testWriteSequenceReadData() throws Throwable { - describe("test that if multiple entries are written, the newest is picked" + - " up"); - long time = System.currentTimeMillis(); - - RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - assertFalse(roleHistory.onStart(fs, historyPath)); - String addr = "localhost"; - NodeInstance instance = roleHistory.getOrCreateNodeInstance(addr); - NodeEntry ne1 = instance.getOrCreate(0); - ne1.setLastUsed(0xf00d); - - Path history1 = roleHistory.saveHistory(time++); - Path history2 = roleHistory.saveHistory(time++); - Path history3 = roleHistory.saveHistory(time); - - //inject a later file with a different name - sliderFileSystem.cat(new Path(historyPath, "file.json"), true, "hello," + - " world"); - - - RoleHistoryWriter historyWriter = new RoleHistoryWriter(); - - List entries = historyWriter.findAllHistoryEntries( - fs, - historyPath, - false); - assertEquals(entries.size(), 3); - assertEquals(entries.get(0), history3); - assertEquals(entries.get(1), history2); - assertEquals(entries.get(2), history1); - } - - //@Test - public void testPathStructure() throws Throwable { - assertEquals(h5fffa.getName(), "history-5fffa.json"); - } - - //@Test - public void testPathnameComparator() throws Throwable { - - NewerFilesFirst newerName = new NewerFilesFirst(); - - LOG.info("{} name is {}", h5fffa, h5fffa.getName()); - LOG.info("{} name is {}", h0406c, h0406c.getName()); - assertEquals(newerName.compare(h5fffa, h5fffa), 0); - assertTrue(newerName.compare(h5fffa, h0406c) < 0); - assertTrue(newerName.compare(h5fffa, h0001a) < 0); - assertTrue(newerName.compare(h0001a, h5fffa) > 0); - - } - - //@Test - public void testPathSort() throws Throwable { - List paths2 = new ArrayList<>(paths); - RoleHistoryWriter.sortHistoryPaths(paths2); - assertListEquals(paths2, - Arrays.asList( - paths.get(1), - paths.get(0), - paths.get(3), - paths.get(2) - )); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRequestTracking.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRequestTracking.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRequestTracking.java deleted file mode 100644 index b84689c..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryRequestTracking.java +++ /dev/null @@ -1,298 +0,0 @@ -/* - * 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.slider.server.appmaster.model.history; - -import org.apache.hadoop.yarn.api.records.Container; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.client.api.AMRMClient; -import org.apache.slider.core.exceptions.BadConfigException; -import org.apache.slider.providers.PlacementPolicy; -import org.apache.slider.providers.ProviderRole; -import org.apache.slider.server.appmaster.model.mock.BaseMockAppStateTest; -import org.apache.slider.server.appmaster.model.mock.MockContainer; -import org.apache.slider.server.appmaster.model.mock.MockFactory; -import org.apache.slider.server.appmaster.model.mock.MockRoleHistory; -import org.apache.slider.server.appmaster.state.ContainerAllocationOutcome; -import org.apache.slider.server.appmaster.state.NodeEntry; -import org.apache.slider.server.appmaster.state.NodeInstance; -import org.apache.slider.server.appmaster.state.OutstandingRequest; -import org.apache.slider.server.appmaster.state.RoleHistory; -import org.apache.slider.server.appmaster.state.RoleStatus; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; -import java.util.List; - -/** - * Test the RH availability list and request tracking: that hosts - * get removed and added. - */ -public class TestRoleHistoryRequestTracking extends BaseMockAppStateTest { - private static final Logger LOG = - LoggerFactory.getLogger(TestRoleHistoryRequestTracking.class); - - private String roleName = "test"; - - private NodeInstance age1Active4; - private NodeInstance age2Active2; - private NodeInstance age2Active0; - private NodeInstance age3Active0; - private NodeInstance age4Active1; - - private RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - // 1MB, 1 vcore - private Resource resource = Resource.newInstance(1, 1); - - private RoleStatus roleStatus; - - public TestRoleHistoryRequestTracking() throws BadConfigException { - } - - AMRMClient.ContainerRequest requestContainer(RoleStatus rs) { - return roleHistory.requestContainerForRole(rs).getIssuedRequest(); - } - - @Override - public String getTestName() { - return "TestRoleHistoryAvailableList"; - } - - @Override - public void setup() throws Exception { - super.setup(); - - age1Active4 = nodeInstance(1, 4, 0, 0); - age2Active2 = nodeInstance(2, 2, 0, 1); - age2Active0 = nodeInstance(2, 0, 0, 0); - age3Active0 = nodeInstance(3, 0, 0, 0); - age4Active1 = nodeInstance(4, 1, 0, 0); - - roleHistory.insert(Arrays.asList(age2Active2, age2Active0, age4Active1, - age1Active4, age3Active0)); - roleHistory.buildRecentNodeLists(); - roleStatus = getRole0Status(); - roleStatus.setResourceRequirements(Resource.newInstance(1, 1)); - } - - //@Test - public void testAvailableListBuiltForRoles() throws Throwable { - List available0 = roleHistory.cloneRecentNodeList( - roleStatus.getKey()); - assertListEquals(Arrays.asList(age3Active0, age2Active0), available0); - } - - //@Test - public void testRequestedNodeOffList() throws Throwable { - NodeInstance ni = roleHistory.findRecentNodeForNewInstance(roleStatus); - assertEquals(age3Active0, ni); - assertListEquals(Arrays.asList(age2Active0), - roleHistory.cloneRecentNodeList(roleStatus.getKey())); - roleHistory.requestInstanceOnNode(ni, - roleStatus, - resource - ); - } - - //@Test - public void testRequestedNodeOffListWithFailures() throws Throwable { - assertFalse(roleHistory.cloneRecentNodeList(roleStatus.getKey()).isEmpty()); - - NodeEntry age3role0 = recordAsFailed(age3Active0, roleStatus.getKey(), 4); - assertTrue(age3Active0.isConsideredUnreliable(roleStatus.getKey(), - roleStatus.getNodeFailureThreshold())); - recordAsFailed(age2Active0, roleStatus.getKey(), 4); - assertTrue(age2Active0.isConsideredUnreliable(roleStatus.getKey(), - roleStatus.getNodeFailureThreshold())); - // expect to get a null node back - NodeInstance ni = roleHistory.findRecentNodeForNewInstance(roleStatus); - assertNull(ni); - - // which is translated to a no-location request - AMRMClient.ContainerRequest req = roleHistory.requestInstanceOnNode(ni, - roleStatus, - resource).getIssuedRequest(); - - assertNull(req.getNodes()); - - LOG.info("resetting failure count"); - age3role0.resetFailedRecently(); - roleHistory.dump(); - assertEquals(0, age3role0.getFailedRecently()); - assertFalse(age3Active0.isConsideredUnreliable(roleStatus.getKey(), - roleStatus.getNodeFailureThreshold())); - assertFalse(roleHistory.cloneRecentNodeList(roleStatus.getKey()).isEmpty()); - // looking for a node should now find one - ni = roleHistory.findRecentNodeForNewInstance(roleStatus); - assertEquals(ni, age3Active0); - req = roleHistory.requestInstanceOnNode(ni, roleStatus, resource) - .getIssuedRequest(); - assertEquals(1, req.getNodes().size()); - } - - /** - * Verify that strict placement policies generate requests for nodes - * irrespective of their failed status. - * @throws Throwable - */ - //@Test - public void testStrictPlacementIgnoresFailures() throws Throwable { - - RoleStatus targetRole = getRole1Status(); - final ProviderRole providerRole1 = targetRole.getProviderRole(); - assertEquals(providerRole1.placementPolicy, PlacementPolicy.STRICT); - int key1 = targetRole.getKey(); - int key0 = getRole0Status().getKey(); - - List nodes0 = Arrays.asList(age1Active4, age2Active0, - age2Active2, age3Active0, age4Active1); - recordAllFailed(key0, 4, nodes0); - recordAllFailed(key1, 4, nodes0); - - // trigger a list rebuild - roleHistory.buildRecentNodeLists(); - List recentRole0 = roleHistory.cloneRecentNodeList(key0); - assertTrue(recentRole0.indexOf(age3Active0) < recentRole0 - .indexOf(age2Active0)); - - // the non-strict role has no suitable nodes - assertNull(roleHistory.findRecentNodeForNewInstance(getRole0Status())); - - - NodeInstance ni = roleHistory.findRecentNodeForNewInstance(targetRole); - assertNotNull(ni); - - NodeInstance ni2 = roleHistory.findRecentNodeForNewInstance(targetRole); - assertNotNull(ni2); - assertNotEquals(ni, ni2); - } - - //@Test - public void testFindAndRequestNode() throws Throwable { - AMRMClient.ContainerRequest req = requestContainer(roleStatus); - - assertEquals(age3Active0.hostname, req.getNodes().get(0)); - List a2 = roleHistory.cloneRecentNodeList(roleStatus - .getKey()); - assertListEquals(Arrays.asList(age2Active0), a2); - } - - //@Test - public void testRequestedNodeIntoReqList() throws Throwable { - requestContainer(roleStatus); - List requests = roleHistory.listPlacedRequests(); - assertEquals(1, requests.size()); - assertEquals(age3Active0.hostname, requests.get(0).hostname); - } - - //@Test - public void testCompletedRequestDropsNode() throws Throwable { - AMRMClient.ContainerRequest req = requestContainer(roleStatus); - List requests = roleHistory.listPlacedRequests(); - assertEquals(1, requests.size()); - String hostname = requests.get(0).hostname; - assertEquals(age3Active0.hostname, hostname); - assertEquals(hostname, req.getNodes().get(0)); - MockContainer container = factory.newContainer(req, hostname); - assertOnContainerAllocated(container, 2, 1); - assertNoOutstandingPlacedRequests(); - } - - public void assertOnContainerAllocated(Container c1, int p1, int p2) { - assertNotEquals(ContainerAllocationOutcome.Open, roleHistory - .onContainerAllocated(c1, p1, p2).outcome); - } - - public void assertOnContainerAllocationOpen(Container c1, int p1, int p2) { - assertEquals(ContainerAllocationOutcome.Open, roleHistory - .onContainerAllocated(c1, p1, p2).outcome); - } - - void assertNoOutstandingPlacedRequests() { - assertTrue(roleHistory.listPlacedRequests().isEmpty()); - } - - public void assertOutstandingPlacedRequests(int i) { - assertEquals(i, roleHistory.listPlacedRequests().size()); - } - - //@Test - public void testTwoRequests() throws Throwable { - AMRMClient.ContainerRequest req = requestContainer(roleStatus); - AMRMClient.ContainerRequest req2 = requestContainer(roleStatus); - List requests = roleHistory.listPlacedRequests(); - assertEquals(2, requests.size()); - MockContainer container = factory.newContainer(req, req.getNodes().get(0)); - assertOnContainerAllocated(container, 2, 1); - assertOutstandingPlacedRequests(1); - container = factory.newContainer(req2, req2.getNodes().get(0)); - assertOnContainerAllocated(container, 2, 2); - assertNoOutstandingPlacedRequests(); - } - - //@Test - public void testThreeRequestsOneUnsatisified() throws Throwable { - AMRMClient.ContainerRequest req = requestContainer(roleStatus); - AMRMClient.ContainerRequest req2 = requestContainer(roleStatus); - AMRMClient.ContainerRequest req3 = requestContainer(roleStatus); - List requests = roleHistory.listPlacedRequests(); - assertEquals(2, requests.size()); - MockContainer container = factory.newContainer(req, req.getNodes().get(0)); - assertOnContainerAllocated(container, 2, 1); - assertOutstandingPlacedRequests(1); - - container = factory.newContainer(req3, "three"); - assertOnContainerAllocationOpen(container, 3, 2); - assertOutstandingPlacedRequests(1); - - // the final allocation will trigger a cleanup - container = factory.newContainer(req2, "four"); - // no node dropped - assertEquals(ContainerAllocationOutcome.Unallocated, - roleHistory.onContainerAllocated(container, 3, 3).outcome); - // yet the list is now empty - assertNoOutstandingPlacedRequests(); - roleHistory.listOpenRequests().isEmpty(); - - // and the remainder goes onto the available list - List a2 = roleHistory.cloneRecentNodeList(roleStatus - .getKey()); - assertListEquals(Arrays.asList(age2Active0), a2); - } - - //@Test - public void testThreeRequests() throws Throwable { - AMRMClient.ContainerRequest req = requestContainer(roleStatus); - AMRMClient.ContainerRequest req2 = requestContainer(roleStatus); - AMRMClient.ContainerRequest req3 = requestContainer(roleStatus); - assertOutstandingPlacedRequests(2); - assertNull(req3.getNodes()); - MockContainer container = factory.newContainer(req, req.getNodes().get(0)); - assertOnContainerAllocated(container, 3, 1); - assertOutstandingPlacedRequests(1); - container = factory.newContainer(req2, req2.getNodes().get(0)); - assertOnContainerAllocated(container, 3, 2); - assertNoOutstandingPlacedRequests(); - container = factory.newContainer(req3, "three"); - assertOnContainerAllocationOpen(container, 3, 3); - assertNoOutstandingPlacedRequests(); - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryUpdateBlacklist.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryUpdateBlacklist.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryUpdateBlacklist.java deleted file mode 100644 index a271859..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/history/TestRoleHistoryUpdateBlacklist.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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.slider.server.appmaster.model.history; - -import org.apache.slider.core.exceptions.BadConfigException; -import org.apache.slider.server.appmaster.actions.ResetFailureWindow; -import org.apache.slider.server.appmaster.model.mock.BaseMockAppStateTest; -import org.apache.slider.server.appmaster.model.mock.MockAM; -import org.apache.slider.server.appmaster.model.mock.MockFactory; -import org.apache.slider.server.appmaster.model.mock.MockRMOperationHandler; -import org.apache.slider.server.appmaster.model.mock.MockRoleHistory; -import org.apache.slider.server.appmaster.operations.AbstractRMOperation; -import org.apache.slider.server.appmaster.operations.UpdateBlacklistOperation; -import org.apache.slider.server.appmaster.state.NodeInstance; -import org.apache.slider.server.appmaster.state.RoleHistory; -import org.apache.slider.server.appmaster.state.RoleStatus; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -/** - * Test updating blacklist. - */ -public class TestRoleHistoryUpdateBlacklist extends BaseMockAppStateTest { - private RoleHistory roleHistory = new MockRoleHistory(MockFactory.ROLES); - private Collection roleStatuses; - private RoleStatus roleStatus; - private NodeInstance ni; - - public TestRoleHistoryUpdateBlacklist() throws BadConfigException { - } - - @Override - public String getTestName() { - return "TestUpdateBlacklist"; - } - - @Override - public void setup() throws Exception { - super.setup(); - ni = nodeInstance(1, 0, 0, 0); - roleHistory.insert(Arrays.asList(ni)); - roleHistory.buildRecentNodeLists(); - appState.setRoleHistory(roleHistory); - roleStatus = getRole0Status(); - roleStatuses = Arrays.asList(roleStatus); - } - - //@Test - public void testUpdateBlacklist() { - assertFalse(ni.isBlacklisted()); - - // at threshold, blacklist is unmodified - recordAsFailed(ni, roleStatus.getKey(), MockFactory.NODE_FAILURE_THRESHOLD); - UpdateBlacklistOperation op = roleHistory.updateBlacklist(roleStatuses); - assertNull(op); - assertFalse(ni.isBlacklisted()); - - // threshold is reached, node goes on blacklist - recordAsFailed(ni, roleStatus.getKey(), 1); - op = roleHistory.updateBlacklist(roleStatuses); - assertNotNull(op); - assertTrue(ni.isBlacklisted()); - - // blacklist remains unmodified - op = roleHistory.updateBlacklist(roleStatuses); - assertNull(op); - assertTrue(ni.isBlacklisted()); - - // failure threshold reset, node goes off blacklist - ni.resetFailedRecently(); - op = roleHistory.updateBlacklist(roleStatuses); - assertNotNull(op); - assertFalse(ni.isBlacklisted()); - } - - //@Test - public void testBlacklistOperations() - throws Exception { - recordAsFailed(ni, roleStatus.getKey(), MockFactory - .NODE_FAILURE_THRESHOLD + 1); - - List ops = appState.reviewRequestAndReleaseNodes(); - assertListLength(ops, 1); - AbstractRMOperation op = ops.get(0); - assertTrue(op instanceof UpdateBlacklistOperation); - assertTrue(ni.isBlacklisted()); - - MockRMOperationHandler handler = new MockRMOperationHandler(); - assertEquals(0, handler.getBlacklisted()); - handler.execute(ops); - assertEquals(1, handler.getBlacklisted()); - - ResetFailureWindow resetter = new ResetFailureWindow(handler); - resetter.execute(new MockAM(), null, appState); - assertEquals(0, handler.getBlacklisted()); - assertFalse(ni.isBlacklisted()); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/5b0c0896/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/mock/Allocator.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/mock/Allocator.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/mock/Allocator.java deleted file mode 100644 index 419f2fb..0000000 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-slider/hadoop-yarn-slider-core/src/test/java/org/apache/slider/server/appmaster/model/mock/Allocator.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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.slider.server.appmaster.model.mock; - -import org.apache.hadoop.yarn.client.api.AMRMClient; -import org.apache.slider.common.tools.SliderUtils; - -/** - * Provides allocation services to a cluster -both random and placed. - * - * Important: container allocations need an app attempt ID put into the - * container ID - */ -public class Allocator { - - private final MockYarnCluster cluster; - /** - * Rolling index into the cluster used for the next "random" assignment. - */ - private int rollingIndex = 0; - - Allocator(MockYarnCluster cluster) { - this.cluster = cluster; - } - - /** - * Allocate a node using the list of nodes in the container as the - * hints. - * @param request request - * @return the allocated container -or null for none - */ - MockContainer allocate(AMRMClient.ContainerRequest request) { - MockYarnCluster.MockYarnClusterNode node = null; - MockYarnCluster.MockYarnClusterContainer allocated = null; - if (SliderUtils.isNotEmpty(request.getNodes())) { - for (String host : request.getNodes()) { - node = cluster.lookup(host); - allocated = node.allocate(); - if (allocated != null) { - break; - } - } - } - - if (allocated != null) { - return createContainerRecord(request, allocated, node); - } else { - if (request.getRelaxLocality() || request.getNodes().isEmpty()) { - // fallback to anywhere - return allocateRandom(request); - } else { - //no match and locality can't be requested - return null; - } - } - } - - /** - * Allocate a node without any positioning -use whatever policy this allocator - * chooses. - * @param request request - * @return the allocated container -or null for none - */ - MockContainer allocateRandom(AMRMClient.ContainerRequest request) { - int start = rollingIndex; - MockYarnCluster.MockYarnClusterNode node = cluster.nodeAt(rollingIndex); - MockYarnCluster.MockYarnClusterContainer allocated = node.allocate(); - // if there is no space, try again -but stop when all the nodes - // have failed - while (allocated == null && start != nextIndex()) { - node = cluster.nodeAt(rollingIndex); - allocated = node.allocate(); - } - - //here the allocation is set, so create the response - return createContainerRecord(request, allocated, node); - } - - /** - * Create a container record -if one was allocated. - * @param allocated allocation -may be null - * @param node node with the container - * @return a container record, or null if there was no allocation - */ - public MockContainer createContainerRecord( - AMRMClient.ContainerRequest request, - MockYarnCluster.MockYarnClusterContainer allocated, - MockYarnCluster.MockYarnClusterNode node) { - if (allocated == null) { - // no space - return null; - } - MockContainer container = new MockContainer(); - container.setId(new MockContainerId(allocated.getCid())); - container.setNodeId(node.getNodeId()); - container.setNodeHttpAddress(node.httpAddress()); - container.setPriority(request.getPriority()); - container.setResource(request.getCapability()); - return container; - } - - public int nextIndex() { - rollingIndex = (rollingIndex + 1) % cluster.getClusterSize(); - return rollingIndex; - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org