From 51b942299238121d9f32e05d39e5e6717c465a08 Mon Sep 17 00:00:00 2001 From: Rohith Sharma K S Date: Wed, 21 Feb 2018 17:36:05 +0530 Subject: [PATCH] YARN-7932 --- .../records/timelineservice/TimelineDomain.java | 194 +++++++++++++++++++++ .../records/timelineservice/TimelineEntity.java | 22 +++ .../hadoop/yarn/client/api/TimelineV2Client.java | 15 ++ .../yarn/client/api/impl/TimelineV2ClientImpl.java | 7 + .../client/api/impl/TestTimelineClientV2Impl.java | 64 ++++++- 5 files changed, 301 insertions(+), 1 deletion(-) create mode 100644 hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineDomain.java diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineDomain.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineDomain.java new file mode 100644 index 00000000000..e3524b94b3f --- /dev/null +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineDomain.java @@ -0,0 +1,194 @@ +/** + * 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.Public; +import org.apache.hadoop.classification.InterfaceStability.Evolving; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + *

+ * This class contains the information about a timeline service domain, which is + * used to a user to host a number of timeline entities, isolating them from + * others'. The user can also define the reader and writer users/groups for + * the domain, which is used to control the access to its entities. + *

+ * + *

+ * The reader and writer users/groups pattern that the user can supply is the + * same as what AccessControlList takes. + *

+ * + */ +@XmlRootElement(name = "domain") +@XmlAccessorType(XmlAccessType.NONE) +@Public +@Evolving +public class TimelineDomain { + + private String id; + private String description; + private String owner; + private String readers; + private String writers; + private Long createdTime; + private Long modifiedTime; + + public TimelineDomain() { + } + + /** + * Get the domain ID + * + * @return the domain ID + */ + @XmlElement(name = "id") + public String getId() { + return id; + } + + /** + * Set the domain ID + * + * @param id the domain ID + */ + public void setId(String id) { + this.id = id; + } + + /** + * Get the domain description + * + * @return the domain description + */ + @XmlElement(name = "description") + public String getDescription() { + return description; + } + + /** + * Set the domain description + * + * @param description the domain description + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * Get the domain owner + * + * @return the domain owner + */ + @XmlElement(name = "owner") + public String getOwner() { + return owner; + } + + /** + * Set the domain owner. The user doesn't need to set it, which will + * automatically set to the user who puts the domain. + * + * @param owner the domain owner + */ + public void setOwner(String owner) { + this.owner = owner; + } + + /** + * Get the reader (and/or reader group) list string + * + * @return the reader (and/or reader group) list string + */ + @XmlElement(name = "readers") + public String getReaders() { + return readers; + } + + /** + * Set the reader (and/or reader group) list string + * + * @param readers the reader (and/or reader group) list string + */ + public void setReaders(String readers) { + this.readers = readers; + } + + /** + * Get the writer (and/or writer group) list string + * + * @return the writer (and/or writer group) list string + */ + @XmlElement(name = "writers") + public String getWriters() { + return writers; + } + + /** + * Set the writer (and/or writer group) list string + * + * @param writers the writer (and/or writer group) list string + */ + public void setWriters(String writers) { + this.writers = writers; + } + + /** + * Get the created time of the domain + * + * @return the created time of the domain + */ + @XmlElement(name = "createdtime") + public Long getCreatedTime() { + return createdTime; + } + + /** + * Set the created time of the domain + * + * @param createdTime the created time of the domain + */ + public void setCreatedTime(Long createdTime) { + this.createdTime = createdTime; + } + + /** + * Get the modified time of the domain + * + * @return the modified time of the domain + */ + @XmlElement(name = "modifiedtime") + public Long getModifiedTime() { + return modifiedTime; + } + + /** + * Set the modified time of the domain + * + * @param modifiedTime the modified time of the domain + */ + public void setModifiedTime(Long modifiedTime) { + this.modifiedTime = modifiedTime; + } + +} diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java index 0af5ea47694..5ec242d1180 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-api/src/main/java/org/apache/hadoop/yarn/api/records/timelineservice/TimelineEntity.java @@ -148,6 +148,7 @@ public boolean equals(Object obj) { private HashMap> relatesToEntities = new HashMap<>(); private Long createdTime; private long idPrefix; + private String domainId; public TimelineEntity() { identifier = new Identifier(); @@ -608,4 +609,25 @@ public void setIdPrefix(long entityIdPrefix) { real.setIdPrefix(entityIdPrefix); } } + + /** + * Get the ID of the domain that the entity is to be put + * + * @return the domain ID + */ + @XmlElement(name = "domain") + public String getDomainId() { + return domainId; + } + + /** + * Set the ID of the domain that the entity is to be put + * + * @param domainId + * the name space ID + */ + @JsonSetter("domain") + public void setDomainId(String domainId) { + this.domainId = domainId; + } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/TimelineV2Client.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/TimelineV2Client.java index 423c059319c..06cbdebbec2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/TimelineV2Client.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/TimelineV2Client.java @@ -24,6 +24,7 @@ import org.apache.hadoop.service.CompositeService; import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.CollectorInfo; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineDomain; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; import org.apache.hadoop.yarn.client.api.impl.TimelineV2ClientImpl; import org.apache.hadoop.yarn.exceptions.YarnException; @@ -93,4 +94,18 @@ public abstract void putEntitiesAsync(TimelineEntity... entities) * address and timeline delegation token. */ public abstract void setTimelineCollectorInfo(CollectorInfo collectorInfo); + + /** + *

+ * Send the information of a domain to the timeline server. It is a + * blocking API. The method will not return until it gets the response from + * the timeline server. + *

+ * + * @param domain an {@link TimelineDomain} object + * @throws IOException + * @throws YarnException + */ + @Public public abstract void putDomain(TimelineDomain domain) + throws IOException, YarnException; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineV2ClientImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineV2ClientImpl.java index 02c9519d9be..2cd546ab096 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineV2ClientImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/client/api/impl/TimelineV2ClientImpl.java @@ -48,6 +48,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.CollectorInfo; import org.apache.hadoop.yarn.api.records.Token; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineDomain; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntities; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; import org.apache.hadoop.yarn.client.api.TimelineV2Client; @@ -173,6 +174,12 @@ public void setTimelineCollectorInfo(CollectorInfo collectorInfo) { } } + @Override + public void putDomain(TimelineDomain domain) + throws IOException, YarnException { + putObjects("domain",new MultivaluedMapImpl() , domain); + } + private void setTimelineDelegationToken(Token delegationToken, String collectorAddr) { // Checks below are to ensure that an invalid token is not updated in UGI. diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientV2Impl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientV2Impl.java index 95595a9f4c4..e42da86c003 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientV2Impl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/client/api/impl/TestTimelineClientV2Impl.java @@ -37,6 +37,7 @@ import org.apache.hadoop.yarn.api.records.ApplicationId; import org.apache.hadoop.yarn.api.records.CollectorInfo; import org.apache.hadoop.yarn.api.records.Token; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineDomain; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntities; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; import org.apache.hadoop.yarn.conf.YarnConfiguration; @@ -114,6 +115,7 @@ protected void putObjects(URI base, String path, private boolean sleepBeforeReturn; private List publishedEntities; + private TimelineDomain timelineDomain; public TimelineEntities getPublishedEntities(int putIndex) { Assert.assertTrue("Not So many entities Published", @@ -129,6 +131,10 @@ public int getNumOfTimelineEntitiesPublished() { return publishedEntities.size(); } + public TimelineDomain getPublishedTimelineDomain() { + return timelineDomain; + } + public TestV2TimelineClient(ApplicationId id) { super(id); publishedEntities = new ArrayList(); @@ -140,7 +146,11 @@ protected void putObjects(String path, if (isThrowYarnException()) { throw new YarnException("ActualException"); } - publishedEntities.add((TimelineEntities) obj); + if (path.equals("domain")) { + timelineDomain = (TimelineDomain) obj; + } else { + publishedEntities.add((TimelineEntities) obj); + } if (sleepBeforeReturn) { try { Thread.sleep(TIME_TO_SLEEP); @@ -230,6 +240,38 @@ public void testASyncCallMerge() throws Exception { } @Test + public void testPutDomain() throws Exception { + try { + TimelineDomain domainSent = + generateDomain("id", "desc", "owner", "reader1,reader2", "writer", 0L, + 1L); + client.putDomain(domainSent); + client.putEntities(generateEntity("1", domainSent.getId())); + + TimelineDomain domainPublished = client.getPublishedTimelineDomain(); + Assert.assertEquals(domainSent.getId(), domainPublished.getId()); + Assert.assertEquals(domainSent.getDescription(), + domainPublished.getDescription()); + Assert.assertEquals(domainSent.getOwner(), domainPublished.getOwner()); + Assert + .assertEquals(domainSent.getReaders(), domainPublished.getReaders()); + Assert + .assertEquals(domainSent.getWriters(), domainPublished.getWriters()); + Assert.assertEquals(domainSent.getCreatedTime(), + domainPublished.getCreatedTime()); + Assert.assertEquals(domainSent.getModifiedTime(), + domainPublished.getModifiedTime()); + + List entities = + client.getPublishedEntities(0).getEntities(); + Assert.assertEquals(1, entities.size()); + Assert.assertEquals(domainSent.getId(), entities.get(0).getDomainId()); + } catch (YarnException e) { + Assert.fail("Exception is not expected"); + } + } + + @Test public void testSyncCall() throws Exception { try { // sync entity should not be be merged with Async @@ -416,13 +458,33 @@ private void printReceivedEntities() { } private static TimelineEntity generateEntity(String id) { + return generateEntity(id, null); + } + + private static TimelineEntity generateEntity(String id, String domain) { TimelineEntity entity = new TimelineEntity(); entity.setId(id); entity.setType("testEntity"); entity.setCreatedTime(System.currentTimeMillis()); + if (domain != null) { + entity.setDomainId(domain); + } return entity; } + private static TimelineDomain generateDomain(String id, String desc, + String owner, String reader, String writer, Long cTime, Long mTime) { + TimelineDomain domain = new TimelineDomain(); + domain.setId(id); + domain.setDescription(desc); + domain.setOwner(owner); + domain.setReaders(reader); + domain.setWriters(writer); + domain.setCreatedTime(cTime); + domain.setModifiedTime(mTime); + return domain; + } + @After public void tearDown() { if (client != null) { -- 2.13.6 (Apple Git-96)