Java Code Examples for org.apache.hadoop.yarn.api.records.timeline.TimelineDomain#setId()

The following examples show how to use org.apache.hadoop.yarn.api.records.timeline.TimelineDomain#setId() . These examples are extracted from open source projects. 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
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 2
Source Project: tez   File: ATSHistoryACLPolicyManager.java    License: 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 3
Source Project: hadoop   File: TestTimelineClient.java    License: 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;
}
 
Example 4
Source Project: hadoop   File: MemoryTimelineStore.java    License: 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 5
Source Project: hadoop   File: TestTimelineWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPutDomainYarnACLsEnabled() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineDomain domain = new TimelineDomain();
    domain.setId("test_domain_id_acl");
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1")
        .path("timeline").path("domain")
        .queryParam("user.name", "tester")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .put(ClientResponse.class, domain);
    assertEquals(Status.OK.getStatusCode(), response.getStatus());

    // Update the domain by another user
    response = r.path("ws").path("v1")
        .path("timeline").path("domain")
        .queryParam("user.name", "other")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .put(ClientResponse.class, domain);
    assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}
 
Example 6
Source Project: hadoop   File: Client.java    License: 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 7
Source Project: big-c   File: TestTimelineClient.java    License: 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;
}
 
Example 8
Source Project: big-c   File: MemoryTimelineStore.java    License: 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 9
Source Project: big-c   File: TestTimelineWebServices.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testPutDomainYarnACLsEnabled() throws Exception {
  AdminACLsManager oldAdminACLsManager =
      timelineACLsManager.setAdminACLsManager(adminACLsManager);
  try {
    TimelineDomain domain = new TimelineDomain();
    domain.setId("test_domain_id_acl");
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1")
        .path("timeline").path("domain")
        .queryParam("user.name", "tester")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .put(ClientResponse.class, domain);
    assertEquals(Status.OK.getStatusCode(), response.getStatus());

    // Update the domain by another user
    response = r.path("ws").path("v1")
        .path("timeline").path("domain")
        .queryParam("user.name", "other")
        .accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .put(ClientResponse.class, domain);
    assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
  } finally {
    timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
  }
}
 
Example 10
Source Project: big-c   File: Client.java    License: 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 11
Source Project: metron   File: Client.java    License: 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 12
Source Project: jstorm   File: JstormOnYarn.java    License: 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 13
Source Project: hadoop   File: TestTimelineWebServices.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testPutDomain() throws Exception {
  TimelineDomain domain = new TimelineDomain();
  domain.setId("test_domain_id");
  WebResource r = resource();
  // No owner, will be rejected
  ClientResponse response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(ClientResponse.Status.FORBIDDEN,
      response.getClientResponseStatus());

  response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertEquals(Status.OK.getStatusCode(), response.getStatus());
  
  // Verify the domain exists
  response = r.path("ws").path("v1").path("timeline")
      .path("domain").path("test_domain_id")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  domain = response.getEntity(TimelineDomain.class);
  Assert.assertNotNull(domain);
  Assert.assertEquals("test_domain_id", domain.getId());
  Assert.assertEquals("tester", domain.getOwner());
  Assert.assertEquals(null, domain.getDescription());

  // Update the domain
  domain.setDescription("test_description");
  response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertEquals(Status.OK.getStatusCode(), response.getStatus());

  // Verify the domain is updated
  response = r.path("ws").path("v1").path("timeline")
      .path("domain").path("test_domain_id")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  domain = response.getEntity(TimelineDomain.class);
  Assert.assertNotNull(domain);
  Assert.assertEquals("test_domain_id", domain.getId());
  Assert.assertEquals("test_description", domain.getDescription());
}
 
Example 14
Source Project: hadoop   File: TimelineStoreTestUtils.java    License: Apache License 2.0 4 votes vote down vote up
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);
  }
}
 
Example 15
Source Project: big-c   File: TestTimelineWebServices.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testPutDomain() throws Exception {
  TimelineDomain domain = new TimelineDomain();
  domain.setId("test_domain_id");
  WebResource r = resource();
  // No owner, will be rejected
  ClientResponse response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(ClientResponse.Status.FORBIDDEN,
      response.getClientResponseStatus());

  response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertEquals(Status.OK.getStatusCode(), response.getStatus());
  
  // Verify the domain exists
  response = r.path("ws").path("v1").path("timeline")
      .path("domain").path("test_domain_id")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  domain = response.getEntity(TimelineDomain.class);
  Assert.assertNotNull(domain);
  Assert.assertEquals("test_domain_id", domain.getId());
  Assert.assertEquals("tester", domain.getOwner());
  Assert.assertEquals(null, domain.getDescription());

  // Update the domain
  domain.setDescription("test_description");
  response = r.path("ws").path("v1")
      .path("timeline").path("domain")
      .queryParam("user.name", "tester")
      .accept(MediaType.APPLICATION_JSON)
      .type(MediaType.APPLICATION_JSON)
      .put(ClientResponse.class, domain);
  assertEquals(Status.OK.getStatusCode(), response.getStatus());

  // Verify the domain is updated
  response = r.path("ws").path("v1").path("timeline")
      .path("domain").path("test_domain_id")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  domain = response.getEntity(TimelineDomain.class);
  Assert.assertNotNull(domain);
  Assert.assertEquals("test_domain_id", domain.getId());
  Assert.assertEquals("test_description", domain.getDescription());
}
 
Example 16
Source Project: big-c   File: TimelineStoreTestUtils.java    License: Apache License 2.0 4 votes vote down vote up
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);
  }
}