You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ol...@apache.org on 2017/03/09 16:39:59 UTC
[30/50] [abbrv] ambari git commit: AMBARI-20353. Log error while
importing the workflow from encrypted path. (Madhan Mohan Reddy via gauravn7)
AMBARI-20353. Log error while importing the workflow from encrypted path. (Madhan Mohan Reddy via gauravn7)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ba04d221
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ba04d221
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ba04d221
Branch: refs/heads/branch-dev-logsearch
Commit: ba04d2211c1db5f6f7ca2feeede1b5667410344d
Parents: 3fd1c24
Author: Gaurav Nagar <gr...@gmail.com>
Authored: Wed Mar 8 17:00:23 2017 +0530
Committer: Gaurav Nagar <gr...@gmail.com>
Committed: Wed Mar 8 17:01:00 2017 +0530
----------------------------------------------------------------------
.../ambari/view/OozieProxyImpersonator.java | 42 ++------------------
.../org/apache/oozie/ambari/view/Utils.java | 30 ++++++++++++++
2 files changed, 34 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/ba04d221/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java
index 9bf2f90..d82f928 100644
--- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java
+++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieProxyImpersonator.java
@@ -23,7 +23,6 @@ import static org.apache.oozie.ambari.view.Constants.STATUS_OK;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
@@ -37,7 +36,6 @@ import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@@ -335,15 +333,7 @@ public class OozieProxyImpersonator {
}
try {
final InputStream is = workflowFilesService.readAssset(assetPath);
- StreamingOutput streamer = new StreamingOutput() {
- @Override
- public void write(OutputStream os) throws IOException,
- WebApplicationException {
- IOUtils.copy(is, os);
- is.close();
- os.close();
- }
- };
+ StreamingOutput streamer = utils.streamResponse(is);
return Response.ok(streamer).status(200).build();
} catch (IOException ex) {
LOGGER.error(ex.getMessage(),ex);
@@ -359,15 +349,7 @@ public class OozieProxyImpersonator {
}
try {
final InputStream is = workflowFilesService.readDraft(workflowPath);
- StreamingOutput streamer = new StreamingOutput() {
- @Override
- public void write(OutputStream os) throws IOException,
- WebApplicationException {
- IOUtils.copy(is, os);
- is.close();
- os.close();
- }
- };
+ StreamingOutput streamer = utils.streamResponse(is);
return Response.ok(streamer).status(200).build();
} catch (IOException ex) {
LOGGER.error(ex.getMessage(),ex);
@@ -426,15 +408,7 @@ public class OozieProxyImpersonator {
private Response getWorkflowResponse(String filePath, String responseType,
boolean olderFormatDraftIngored) throws IOException {
final InputStream is = workflowFilesService.readWorkflowXml(filePath);
- StreamingOutput streamer = new StreamingOutput() {
- @Override
- public void write(OutputStream os) throws IOException,
- WebApplicationException {
- IOUtils.copy(is, os);
- is.close();
- os.close();
- }
- };
+ StreamingOutput streamer = utils.streamResponse(is);
Response.ResponseBuilder responseBuilder = Response.ok(streamer).header(RESPONSE_TYPE, responseType);
if (olderFormatDraftIngored) {
responseBuilder.header(OLDER_FORMAT_DRAFT_INGORED, Boolean.TRUE.toString());
@@ -455,15 +429,7 @@ public class OozieProxyImpersonator {
throw new WfmWebException(ErrorCode.WORKFLOW_XML_DOES_NOT_EXIST);
}
final InputStream is = workflowFilesService.readWorkflowXml(workflowPath);
- StreamingOutput streamer = new StreamingOutput() {
- @Override
- public void write(OutputStream os) throws IOException,
- WebApplicationException {
- IOUtils.copy(is, os);
- is.close();
- os.close();
- }
- };
+ StreamingOutput streamer = utils.streamResponse(is);
return Response.ok(streamer).status(200).build();
} catch (WfmWebException ex) {
LOGGER.error(ex.getMessage(),ex);
http://git-wip-us.apache.org/repos/asf/ambari/blob/ba04d221/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java
index 0b9adda..8f427bd 100644
--- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java
+++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/Utils.java
@@ -18,6 +18,10 @@
package org.apache.oozie.ambari.view;
import java.io.IOException;
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.io.BufferedOutputStream;
+import java.io.BufferedInputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
@@ -26,9 +30,11 @@ import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.core.StreamingOutput;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -163,4 +169,28 @@ public class Utils {
return false;
}
}
+ public StreamingOutput streamResponse(final InputStream is) {
+ return new StreamingOutput() {
+ @Override
+ public void write(OutputStream os) throws IOException,
+ WebApplicationException {
+ BufferedInputStream bis=new BufferedInputStream(is);
+ BufferedOutputStream bos=new BufferedOutputStream(os);
+ try {
+ int data;
+ while ((data = bis.read()) != -1) {
+ bos.write(data);
+ }
+ is.close();
+ os.close();
+ }catch (IOException e){
+ LOGGER.error(e.getMessage(),e);
+ throw e;
+ }catch (Exception e){
+ LOGGER.error(e.getMessage(),e);
+ throw new RuntimeException(e);
+ }
+ }
+ };
+ }
}