org.apache.hadoop.yarn.api.records.timeline.TimelineDomain Java Examples

The following examples show how to use org.apache.hadoop.yarn.api.records.timeline.TimelineDomain. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemoryTimelineStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void put(TimelineDomain domain) throws IOException {
  TimelineDomain domainToReplace =
      domainsById.get(domain.getId());
  Long currentTimestamp = System.currentTimeMillis();
  TimelineDomain domainToStore = createTimelineDomain(
      domain.getId(), domain.getDescription(), domain.getOwner(),
      domain.getReaders(), domain.getWriters(),
      (domainToReplace == null ?
          currentTimestamp : domainToReplace.getCreatedTime()),
      currentTimestamp);
  domainsById.put(domainToStore.getId(), domainToStore);
  Set<TimelineDomain> domainsByOneOwner =
      domainsByOwner.get(domainToStore.getOwner());
  if (domainsByOneOwner == null) {
    domainsByOneOwner = new HashSet<TimelineDomain>();
    domainsByOwner.put(domainToStore.getOwner(), domainsByOneOwner);
  }
  if (domainToReplace != null) {
    domainsByOneOwner.remove(domainToReplace);
  }
  domainsByOneOwner.add(domainToStore);
}
 
Example #2
Source File: TestTimelineAuthenticationFilter.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutDomains() throws Exception {
  KerberosTestUtils.doAs(HTTP_USER + "/localhost", new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      TimelineClient client = createTimelineClientForUGI();
      TimelineDomain domainToStore = new TimelineDomain();
      domainToStore.setId(TestTimelineAuthenticationFilter.class.getName());
      domainToStore.setReaders("*");
      domainToStore.setWriters("*");
      client.putDomain(domainToStore);
      TimelineDomain domainToRead =
          testTimelineServer.getTimelineStore().getDomain(
              TestTimelineAuthenticationFilter.class.getName());
      Assert.assertNotNull(domainToRead);
      return null;
    }
  });
}
 
Example #3
Source File: TestTimelineACLsManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testYarnACLsEnabledForDomain() throws Exception {
  Configuration conf = new YarnConfiguration();
  conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
  conf.set(YarnConfiguration.YARN_ADMIN_ACL, "admin");
  TimelineACLsManager timelineACLsManager =
      new TimelineACLsManager(conf);
  TimelineDomain domain = new TimelineDomain();
  domain.setOwner("owner");
  Assert.assertTrue(
      "Owner should be allowed to access",
      timelineACLsManager.checkAccess(
          UserGroupInformation.createRemoteUser("owner"), domain));
  Assert.assertFalse(
      "Other shouldn't be allowed to access",
      timelineACLsManager.checkAccess(
          UserGroupInformation.createRemoteUser("other"), domain));
  Assert.assertTrue(
      "Admin should be allowed to access",
      timelineACLsManager.checkAccess(
          UserGroupInformation.createRemoteUser("admin"), domain));
}
 
Example #4
Source File: TestTimelineACLsManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
@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."));
  }
}
 
Example #5
Source File: TestTimelineACLsManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@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."));
  }
}
 
Example #6
Source File: TestTimelineACLsManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testYarnACLsEnabledForDomain() throws Exception {
  Configuration conf = new YarnConfiguration();
  conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
  conf.set(YarnConfiguration.YARN_ADMIN_ACL, "admin");
  TimelineACLsManager timelineACLsManager =
      new TimelineACLsManager(conf);
  TimelineDomain domain = new TimelineDomain();
  domain.setOwner("owner");
  Assert.assertTrue(
      "Owner should be allowed to access",
      timelineACLsManager.checkAccess(
          UserGroupInformation.createRemoteUser("owner"), domain));
  Assert.assertFalse(
      "Other shouldn't be allowed to access",
      timelineACLsManager.checkAccess(
          UserGroupInformation.createRemoteUser("other"), domain));
  Assert.assertTrue(
      "Admin should be allowed to access",
      timelineACLsManager.checkAccess(
          UserGroupInformation.createRemoteUser("admin"), domain));
}
 
