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);
}
}
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;
}
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);
}
}
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);
}
}
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."));
}
}
Aggregations