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 3A590200D16 for ; Tue, 26 Sep 2017 01:38:07 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 38A941609EF; Mon, 25 Sep 2017 23:38:07 +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 21B391609EC for ; Tue, 26 Sep 2017 01:38:03 +0200 (CEST) Received: (qmail 95872 invoked by uid 500); 25 Sep 2017 23:38:01 -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 95602 invoked by uid 99); 25 Sep 2017 23:38:01 -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; Mon, 25 Sep 2017 23:38:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6C027F5B21; Mon, 25 Sep 2017 23:38:00 +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: Mon, 25 Sep 2017 23:38:03 -0000 Message-Id: <3b8cc00258864c12b295782811ef42bd@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/86] [abbrv] hadoop git commit: YARN-7050. Post cleanup after YARN-6903, removal of org.apache.slider package. Contributed by Jian He archived-at: Mon, 25 Sep 2017 23:38:07 -0000 http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/BaseMockAppStateTest.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/BaseMockAppStateTest.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/BaseMockAppStateTest.java deleted file mode 100644 index 9632265..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/BaseMockAppStateTest.java +++ /dev/null @@ -1,539 +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 com.fasterxml.jackson.core.JsonProcessingException; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.yarn.api.records.Container; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerState; -import org.apache.hadoop.yarn.api.records.ContainerStatus; -import org.apache.hadoop.yarn.api.records.NodeReport; -import org.apache.hadoop.yarn.client.api.AMRMClient; -import org.apache.hadoop.yarn.conf.YarnConfiguration; -import org.apache.slider.api.resource.Application; -import org.apache.slider.common.tools.SliderFileSystem; -import org.apache.slider.common.tools.SliderUtils; -import org.apache.slider.core.exceptions.BadClusterStateException; -import org.apache.slider.core.exceptions.BadConfigException; -import org.apache.slider.core.exceptions.SliderInternalStateException; -import org.apache.slider.core.exceptions.TriggerClusterTeardownException; -import org.apache.slider.core.main.LauncherExitCodes; -import org.apache.slider.server.appmaster.operations.AbstractRMOperation; -import org.apache.slider.server.appmaster.operations.CancelSingleRequest; -import org.apache.slider.server.appmaster.operations.ContainerReleaseOperation; -import org.apache.slider.server.appmaster.operations.ContainerRequestOperation; -import org.apache.slider.server.appmaster.state.AppState; -import org.apache.slider.server.appmaster.state.AppStateBindingInfo; -import org.apache.slider.server.appmaster.state.ContainerAssignment; -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.NodeMap; -import org.apache.slider.server.appmaster.state.ProviderAppState; -import org.apache.slider.server.appmaster.state.RoleInstance; -import org.apache.slider.server.appmaster.state.RoleStatus; -import org.apache.slider.server.appmaster.state.StateAccessForProviders; -import org.apache.hadoop.yarn.service.utils.ServiceApiUtil; -import org.apache.slider.utils.SliderTestBase; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Map.Entry; - -/** - * Base for app state tests. - */ -public abstract class BaseMockAppStateTest extends SliderTestBase implements - MockRoles { - private static final Logger LOG = - LoggerFactory.getLogger(BaseMockAppStateTest.class); - protected static final List EMPTY_ID_LIST = Collections - .emptyList(); - - protected final MockFactory factory = MockFactory.INSTANCE; - protected MockAppState appState; - protected MockYarnEngine engine; - protected FileSystem fs; - protected SliderFileSystem sliderFileSystem; - protected File historyWorkDir; - protected Path historyPath; - protected MockApplicationId applicationId; - protected MockApplicationAttemptId applicationAttemptId; - protected StateAccessForProviders stateAccess; - - /** - * Override point: called in setup() to create the YARN engine; can - * be changed for different sizes and options. - * @return - */ - public MockYarnEngine createYarnEngine() { - return new MockYarnEngine(8, 8); - } - - @Override - public void setup() throws Exception { - super.setup(); - YarnConfiguration conf = SliderUtils.createConfiguration(); - fs = FileSystem.get(new URI("file:///"), conf); - sliderFileSystem = new SliderFileSystem(fs, conf); - engine = createYarnEngine(); - initApp(); - } - - /** - * Initialize the application. - * This uses the binding information supplied by {@link #buildBindingInfo()}. - */ - protected void initApp() - throws IOException, BadConfigException, BadClusterStateException { - String historyDirName = getTestName(); - applicationId = new MockApplicationId(1, 0); - applicationAttemptId = new MockApplicationAttemptId(applicationId, 1); - - historyWorkDir = new File("target/history", historyDirName); - historyPath = new Path(historyWorkDir.toURI()); - fs.delete(historyPath, true); - appState = new MockAppState(buildBindingInfo()); - stateAccess = new ProviderAppState(getValidTestName(), appState); - } - - /** - * Build the binding info from the default constructor values, - * the roles from {@link #factory}, and an instance definition. - * from {@link #buildApplication()} ()} - * @return - */ - protected AppStateBindingInfo buildBindingInfo() throws IOException { - AppStateBindingInfo binding = new AppStateBindingInfo(); - binding.application = buildApplication(); - ServiceApiUtil.validateAndResolveApplication(binding.application, - sliderFileSystem, SliderUtils.createConfiguration()); - //binding.roles = new ArrayList<>(factory.ROLES); - binding.fs = fs; - binding.historyPath = historyPath; - binding.nodeReports = engine.getNodeReports(); - return binding; - } - - /** - * Override point, define the instance definition. - * @return the instance definition - */ - public Application buildApplication() { - return factory.newApplication(0, 0, 0).name(getValidTestName()); - } - - /** - * Get the test name ... defaults to method name - * @return the method name - */ - public String getTestName() { - return methodName.getMethodName(); - } - - public String getValidTestName() { - return getTestName().toLowerCase(Locale.ENGLISH); - } - - public RoleStatus getRole0Status() { - return lookupRole(ROLE0); - } - - public RoleStatus lookupRole(String role) { - return appState.lookupRoleStatus(role); - } - - public RoleStatus getRole1Status() { - return lookupRole(ROLE1); - } - - public RoleStatus getRole2Status() { - return lookupRole(ROLE2); - } - - /** - * Build a role instance from a container assignment. - * @param assigned - * @return the instance - */ - public RoleInstance roleInstance(ContainerAssignment assigned) { - Container target = assigned.container; - RoleInstance failedInstance = - assigned.role.getProviderRole().failedInstances.poll(); - RoleInstance ri; - if (failedInstance != null) { - ri = new RoleInstance(target, failedInstance); - } else { - ri = new RoleInstance(target, assigned.role.getProviderRole()); - } - ri.roleId = assigned.role.getPriority(); - ri.role = assigned.role.getName(); - return ri; - } - - public NodeInstance nodeInstance(long age, int live0, int live1, int live2) { - NodeInstance ni = new NodeInstance(String.format("age%d-[%d,%d,%d]", age, - live0, live1, live2), MockFactory.ROLE_COUNT); - ni.getOrCreate(getRole0Status().getKey()).setLastUsed(age); - ni.getOrCreate(getRole0Status().getKey()).setLive(live0); - if (live1 > 0) { - ni.getOrCreate(getRole1Status().getKey()).setLive(live1); - } - if (live2 > 0) { - ni.getOrCreate(getRole2Status().getKey()).setLive(live2); - } - return ni; - } - - /** - * Create a container status event. - * @param c container - * @return a status - */ - ContainerStatus containerStatus(Container c) { - return containerStatus(c.getId()); - } - - /** - * Create a container status instance for the given ID, declaring - * that it was shut down by the application itself. - * @param cid container Id - * @return the instance - */ - public ContainerStatus containerStatus(ContainerId cid) { - ContainerStatus status = containerStatus(cid, - LauncherExitCodes.EXIT_CLIENT_INITIATED_SHUTDOWN); - return status; - } - - public ContainerStatus containerStatus(ContainerId cid, int exitCode) { - ContainerStatus status = ContainerStatus.newInstance( - cid, - ContainerState.COMPLETE, - "", - exitCode); - return status; - } - - /** - * Create nodes and bring them to the started state. - * @return a list of roles - */ - protected List createAndStartNodes() - throws TriggerClusterTeardownException, SliderInternalStateException { - return createStartAndStopNodes(new ArrayList<>()); - } - - /** - * Create, Start and stop nodes. - * @param completionResults List filled in with the status on all completed - * nodes - * @return the nodes - */ - public List createStartAndStopNodes( - List completionResults) - throws TriggerClusterTeardownException, SliderInternalStateException { - List released = new ArrayList<>(); - List instances = createAndSubmitNodes(released); - processSubmissionOperations(instances, completionResults, released); - return instances; - } - - /** - * Process the start/stop operations. - * @param instances - * @param completionResults - * @param released - */ - public void processSubmissionOperations( - List instances, - List completionResults, - List released) { - for (RoleInstance instance : instances) { - LOG.debug("Started {} on {}", instance.role, instance.id); - assertNotNull(appState.onNodeManagerContainerStarted(instance - .getContainerId())); - } - releaseContainers(completionResults, - released, - ContainerState.COMPLETE, - "released", - 0 - ); - } - - /** - * Release a list of containers, updating the completion results. - * @param completionResults - * @param containerIds - * @param containerState - * @param exitText - * @param containerExitCode - * @return - */ - public void releaseContainers( - List completionResults, - List containerIds, - ContainerState containerState, - String exitText, - int containerExitCode) { - for (ContainerId id : containerIds) { - ContainerStatus status = ContainerStatus.newInstance(id, - containerState, - exitText, - containerExitCode); - completionResults.add(appState.onCompletedContainer(status)); - } - } - - /** - * Create nodes and submit them. - * @return a list of roles - */ - public List createAndSubmitNodes() - throws TriggerClusterTeardownException, SliderInternalStateException { - return createAndSubmitNodes(new ArrayList<>()); - } - - /** - * Create nodes and submit them. - * @return a list of roles - */ - public List createAndSubmitNodes(List containerIds) - throws TriggerClusterTeardownException, SliderInternalStateException { - return createAndSubmitNodes(containerIds, new ArrayList<>()); - } - - /** - * Create nodes and submit them. - * @return a list of roles allocated - */ - public List createAndSubmitNodes( - List containerIds, - List operationsOut) - throws TriggerClusterTeardownException, SliderInternalStateException { - List ops = appState.reviewRequestAndReleaseNodes(); - return submitOperations(ops, containerIds, operationsOut); - } - - public List submitOperations( - List operationsIn, - List released) { - return submitOperations(operationsIn, released, new ArrayList<>()); - } - - /** - * Process the RM operations and send onContainersAllocated - * events to the app state. - * @param operationsIn list of incoming ops - * @param released released containers - * @return list of outbound operations - */ - public List submitOperations( - List operationsIn, - List released, - List operationsOut) { - List allocatedContainers = engine.execute(operationsIn, - released); - List assignments = new ArrayList<>(); - appState.onContainersAllocated(allocatedContainers, assignments, - operationsOut); - - List roles = new ArrayList<>(); - for (ContainerAssignment assigned : assignments) { - Container container = assigned.container; - RoleInstance ri = roleInstance(assigned); - //tell the app it arrived - LOG.debug("Start submitted {} on ${}", ri.role, container.getId()); - appState.containerStartSubmitted(container, ri); - roles.add(ri); - } - return roles; - } - - /** - * Add the AM to the app state. - */ - protected void addAppMastertoAppState() { -// appState.buildAppMasterNode( -// new MockContainerId(applicationAttemptId, 999999L), -// "appmaster", -// 0, -// null); - } - - /** - * Extract the list of container IDs from the list of role instances. - * @param instances instance list - * @param role role to look up - * @return the list of CIDs - */ - public List extractContainerIds( - List instances, - String role) { - List ids = new ArrayList<>(); - for (RoleInstance ri : instances) { - if (ri.role.equals(role)) { - ids.add(ri.getContainerId()); - } - } - return ids; - } - - /** - * Record a node as failing. - * @param node - * @param id - * @param count - * @return the entry - */ - public NodeEntry recordAsFailed(NodeInstance node, int id, int count) { - NodeEntry entry = node.getOrCreate(id); - for (int i = 1; i <= count; i++) { - entry.containerCompleted( - false, - ContainerOutcome.Failed); - } - return entry; - } - - protected void recordAllFailed(int id, int count, List nodes) { - for (NodeInstance node : nodes) { - recordAsFailed(node, id, count); - } - } - - /** - * Get the container request of an indexed entry. Includes some assertions - * for better diagnostics - * @param ops operation list - * @param index index in the list - * @return the request. - */ - public AMRMClient.ContainerRequest getRequest(List ops, - int index) { - assertTrue(index < ops.size()); - AbstractRMOperation op = ops.get(index); - assertTrue(op instanceof ContainerRequestOperation); - return ((ContainerRequestOperation) op).getRequest(); - } - - /** - * Get the cancel request of an indexed entry. Includes some assertions for - * better diagnostics - * @param ops operation list - * @param index index in the list - * @return the request. - */ - public AMRMClient.ContainerRequest getCancel(List ops, - int index) { - assertTrue(index < ops.size()); - AbstractRMOperation op = ops.get(index); - assertTrue(op instanceof CancelSingleRequest); - return ((CancelSingleRequest) op).getRequest(); - } - - /** - * Get the single request of a list of operations; includes the check for - * the size. - * @param ops operations list of size 1 - * @return the request within the first ContainerRequestOperation - */ - public AMRMClient.ContainerRequest getSingleRequest( - List ops) { - assertEquals(1, ops.size()); - return getRequest(ops, 0); - } - - /** - * Get the single request of a list of operations; includes the check for - * the size. - * @param ops operations list of size 1 - * @return the request within the first operation - */ - public AMRMClient.ContainerRequest getSingleCancel( - List ops) { - assertEquals(1, ops.size()); - return getCancel(ops, 0); - } - - /** - * Get the single release of a list of operations; includes the check for - * the size. - * @param ops operations list of size 1 - * @return the request within the first operation - */ - public ContainerReleaseOperation getSingleRelease( - List ops) { - assertEquals(1, ops.size()); - AbstractRMOperation op = ops.get(0); - assertTrue(op instanceof ContainerReleaseOperation); - return (ContainerReleaseOperation) op; - } - - /** - * Get the node information as a large JSON String. - * @return - */ - protected String nodeInformationSnapshotAsString() - throws UnsupportedEncodingException, JsonProcessingException { - return prettyPrintAsJson(stateAccess.getNodeInformationSnapshot()); - } - - /** - * Scan through all containers and assert that the assignment is AA. - * @param index role index - */ - protected void assertAllContainersAA(int index) { - for (Entry nodeMapEntry : cloneNodemap().entrySet()) { - String name = nodeMapEntry.getKey(); - NodeInstance ni = nodeMapEntry.getValue(); - NodeEntry nodeEntry = ni.get(index); - assertTrue("too many instances on node " + name, nodeEntry == null || - nodeEntry.isAntiAffinityConstraintHeld()); - } - } - - /** - * Get a snapshot of the nodemap of the application state. - * @return a cloned nodemap - */ - protected NodeMap cloneNodemap() { - return appState.getRoleHistory().cloneNodemap(); - } - - /** - * Issue a nodes updated event. - * @param report report to notify - * @return response of AM - */ - protected AppState.NodeUpdatedOutcome updateNodes(NodeReport report) { - return appState.onNodesUpdated(Collections.singletonList(report)); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockAM.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/MockAM.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/MockAM.java deleted file mode 100644 index 66ae0f9..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/MockAM.java +++ /dev/null @@ -1,26 +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.slider.server.appmaster.SliderAppMaster; - -/** - * Mock AM. - */ -public class MockAM extends SliderAppMaster { -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockAppState.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/MockAppState.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/MockAppState.java deleted file mode 100644 index 2fcf054..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/MockAppState.java +++ /dev/null @@ -1,82 +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.slider.core.exceptions.BadClusterStateException; -import org.apache.slider.core.exceptions.BadConfigException; -import org.apache.slider.providers.ProviderRole; -import org.apache.slider.server.appmaster.management.MetricsAndMonitoring; -import org.apache.slider.server.appmaster.state.AbstractClusterServices; -import org.apache.slider.server.appmaster.state.AppState; -import org.apache.slider.server.appmaster.state.AppStateBindingInfo; - -import java.io.IOException; -import java.util.Map; - -/** - * Extended app state that makes more things public. - */ -public class MockAppState extends AppState { - public static final int RM_MAX_RAM = 4096; - public static final int RM_MAX_CORES = 64; - - private long time = -1; - - public MockAppState(AbstractClusterServices recordFactory) { - super(recordFactory, new MetricsAndMonitoring()); - setContainerLimits(1, RM_MAX_RAM, 1, RM_MAX_CORES); - } - - /** - * Instance with a mock record factory. - */ - public MockAppState() { - this(new MockClusterServices()); - } - - public MockAppState(AppStateBindingInfo bindingInfo) - throws BadClusterStateException, IOException, BadConfigException { - this(); - buildInstance(bindingInfo); - } - - public Map getRoleMap() { - return super.getRoleMap(); - } - - /** - * Current time. if the time field - * is set, that value is returned - * @return the current time. - */ - protected long now() { - if (time > 0) { - return time; - } - return System.currentTimeMillis(); - } - - public void setTime(long newTime) { - this.time = newTime; - } - - public void incTime(long inc) { - this.time = this.time + inc; - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockApplicationAttemptId.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/MockApplicationAttemptId.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/MockApplicationAttemptId.java deleted file mode 100644 index b509625..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/MockApplicationAttemptId.java +++ /dev/null @@ -1,61 +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.api.records.ApplicationAttemptId; -import org.apache.hadoop.yarn.api.records.ApplicationId; - -class MockApplicationAttemptId extends ApplicationAttemptId { - - private ApplicationId applicationId; - private int attemptId; - - public MockApplicationAttemptId() { - } - - public MockApplicationAttemptId(ApplicationId applicationId, int attemptId) { - this.applicationId = applicationId; - this.attemptId = attemptId; - } - - @Override - public ApplicationId getApplicationId() { - return applicationId; - } - - @Override - public void setApplicationId(ApplicationId applicationId) { - this.applicationId = applicationId; - } - - @Override - public int getAttemptId() { - return attemptId; - } - - @Override - public void setAttemptId(int attemptId) { - this.attemptId = attemptId; - } - - @Override - protected void build() { - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockApplicationId.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/MockApplicationId.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/MockApplicationId.java deleted file mode 100644 index 01da470..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/MockApplicationId.java +++ /dev/null @@ -1,67 +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.api.records.ApplicationId; - -/** - * Mock app id. - */ -public class MockApplicationId extends ApplicationId { - - private int id; - private long clusterTimestamp; - - public MockApplicationId() { - } - - public MockApplicationId(int id) { - this.id = id; - } - - public MockApplicationId(int id, long clusterTimestamp) { - this.id = id; - this.clusterTimestamp = clusterTimestamp; - } - - @Override - public int getId() { - return id; - } - - @Override - public void setId(int id) { - this.id = id; - } - - @Override - public long getClusterTimestamp() { - return clusterTimestamp; - } - - @Override - public void setClusterTimestamp(long clusterTimestamp) { - this.clusterTimestamp = clusterTimestamp; - } - - @Override - public void build() { - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockClusterServices.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/MockClusterServices.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/MockClusterServices.java deleted file mode 100644 index 2578595..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/MockClusterServices.java +++ /dev/null @@ -1,38 +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.api.records.Resource; -import org.apache.slider.server.appmaster.state.AbstractClusterServices; - -/** - * Mock cluster services. - */ -public class MockClusterServices extends AbstractClusterServices { - - @Override - public Resource newResource() { - return new MockResource(0, 0); - } - - @Override - public Resource newResource(int memory, int cores) { - return new MockResource(memory, cores); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockContainer.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/MockContainer.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/MockContainer.java deleted file mode 100644 index 148b7f6..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/MockContainer.java +++ /dev/null @@ -1,131 +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.api.records.Container; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ExecutionType; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.api.records.Priority; -import org.apache.hadoop.yarn.api.records.Resource; -import org.apache.hadoop.yarn.api.records.Token; - -/** - * Mock container. - */ -public class MockContainer extends Container { - - private ContainerId id; - private NodeId nodeId; - private String nodeHttpAddress; - private Resource resource; - private Priority priority; - private Token containerToken; - - @Override - public int compareTo(Container other) { - if (this.getId().compareTo(other.getId()) == 0) { - if (this.getNodeId().compareTo(other.getNodeId()) == 0) { - return this.getResource().compareTo(other.getResource()); - } else { - return this.getNodeId().compareTo(other.getNodeId()); - } - } else { - return this.getId().compareTo(other.getId()); - } - } - - @Override - public String toString() { - return "MockContainer{ id=" + id + - ", nodeHttpAddress='" + nodeHttpAddress + "'," + - " priority=" + priority + " }"; - } - - @Override - public ContainerId getId() { - return id; - } - - @Override - public void setId(ContainerId id) { - this.id = id; - } - - @Override - public NodeId getNodeId() { - return nodeId; - } - - @Override - public void setNodeId(NodeId nodeId) { - this.nodeId = nodeId; - } - - @Override - public String getNodeHttpAddress() { - return nodeHttpAddress; - } - - @Override - public void setNodeHttpAddress(String nodeHttpAddress) { - this.nodeHttpAddress = nodeHttpAddress; - } - - @Override - public Resource getResource() { - return resource; - } - - @Override - public void setResource(Resource resource) { - this.resource = resource; - } - - @Override - public Priority getPriority() { - return priority; - } - - @Override - public void setPriority(Priority priority) { - this.priority = priority; - } - - @Override - public Token getContainerToken() { - return containerToken; - } - - @Override - public void setContainerToken(Token containerToken) { - this.containerToken = containerToken; - } - - @Override - public ExecutionType getExecutionType() { - return null; - } - - @Override - public void setExecutionType(ExecutionType executionType) { - - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockContainerId.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/MockContainerId.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/MockContainerId.java deleted file mode 100644 index 3cbc7e5..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/MockContainerId.java +++ /dev/null @@ -1,104 +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.api.records.ApplicationAttemptId; -import org.apache.hadoop.yarn.api.records.ContainerId; - -/** - * Mock container id. - */ -public class MockContainerId extends ContainerId implements Cloneable { - - private static final MockApplicationAttemptId DEFAULT_APP_ATTEMPT_ID = - new MockApplicationAttemptId(new MockApplicationId(1), 1); - - private long containerId; - private ApplicationAttemptId applicationAttemptId; - - MockContainerId() { - } - - /** - * Sets up a default app Attempt ID. - * @param containerId - */ - MockContainerId(long containerId) { - this.containerId = containerId; - this.applicationAttemptId = DEFAULT_APP_ATTEMPT_ID; - } - - public MockContainerId(ApplicationAttemptId applicationAttemptId, - long containerId) { - this.containerId = containerId; - this.applicationAttemptId = applicationAttemptId; - } - - MockContainerId(ContainerId that) { - containerId = that.getContainerId(); - applicationAttemptId = that.getApplicationAttemptId(); - } - - @Deprecated - @Override - public int getId() { - return (int) containerId; - } - - // TODO: Temporarily adding it back - void setId(int id) { - containerId = (long) id; - } - - @Override - public long getContainerId() { - return this.containerId; - } - - @Override - public void setContainerId(long id) { - this.containerId = id; - } - - @Override - public ApplicationAttemptId getApplicationAttemptId() { - return applicationAttemptId; - } - - @Override - public void setApplicationAttemptId(ApplicationAttemptId - applicationAttemptId) { - this.applicationAttemptId = applicationAttemptId; - } - - @Override - public void build() { - - } - - @Override - public String toString() { - return "mockcontainer_" + containerId; - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return super.clone(); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockFactory.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/MockFactory.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/MockFactory.java deleted file mode 100644 index 8785b92..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/MockFactory.java +++ /dev/null @@ -1,273 +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.api.records.ApplicationAttemptId; -import org.apache.hadoop.yarn.api.records.ApplicationId; -import org.apache.hadoop.yarn.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.ContainerState; -import org.apache.hadoop.yarn.api.records.ContainerStatus; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.api.records.NodeReport; -import org.apache.hadoop.yarn.api.records.NodeState; -import org.apache.hadoop.yarn.api.records.Priority; -import org.apache.hadoop.yarn.api.records.impl.pb.NodeReportPBImpl; -import org.apache.hadoop.yarn.client.api.AMRMClient; -import org.apache.slider.api.ResourceKeys; -import org.apache.slider.api.resource.Application; -import org.apache.slider.api.resource.Component; -import org.apache.slider.api.resource.Resource; -import org.apache.slider.providers.PlacementPolicy; -import org.apache.slider.providers.ProviderRole; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; - -import static org.apache.slider.api.ResourceKeys.COMPONENT_PLACEMENT_POLICY; - -/** - * Factory for creating things. - */ -public class MockFactory implements MockRoles { - - public static final int NODE_FAILURE_THRESHOLD = 2; - - public static final MockFactory INSTANCE = new MockFactory(); - - /** - * Basic role. - */ - public static final ProviderRole PROVIDER_ROLE0 = new ProviderRole( - MockRoles.ROLE0, - 0, - PlacementPolicy.DEFAULT, - NODE_FAILURE_THRESHOLD, - 1, - ResourceKeys.DEF_YARN_LABEL_EXPRESSION); - /** - * role 1 is strict. timeout should be irrelevant; same as failures - */ - public static final ProviderRole PROVIDER_ROLE1 = new ProviderRole( - MockRoles.ROLE1, - 1, - PlacementPolicy.STRICT, - NODE_FAILURE_THRESHOLD, - 1, - ResourceKeys.DEF_YARN_LABEL_EXPRESSION); - - /** - * role 2: longer delay. - */ - public static final ProviderRole PROVIDER_ROLE2 = new ProviderRole( - MockRoles.ROLE2, - 2, - PlacementPolicy.ANYWHERE, - NODE_FAILURE_THRESHOLD, - 2, - ResourceKeys.DEF_YARN_LABEL_EXPRESSION); - - /** - * Patch up a "role2" role to have anti-affinity set. - */ - public static final ProviderRole AAROLE_2 = new ProviderRole( - MockRoles.ROLE2, - 2, - PlacementPolicy.ANTI_AFFINITY_REQUIRED, - NODE_FAILURE_THRESHOLD, - 2, - null); - - /** - * Patch up a "role1" role to have anti-affinity set and GPI as the label. - */ - public static final ProviderRole AAROLE_1_GPU = new ProviderRole( - MockRoles.ROLE1, - 1, - PlacementPolicy.ANTI_AFFINITY_REQUIRED, - NODE_FAILURE_THRESHOLD, - 1, - MockRoles.LABEL_GPU); - - private int appIdCount; - private int attemptIdCount; - private int containerIdCount; - - private ApplicationId appId = newAppId(); - private ApplicationAttemptId attemptId = newApplicationAttemptId(appId); - - /** - * List of roles. - */ - public static final List ROLES = Arrays.asList( - PROVIDER_ROLE0, - PROVIDER_ROLE1, - PROVIDER_ROLE2 - ); - - public static final int ROLE_COUNT = ROLES.size(); - - MockContainerId newContainerId() { - return newContainerId(attemptId); - } - - MockContainerId newContainerId(ApplicationAttemptId attemptId0) { - MockContainerId cid = new MockContainerId(attemptId0, containerIdCount++); - return cid; - } - - MockApplicationAttemptId newApplicationAttemptId(ApplicationId appId0) { - MockApplicationAttemptId id = new MockApplicationAttemptId(appId0, - attemptIdCount++); - return id; - } - - MockApplicationId newAppId() { - MockApplicationId id = new MockApplicationId(); - id.setId(appIdCount++); - return id; - } - - public MockNodeId newNodeId(String host) { - return new MockNodeId(host); - } - - MockContainer newContainer(ContainerId cid) { - MockContainer c = new MockContainer(); - c.setId(cid); - return c; - } - - public MockContainer newContainer() { - return newContainer(newContainerId()); - } - - public MockContainer newContainer(NodeId nodeId, Priority priority) { - MockContainer container = newContainer(newContainerId()); - container.setNodeId(nodeId); - container.setPriority(priority); - return container; - } - - /** - * Build a new container using the request to supply priority and resource. - * @param req request - * @param host hostname to assign to - * @return the container - */ - public MockContainer newContainer(AMRMClient.ContainerRequest req, String - host) { - MockContainer container = newContainer(newContainerId()); - container.setResource(req.getCapability()); - container.setPriority(req.getPriority()); - container.setNodeId(new MockNodeId(host)); - return container; - } - - /** - * Create a new instance with the given components definined in the - * resources section. - * @param r1 - * @param r2 - * @param r3 - * @return - */ - public Application newApplication(long r1, long r2, long r3) { - Application application = new Application(); - application.setLaunchCommand("sleep 60"); - application.setResource(new Resource().memory("256")); - application.getConfiguration().setProperty(ResourceKeys - .NODE_FAILURE_THRESHOLD, Integer.toString(NODE_FAILURE_THRESHOLD)); - List components = application.getComponents(); - Component c1 = new Component().name(ROLE0).numberOfContainers(r1); - c1.getConfiguration().setProperty(COMPONENT_PLACEMENT_POLICY, - Integer.toString(PlacementPolicy.DEFAULT)); - Component c2 = new Component().name(ROLE1).numberOfContainers(r2); - c2.getConfiguration().setProperty(COMPONENT_PLACEMENT_POLICY, - Integer.toString(PlacementPolicy.STRICT)); - Component c3 = new Component().name(ROLE2).numberOfContainers(r3); - c3.getConfiguration().setProperty(COMPONENT_PLACEMENT_POLICY, - Integer.toString(PlacementPolicy.ANYWHERE)); - components.add(c1); - components.add(c2); - components.add(c3); - return application; - } - - public MockResource newResource(int memory, int vcores) { - return new MockResource(memory, vcores); - } - - ContainerStatus newContainerStatus() { - return newContainerStatus(null, null, "", 0); - } - - ContainerStatus newContainerStatus(ContainerId containerId, - ContainerState containerState, String diagnostics, int exitStatus) { - return ContainerStatus.newInstance(containerId, containerState, - diagnostics, exitStatus); - } - - /** - * Create a single instance. - * @param hostname - * @param nodeState - * @param label - */ - public NodeReport newNodeReport(String hostname, NodeState nodeState, - String label) { - NodeId nodeId = NodeId.newInstance(hostname, 80); - Integer.valueOf(hostname, 16); - return newNodeReport(hostname, nodeId, nodeState, label); - } - - NodeReport newNodeReport( - String hostname, - NodeId nodeId, - NodeState nodeState, - String label) { - NodeReport report = new NodeReportPBImpl(); - HashSet nodeLabels = new HashSet<>(); - nodeLabels.add(label); - report.setNodeId(nodeId); - report.setNodeLabels(nodeLabels); - report.setNodeState(nodeState); - report.setHttpAddress("http$hostname:80"); - return report; - } - - /** - * Create a list of instances -one for each hostname. - * @param hostnames hosts - * @return - */ - public List createNodeReports( - List hostnames, NodeState nodeState, String label) { - if (nodeState == null) { - nodeState = NodeState.RUNNING; - } - List reports = new ArrayList<>(); - for (String name : hostnames) { - reports.add(newNodeReport(name, nodeState, label)); - } - return reports; - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockFileSystem.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/MockFileSystem.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/MockFileSystem.java deleted file mode 100644 index 72d1665..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/MockFileSystem.java +++ /dev/null @@ -1,32 +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.fs.FilterFileSystem; -import org.apache.hadoop.fs.Path; - -import java.io.IOException; - -/** - * - */ -class MockFileSystem extends FilterFileSystem{ - @Override - public Path resolvePath(Path p) throws IOException { - return new Path("hdfs://localhost/", p); - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockNodeId.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/MockNodeId.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/MockNodeId.java deleted file mode 100644 index 9d2379a..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/MockNodeId.java +++ /dev/null @@ -1,62 +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.api.records.NodeId; - -/** - * Mock node id. - */ -public class MockNodeId extends NodeId { - private String host; - private int port; - - public MockNodeId() { - } - - MockNodeId(String host) { - this.host = host; - } - - public MockNodeId(String host, int port) { - this.host = host; - this.port = port; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - @Override - protected void build() { - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockPriority.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/MockPriority.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/MockPriority.java deleted file mode 100644 index 36f97cc..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/MockPriority.java +++ /dev/null @@ -1,46 +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.api.records.Priority; - -/** - * Mock priority. - */ -public class MockPriority extends Priority { - - private int priority; - - public MockPriority(int priority) { - this.priority = priority; - } - - MockPriority() { - } - - @Override - public int getPriority() { - return priority; - } - - @Override - public void setPriority(int priority) { - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockRMOperationHandler.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/MockRMOperationHandler.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/MockRMOperationHandler.java deleted file mode 100644 index 3dd764a..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/MockRMOperationHandler.java +++ /dev/null @@ -1,120 +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.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.Priority; -import org.apache.hadoop.yarn.client.api.AMRMClient; -import org.apache.slider.server.appmaster.operations.AbstractRMOperation; -import org.apache.slider.server.appmaster.operations.ContainerReleaseOperation; -import org.apache.slider.server.appmaster.operations.ContainerRequestOperation; -import org.apache.slider.server.appmaster.operations.RMOperationHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -/** - * Mock RM operation handler. - */ -public class MockRMOperationHandler extends RMOperationHandler { - protected static final Logger LOG = - LoggerFactory.getLogger(MockRMOperationHandler.class); - - private List operations = new ArrayList<>(); - private int requests; - private int releases; - // number available to cancel - private int availableToCancel = 0; - // count of cancelled values. This must be explicitly set - private int cancelled; - // number blacklisted - private int blacklisted = 0; - - @Override - public void releaseAssignedContainer(ContainerId containerId) { - operations.add(new ContainerReleaseOperation(containerId)); - LOG.info("Releasing container ID " + containerId.getContainerId()); - releases++; - } - - @Override - public void addContainerRequest(AMRMClient.ContainerRequest req) { - operations.add(new ContainerRequestOperation(req)); - LOG.info("Requesting container role #" + req.getPriority()); - requests++; - } - - @Override - public int cancelContainerRequests( - Priority priority1, - Priority priority2, - int count) { - int releaseable = Math.min(count, availableToCancel); - availableToCancel -= releaseable; - cancelled += releaseable; - return releaseable; - } - - @Override - public void cancelSingleRequest(AMRMClient.ContainerRequest request) { - // here assume that there is a copy of this request in the list - if (availableToCancel > 0) { - availableToCancel--; - cancelled++; - } - } - - @Override - public void updateBlacklist(List blacklistAdditions, List - blacklistRemovals) { - blacklisted += blacklistAdditions.size(); - blacklisted -= blacklistRemovals.size(); - } - - /** - * Clear the history. - */ - public void clear() { - operations.clear(); - releases = 0; - requests = 0; - } - - public AbstractRMOperation getFirstOp() { - return operations.get(0); - } - - public int getNumReleases() { - return releases; - } - - public void setAvailableToCancel(int num) { - this.availableToCancel = num; - } - - public int getAvailableToCancel() { - return availableToCancel; - } - - public int getBlacklisted() { - return blacklisted; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockRecordFactory.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/MockRecordFactory.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/MockRecordFactory.java deleted file mode 100644 index eb34586..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/MockRecordFactory.java +++ /dev/null @@ -1,27 +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; - -/** - * Node report for testing. - */ -class MockRecordFactory { - - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockRegistryOperations.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/MockRegistryOperations.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/MockRegistryOperations.java deleted file mode 100644 index 4917f1b..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/MockRegistryOperations.java +++ /dev/null @@ -1,83 +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.fs.PathNotFoundException; -import org.apache.hadoop.registry.client.api.RegistryOperations; -import org.apache.hadoop.registry.client.types.RegistryPathStatus; -import org.apache.hadoop.registry.client.types.ServiceRecord; -import org.apache.hadoop.service.AbstractService; - -import java.util.List; - -/** - * Simple stub registry for when one is needed for its API, but the operations - * are not actually required. - */ -class MockRegistryOperations extends AbstractService implements - RegistryOperations { - - MockRegistryOperations() { - super("mock"); - } - - @Override - public boolean mknode(String path, boolean createParents) { - return true; - } - - @Override - public void bind(String path, ServiceRecord record, int flags) { - } - - @Override - public ServiceRecord resolve(String path) throws PathNotFoundException { - throw new PathNotFoundException(path); - } - - @Override - public RegistryPathStatus stat(String path) throws PathNotFoundException { - throw new PathNotFoundException(path); - } - - @Override - public boolean exists(String path) { - return false; - } - - @Override - public List list(String path) throws PathNotFoundException { - throw new PathNotFoundException(path); - } - - @Override - public void delete(String path, boolean recursive) { - - } - - @Override - public boolean addWriteAccessor(String id, String pass) { - return true; - } - - @Override - public void clearWriteAccessors() { - - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockResource.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/MockResource.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/MockResource.java deleted file mode 100644 index 3a2ccd7..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/MockResource.java +++ /dev/null @@ -1,75 +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.api.records.Resource; - -/** - * Mock resource. - */ -public class MockResource extends Resource { - private int memory; - private int virtualCores; - - public MockResource(int memory, int vcores) { - this.memory = memory; - this.virtualCores = vcores; - } - - @Override - public int compareTo(Resource other) { - long diff = this.getMemorySize() - other.getMemorySize(); - if (diff == 0) { - diff = this.getVirtualCores() - other.getVirtualCores(); - } - return diff == 0 ? 0 : (diff > 0 ? 1 : -1); - } - - @Override - public long getMemorySize() { - return memory; - } - - @Override - public void setMemorySize(long memorySize) { - memory = (int) memorySize; - } - - @Override - public int getVirtualCores() { - return virtualCores; - } - - @Override - public void setVirtualCores(int vCores) { - this.virtualCores = vCores; - } - - @Deprecated - @Override - public int getMemory() { - return memory; - } - - @Deprecated - @Override - public void setMemory(int memory) { - this.memory = memory; - } -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockRoleHistory.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/MockRoleHistory.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/MockRoleHistory.java deleted file mode 100644 index 8e88b0d..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/MockRoleHistory.java +++ /dev/null @@ -1,53 +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.slider.core.exceptions.BadConfigException; -import org.apache.slider.providers.ProviderRole; -import org.apache.slider.server.appmaster.state.RoleHistory; -import org.apache.slider.server.appmaster.state.RoleStatus; - -import java.util.ArrayList; -import java.util.List; - -/** - * Subclass to enable access to some of the protected methods. - */ -public class MockRoleHistory extends RoleHistory { - - /** - * Take a list of provider roles and build the history from them, - * dynamically creating the role status entries on the way. - * @param providerRoles provider role list - * @throws BadConfigException configuration problem with the role list - */ - public MockRoleHistory(List providerRoles) throws - BadConfigException { - super(convertRoles(providerRoles), new MockClusterServices()); - } - - static List convertRoles(List providerRoles) { - List statuses = new ArrayList<>(); - for (ProviderRole role : providerRoles) { - statuses.add(new RoleStatus(role)); - } - return statuses; - } - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockRoles.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/MockRoles.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/MockRoles.java deleted file mode 100644 index bad82bd..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/MockRoles.java +++ /dev/null @@ -1,30 +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; - -/** - * Mock role constants. - */ -public interface MockRoles { - - String ROLE0 = "role0"; - String ROLE1 = "role1"; - String ROLE2 = "role2"; - String LABEL_GPU = "gpu"; - -} http://git-wip-us.apache.org/repos/asf/hadoop/blob/727e6d78/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/MockYarnCluster.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/MockYarnCluster.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/MockYarnCluster.java deleted file mode 100644 index 6b685a0..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/MockYarnCluster.java +++ /dev/null @@ -1,342 +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.api.records.ContainerId; -import org.apache.hadoop.yarn.api.records.NodeId; -import org.apache.hadoop.yarn.api.records.NodeReport; -import org.apache.hadoop.yarn.api.records.NodeState; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; - -/** - * Models the cluster itself: a set of mock cluster nodes. - * - * nodes retain the slot model with a limit of 2^8 slots/host -this - * lets us use 24 bits of the container ID for hosts, and so simulate - * larger hosts. - * - * upper 32: index into nodes in the cluster - * NodeID hostname is the index in hex format; this is parsed down to the index - * to resolve the host - * - * Important: container IDs will be reused as containers get recycled. This - * is not an attempt to realistically mimic a real YARN cluster, just - * simulate it enough for Slider to explore node re-use and its handling - * of successful and unsuccessful allocations. - * - * There is little or no checking of valid parameters in here -this is for - * test use, not production. - */ -public class MockYarnCluster { - protected static final Logger LOG = - LoggerFactory.getLogger(MockYarnCluster.class); - - private final int clusterSize; - private final int containersPerNode; - private MockYarnClusterNode[] nodes; - - MockYarnCluster(int clusterSize, int containersPerNode) { - this.clusterSize = clusterSize; - this.containersPerNode = containersPerNode; - build(); - } - - public int getClusterSize() { - return clusterSize; - } - - @Override - public String toString() { - return "MockYarnCluster size=" + clusterSize + ", capacity=" + - totalClusterCapacity()+ ", in use=" + containersInUse(); - } - - /** - * Build the cluster. - */ - private void build() { - nodes = new MockYarnClusterNode[clusterSize]; - for (int i = 0; i < clusterSize; i++) { - nodes[i] = new MockYarnClusterNode(i, containersPerNode); - } - } - - public MockYarnClusterNode nodeAt(int index) { - return nodes[index]; - } - - MockYarnClusterNode lookup(String hostname) { - int index = Integer.valueOf(hostname, 16); - return nodeAt(index); - } - - MockYarnClusterNode lookup(NodeId nodeId) { - return lookup(nodeId.getHost()); - } - - MockYarnClusterNode lookupOwner(ContainerId cid) { - return nodeAt(extractHost(cid.getContainerId())); - } - - /** - * Release a container: return true if it was actually in use. - * @param cid container ID - * @return the container released - */ - MockYarnClusterContainer release(ContainerId cid) { - int host = extractHost(cid.getContainerId()); - MockYarnClusterContainer inUse = nodeAt(host).release(cid.getContainerId()); - LOG.debug("Released {} inuse={}", cid, inUse); - return inUse; - } - - int containersInUse() { - int count = 0; - for (MockYarnClusterNode it : nodes) { - count += it.containersInUse(); - } - return count; - } - - /** - * Containers free. - * @return - */ - int containersFree() { - return totalClusterCapacity() - containersInUse(); - } - - int totalClusterCapacity() { - return clusterSize * containersPerNode; - } - - /** - * Reset all the containers. - */ - public void reset() { - for (MockYarnClusterNode node : nodes) { - node.reset(); - } - } - - /** - * Bulk allocate the specific number of containers on a range of the cluster. - * @param startNode start of the range - * @param endNode end of the range - * @param count count - * @return the number actually allocated -it will be less the count supplied - * if the node was full - */ - public int bulkAllocate(int startNode, int endNode, int count) { - int total = 0; - for (int i = startNode; i <= endNode; i++) { - total += nodeAt(i).bulkAllocate(count).size(); - } - return total; - } - - /** - * Get the list of node reports. These are not cloned; updates will persist - * in the nodemap - * @return current node report list - */ - List getNodeReports() { - List reports = new ArrayList<>(); - - for (MockYarnClusterNode n : nodes) { - reports.add(n.nodeReport); - } - return reports; - } - - /** - * Model cluster nodes on the simpler "slot" model than the YARN-era - * resource allocation model. Why? Easier to implement scheduling. - * Of course, if someone does want to implement the full process... - * - */ - public static class MockYarnClusterNode { - - private final int nodeIndex; - private final String hostname; - private List labels = new ArrayList<>(); - private final MockNodeId nodeId; - private final MockYarnClusterContainer[] containers; - private boolean offline; - private NodeReport nodeReport; - - public MockYarnClusterNode(int index, int size) { - nodeIndex = index; - hostname = String.format(Locale.ENGLISH, "%08x", index); - nodeId = new MockNodeId(hostname, 0); - - containers = new MockYarnClusterContainer[size]; - for (int i = 0; i < size; i++) { - int cid = makeCid(index, i); - MockContainerId mci = new MockContainerId(cid); - containers[i] = new MockYarnClusterContainer(mci); - } - - nodeReport = MockFactory.INSTANCE.newNodeReport(hostname, nodeId, - NodeState.RUNNING, ""); - } - - public String getHostname() { - return hostname; - } - - public NodeId getNodeId() { - return nodeId; - } - - /** - * Look up a container. - * @param containerId - * @return - */ - public MockYarnClusterContainer lookup(int containerId) { - return containers[extractContainer(containerId)]; - } - - /** - * Go offline; release all containers. - */ - public void goOffline() { - if (!offline) { - offline = true; - reset(); - } - } - - public void goOnline() { - offline = false; - } - - /** - * Allocate a container -if one is available. - * @return the container or null for none free - * -or the cluster node is offline - */ - public MockYarnClusterContainer allocate() { - if (!offline) { - for (int i = 0; i < containers.length; i++) { - MockYarnClusterContainer c = containers[i]; - if (!c.busy) { - c.busy = true; - return c; - } - } - } - return null; - } - - /** - * Bulk allocate the specific number of containers. - * @param count count - * @return the list actually allocated -it will be less the count supplied - * if the node was full - */ - public List bulkAllocate(int count) { - List result = new ArrayList<>(); - for (int i = 0; i < count; i++) { - MockYarnClusterContainer allocation = allocate(); - if (allocation == null) { - break; - } - result.add(allocation); - } - return result; - } - - /** - * Release a container. - * @param cid container ID - * @return the container if the container was busy before the release - */ - public MockYarnClusterContainer release(long cid) { - MockYarnClusterContainer container = containers[extractContainer(cid)]; - boolean b = container.busy; - container.busy = false; - return b? container: null; - } - - public String httpAddress() { - return "http://$hostname/"; - } - - /** - * Reset all the containers. - */ - public void reset() { - for (MockYarnClusterContainer cont : containers) { - cont.reset(); - } - } - - public int containersInUse() { - int c = 0; - for (MockYarnClusterContainer cont : containers) { - c += cont.busy ? 1 : 0; - } - return c; - } - - public int containersFree() { - return containers.length - containersInUse(); - } - } - - /** - * Cluster container. - */ - public static class MockYarnClusterContainer { - private MockContainerId cid; - private boolean busy; - - MockYarnClusterContainer(MockContainerId cid) { - this.cid = cid; - } - - public MockContainerId getCid() { - return cid; - } - - void reset() { - busy = false; - } - } - - public static int makeCid(int hostIndex, int containerIndex) { - return (hostIndex << 8) | containerIndex & 0xff; - } - - public static final int extractHost(long cid) { - return (int)((cid >>> 8) & 0xffff); - } - - public static final int extractContainer(long cid) { - return (int)(cid & 0xff); - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org