Navigation Menu

Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
LENS-1521 : Download url config needs to be specific to Query and not…
Browse files Browse the repository at this point in the history
… Service
  • Loading branch information
Amareshwari Sriramadasu authored and Rajitha.R committed Jun 22, 2018
1 parent 11cc185 commit 3076b26
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
4 changes: 4 additions & 0 deletions lens-api/src/main/java/org/apache/lens/api/LensConf.java
Expand Up @@ -79,4 +79,8 @@ public void addProperties(Map<String, String> props) {
public String getProperty(Object key) {
return properties.get(key);
}

public String getProperty(Object key, String defaultValue) {
return properties.getOrDefault(key, defaultValue);
}
}
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.lens.server.api.query;

import org.apache.lens.api.LensConf;
import org.apache.lens.server.api.LensConfConstants;

import org.apache.hadoop.conf.Configuration;
Expand All @@ -28,8 +29,8 @@
public class DefaultDownloadResultUrlProvider implements DownloadResultUrlProvider {

@Override
public String getResultUrl(Configuration conf, String queryHandle) {
log.debug("Returning Default result set url ");
public String getResultUrl(Configuration conf, LensConf qconf, String queryHandle) {
log.debug("Returning Default result set url " + conf.get(LensConfConstants.SERVER_BASE_URL));
return conf.get(LensConfConstants.SERVER_BASE_URL, LensConfConstants.DEFAULT_SERVER_BASE_URL)
+ "queryapi/queries/" + queryHandle + "/httpresultset";
}
Expand Down
Expand Up @@ -18,12 +18,20 @@
*/
package org.apache.lens.server.api.query;

import org.apache.lens.api.LensConf;

import org.apache.hadoop.conf.Configuration;

/*
* The interface to implement for returning download url. This is embedded in the query competion email sent to the user
* */
public interface DownloadResultUrlProvider {

String getResultUrl(Configuration conf, String queryHandle);
/*
@param : conf : server conf
@param : qconf : query conf
@param : queryHandle : the query handle
@return : download url sent to user via email
* */
String getResultUrl(Configuration conf, LensConf qconf, String queryHandle);
}
Expand Up @@ -280,7 +280,6 @@ public QueryContext(PreparedQueryContext prepared, String user, LensConf qconf,
if (selectedDriver != null) {
this.setSelectedDriver(selectedDriver);
}
this.lensConf = qconf;
this.driverStatus = new DriverQueryStatus();
}

Expand Down
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;

import org.apache.lens.api.LensConf;
import org.apache.lens.api.query.QueryHandle;
import org.apache.lens.server.api.LensConfConstants;
import org.apache.lens.server.api.driver.LensResultSetMetadata;
Expand All @@ -32,7 +33,7 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.util.ReflectionUtils;
import org.apache.hadoop.util.ReflectionUtils;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -53,6 +54,7 @@ public class LensPersistentResult extends PersistentResultSet {
/** The file size. */
private final Long fileSize;
private final Configuration conf;
private final LensConf queryConf;
@Getter
private String httpResultUrl = null;

Expand All @@ -68,35 +70,36 @@ public class LensPersistentResult extends PersistentResultSet {
*/
public LensPersistentResult(QueryHandle queryHandle, LensResultSetMetadata metadata, String outputPath, Integer
numRows, Long fileSize,
Configuration conf) {
Configuration conf, LensConf qconf) {
this.metadata = metadata;
this.outputPath = outputPath;
this.numRows = numRows;
this.fileSize = fileSize;
this.conf = conf;
this.queryConf = qconf;
if (isHttpResultAvailable()) {
resultUrlSetter = ReflectionUtils.newInstance(this.conf.getClass(
LensConfConstants.RESULT_DOWNLOAD_URL_PROVIDER_CLASS,
LensConfConstants.DEFAULT_RESULT_DOWNLOAD_URL_PROVIDER, DownloadResultUrlProvider.class));
this.httpResultUrl = resultUrlSetter.getResultUrl(this.conf, queryHandle.toString());
LensConfConstants.DEFAULT_RESULT_DOWNLOAD_URL_PROVIDER, DownloadResultUrlProvider.class), this.conf);
this.httpResultUrl = resultUrlSetter.getResultUrl(this.conf, this.queryConf, queryHandle.toString());
log.info("Config : " + this.conf.get(LensConfConstants.RESULT_DOWNLOAD_URL_PROVIDER_CLASS)
+ " Result url set as : " + this.httpResultUrl);
}
}

public LensPersistentResult(QueryContext ctx, Configuration conf) {
LensPersistentResult(QueryContext ctx, Configuration conf, LensConf qconf) {
this(ctx.getQueryHandle(),
ctx.getQueryOutputFormatter().getMetadata(),
ctx.getQueryOutputFormatter().getFinalOutputPath(),
ctx.getQueryOutputFormatter().getNumRows(),
ctx.getQueryOutputFormatter().getFileSize(), conf);
ctx.getQueryOutputFormatter().getFileSize(), conf, qconf);
}

public LensPersistentResult(FinishedLensQuery query, Configuration conf) throws
LensPersistentResult(FinishedLensQuery query, Configuration conf, LensConf qconf) throws
ClassNotFoundException, IOException {
this(QueryHandle.fromString(query.getHandle()),
LensResultSetMetadata.fromJson(query.getMetadata()),
query.getResult(), query.getRows(), query.getFileSize(), conf);
query.getResult(), query.getRows(), query.getFileSize(), conf, qconf);
}

@Override
Expand Down
Expand Up @@ -1938,11 +1938,11 @@ private LensPersistentResult getResultsetFromDAO(QueryHandle queryHandle) throws
throw new NotFoundException("InMemory Query result purged " + queryHandle);
}
try {
Configuration queryConf = conf;
if (ctx != null && ctx.getConf() != null) {
queryConf.addResource(ctx.getConf());
LensConf qConf = null;
if (ctx != null && ctx.getLensConf() != null) {
qConf = ctx.getLensConf();
}
return new LensPersistentResult(query, queryConf);
return new LensPersistentResult(query, conf, qConf);
} catch (Exception e) {
throw new LensException(e);
}
Expand Down Expand Up @@ -1971,9 +1971,7 @@ LensResultSet getResultset(QueryHandle queryHandle) throws LensException {
LensResultSet resultSet = resultSets.get(queryHandle);
if (resultSet == null) {
if (ctx.isPersistent() && ctx.getQueryOutputFormatter() != null) {
Configuration queryConf = conf;
queryConf.addResource(ctx.getConf());
resultSets.put(queryHandle, new LensPersistentResult(ctx, queryConf));
resultSets.put(queryHandle, new LensPersistentResult(ctx, conf, ctx.getLensConf()));
} else if (ctx.isResultAvailableInDriver() && !ctx.isQueryClosedOnDriver()) {
//InMemory result can not be returned for a closed query
resultSet = getDriverResultset(queryHandle);
Expand Down

0 comments on commit 3076b26

Please sign in to comment.