You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lens.apache.org by ra...@apache.org on 2015/10/09 06:17:19 UTC
[14/50] [abbrv] lens git commit: LENS-737 : Throw single error out
with LensMultiException
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensException.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensException.java b/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensException.java
index 603d7cb..ac1c558 100644
--- a/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensException.java
+++ b/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensException.java
@@ -31,7 +31,9 @@ import org.apache.lens.api.error.ErrorCollection;
import org.apache.lens.api.error.LensError;
import org.apache.lens.api.result.LensAPIResult;
import org.apache.lens.api.result.LensErrorTO;
+import org.apache.lens.server.api.LensErrorInfo;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import lombok.Getter;
@@ -41,14 +43,28 @@ import lombok.NonNull;
* The Class LensException.
*/
@SuppressWarnings("serial")
-public class LensException extends Exception {
+public class LensException extends Exception implements Comparable<LensException> {
private static final int DEFAULT_LENS_EXCEPTION_ERROR_CODE = INTERNAL_SERVER_ERROR.getValue();
+ private static final int DEFAULT_LENS_EXCEPTION_WEIGHT = 0;
+
+ private static LensErrorInfo defaultErrorInfo =
+ new LensErrorInfo(DEFAULT_LENS_EXCEPTION_ERROR_CODE, DEFAULT_LENS_EXCEPTION_WEIGHT, INTERNAL_SERVER_ERROR.name());
- @Getter
- private final int errorCode;
private Object[] errorMsgFormattingArgs = new Object[0];
+ @Getter
+ private final LensErrorInfo errorInfo;
+
+ public int getErrorCode() {
+ return errorInfo.getErrorCode();
+ }
+
+ public int getErrorWeight() {
+ return errorInfo.getErrorWeight();
+ }
+
+
/**
* The lensResponse prepared by {@link #buildLensErrorResponse(ErrorCollection, String, String)}
* */
@@ -61,7 +77,7 @@ public class LensException extends Exception {
* @see Exception#Exception(String)
*/
public LensException(String errorMsg) {
- this(errorMsg, DEFAULT_LENS_EXCEPTION_ERROR_CODE);
+ this(errorMsg, defaultErrorInfo);
}
/**
@@ -70,7 +86,7 @@ public class LensException extends Exception {
* @see Exception#Exception(String, Throwable)
*/
public LensException(String errorMsg, Throwable cause) {
- this(errorMsg, DEFAULT_LENS_EXCEPTION_ERROR_CODE, cause);
+ this(errorMsg, defaultErrorInfo, cause);
}
/**
@@ -79,7 +95,7 @@ public class LensException extends Exception {
* @see Exception#Exception()
*/
public LensException() {
- this(null, DEFAULT_LENS_EXCEPTION_ERROR_CODE);
+ this(null, defaultErrorInfo);
}
/**
@@ -88,79 +104,100 @@ public class LensException extends Exception {
* @see Exception#Exception(Throwable)
*/
public LensException(Throwable cause) {
- this(null, DEFAULT_LENS_EXCEPTION_ERROR_CODE, cause);
+ this(defaultErrorInfo, cause);
}
/**
- * Constructs a new Lens Exception with error code.
+ * Constructs a new Lens Exception with error info.
*
* @see Exception#Exception()
*/
- public LensException(final int errorCode) {
- this(null, errorCode);
+ public LensException(final LensErrorInfo errorInfo) {
+ this(null, errorInfo);
}
/**
- * Constructs a new Lens Exception with error msg and error code.
+ * Constructs a new Lens Exception with error msg and error info.
*
* @see Exception#Exception()
*/
- public LensException(final String errorMsg, final int errorCode) {
- this(errorMsg, errorCode, null);
+ public LensException(final String errorMsg, final LensErrorInfo errorInfo) {
+ this(errorMsg, errorInfo, null);
}
/**
- * Constructs a new Lens Exception with error code, cause and error msg formatting arguments.
+ * Constructs a new Lens Exception with error info, cause and error msg formatting arguments.
*
* @see Exception#Exception(Throwable)
*/
- public LensException(final int errorCode, final Throwable cause, @NonNull final Object... errorMsgFormattingArgs) {
- this(null, errorCode, cause, errorMsgFormattingArgs);
+ public LensException(final LensErrorInfo errorInfo, final Throwable cause,
+ @NonNull final Object... errorMsgFormattingArgs) {
+ this(null, errorInfo, cause, errorMsgFormattingArgs);
}
/**
- * Constructs a new Lens Exception with error code and error msg formatting arguments.
+ * Constructs a new Lens Exception with error info and error msg formatting arguments.
*
* @see Exception#Exception(Throwable)
*/
- public LensException(final int errorCode, @NonNull final Object... errorMsgFormattingArgs) {
- this(null, errorCode, null, errorMsgFormattingArgs);
+ public LensException(final LensErrorInfo errorInfo, @NonNull final Object... errorMsgFormattingArgs) {
+ this(null, errorInfo, null, errorMsgFormattingArgs);
}
-
/**
- * Constructs a new Lens Exception with exception error message, error code, cause and error msg formatting arguments.
+ * Constructs a new Lens Exception with exception error message, error info, cause and error msg formatting arguments.
*
* @see Exception#Exception(Throwable)
*/
- public LensException(final String errorMsg, final int errorcode, final Throwable cause,
+ public LensException(final String errorMsg, final LensErrorInfo errorInfo, final Throwable cause,
@NonNull final Object... errorMsgFormattingArgs) {
- super(errorMsg, cause);
- checkArgument(errorcode > 0);
+ super(getErrorMessage(errorMsg, errorInfo, errorMsgFormattingArgs), cause);
+ checkArgument(errorInfo.getErrorCode() > 0);
- this.errorCode = errorcode;
+ this.errorInfo = errorInfo;
this.errorMsgFormattingArgs = errorMsgFormattingArgs;
}
+ private static String getErrorMessage(final String errorMsg, final LensErrorInfo errorInfo,
+ @NonNull final Object... errorMsgFormattingArgs) {
+
+ if (StringUtils.isBlank(errorMsg)) {
+ StringBuilder error = new StringBuilder(errorInfo.getErrorName());
+ if (errorMsgFormattingArgs != null && errorMsgFormattingArgs.length != 0) {
+ error.append(Arrays.asList(errorMsgFormattingArgs));
+ }
+ return error.toString();
+ }
+ return errorMsg;
+ }
+
+ /**
+ * Copy Constructor
+ * @param e
+ */
+ public LensException(LensException e) {
+ this(e.getMessage(), e.getErrorInfo(), e.getCause(), e.errorMsgFormattingArgs);
+ }
+
public final void buildLensErrorResponse(final ErrorCollection errorCollection,
final String apiVersion, final String id) {
- final LensError lensError = errorCollection.getLensError(errorCode);
+ final LensError lensError = errorCollection.getLensError(getErrorCode());
final LensErrorTO lensErrorTO = buildLensErrorTO(errorCollection, lensError);
lensAPIResult = LensAPIResult.composedOf(apiVersion, id, lensErrorTO, lensError.getHttpStatusCode());
}
public final LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection) {
- final LensError lensError = errorCollection.getLensError(errorCode);
+ final LensError lensError = errorCollection.getLensError(getErrorCode());
return buildLensErrorTO(errorCollection, lensError);
}
protected LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection, final String errorMsg,
final String stackTrace) {
- return LensErrorTO.composedOf(errorCode, errorMsg, stackTrace);
+ return LensErrorTO.composedOf(getErrorCode(), errorMsg, stackTrace);
}
private LensErrorTO buildLensErrorTO(final ErrorCollection errorCollection, final LensError lensError) {
@@ -182,7 +219,7 @@ public class LensException extends Exception {
}
LensException e = (LensException) o;
- if (errorCode == e.errorCode && isErrorMsgEqual(e)
+ if (errorInfo.equals(e.errorInfo) && isErrorMsgEqual(e)
&& Arrays.deepEquals(errorMsgFormattingArgs, e.errorMsgFormattingArgs)) {
return true;
}
@@ -216,7 +253,7 @@ public class LensException extends Exception {
final int PRIME = 59;
int result = 1;
- result = result * PRIME + errorCode;
+ result = result * PRIME + errorInfo.hashCode();
result = result * PRIME + (this.getMessage() == null ? 0 : this.getMessage().hashCode());
result = result * PRIME + Arrays.deepHashCode(errorMsgFormattingArgs);
return result;
@@ -228,4 +265,9 @@ public class LensException extends Exception {
}
return new LensException(e);
}
+
+ @Override
+ public int compareTo(LensException e) {
+ return this.getErrorWeight() - e.getErrorWeight();
+ }
}
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensMultiCauseException.java
----------------------------------------------------------------------
diff --git a/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensMultiCauseException.java b/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensMultiCauseException.java
index af9e33a..5248489 100644
--- a/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensMultiCauseException.java
+++ b/lens-server-api/src/main/java/org/apache/lens/server/api/error/LensMultiCauseException.java
@@ -18,10 +18,7 @@
*/
package org.apache.lens.server.api.error;
-import static org.apache.lens.api.error.LensCommonErrorCode.INTERNAL_SERVER_ERROR;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -29,6 +26,7 @@ import org.apache.lens.api.error.ErrorCollection;
import org.apache.lens.api.result.LensErrorTO;
import com.google.common.collect.ImmutableList;
+
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
@@ -50,14 +48,14 @@ public class LensMultiCauseException extends LensException {
@Getter(AccessLevel.PROTECTED)
private final ImmutableList<LensException> causes;
- public LensMultiCauseException(final String errMsg, @NonNull
- final ImmutableList<LensException> causes) {
-
- super(errMsg, INTERNAL_SERVER_ERROR.getValue());
- checkArgument(causes.size() >= 2, "LensMultiCauseException should only be created when there are atleast "
- + "two causes. An instance of LensException should be sufficient if there is only one cause.");
+ public LensMultiCauseException(@NonNull final ImmutableList<LensException> excpList) {
+ super(getAppropriateError(excpList));
+ this.causes = excpList;
+ }
- this.causes = causes;
+ // Get appropriate error code
+ public static LensException getAppropriateError(final ImmutableList<LensException> excpList) {
+ return Collections.max(excpList);
}
@Override
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/main/java/org/apache/lens/server/error/LensServerErrorCode.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/error/LensServerErrorCode.java b/lens-server/src/main/java/org/apache/lens/server/error/LensServerErrorCode.java
index 917eba3..dc20f0f 100644
--- a/lens-server/src/main/java/org/apache/lens/server/error/LensServerErrorCode.java
+++ b/lens-server/src/main/java/org/apache/lens/server/error/LensServerErrorCode.java
@@ -18,20 +18,22 @@
*/
package org.apache.lens.server.error;
+import org.apache.lens.server.api.LensErrorInfo;
+
public enum LensServerErrorCode {
- SESSION_ID_NOT_PROVIDED(2001),
- NULL_OR_EMPTY_OR_BLANK_QUERY(2002),
- UNSUPPORTED_QUERY_SUBMIT_OPERATION(2003);
+ SESSION_ID_NOT_PROVIDED(2001, 0),
+ NULL_OR_EMPTY_OR_BLANK_QUERY(2002, 0),
+ UNSUPPORTED_QUERY_SUBMIT_OPERATION(2003, 0);
- public int getValue() {
- return this.errorCode;
+ public LensErrorInfo getLensErrorInfo() {
+ return this.errorInfo;
}
- private LensServerErrorCode(final int code) {
- this.errorCode = code;
+ LensServerErrorCode(final int code, final int weight) {
+ this.errorInfo = new LensErrorInfo(code, weight, name());
}
- private final int errorCode;
+ private final LensErrorInfo errorInfo;
}
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/main/java/org/apache/lens/server/error/UnSupportedQuerySubmitOpException.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/error/UnSupportedQuerySubmitOpException.java b/lens-server/src/main/java/org/apache/lens/server/error/UnSupportedQuerySubmitOpException.java
index 366b306..d90f8fd 100644
--- a/lens-server/src/main/java/org/apache/lens/server/error/UnSupportedQuerySubmitOpException.java
+++ b/lens-server/src/main/java/org/apache/lens/server/error/UnSupportedQuerySubmitOpException.java
@@ -31,11 +31,11 @@ public class UnSupportedQuerySubmitOpException extends LensException {
private final SupportedQuerySubmitOperations supportedOps = new SupportedQuerySubmitOperations();
public UnSupportedQuerySubmitOpException() {
- super(UNSUPPORTED_QUERY_SUBMIT_OPERATION.getValue());
+ super(UNSUPPORTED_QUERY_SUBMIT_OPERATION.getLensErrorInfo());
}
public UnSupportedQuerySubmitOpException(final Throwable cause) {
- super(UNSUPPORTED_QUERY_SUBMIT_OPERATION.getValue(), cause);
+ super(UNSUPPORTED_QUERY_SUBMIT_OPERATION.getLensErrorInfo(), cause);
}
@Override
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java b/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
index c29a1ac..23cc748 100644
--- a/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
+++ b/lens-server/src/main/java/org/apache/lens/server/query/QueryExecutionServiceImpl.java
@@ -1275,7 +1275,7 @@ public class QueryExecutionServiceImpl extends BaseLensService implements QueryE
final LensException firstCause = causes.get(0);
for (LensException cause : causes) {
if (!cause.equals(firstCause)) {
- throw new LensMultiCauseException(StringUtils.join(failureCauses, '\n'), ImmutableList.copyOf(causes));
+ throw new LensMultiCauseException(ImmutableList.copyOf(causes));
}
}
throw firstCause;
@@ -1555,15 +1555,11 @@ public class QueryExecutionServiceImpl extends BaseLensService implements QueryE
if (prepared != null) {
destroyPreparedQuery(prepared);
}
- log.error("Explain and prepare failed", e);
- QueryPlan plan;
- if (e.getCause() != null && e.getCause().getMessage() != null) {
- plan = new QueryPlan(true, e.getCause().getMessage());
- } else {
- plan = new QueryPlan(true, e.getMessage());
- }
- return plan;
+ throw e;
} catch (UnsupportedEncodingException e) {
+ if (prepared != null) {
+ destroyPreparedQuery(prepared);
+ }
throw new LensException(e);
} finally {
release(sessionHandle);
@@ -2259,25 +2255,16 @@ public class QueryExecutionServiceImpl extends BaseLensService implements QueryE
public QueryPlan explain(final String requestId, LensSessionHandle sessionHandle, String query, LensConf lensConf)
throws LensException {
try {
- log.info("Explain: session:{} query:{}", sessionHandle, query);
+ log.info("Explain: session:{} query:{}", sessionHandle, query);
acquire(sessionHandle);
Configuration qconf = getLensConf(sessionHandle, lensConf);
- ExplainQueryContext explainQueryContext = new ExplainQueryContext(requestId, query,
- getSession(sessionHandle).getLoggedInUser(), lensConf, qconf, drivers.values());
+ ExplainQueryContext explainQueryContext = new ExplainQueryContext(requestId, query, getSession(sessionHandle)
+ .getLoggedInUser(), lensConf, qconf, drivers.values());
explainQueryContext.setLensSessionIdentifier(sessionHandle.getPublicId().toString());
accept(query, qconf, SubmitOp.EXPLAIN);
rewriteAndSelect(explainQueryContext);
addSessionResourcesToDriver(explainQueryContext);
return explainQueryContext.getSelectedDriver().explain(explainQueryContext).toQueryPlan();
- } catch (LensException e) {
- log.error("Error during explain :", e);
- QueryPlan plan;
- if (e.getCause() != null && e.getCause().getMessage() != null) {
- plan = new QueryPlan(true, e.getCause().getMessage());
- } else {
- plan = new QueryPlan(true, e.getMessage());
- }
- return plan;
} catch (UnsupportedEncodingException e) {
throw new LensException(e);
} finally {
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/main/java/org/apache/lens/server/query/QueryServiceResource.java
----------------------------------------------------------------------
diff --git a/lens-server/src/main/java/org/apache/lens/server/query/QueryServiceResource.java b/lens-server/src/main/java/org/apache/lens/server/query/QueryServiceResource.java
index 6bfd77a..96f6aea 100644
--- a/lens-server/src/main/java/org/apache/lens/server/query/QueryServiceResource.java
+++ b/lens-server/src/main/java/org/apache/lens/server/query/QueryServiceResource.java
@@ -77,7 +77,7 @@ public class QueryServiceResource {
private void validateSessionId(final LensSessionHandle sessionHandle) throws LensException {
if (sessionHandle == null) {
- throw new LensException(SESSION_ID_NOT_PROVIDED.getValue());
+ throw new LensException(SESSION_ID_NOT_PROVIDED.getLensErrorInfo());
}
}
@@ -104,7 +104,7 @@ public class QueryServiceResource {
private void validateQuery(String query) throws LensException {
if (StringUtils.isBlank(query)) {
- throw new LensException(NULL_OR_EMPTY_OR_BLANK_QUERY.getValue());
+ throw new LensException(NULL_OR_EMPTY_OR_BLANK_QUERY.getLensErrorInfo());
}
}
/**
@@ -340,19 +340,24 @@ public class QueryServiceResource {
* @return {@link QueryPrepareHandle} incase of {link org.apache.lens.api.query.SubmitOp#PREPARE} operation.
* {@link QueryPlan} incase of {@link org.apache.lens.api.query.SubmitOp#EXPLAIN_AND_PREPARE}
* and the query plan will contain the prepare handle as well.
+ * @throws LensException
*/
@POST
@Path("preparedqueries")
@Consumes({MediaType.MULTIPART_FORM_DATA})
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
@MultiPurposeResource(formParamName = "operation")
- public QuerySubmitResult prepareQuery(@FormDataParam("sessionid") LensSessionHandle sessionid,
- @FormDataParam("query") String query, @DefaultValue("") @FormDataParam("operation") String operation,
- @FormDataParam("conf") LensConf conf, @DefaultValue("") @FormDataParam("queryName") String queryName) {
+ public LensAPIResult<? extends QuerySubmitResult> prepareQuery(
+ @FormDataParam("sessionid") LensSessionHandle sessionid, @FormDataParam("query") String query,
+ @DefaultValue("") @FormDataParam("operation") String operation, @FormDataParam("conf") LensConf conf,
+ @DefaultValue("") @FormDataParam("queryName") String queryName) throws LensException {
+ final String requestId = this.logSegregationContext.getLogSegragationId();
+
try {
checkSessionId(sessionid);
checkQuery(query);
SubmitOp sop = null;
+ QuerySubmitResult result;
try {
sop = SubmitOp.valueOf(operation.toUpperCase());
} catch (IllegalArgumentException e) {
@@ -363,17 +368,20 @@ public class QueryServiceResource {
}
switch (sop) {
case PREPARE:
- return queryServer.prepare(sessionid, query, conf, queryName);
+ result = queryServer.prepare(sessionid, query, conf, queryName);
+ break;
case EXPLAIN_AND_PREPARE:
- return queryServer.explainAndPrepare(sessionid, query, conf, queryName);
+ result = queryServer.explainAndPrepare(sessionid, query, conf, queryName);
+ break;
default:
throw new BadRequestException("Invalid operation type: " + operation + prepareClue);
}
+ return LensAPIResult.composedOf(null, requestId, result);
} catch (LensException e) {
- throw new WebApplicationException(e);
+ e.buildLensErrorResponse(errorCollection, null, requestId);
+ throw e;
}
}
-
/**
* Destroy all the prepared queries; Can be filtered with user.
*
@@ -390,10 +398,11 @@ public class QueryServiceResource {
*/
@DELETE
@Path("preparedqueries")
- @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN})
+ @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
public APIResult destroyPreparedQueries(@QueryParam("sessionid") LensSessionHandle sessionid,
- @DefaultValue("") @QueryParam("user") String user, @DefaultValue("") @QueryParam("queryName") String queryName,
- @DefaultValue("-1") @QueryParam("fromDate") long fromDate, @DefaultValue("-1") @QueryParam("toDate") long toDate) {
+ @DefaultValue("") @QueryParam("user") String user, @DefaultValue("") @QueryParam("queryName") String queryName,
+ @DefaultValue("-1") @QueryParam("fromDate") long fromDate,
+ @DefaultValue("-1") @QueryParam("toDate") long toDate) {
checkSessionId(sessionid);
int numDestroyed = 0;
boolean failed = false;
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/test/java/org/apache/lens/server/common/ErrorResponseExpectedData.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/common/ErrorResponseExpectedData.java b/lens-server/src/test/java/org/apache/lens/server/common/ErrorResponseExpectedData.java
index 38b5ea0..4d4f137 100644
--- a/lens-server/src/test/java/org/apache/lens/server/common/ErrorResponseExpectedData.java
+++ b/lens-server/src/test/java/org/apache/lens/server/common/ErrorResponseExpectedData.java
@@ -49,7 +49,7 @@ public class ErrorResponseExpectedData {
/* Assert Equal LensErrorTO (stack trace gets excluded in equality check) */
final LensErrorTO actualLensErrorTO = lensAPIResult.getLensErrorTO();
- assertEquals(actualLensErrorTO, expectedLensErrorTO);
+ assertEquals(actualLensErrorTO.getMessage(), expectedLensErrorTO.getMessage());
/* Assert receipt of valid stacktraces */
assertTrue(lensAPIResult.areValidStackTracesPresent(), "Received Lens Response:" + lensAPIResult);
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/test/java/org/apache/lens/server/common/FailingQueryDriver.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/common/FailingQueryDriver.java b/lens-server/src/test/java/org/apache/lens/server/common/FailingQueryDriver.java
index 64a75ce..2f74ceb 100644
--- a/lens-server/src/test/java/org/apache/lens/server/common/FailingQueryDriver.java
+++ b/lens-server/src/test/java/org/apache/lens/server/common/FailingQueryDriver.java
@@ -34,7 +34,7 @@ public class FailingQueryDriver extends MockDriver {
if (ctx.getUserQuery().contains("fail")) {
return new FactPartitionBasedQueryCost(0.0);
} else {
- throw new LensException();
+ throw new LensException("Simulated Estimate Failure");
}
}
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/test/java/org/apache/lens/server/query/QueryAPIErrorResponseTest.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/query/QueryAPIErrorResponseTest.java b/lens-server/src/test/java/org/apache/lens/server/query/QueryAPIErrorResponseTest.java
index 2189eb8..18a8c8d 100644
--- a/lens-server/src/test/java/org/apache/lens/server/query/QueryAPIErrorResponseTest.java
+++ b/lens-server/src/test/java/org/apache/lens/server/query/QueryAPIErrorResponseTest.java
@@ -111,8 +111,8 @@ public class QueryAPIErrorResponseTest extends LensJerseyTest {
Response response = estimate(target(), Optional.<LensSessionHandle>absent(), Optional.of(MOCK_QUERY));
final String expectedErrMsg = "Session id not provided. Please provide a session id.";
- LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(SESSION_ID_NOT_PROVIDED.getValue(), expectedErrMsg,
- MOCK_STACK_TRACE);
+ LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(
+ SESSION_ID_NOT_PROVIDED.getLensErrorInfo().getErrorCode(), expectedErrMsg, MOCK_STACK_TRACE);
ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO);
expectedData.verify(response);
@@ -126,8 +126,8 @@ public class QueryAPIErrorResponseTest extends LensJerseyTest {
Response response = estimate(target(), Optional.of(sessionId), testQuery);
final String expectedErrMsg = "Query is not provided, or it is empty or blank. Please provide a valid query.";
- LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(NULL_OR_EMPTY_OR_BLANK_QUERY.getValue(), expectedErrMsg,
- MOCK_STACK_TRACE);
+ LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(
+ NULL_OR_EMPTY_OR_BLANK_QUERY.getLensErrorInfo().getErrorCode(), expectedErrMsg, MOCK_STACK_TRACE);
ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO);
expectedData.verify(response);
@@ -144,7 +144,8 @@ public class QueryAPIErrorResponseTest extends LensJerseyTest {
final String expectedErrMsg = "Provided Operation is not supported. Supported Operations are: "
+ "[estimate, execute, explain, execute_with_timeout]";
- LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(UNSUPPORTED_QUERY_SUBMIT_OPERATION.getValue(),
+ LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(
+ UNSUPPORTED_QUERY_SUBMIT_OPERATION.getLensErrorInfo().getErrorCode(),
expectedErrMsg, MOCK_STACK_TRACE, new SupportedQuerySubmitOperations());
ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO);
@@ -165,11 +166,9 @@ public class QueryAPIErrorResponseTest extends LensJerseyTest {
expectedErrMsg, MOCK_STACK_TRACE);
LensErrorTO childError2 = LensErrorTO.composedOf(INTERNAL_SERVER_ERROR.getValue(),
expectedErrMsg, MOCK_STACK_TRACE);
- LensErrorTO childError3 = LensErrorTO.composedOf(INTERNAL_SERVER_ERROR.getValue(),
- expectedErrMsg, MOCK_STACK_TRACE);
LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(INTERNAL_SERVER_ERROR.getValue(),
- expectedErrMsg, MOCK_STACK_TRACE, Arrays.asList(childError1, childError2, childError3));
+ expectedErrMsg, MOCK_STACK_TRACE, Arrays.asList(childError1, childError2));
ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(Status.INTERNAL_SERVER_ERROR,
expectedLensErrorTO);
@@ -185,7 +184,7 @@ public class QueryAPIErrorResponseTest extends LensJerseyTest {
Response response = estimate(target(), Optional.of(sessionId), Optional.of(MOCK_QUERY));
final String expectedErrMsg = "Syntax Error: line 1:0 cannot recognize input near 'mock' '-' 'query'";
- LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(SYNTAX_ERROR.getValue(),
+ LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(SYNTAX_ERROR.getLensErrorInfo().getErrorCode(),
expectedErrMsg, MOCK_STACK_TRACE);
ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO);
@@ -290,8 +289,9 @@ public class QueryAPIErrorResponseTest extends LensJerseyTest {
final ColUnAvailableInTimeRange expectedErrorPayload = new ColUnAvailableInTimeRange(testDimensionField,
expecAvailableFrom, expecAvailableTill);
- LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(COLUMN_UNAVAILABLE_IN_TIME_RANGE.getValue(),
- expectedErrMsg, MOCK_STACK_TRACE, expectedErrorPayload, null);
+ LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(
+ COLUMN_UNAVAILABLE_IN_TIME_RANGE.getLensErrorInfo().getErrorCode(),
+ expectedErrMsg, MOCK_STACK_TRACE, expectedErrorPayload, null);
ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO);
expectedData.verify(response);
http://git-wip-us.apache.org/repos/asf/lens/blob/ab74f6ea/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
----------------------------------------------------------------------
diff --git a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
index b3f5d93..fa8d6ee 100644
--- a/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
+++ b/lens-server/src/test/java/org/apache/lens/server/query/TestQueryService.java
@@ -375,7 +375,7 @@ public class TestQueryService extends LensJerseyTest {
MediaType.APPLICATION_XML_TYPE));
final QueryPlan plan2 = ptarget.request().post(Entity.entity(mp2, MediaType.MULTIPART_FORM_DATA_TYPE),
- QueryPlan.class);
+ new GenericType<LensAPIResult<QueryPlan>>() {}).getData();
assertEquals(plan2.getTablesQueried().size(), 1);
assertTrue(plan2.getTablesQueried().get(0).endsWith(TEST_TABLE.toLowerCase()));
assertNotNull(plan2.getPrepareHandle());
@@ -387,47 +387,41 @@ public class TestQueryService extends LensJerseyTest {
* Test explain failure.
*
* @throws InterruptedException the interrupted exception
+ * @throws UnsupportedEncodingException
*/
@Test
- public void testExplainFailure() throws InterruptedException {
+ public void testExplainFailure() throws InterruptedException, UnsupportedEncodingException {
final WebTarget target = target().path("queryapi/queries");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
- mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(),
- "select NO_ID from " + TEST_TABLE));
+ MediaType.APPLICATION_XML_TYPE));
+ mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select NO_ID from "
+ + TEST_TABLE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain"));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ MediaType.APPLICATION_XML_TYPE));
- final QueryPlan plan = target.request()
- .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
- new GenericType<LensAPIResult<QueryPlan>>() {}).getData();
- assertTrue(plan.isError());
- assertNotNull(plan.getErrorMsg());
- assertTrue(plan.getErrorMsg()
- .contains("Invalid table alias or column reference 'NO_ID': " + "(possible column names are: id, idstr)"));
+ final Response responseExplain = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
+
+ assertEquals(responseExplain.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
// Test explain and prepare
final WebTarget ptarget = target().path("queryapi/preparedqueries");
final FormDataMultiPart mp2 = new FormDataMultiPart();
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("sessionid").build(), lensSessionId,
- MediaType.APPLICATION_XML_TYPE));
+ MediaType.APPLICATION_XML_TYPE));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("query").build(), "select NO_ID from "
- + TEST_TABLE));
+ + TEST_TABLE));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("operation").build(), "explain_and_prepare"));
mp2.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("conf").fileName("conf").build(), new LensConf(),
- MediaType.APPLICATION_XML_TYPE));
+ MediaType.APPLICATION_XML_TYPE));
- final QueryPlan plan2 = ptarget.request().post(Entity.entity(mp2, MediaType.MULTIPART_FORM_DATA_TYPE),
- QueryPlan.class);
- assertTrue(plan2.isError());
- assertNotNull(plan2.getErrorMsg());
- assertNull(plan2.getPrepareHandle());
- assertTrue(plan2.getErrorMsg().contains("Invalid table alias or column reference 'NO_ID': "
- + "(possible column names are: id, idstr)"));
+ final Response responseExplainAndPrepare = target.request().post(
+ Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
+
+ assertEquals(responseExplainAndPrepare.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
// post to preparedqueries
@@ -457,7 +451,7 @@ public class TestQueryService extends LensJerseyTest {
MediaType.APPLICATION_XML_TYPE));
final QueryPrepareHandle pHandle = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
- QueryPrepareHandle.class);
+ new GenericType<LensAPIResult<QueryPrepareHandle>>() {}).getData();
// Get all prepared queries
List<QueryPrepareHandle> allQueries = (List<QueryPrepareHandle>) target.queryParam("sessionid", lensSessionId)
@@ -555,7 +549,9 @@ public class TestQueryService extends LensJerseyTest {
MediaType.APPLICATION_XML_TYPE));
final QueryPlan plan = target.request()
- .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), QueryPlan.class);
+ .post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE),
+ new GenericType<LensAPIResult<QueryPlan>>() {}).getData();
+
assertEquals(plan.getTablesQueried().size(), 1);
assertTrue(plan.getTablesQueried().get(0).endsWith(TEST_TABLE.toLowerCase()));
assertNotNull(plan.getPrepareHandle());
@@ -1425,7 +1421,9 @@ public class TestQueryService extends LensJerseyTest {
final Response response = target.request()
.post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
- LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(LensCubeErrorCode.NEITHER_CUBE_NOR_DIMENSION.getValue(),
+
+ LensErrorTO expectedLensErrorTO = LensErrorTO.composedOf(
+ LensCubeErrorCode.NEITHER_CUBE_NOR_DIMENSION.getLensErrorInfo().getErrorCode(),
"Neither cube nor dimensions accessed in the query", TestDataUtils.MOCK_STACK_TRACE);
ErrorResponseExpectedData expectedData = new ErrorResponseExpectedData(BAD_REQUEST, expectedLensErrorTO);