Search in sources :

Example 21 with TimelineDomain

use of org.apache.hadoop.yarn.api.records.timeline.TimelineDomain in project hadoop by apache.

the class TimelineDataManager method doPutDomain.

private void doPutDomain(TimelineDomain domain, UserGroupInformation callerUGI) throws YarnException, IOException {
    TimelineDomain existingDomain = store.getDomain(domain.getId());
    if (existingDomain != null) {
        if (!timelineACLsManager.checkAccess(callerUGI, existingDomain)) {
            throw new YarnException(callerUGI.getShortUserName() + " is not allowed to override an existing domain " + existingDomain.getId());
        }
        // Set it again in case ACLs are not enabled: The domain can be
        // modified by every body, but the owner is not changed.
        domain.setOwner(existingDomain.getOwner());
    }
    store.put(domain);
    // We need to invalidate it.
    if (existingDomain != null) {
        timelineACLsManager.replaceIfExist(domain);
    }
}
Also used : TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 22 with TimelineDomain

use of org.apache.hadoop.yarn.api.records.timeline.TimelineDomain in project hadoop by apache.

the class TimelineWebServices method getDomain.

/**
   * Return a single domain of the given domain Id.
   */
@GET
@Path("/domain/{domainId}")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
public TimelineDomain getDomain(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("domainId") String domainId) {
    init(res);
    domainId = parseStr(domainId);
    if (domainId == null || domainId.length() == 0) {
        throw new BadRequestException("Domain ID is not specified.");
    }
    TimelineDomain domain = null;
    try {
        domain = timelineDataManager.getDomain(parseStr(domainId), getUser(req));
    } catch (Exception e) {
        LOG.error("Error getting domain", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
    if (domain == null) {
        throw new NotFoundException("Timeline domain [" + domainId + "] is not found");
    }
    return domain;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 23 with TimelineDomain

use of org.apache.hadoop.yarn.api.records.timeline.TimelineDomain in project hadoop by apache.

the class RollingLevelDBTimelineStore method getDomains.

@Override
public TimelineDomains getDomains(String owner) throws IOException {
    DBIterator iterator = null;
    try {
        byte[] prefix = KeyBuilder.newInstance().add(owner).getBytesForLookup();
        List<TimelineDomain> domains = new ArrayList<TimelineDomain>();
        for (iterator = ownerdb.iterator(), iterator.seek(prefix); iterator.hasNext(); ) {
            byte[] key = iterator.peekNext().getKey();
            if (!prefixMatches(prefix, prefix.length, key)) {
                break;
            }
            // Iterator to parse the rows of an individual domain
            KeyParser kp = new KeyParser(key, prefix.length);
            String domainId = kp.getNextString();
            byte[] prefixExt = KeyBuilder.newInstance().add(owner).add(domainId).getBytesForLookup();
            TimelineDomain domainToReturn = getTimelineDomain(iterator, domainId, prefixExt);
            if (domainToReturn != null) {
                domains.add(domainToReturn);
            }
        }
        // Sort the domains to return
        Collections.sort(domains, new Comparator<TimelineDomain>() {

            @Override
            public int compare(TimelineDomain domain1, TimelineDomain domain2) {
                int result = domain2.getCreatedTime().compareTo(domain1.getCreatedTime());
                if (result == 0) {
                    return domain2.getModifiedTime().compareTo(domain1.getModifiedTime());
                } else {
                    return result;
                }
            }
        });
        TimelineDomains domainsToReturn = new TimelineDomains();
        domainsToReturn.addDomains(domains);
        return domainsToReturn;
    } finally {
        IOUtils.cleanup(LOG, iterator);
    }
}
Also used : DBIterator(org.iq80.leveldb.DBIterator) TimelineDomains(org.apache.hadoop.yarn.api.records.timeline.TimelineDomains) ArrayList(java.util.ArrayList) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) KeyParser(org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser)

Example 24 with TimelineDomain

use of org.apache.hadoop.yarn.api.records.timeline.TimelineDomain in project hadoop by apache.

the class TimelineStoreTestUtils method loadTestDomainData.

protected void loadTestDomainData() throws IOException {
    domain1 = new TimelineDomain();
    domain1.setId("domain_id_1");
    domain1.setDescription("description_1");
    domain1.setOwner("owner_1");
    domain1.setReaders("reader_user_1 reader_group_1");
    domain1.setWriters("writer_user_1 writer_group_1");
    store.put(domain1);
    domain2 = new TimelineDomain();
    domain2.setId("domain_id_2");
    domain2.setDescription("description_2");
    domain2.setOwner("owner_2");
    domain2.setReaders("reader_user_2 reader_group_2");
    domain2.setWriters("writer_user_2 writer_group_2");
    store.put(domain2);
    // Wait a second before updating the domain information
    elapsedTime = 1000;
    try {
        Thread.sleep(elapsedTime);
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
    domain2.setDescription("description_3");
    domain2.setOwner("owner_3");
    domain2.setReaders("reader_user_3 reader_group_3");
    domain2.setWriters("writer_user_3 writer_group_3");
    store.put(domain2);
    domain3 = new TimelineDomain();
    domain3.setId("domain_id_4");
    domain3.setDescription("description_4");
    domain3.setOwner("owner_1");
    domain3.setReaders("reader_user_4 reader_group_4");
    domain3.setWriters("writer_user_4 writer_group_4");
    store.put(domain3);
    TimelineEntities entities = new TimelineEntities();
    if (store instanceof LeveldbTimelineStore) {
        LeveldbTimelineStore leveldb = (LeveldbTimelineStore) store;
        entities.setEntities(Collections.singletonList(createEntity("ACL_ENTITY_ID_11", "ACL_ENTITY_TYPE_1", 63l, null, null, null, null, "domain_id_4")));
        leveldb.put(entities);
        entities.setEntities(Collections.singletonList(createEntity("ACL_ENTITY_ID_22", "ACL_ENTITY_TYPE_1", 64l, null, null, null, null, "domain_id_2")));
        leveldb.put(entities);
    }
}
Also used : TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) IOException(java.io.IOException)

Example 25 with TimelineDomain

use of org.apache.hadoop.yarn.api.records.timeline.TimelineDomain in project hadoop by apache.

the class TestTimelineACLsManager method testCorruptedOwnerInfoForDomain.

@Test
public void testCorruptedOwnerInfoForDomain() throws Exception {
    Configuration conf = new YarnConfiguration();
    conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
    conf.set(YarnConfiguration.YARN_ADMIN_ACL, "owner");
    TimelineACLsManager timelineACLsManager = new TimelineACLsManager(conf);
    TimelineDomain domain = new TimelineDomain();
    try {
        timelineACLsManager.checkAccess(UserGroupInformation.createRemoteUser("owner"), domain);
        Assert.fail("Exception is expected");
    } catch (YarnException e) {
        Assert.assertTrue("It's not the exact expected exception", e.getMessage().contains("is corrupted."));
    }
}
Also used : YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) Test(org.junit.Test)

Aggregations

TimelineDomain (org.apache.hadoop.yarn.api.records.timeline.TimelineDomain)28 Test (org.junit.Test)9 IOException (java.io.IOException)7 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)7 Configuration (org.apache.hadoop.conf.Configuration)5 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)5 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 WebResource (com.sun.jersey.api.client.WebResource)4 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)4 Path (org.apache.hadoop.fs.Path)3 TimelineDomains (org.apache.hadoop.yarn.api.records.timeline.TimelineDomains)3 TimelineClient (org.apache.hadoop.yarn.client.api.TimelineClient)3 ArrayList (java.util.ArrayList)2 ParseException (org.apache.commons.cli.ParseException)2 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 AdminACLsManager (org.apache.hadoop.yarn.security.AdminACLsManager)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 File (java.io.File)1