Example #7
Source File: TestTimelineAuthenticationFilter.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutDomains() throws Exception {
  KerberosTestUtils.doAs(HTTP_USER + "/localhost", new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      TimelineClient client = createTimelineClientForUGI();
      TimelineDomain domainToStore = new TimelineDomain();
      domainToStore.setId(TestTimelineAuthenticationFilter.class.getName());
      domainToStore.setReaders("*");
      domainToStore.setWriters("*");
      client.putDomain(domainToStore);
      TimelineDomain domainToRead =
          testTimelineServer.getTimelineStore().getDomain(
              TestTimelineAuthenticationFilter.class.getName());
      Assert.assertNotNull(domainToRead);
      return null;
    }
  });
}
 
Example #8
Source File: TimelineDataManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Add or update an domain. If the domain already exists, only the owner
 * and the admin can update it.
 */
public void putDomain(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);
  // If the domain exists already, it is likely to be in the cache.
  // We need to invalidate it.
  if (existingDomain != null) {
    timelineACLsManager.replaceIfExist(domain);
  }
}
 
Example #9
Source File: TimelineDataManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Add or update an domain. If the domain already exists, only the owner
 * and the admin can update it.
 */
public void putDomain(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);
  // If the domain exists already, it is likely to be in the cache.
  // We need to invalidate it.
  if (existingDomain != null) {
    timelineACLsManager.replaceIfExist(domain);
  }
}
 
Example #10
Source File: TimelineStoreTestUtils.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public void testGetDomain() throws IOException {
  TimelineDomain actualDomain1 =
      store.getDomain(domain1.getId());
  verifyDomainInfo(domain1, actualDomain1);
  assertTrue(actualDomain1.getCreatedTime() > 0);
  assertTrue(actualDomain1.getModifiedTime() > 0);
  assertEquals(
      actualDomain1.getCreatedTime(), actualDomain1.getModifiedTime());

  TimelineDomain actualDomain2 =
      store.getDomain(domain2.getId());
  verifyDomainInfo(domain2, actualDomain2);
  assertEquals("domain_id_2", actualDomain2.getId());
  assertTrue(actualDomain2.getCreatedTime() > 0);
  assertTrue(actualDomain2.getModifiedTime() > 0);
  assertTrue(
      actualDomain2.getCreatedTime() < actualDomain2.getModifiedTime());
}
 
Example #11
Source File: MemoryTimelineStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void put(TimelineDomain domain) throws IOException {
  TimelineDomain domainToReplace =
      domainsById.get(domain.getId());
  Long currentTimestamp = System.currentTimeMillis();
  TimelineDomain domainToStore = createTimelineDomain(
      domain.getId(), domain.getDescription(), domain.getOwner(),
      domain.getReaders(), domain.getWriters(),
      (domainToReplace == null ?
          currentTimestamp : domainToReplace.getCreatedTime()),
      currentTimestamp);
  domainsById.put(domainToStore.getId(), domainToStore);
  Set<TimelineDomain> domainsByOneOwner =
      domainsByOwner.get(domainToStore.getOwner());
  if (domainsByOneOwner == null) {
    domainsByOneOwner = new HashSet<TimelineDomain>();
    domainsByOwner.put(domainToStore.getOwner(), domainsByOneOwner);
  }
  if (domainToReplace != null) {
    domainsByOneOwner.remove(domainToReplace);
  }
  domainsByOneOwner.add(domainToStore);
}
 
Example #12
Source File: MemoryTimelineStore.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public TimelineDomain getDomain(String domainId)
    throws IOException {
  TimelineDomain domain = domainsById.get(domainId);
  if (domain == null) {
    return null;
  } else {
    return createTimelineDomain(
        domain.getId(),
        domain.getDescription(),
        domain.getOwner(),
        domain.getReaders(),
        domain.getWriters(),
        domain.getCreatedTime(),
        domain.getModifiedTime());
  }
}
 
Example #13
Source File: TimelineStoreTestUtils.java    From big-c with Apache License 2.0 6 votes vote down vote up
public void testGetDomain() throws IOException {
  TimelineDomain actualDomain1 =
      store.getDomain(domain1.getId());
  verifyDomainInfo(domain1, actualDomain1);
  assertTrue(actualDomain1.getCreatedTime() > 0);
  assertTrue(actualDomain1.getModifiedTime() > 0);
  assertEquals(
      actualDomain1.getCreatedTime(), actualDomain1.getModifiedTime());

  TimelineDomain actualDomain2 =
      store.getDomain(domain2.getId());
  verifyDomainInfo(domain2, actualDomain2);
  assertEquals("domain_id_2", actualDomain2.getId());
  assertTrue(actualDomain2.getCreatedTime() > 0);
  assertTrue(actualDomain2.getModifiedTime() > 0);
  assertTrue(
      actualDomain2.getCreatedTime() < actualDomain2.getModifiedTime());
}
 
