Search in sources :

Example 1 with TimelineDomains

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

the class TimelineDataManager method doGetDomains.

private TimelineDomains doGetDomains(String owner, UserGroupInformation callerUGI) throws YarnException, IOException {
    TimelineDomains domains = store.getDomains(owner);
    boolean hasAccess = true;
    if (domains.getDomains().size() > 0) {
        // The owner for each domain is the same, just need to check one
        hasAccess = timelineACLsManager.checkAccess(callerUGI, domains.getDomains().get(0));
    }
    if (hasAccess) {
        return domains;
    } else {
        return new TimelineDomains();
    }
}
Also used : TimelineDomains(org.apache.hadoop.yarn.api.records.timeline.TimelineDomains)

Example 2 with TimelineDomains

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

the class TimelineDataManager method getDomains.

/**
   * Get all the domains that belong to the given owner. If callerUGI is not
   * the owner or the admin of the domain, empty list is going to be returned.
   */
public TimelineDomains getDomains(String owner, UserGroupInformation callerUGI) throws YarnException, IOException {
    long startTime = Time.monotonicNow();
    metrics.incrGetDomainsOps();
    try {
        TimelineDomains domains = doGetDomains(owner, callerUGI);
        metrics.incrGetDomainsTotal(domains.getDomains().size());
        return domains;
    } finally {
        metrics.addGetDomainsTime(Time.monotonicNow() - startTime);
    }
}
Also used : TimelineDomains(org.apache.hadoop.yarn.api.records.timeline.TimelineDomains)

Example 3 with TimelineDomains

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

the class KeyValueBasedTimelineStore method getDomains.

@Override
public TimelineDomains getDomains(String owner) throws IOException {
    if (getServiceStopped()) {
        LOG.info("Service stopped, return null for the storage");
        return null;
    }
    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 = KeyValueBasedTimelineStoreUtils.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;
}
Also used : TimelineDomains(org.apache.hadoop.yarn.api.records.timeline.TimelineDomains) ArrayList(java.util.ArrayList) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain)

Example 4 with TimelineDomains

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

the class TimelineClientImpl method putTimelineDataInJSONFile.

/**
   * Put timeline data in a JSON file via command line.
   * 
   * @param path
   *          path to the timeline data JSON file
   * @param type
   *          the type of the timeline data in the JSON file
   */
private static void putTimelineDataInJSONFile(String path, String type) {
    File jsonFile = new File(path);
    if (!jsonFile.exists()) {
        LOG.error("File [" + jsonFile.getAbsolutePath() + "] doesn't exist");
        return;
    }
    YarnJacksonJaxbJsonProvider.configObjectMapper(MAPPER);
    TimelineEntities entities = null;
    TimelineDomains domains = null;
    try {
        if (type.equals(ENTITY_DATA_TYPE)) {
            entities = MAPPER.readValue(jsonFile, TimelineEntities.class);
        } else if (type.equals(DOMAIN_DATA_TYPE)) {
            domains = MAPPER.readValue(jsonFile, TimelineDomains.class);
        }
    } catch (Exception e) {
        LOG.error("Error when reading  " + e.getMessage());
        e.printStackTrace(System.err);
        return;
    }
    Configuration conf = new YarnConfiguration();
    TimelineClient client = TimelineClient.createTimelineClient();
    client.init(conf);
    client.start();
    try {
        if (UserGroupInformation.isSecurityEnabled() && conf.getBoolean(YarnConfiguration.TIMELINE_SERVICE_ENABLED, false)) {
            Token<TimelineDelegationTokenIdentifier> token = client.getDelegationToken(UserGroupInformation.getCurrentUser().getUserName());
            UserGroupInformation.getCurrentUser().addToken(token);
        }
        if (type.equals(ENTITY_DATA_TYPE)) {
            TimelinePutResponse response = client.putEntities(entities.getEntities().toArray(new TimelineEntity[entities.getEntities().size()]));
            if (response.getErrors().size() == 0) {
                LOG.info("Timeline entities are successfully put");
            } else {
                for (TimelinePutResponse.TimelinePutError error : response.getErrors()) {
                    LOG.error("TimelineEntity [" + error.getEntityType() + ":" + error.getEntityId() + "] is not successfully put. Error code: " + error.getErrorCode());
                }
            }
        } else if (type.equals(DOMAIN_DATA_TYPE) && domains != null) {
            boolean hasError = false;
            for (TimelineDomain domain : domains.getDomains()) {
                try {
                    client.putDomain(domain);
                } catch (Exception e) {
                    LOG.error("Error when putting domain " + domain.getId(), e);
                    hasError = true;
                }
            }
            if (!hasError) {
                LOG.info("Timeline domains are successfully put");
            }
        }
    } catch (RuntimeException e) {
        LOG.error("Error when putting the timeline data", e);
    } catch (Exception e) {
        LOG.error("Error when putting the timeline data", e);
    } finally {
        client.stop();
    }
}
Also used : TimelineDomains(org.apache.hadoop.yarn.api.records.timeline.TimelineDomains) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) Configuration(org.apache.hadoop.conf.Configuration) TimelineDelegationTokenIdentifier(org.apache.hadoop.yarn.security.client.TimelineDelegationTokenIdentifier) TimelinePutResponse(org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) IOException(java.io.IOException) TimelineClient(org.apache.hadoop.yarn.client.api.TimelineClient) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) File(java.io.File)

Example 5 with TimelineDomains

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

the class TestTimelineWebServices method testGetDomainsYarnACLsEnabled.

@Test
public void testGetDomainsYarnACLsEnabled() throws Exception {
    AdminACLsManager oldAdminACLsManager = timelineACLsManager.setAdminACLsManager(adminACLsManager);
    try {
        WebResource r = resource();
        ClientResponse response = r.path("ws").path("v1").path("timeline").path("domain").queryParam("user.name", "owner_1").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
        TimelineDomains domains = response.getEntity(TimelineDomains.class);
        Assert.assertEquals(2, domains.getDomains().size());
        for (int i = 0; i < domains.getDomains().size(); ++i) {
            verifyDomain(domains.getDomains().get(i), i == 0 ? "domain_id_4" : "domain_id_1");
        }
        response = r.path("ws").path("v1").path("timeline").path("domain").queryParam("owner", "owner_1").queryParam("user.name", "tester").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString());
        domains = response.getEntity(TimelineDomains.class);
        Assert.assertEquals(0, domains.getDomains().size());
    } finally {
        timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) AdminACLsManager(org.apache.hadoop.yarn.security.AdminACLsManager) TimelineDomains(org.apache.hadoop.yarn.api.records.timeline.TimelineDomains) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Aggregations

TimelineDomains (org.apache.hadoop.yarn.api.records.timeline.TimelineDomains)8 TimelineDomain (org.apache.hadoop.yarn.api.records.timeline.TimelineDomain)3 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 Configuration (org.apache.hadoop.conf.Configuration)1 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)1 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)1 TimelinePutResponse (org.apache.hadoop.yarn.api.records.timeline.TimelinePutResponse)1 TimelineClient (org.apache.hadoop.yarn.client.api.TimelineClient)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 AdminACLsManager (org.apache.hadoop.yarn.security.AdminACLsManager)1 TimelineDelegationTokenIdentifier (org.apache.hadoop.yarn.security.client.TimelineDelegationTokenIdentifier)1 KeyParser (org.apache.hadoop.yarn.server.timeline.util.LeveldbUtils.KeyParser)1 DBIterator (org.iq80.leveldb.DBIterator)1