diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ApplicationAttemptEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ApplicationAttemptEntity.java new file mode 100644 index 0000000..66a8040 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ApplicationAttemptEntity.java @@ -0,0 +1,53 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collections; +import java.util.Set; + +@XmlRootElement(name = "appattempt") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class ApplicationAttemptEntity extends HierarchicalTimelineEntity { + public static final String TYPE = "YARN_APPLICATION_ATTEMPT"; + public static final Set ACCEPTABLE_CHILD_ENTITY_TYPES = + Collections.singleton(ContainerEntity.TYPE); + public static final Set ACCEPTABLE_PARENT_ENTITY_TYPES = + Collections.singleton(ApplicationEntity.TYPE); + + public ApplicationAttemptEntity() { + super(TYPE); + } + + @Override + protected Set getAcceptableChildEntityTypes() { + return ACCEPTABLE_CHILD_ENTITY_TYPES; + } + + @Override + protected Set getAcceptableParentEntityTypes() { + return ACCEPTABLE_PARENT_ENTITY_TYPES; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ApplicationEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ApplicationEntity.java new file mode 100644 index 0000000..39cc626 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ApplicationEntity.java @@ -0,0 +1,82 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +@XmlRootElement(name = "application") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class ApplicationEntity extends HierarchicalTimelineEntity { + public static final String TYPE = "YARN_APPLICATION"; + public static final Set ACCEPTABLE_CHILD_ENTITY_TYPES = + Collections.singleton(ApplicationAttemptEntity.TYPE); + public static final Set ACCEPTABLE_PARENT_ENTITY_TYPES = new HashSet<>(); + + static { + ACCEPTABLE_PARENT_ENTITY_TYPES.add(ClusterEntity.TYPE); + ACCEPTABLE_PARENT_ENTITY_TYPES.add(FlowEntity.TYPE); + ACCEPTABLE_PARENT_ENTITY_TYPES.add(FlowRunEntity.TYPE); + } + + private TimelineUser user; + private TimelineQueue queue; + + public ApplicationEntity() { + super(TYPE); + } + + @XmlElement(name = "user") + public TimelineUser getUser() { + return user; + } + + public void setUser(TimelineUser user) { + this.user = user; + } + + + @XmlElement(name = "queue") + public TimelineQueue getQueue() { + return queue; + } + + public void setQueue(TimelineQueue queue) { + this.queue = queue; + } + + @Override + protected Set getAcceptableChildEntityTypes() { + return ACCEPTABLE_CHILD_ENTITY_TYPES; + } + + @Override + protected Set getAcceptableParentEntityTypes() { + return ACCEPTABLE_PARENT_ENTITY_TYPES; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ClusterEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ClusterEntity.java new file mode 100644 index 0000000..3553638 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ClusterEntity.java @@ -0,0 +1,56 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +@XmlRootElement(name = "cluster") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class ClusterEntity extends HierarchicalTimelineEntity { + public static final String TYPE = "YARN_CLUSTER"; + public static final Set ACCEPTABLE_CHILD_ENTITY_TYPES = new HashSet<>(); + + static { + ACCEPTABLE_CHILD_ENTITY_TYPES.add(FlowEntity.TYPE); + ACCEPTABLE_CHILD_ENTITY_TYPES.add(ApplicationEntity.TYPE); + } + + public ClusterEntity() { + super(TYPE); + } + + @Override + protected Set getAcceptableChildEntityTypes() { + return ACCEPTABLE_CHILD_ENTITY_TYPES; + } + + @Override + protected Set getAcceptableParentEntityTypes() { + return Collections.emptySet(); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ContainerEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ContainerEntity.java new file mode 100644 index 0000000..54dfe0d --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/ContainerEntity.java @@ -0,0 +1,51 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collections; +import java.util.Set; + +@XmlRootElement(name = "container") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class ContainerEntity extends HierarchicalTimelineEntity { + public static final String TYPE = "YARN_CONTAINER"; + public static final Set ACCEPTABLE_PARENT_ENTITY_TYPES = + Collections.singleton(ApplicationAttemptEntity.TYPE); + + public ContainerEntity() { + super(TYPE); + } + + @Override + protected Set getAcceptableChildEntityTypes() { + return Collections.emptySet(); + } + + @Override + protected Set getAcceptableParentEntityTypes() { + return ACCEPTABLE_PARENT_ENTITY_TYPES; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/FlowEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/FlowEntity.java new file mode 100644 index 0000000..037a9a6 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/FlowEntity.java @@ -0,0 +1,81 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +@XmlRootElement(name = "flow") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class FlowEntity extends HierarchicalTimelineEntity { + public static final String TYPE = "YARN_FLOW"; + public static final Set ACCEPTABLE_CHILD_ENTITY_TYPES = new HashSet<>(); + public static final Set ACCEPTABLE_PARENT_ENTITY_TYPES = + Collections.singleton(ClusterEntity.TYPE); + + private String version; + + static { + ACCEPTABLE_CHILD_ENTITY_TYPES.add(FlowRunEntity.TYPE); + ACCEPTABLE_CHILD_ENTITY_TYPES.add(ApplicationEntity.TYPE); + } + + private TimelineUser user; + + public FlowEntity() { + super(TYPE); + } + + @XmlElement(name = "user") + public TimelineUser getUser() { + return user; + } + + public void setUser(TimelineUser user) { + this.user = user; + } + + @XmlElement(name = "version") + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + @Override + protected Set getAcceptableChildEntityTypes() { + return ACCEPTABLE_CHILD_ENTITY_TYPES; + } + + @Override + protected Set getAcceptableParentEntityTypes() { + return ACCEPTABLE_PARENT_ENTITY_TYPES; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/FlowRunEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/FlowRunEntity.java new file mode 100644 index 0000000..af30262 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/FlowRunEntity.java @@ -0,0 +1,70 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashSet; +import java.util.Set; + +@XmlRootElement(name = "flowrun") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class FlowRunEntity extends HierarchicalTimelineEntity { + public static final String TYPE = "YARN_FLOW_RUN"; + public static final Set ACCEPTABLE_CHILD_ENTITY_TYPES = new HashSet<>(); + public static final Set ACCEPTABLE_PARENT_ENTITY_TYPES = new HashSet<>(); + + static { + ACCEPTABLE_CHILD_ENTITY_TYPES.add(FlowRunEntity.TYPE); + ACCEPTABLE_CHILD_ENTITY_TYPES.add(ApplicationEntity.TYPE); + ACCEPTABLE_PARENT_ENTITY_TYPES.add(FlowEntity.TYPE); + ACCEPTABLE_PARENT_ENTITY_TYPES.add(FlowRunEntity.TYPE); + } + + private TimelineUser user; + + public FlowRunEntity() { + super(TYPE); + } + + @XmlElement(name = "user") + public TimelineUser getUser() { + return user; + } + + public void setUser(TimelineUser user) { + this.user = user; + } + + @Override + protected Set getAcceptableChildEntityTypes() { + return ACCEPTABLE_CHILD_ENTITY_TYPES; + } + + @Override + protected Set getAcceptableParentEntityTypes() { + return ACCEPTABLE_PARENT_ENTITY_TYPES; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/HierarchicalTimelineEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/HierarchicalTimelineEntity.java new file mode 100644 index 0000000..1f6e5e1 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/HierarchicalTimelineEntity.java @@ -0,0 +1,118 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public abstract class HierarchicalTimelineEntity extends TimelineEntity { + private Identifier parent; + private Map> children = new HashMap<>(); + + public HierarchicalTimelineEntity() { + + } + + HierarchicalTimelineEntity(String type) { + super(type); + } + + @XmlElement(name = "parent") + public Identifier getParent() { + return parent; + } + + public void setParent(Identifier parent) { + validateParent(parent.getType()); + this.parent = parent; + } + + public void setParent(String type, String id) { + validateParent(type); + parent = new Identifier(); + parent.setType(type); + parent.setId(id); + } + + @XmlElement(name = "children") + public Map> getChildren() { + return children; + } + + public void setChildren(Map> children) { + validateChildren(children); + this.children = children; + } + + public void addChildren(Map> children) { + validateChildren(children); + for (Map.Entry> entry : children.entrySet()) { + Set ids = children.get(entry.getKey()); + if (ids == null) { + ids = new HashSet<>(); + children.put(entry.getKey(), ids); + } + ids.addAll(entry.getValue()); + } + } + + public void addChild(String type, String id) { + if (getAcceptableChildEntityTypes().contains(type)) { + Set ids = children.get(type); + if (ids == null) { + ids = new HashSet<>(); + children.put(type, ids); + } + ids.add(id); + } else { + throw new IllegalArgumentException( + type + " is not the acceptable child of " + this.getType()); + } + } + + private void validateParent(String type) { + if (!getAcceptableParentEntityTypes().contains(type)) { + throw new IllegalArgumentException( + type + " is not the acceptable parent of " + this.getType()); + } + } + private void validateChildren(Map> children) { + for (Map.Entry> entry : children.entrySet()) { + if (!getAcceptableChildEntityTypes().contains(entry.getKey())) { + throw new IllegalArgumentException( + entry.getKey() + " is not the acceptable child of " + this.getType()); + } + } + } + + protected abstract Set getAcceptableChildEntityTypes(); + + protected abstract Set getAcceptableParentEntityTypes(); +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java new file mode 100644 index 0000000..2c3f773 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java @@ -0,0 +1,257 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@XmlRootElement(name = "entity") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class TimelineEntity { + + @XmlRootElement(name = "identifier") + @XmlAccessorType(XmlAccessType.NONE) + public static class Identifier { + private String type; + private String id; + + public Identifier() { + + } + + @XmlElement(name = "type") + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @XmlElement(name = "id") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + } + + private Identifier identifier; + private Map info = new HashMap<>(); + private Map configs = new HashMap<>(); + private Set metrics = new HashSet<>(); + private Set events = new HashSet<>(); + private Map> isRelatedToEntities = new HashMap<>(); + private Map> relatesToEntities = new HashMap<>(); + private long createdTime; + private long modifiedTime; + + public TimelineEntity() { + identifier = new Identifier(); + } + + protected TimelineEntity(String type) { + this(); + identifier.type = type; + } + + @XmlElement(name = "type") + public String getType() { + return identifier.type; + } + + public void setType(String type) { + identifier.type = type; + } + + @XmlElement(name = "id") + public String getId() { + return identifier.id; + } + + public void setId(String id) { + identifier.id = id; + } + + public Identifier getIdentifier() { + return identifier; + } + + public void setIdentifier(Identifier identifier) { + this.identifier = identifier; + } + + @XmlElement(name = "info") + public Map getInfo() { + return info; + } + + public void setInfo(Map info) { + this.info = info; + } + + public void addInfo(Map info) { + this.info.putAll(info); + } + + public void addInfo(String key, Object value) { + info.put(key, value); + } + + @XmlElement(name = "configs") + public Map getConfigs() { + return configs; + } + + public void setConfigs(Map configs) { + this.configs = configs; + } + + public void addConfigs(Map configs) { + this.configs.putAll(configs); + } + + public void addConfig(String key, Object value) { + configs.put(key, value); + } + + @XmlElement(name = "metrics") + public Set getMetrics() { + return metrics; + } + + public void setMetrics(Set metrics) { + this.metrics = metrics; + } + + public void addMetrics(Set metrics) { + this.metrics.addAll(metrics); + } + + public void addMetric(TimelineMetric metric) { + metrics.add(metric); + } + + @XmlElement(name = "events") + public Set getEvents() { + return events; + } + + public void setEvents(Set events) { + this.events = events; + } + + public void addEvents(Set events) { + this.events.addAll(events); + } + + public void addEvent(TimelineEvent event) { + events.add(event); + } + + @XmlElement(name = "isrelatedto") + public Map> getIsRelatedToEntities() { + return isRelatedToEntities; + } + + public void setIsRelatedToEntities( + Map> isRelatedToEntities) { + this.isRelatedToEntities = isRelatedToEntities; + } + + public void addIsRelatedToEntities(Map> isRelatedToEntities) { + for (Map.Entry> entry : isRelatedToEntities.entrySet()) { + Set ids = isRelatedToEntities.get(entry.getKey()); + if (ids == null) { + ids = new HashSet<>(); + isRelatedToEntities.put(entry.getKey(), ids); + } + ids.addAll(entry.getValue()); + } + } + public void addIsRelatedToEntity(String type, String id) { + Set ids = isRelatedToEntities.get(type); + if (ids == null) { + ids = new HashSet<>(); + isRelatedToEntities.put(type, ids); + } + ids.add(id); + } + + @XmlElement(name = "relatesto") + public Map> getRelatesToEntities() { + return relatesToEntities; + } + + public void addRelatesToEntities(Map> relatesToEntities) { + for (Map.Entry> entry : relatesToEntities.entrySet()) { + Set ids = relatesToEntities.get(entry.getKey()); + if (ids == null) { + ids = new HashSet<>(); + relatesToEntities.put(entry.getKey(), ids); + } + ids.addAll(entry.getValue()); + } + } + + public void addRelatesToEntity(String type, String id) { + Set ids = relatesToEntities.get(type); + if (ids == null) { + ids = new HashSet<>(); + relatesToEntities.put(type, ids); + } + ids.add(id); + } + + public void setRelatesToEntities(Map> relatesToEntities) { + this.relatesToEntities = relatesToEntities; + } + + @XmlElement(name = "createdtime") + public long getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(long createdTime) { + this.createdTime = createdTime; + } + + @XmlElement(name = "modifiedtime") + public long getModifiedTime() { + return modifiedTime; + } + + public void setModifiedTime(long modifiedTime) { + this.modifiedTime = modifiedTime; + } + + +} \ No newline at end of file diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEvent.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEvent.java new file mode 100644 index 0000000..b4815bb --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEvent.java @@ -0,0 +1,77 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashMap; +import java.util.Map; + +@XmlRootElement(name = "event") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class TimelineEvent { + private String id; + private Map info = new HashMap<>(); + private long timestamp; + + public TimelineEvent() { + + } + + @XmlElement(name = "id") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @XmlElement(name = "info") + public Map getInfo() { + return info; + } + + public void setInfo(Map info) { + this.info = info; + } + + public void addInfo(Map info) { + this.info.putAll(info); + } + + public void addInfo(String key, Object value) { + info.put(key, value); + } + + @XmlElement(name = "timestamp") + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineMetric.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineMetric.java new file mode 100644 index 0000000..6988f69 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineMetric.java @@ -0,0 +1,106 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +@XmlRootElement(name = "metric") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class TimelineMetric { + private String id; + private Map info = new HashMap<>(); + private Object singleData; + private Map timeSeries = new LinkedHashMap<>(); + private long timestamp; + + public TimelineMetric() { + + } + + @XmlElement(name = "id") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @XmlElement(name = "info") + public Map getInfo() { + return info; + } + + public void setInfo(Map info) { + this.info = info; + } + + public void addInfo(Map info) { + this.info.putAll(info); + } + + public void addInfo(String key, Object value) { + info.put(key, value); + } + + @XmlElement(name = "data") + public Object getSingleData() { + return singleData; + } + + public void setSingleData(Object singleData) { + this.singleData = singleData; + } + + @XmlElement(name = "timeseries") + public Map getTimeSeries() { + return timeSeries; + } + + public void setTimeSeries(Map timeSeries) { + this.timeSeries = timeSeries; + } + + public void addTimeSeries(Map timeSeries) { + this.timeSeries.putAll(timeSeries); + } + + public void addTimeSeriesData(long timestamp, Object value) { + timeSeries.put(timestamp, value); + } + + @XmlElement(name = "timestamp") + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineQueue.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineQueue.java new file mode 100644 index 0000000..3c08a54 --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineQueue.java @@ -0,0 +1,97 @@ +/* + * 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.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +@XmlRootElement(name = "queue") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class TimelineQueue { + private String id; + private Map info = new HashMap<>(); + private String parent; + private Set children = new HashSet<>(); + + public TimelineQueue() { + + } + + @XmlElement(name = "id") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @XmlElement(name = "info") + public Map getInfo() { + return info; + } + + public void setInfo(Map info) { + this.info = info; + } + + public void addInfo(Map info) { + this.info.putAll(info); + } + + public void addInfo(String key, Object value) { + info.put(key, value); + } + + @XmlElement(name = "parent") + public String getParent() { + return parent; + } + + public void setParent(String parent) { + this.parent = parent; + } + + @XmlElement(name = "children") + public Set getChildren() { + return children; + } + + public void setChildren(Set children) { + this.children = children; + } + + public void addChildren(Set children) { + this.children.addAll(children); + } + + public void addChild(String child) { + children.add(child); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineUser.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineUser.java new file mode 100644 index 0000000..05c043b --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineUser.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.yarn.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.HashMap; +import java.util.Map; + +@XmlRootElement(name = "user") +@XmlAccessorType(XmlAccessType.NONE) +@InterfaceAudience.Public +@InterfaceStability.Unstable +public class TimelineUser { + private String id; + private Map info = new HashMap<>(); + + public TimelineUser() { + } + + @XmlElement(name = "id") + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @XmlElement(name = "info") + public Map getInfo() { + return info; + } + + public void addInfo(Map info) { + this.info.putAll(info); + } + + public void setInfo(Map info) { + this.info = info; + } + + public void addInfo(String key, Object value) { + info.put(key, value); + } +} diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/package-info.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/package-info.java new file mode 100644 index 0000000..89a9e9b --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/package-info.java @@ -0,0 +1,21 @@ +/* + * 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. + */ +@InterfaceAudience.Public package org.apache.hadoop.yarn.api.records.timelineservice; + +import org.apache.hadoop.classification.InterfaceAudience; + diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/timelineservice/TestTimelineServiceRecords.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/timelineservice/TestTimelineServiceRecords.java new file mode 100644 index 0000000..5e0ee6d --- /dev/null +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/timelineservice/TestTimelineServiceRecords.java @@ -0,0 +1,155 @@ +/* + * 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.api.records.timelineservice; + + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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.util.timeline.TimelineUtils; +import org.apache.hadoop.yarn.webapp.hamlet.HamletSpec; +import org.junit.Test; + + + +public class TestTimelineServiceRecords { + private static final Log LOG = + LogFactory.getLog(TestTimelineServiceRecords.class); + + @Test + public void testTimelineEntities() throws Exception { + TimelineEntity entity = new TimelineEntity(); + entity.setType("test type 1"); + entity.setId("test id 1"); + entity.addInfo("test info key 1", "test info value 1"); + entity.addInfo("test info key 2", "test info value 2"); + entity.addConfig("test config key 1", "test config value 1"); + entity.addConfig("test config key 2", "test config value 2"); + TimelineMetric metric1 = new TimelineMetric(); + metric1.setId("test metric id 1"); + metric1.addInfo("test info key 1", "test info value 1"); + metric1.addInfo("test info key 2", "test info value 2"); + metric1.addTimeSeriesData(1L, "test time series 1"); + metric1.addTimeSeriesData(2L, "test time series 2"); + metric1.setTimestamp(0L); + entity.addMetric(metric1); + TimelineMetric metric2 = new TimelineMetric(); + metric2.setId("test metric id 1"); + metric2.addInfo("test info key 1", "test info value 1"); + metric2.addInfo("test info key 2", "test info value 2"); + metric2.setSingleData("test info value 3"); + metric1.setTimestamp(0L); + entity.addMetric(metric2); + TimelineEvent event1 = new TimelineEvent(); + event1.setId("test event id 1"); + event1.addInfo("test info key 1", "test info value 1"); + event1.addInfo("test info key 2", "test info value 2"); + event1.setTimestamp(0L); + entity.addEvent(event1); + TimelineEvent event2 = new TimelineEvent(); + event2.setId("test event id 2"); + event2.addInfo("test info key 1", "test info value 1"); + event2.addInfo("test info key 2", "test info value 2"); + event2.setTimestamp(1L); + entity.addEvent(event2); + entity.setCreatedTime(0L); + entity.setModifiedTime(1L); + entity.addRelatesToEntity("test type 2", "test id 2"); + entity.addRelatesToEntity("test type 3", "test id 3"); + entity.addIsRelatedToEntity("test type 4", "test id 4"); + entity.addIsRelatedToEntity("test type 5", "test id 5"); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(entity, true)); + } + + @Test + public void testFirstClassCitizenEntities() throws Exception { + TimelineUser user = new TimelineUser(); + user.setId("test user id"); + + TimelineQueue queue = new TimelineQueue(); + queue.setId("test queue id"); + + + ClusterEntity cluster = new ClusterEntity(); + cluster.setId("test cluster id"); + + FlowEntity flow = new FlowEntity(); + flow.setId("test flow id"); + flow.setUser(user); + flow.setVersion("test flow version"); + + FlowRunEntity flowRun = new FlowRunEntity(); + flowRun.setId("test flow run id"); + flowRun.setUser(user); + + ApplicationEntity app = new ApplicationEntity(); + app.setId(ApplicationId.newInstance(0, 1).toString()); + app.setUser(user); + app.setQueue(queue); + + ApplicationAttemptEntity appAttempt = new ApplicationAttemptEntity(); + appAttempt.setId(ApplicationAttemptId.newInstance( + ApplicationId.newInstance(0, 1), 1).toString()); + + ContainerEntity container = new ContainerEntity(); + container.setId(ContainerId.newContainerId( + ApplicationAttemptId.newInstance( + ApplicationId.newInstance(0, 1), 1), 1).toString()); + + cluster.addChild(FlowEntity.TYPE, flow.getId()); + flow.setParent(ClusterEntity.TYPE, cluster.getId()); + flow.addChild(FlowRunEntity.TYPE, flowRun.getId()); + flowRun.setParent(FlowEntity.TYPE, flow.getId()); + flowRun.addChild(ApplicationEntity.TYPE, app.getId()); + app.setParent(FlowRunEntity.TYPE, flowRun.getId()); + app.addChild(ApplicationAttemptEntity.TYPE, appAttempt.getId()); + appAttempt.setParent(ApplicationEntity.TYPE, app.getId()); + appAttempt.addChild(ContainerEntity.TYPE, container.getId()); + container.setParent(ApplicationAttemptEntity.TYPE, appAttempt.getId()); + + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(cluster, true)); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(flow, true)); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(flowRun, true)); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(app, true)); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(appAttempt, true)); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(container, true)); + } + + @Test + public void testUser() throws Exception { + TimelineUser user = new TimelineUser(); + user.setId("test user id"); + user.addInfo("test info key 1", "test info value 1"); + user.addInfo("test info key 2", "test info value 2"); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(user, true)); + } + + @Test + public void testQueue() throws Exception { + TimelineQueue queue = new TimelineQueue(); + queue.setId("test queue id"); + queue.addInfo("test info key 1", "test info value 1"); + queue.addInfo("test info key 2", "test info value 2"); + queue.setParent("test parent queue id"); + queue.addChild("test child queue id 1"); + queue.addChild("test child queue id 2"); + LOG.info(TimelineUtils.dumpTimelineRecordtoJSON(queue, true)); + } +}