Example #14
Source File: TimelineACLsManager.java    From hadoop with Apache License 2.0 6 votes vote down vote up
public boolean checkAccess(UserGroupInformation callerUGI,
    TimelineDomain domain) throws YarnException, IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Verifying the access of "
        + (callerUGI == null ? null : callerUGI.getShortUserName())
        + " on the timeline domain " + domain);
  }

  if (!adminAclsManager.areACLsEnabled()) {
    return true;
  }

  String owner = domain.getOwner();
  if (owner == null || owner.length() == 0) {
    throw new YarnException("Owner information of the timeline domain "
        + domain.getId() + " is corrupted.");
  }
  if (callerUGI != null
      && (adminAclsManager.isAdmin(callerUGI) ||
          callerUGI.getShortUserName().equals(owner))) {
    return true;
  }
  return false;
}
 
Example #15
Source File: MemoryTimelineStore.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public TimelineDomain getDomain(String domainId)
    throws IOException {
  TimelineDomain domain = domainsById.get(domainId);
  if (domain == null) {
    return null;
  } else {
    return createTimelineDomain(
        domain.getId(),
        domain.getDescription(),
        domain.getOwner(),
        domain.getReaders(),
        domain.getWriters(),
        domain.getCreatedTime(),
        domain.getModifiedTime());
  }
}
 
Example #16
Source File: ATSV15HistoryACLPolicyManager.java    From tez with Apache License 2.0 6 votes vote down vote up
private void createTimelineDomain(ApplicationId applicationId,
    String domainId, Configuration tezConf, DAGAccessControls dagAccessControls)
    throws IOException, HistoryACLPolicyException {
  TimelineDomain timelineDomain = new TimelineDomain();
  timelineDomain.setId(domainId);

  ACLConfigurationParser parser = new ACLConfigurationParser(tezConf, false);
  timelineDomain.setReaders(getMergedViewACLs(parser, dagAccessControls));
  timelineDomain.setWriters(user);

  // Use dummy app attempt id
  ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(applicationId, 1);
  try {
    if (timelineClient != null) {
      timelineClient.putDomain(appAttemptId, timelineDomain);
    }
  } catch (Exception e) {
    LOG.warn("Could not post timeline domain", e);
    throw new
      HistoryACLPolicyException("Fail to create ACL-related domain in Timeline", e);
  }
}
 
Example #17
Source File: ATSHistoryACLPolicyManager.java    From tez with Apache License 2.0 6 votes vote down vote up
private void createTimelineDomain(String domainId, Configuration tezConf,
    DAGAccessControls dagAccessControls) throws IOException, HistoryACLPolicyException {
  TimelineDomain timelineDomain = new TimelineDomain();
  timelineDomain.setId(domainId);

  ACLConfigurationParser parser = new ACLConfigurationParser(tezConf, false);
  timelineDomain.setReaders(getMergedViewACLs(parser, dagAccessControls));
  timelineDomain.setWriters(user);

  try {
    if (timelineClient != null) {
      timelineClient.putDomain(timelineDomain);
    }
  } catch (Exception e) {
    LOG.warn("Could not post timeline domain", e);
    throw new
      HistoryACLPolicyException("Fail to create ACL-related domain in Timeline", e);
  }
}
 
Example #18
Source File: TimelineACLsManager.java    From big-c with Apache License 2.0 6 votes vote down vote up
public boolean checkAccess(UserGroupInformation callerUGI,
    TimelineDomain domain) throws YarnException, IOException {
  if (LOG.isDebugEnabled()) {
    LOG.debug("Verifying the access of "
        + (callerUGI == null ? null : callerUGI.getShortUserName())
        + " on the timeline domain " + domain);
  }

  if (!adminAclsManager.areACLsEnabled()) {
    return true;
  }

  String owner = domain.getOwner();
  if (owner == null || owner.length() == 0) {
    throw new YarnException("Owner information of the timeline domain "
        + domain.getId() + " is corrupted.");
  }
  if (callerUGI != null
      && (adminAclsManager.isAdmin(callerUGI) ||
          callerUGI.getShortUserName().equals(owner))) {
    return true;
  }
  return false;
}
 
