Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryStore.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryStore.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryStore.java (revision 0) @@ -0,0 +1,28 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.yarn.server.applicationhistoryservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +@InterfaceAudience.Public +@InterfaceStability.Unstable +public interface ApplicationHistoryStore extends ApplicationHistoryReader, + ApplicationHistoryWriter { +} Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryReader.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryReader.java (revision 1508684) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryReader.java (working copy) @@ -74,7 +74,7 @@ * @param {@link ContainerId} * @return {@link Container} for ContainerId */ - ContainerHistoryData getAMContainer(ContainerId containerId); + ContainerHistoryData getContainer(ContainerId containerId); /** * This method returns {@link ContainerHistoryData} for specified @@ -83,5 +83,5 @@ * @param {@link ApplicationAttemptId} * @return {@link ContainerHistoryData} for ApplicationAttemptId */ - ContainerHistoryData getContainer(ApplicationAttemptId appAttemptId); + ContainerHistoryData getAMContainer(ApplicationAttemptId appAttemptId); } Index: hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/MemoryApplicationHistoryStore.java =================================================================== --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/MemoryApplicationHistoryStore.java (revision 0) +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/MemoryApplicationHistoryStore.java (revision 0) @@ -0,0 +1,156 @@ +package org.apache.hadoop.yarn.server.applicationhistoryservice; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +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.exceptions.YarnException; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationAttemptHistoryData; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ApplicationHistoryData; +import org.apache.hadoop.yarn.server.applicationhistoryservice.records.ContainerHistoryData; + +public class MemoryApplicationHistoryStore implements ApplicationHistoryStore { + + private static MemoryApplicationHistoryStore memStore = null; + + private ConcurrentHashMap applicationData = + new ConcurrentHashMap(); + private ConcurrentHashMap> applicationAttemptData = + new ConcurrentHashMap>(); + private ConcurrentHashMap containerData = + new ConcurrentHashMap(); + + private MemoryApplicationHistoryStore() { + } + + public static MemoryApplicationHistoryStore getMemoryStore() { + if (memStore == null) { + memStore = new MemoryApplicationHistoryStore(); + } + return memStore; + } + + @Override + public Map getAllApplications() { + Map listApps = + new HashMap(); + for (ApplicationId appId : applicationData.keySet()) { + listApps.put(appId, applicationData.get(appId)); + } + return listApps; + } + + @Override + public ApplicationHistoryData getApplication(ApplicationId appId) { + return applicationData.get(appId); + } + + @Override + public Map getApplicationAttempts( + ApplicationId appId) { + Map listAttempts = + null; + ConcurrentHashMap appAttempts = + applicationAttemptData.get(appId); + if (appAttempts != null) { + listAttempts = + new HashMap(); + for (ApplicationAttemptId attemptId : appAttempts.keySet()) { + listAttempts.put(attemptId, appAttempts.get(attemptId)); + } + } + return listAttempts; + } + + @Override + public ApplicationAttemptHistoryData getApplicationAttempt( + ApplicationAttemptId appAttemptId) { + ApplicationAttemptHistoryData appAttemptHistoryData = null; + ConcurrentHashMap appAttempts = + applicationAttemptData.get(appAttemptId.getApplicationId()); + if (appAttempts != null) { + for (ApplicationAttemptId attemptId : appAttempts.keySet()) { + if (attemptId.toString().equalsIgnoreCase(appAttemptId.toString())) { + appAttemptHistoryData = appAttempts.get(attemptId); + } + } + } + return appAttemptHistoryData; + } + + @Override + public ContainerHistoryData getAMContainer(ApplicationAttemptId appAttemptId) { + ContainerHistoryData Container = null; + ConcurrentHashMap appAttempts = + applicationAttemptData.get(appAttemptId.getApplicationId()); + if (appAttempts != null) { + for (ApplicationAttemptId attemptId : appAttempts.keySet()) { + if (attemptId.toString().equalsIgnoreCase(appAttemptId.toString())) { + Container = + containerData.get(appAttempts.get(attemptId) + .getMasterContainerId()); + } + } + } + return Container; + } + + @Override + public ContainerHistoryData getContainer(ContainerId containerId) { + return containerData.get(containerId); + } + + @Override + public void writeApplication(ApplicationHistoryData app) throws Throwable { + if (app != null) { + ApplicationHistoryData oldData = + applicationData.putIfAbsent(app.getApplicationId(), app); + if (oldData != null) { + throw new YarnException("This application " + + app.getApplicationId().toString() + " is already present."); + } + } + } + + @Override + public void writeApplicationAttempt(ApplicationAttemptHistoryData appAttempt) + throws Throwable { + if (appAttempt != null) { + if (applicationAttemptData.containsKey(appAttempt + .getApplicationAttemptId().getApplicationId())) { + ConcurrentHashMap appAttemptmap = + applicationAttemptData.get(appAttempt.getApplicationAttemptId() + .getApplicationId()); + ApplicationAttemptHistoryData oldAppAttempt = + appAttemptmap.putIfAbsent(appAttempt.getApplicationAttemptId(), + appAttempt); + if (oldAppAttempt != null) { + throw new YarnException("This application attempt " + + appAttempt.getApplicationAttemptId().toString() + + " already present."); + } + } else { + ConcurrentHashMap appAttemptmap = + new ConcurrentHashMap(); + appAttemptmap.put(appAttempt.getApplicationAttemptId(), appAttempt); + applicationAttemptData.putIfAbsent(appAttempt.getApplicationAttemptId() + .getApplicationId(), appAttemptmap); + } + } + } + + @Override + public void writeContainer(ContainerHistoryData container) throws Throwable { + if (container != null) { + ContainerHistoryData oldContainer = + containerData.putIfAbsent(container.getContainerId(), container); + if (oldContainer != null) { + throw new YarnException("This container " + + container.getContainerId().toString() + " is already present."); + } + } + } +}