Example #19
Source File: JstormOnYarn.java    From jstorm with Apache License 2.0 5 votes vote down vote up
private void prepareTimelineDomain() {
    TimelineClient timelineClient = null;
    if (jstormClientContext.conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
            YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
        timelineClient = TimelineClient.createTimelineClient();
        timelineClient.init(jstormClientContext.conf);
        timelineClient.start();
    } else {
        LOG.warn("Cannot put the domain " + jstormClientContext.domainId +
                " because the timeline service is not enabled");
        return;
    }
    try {
        TimelineDomain domain = new TimelineDomain();
        domain.setId(jstormClientContext.domainId);
        domain.setReaders(
                jstormClientContext.viewACLs != null && jstormClientContext.viewACLs.length() > 0 ? jstormClientContext.viewACLs : JOYConstants.BLANK);
        domain.setWriters(
                jstormClientContext.modifyACLs != null && jstormClientContext.modifyACLs.length() > 0 ? jstormClientContext.modifyACLs : JOYConstants.BLANK);
        timelineClient.putDomain(domain);
        LOG.info("Put the timeline domain: " +
                TimelineUtils.dumpTimelineRecordtoJSON(domain));
    } catch (Exception e) {
        LOG.error("Error when putting the timeline domain", e);
    } finally {
        timelineClient.stop();
    }
}
 
Example #20
Source File: Client.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void prepareTimelineDomain() {
  TimelineClient timelineClient = null;
  if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
      YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
    timelineClient = TimelineClient.createTimelineClient();
    timelineClient.init(conf);
    timelineClient.start();
  } else {
    LOG.warn("Cannot put the domain " + domainId +
        " because the timeline service is not enabled");
    return;
  }
  try {
    //TODO: we need to check and combine the existing timeline domain ACLs,
    //but let's do it once we have client java library to query domains.
    TimelineDomain domain = new TimelineDomain();
    domain.setId(domainId);
    domain.setReaders(
        viewACLs != null && viewACLs.length() > 0 ? viewACLs : " ");
    domain.setWriters(
        modifyACLs != null && modifyACLs.length() > 0 ? modifyACLs : " ");
    timelineClient.putDomain(domain);
    LOG.info("Put the timeline domain: " +
        TimelineUtils.dumpTimelineRecordtoJSON(domain));
  } catch (Exception e) {
    LOG.error("Error when putting the timeline domain", e);
  } finally {
    timelineClient.stop();
  }
}
 
Example #21
Source File: TestTimelineWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static void verifyDomain(TimelineDomain domain, String domainId) {
  Assert.assertNotNull(domain);
  Assert.assertEquals(domainId, domain.getId());
  // The specific values have been verified in TestMemoryTimelineStore
  Assert.assertNotNull(domain.getDescription());
  Assert.assertNotNull(domain.getOwner());
  Assert.assertNotNull(domain.getReaders());
  Assert.assertNotNull(domain.getWriters());
  Assert.assertNotNull(domain.getCreatedTime());
  Assert.assertNotNull(domain.getModifiedTime());
}
 
Example #22
Source File: TimelineStoreTestUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static void verifyDomainInfo(
    TimelineDomain expected, TimelineDomain actual) {
  assertEquals(expected.getId(), actual.getId());
  assertEquals(expected.getDescription(), actual.getDescription());
  assertEquals(expected.getOwner(), actual.getOwner());
  assertEquals(expected.getReaders(), actual.getReaders());
  assertEquals(expected.getWriters(), actual.getWriters());
}
 
Example #23
Source File: TestATSHistoryWithACLs.java    From tez with Apache License 2.0 5 votes vote down vote up
private TimelineDomain getDomain(String domainId) {
  assertNotNull(timelineAddress);
  String url = "http://" + timelineAddress + "/ws/v1/timeline/domain/" + domainId;
  LOG.info("Getting timeline domain: " + url);
  TimelineDomain domain = getTimelineData(url, TimelineDomain.class);
  assertNotNull(domain);
  assertNotNull(domain.getOwner());
  assertNotNull(domain.getReaders());
  assertNotNull(domain.getWriters());
  LOG.info("TimelineDomain for id " + domainId
      + ", owner=" + domain.getOwner()
      + ", readers=" + domain.getReaders()
      + ", writers=" + domain.getWriters());
  return domain;
}
 
Example #24
Source File: TimelineACLsManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
private AccessControlListExt putDomainIntoCache(
    TimelineDomain domain) {
  Map<ApplicationAccessType, AccessControlList> acls
  = new HashMap<ApplicationAccessType, AccessControlList>(2);
  acls.put(ApplicationAccessType.VIEW_APP,
      new AccessControlList(StringHelper.cjoin(domain.getReaders())));
  acls.put(ApplicationAccessType.MODIFY_APP,
      new AccessControlList(StringHelper.cjoin(domain.getWriters())));
  AccessControlListExt aclExt =
      new AccessControlListExt(domain.getOwner(), acls);
  aclExts.put(domain.getId(), aclExt);
  return aclExt;
}
 
Example #25
Source File: Client.java    From metron with Apache License 2.0 5 votes vote down vote up
private void prepareTimelineDomain() {
  TimelineClient timelineClient = null;
  if (conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED,
          YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ENABLED)) {
    timelineClient = TimelineClient.createTimelineClient();
    timelineClient.init(conf);
    timelineClient.start();
  } else {
    LOG.warn("Cannot put the domain " + domainId +
            " because the timeline service is not enabled");
    return;
  }
  try {
    TimelineDomain domain = new TimelineDomain();
    domain.setId(domainId);
    domain.setReaders(
            viewACLs != null && viewACLs.length() > 0 ? viewACLs : " ");
    domain.setWriters(
            modifyACLs != null && modifyACLs.length() > 0 ? modifyACLs : " ");
    timelineClient.putDomain(domain);
    LOG.info("Put the timeline domain: " +
            TimelineUtils.dumpTimelineRecordtoJSON(domain));
  } catch (Exception e) {
    LOG.error("Error when putting the timeline domain", e);
  } finally {
    timelineClient.stop();
  }
}
 
Example #26
Source File: TimelineDataManager.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Get a single domain of the particular ID. If callerUGI is not the owner
 * or the admin of the domain, null will be returned.
 */
public TimelineDomain getDomain(String domainId,
    UserGroupInformation callerUGI) throws YarnException, IOException {
  TimelineDomain domain = store.getDomain(domainId);
  if (domain != null) {
    if (timelineACLsManager.checkAccess(callerUGI, domain)) {
      return domain;
    }
  }
  return null;
}
 
Example #27
Source File: MemoryTimelineStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static TimelineDomain createTimelineDomain(
    String id, String description, String owner,
    String readers, String writers,
    Long createdTime, Long modifiedTime) {
  TimelineDomain domainToStore = new TimelineDomain();
  domainToStore.setId(id);
  domainToStore.setDescription(description);
  domainToStore.setOwner(owner);
  domainToStore.setReaders(readers);
  domainToStore.setWriters(writers);
  domainToStore.setCreatedTime(createdTime);
  domainToStore.setModifiedTime(modifiedTime);
  return domainToStore;
}
 
Example #28
Source File: MemoryTimelineStore.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public TimelineDomains getDomains(String owner)
    throws IOException {
  List<TimelineDomain> domains = new ArrayList<TimelineDomain>();
  Set<TimelineDomain> domainsOfOneOwner = domainsByOwner.get(owner);
  if (domainsOfOneOwner == null) {
    return new TimelineDomains();
  }
  for (TimelineDomain domain : domainsByOwner.get(owner)) {
    TimelineDomain domainToReturn = createTimelineDomain(
        domain.getId(),
        domain.getDescription(),
        domain.getOwner(),
        domain.getReaders(),
        domain.getWriters(),
        domain.getCreatedTime(),
        domain.getModifiedTime());
    domains.add(domainToReturn);
  }
  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;
}
 
Example #29
Source File: TimelineWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
/**
 * Return a single domain of the given domain Id.
 */
@GET
@Path("/domain/{domainId}")
@Produces({ MediaType.APPLICATION_JSON /* , MediaType.APPLICATION_XML */})
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;
}
 
Example #30
Source File: TestTimelineClient.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static TimelineDomain generateDomain() {
  TimelineDomain domain = new TimelineDomain();
  domain.setId("namesapce id");
  domain.setDescription("domain description");
  domain.setOwner("domain owner");
  domain.setReaders("domain_reader");
  domain.setWriters("domain_writer");
  domain.setCreatedTime(0L);
  domain.setModifiedTime(1L);
  return domain;
}