[ambari] 01/01: AMBARI-25424 Failed to edit workflow from Ambari workflow Manager while accessing Ambari UI over Knox

2019-12-06 Thread vsairam
This is an automated email from the ASF dual-hosted git repository.

vsairam pushed a commit to branch AMBARI-25424-branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit e7ee83767daa1a8145b8d375ad2fe1a7e4d1a871
Author: vsairam 
AuthorDate: Fri Dec 6 19:14:11 2019 +0530

AMBARI-25424 Failed to edit workflow from Ambari workflow Manager while 
accessing Ambari UI over Knox
---
 .../src/main/resources/ui/app/components/flow-designer.js   | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
index 2c77b5b..c5d2a45 100644
--- 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
@@ -350,7 +350,10 @@ export default Ember.Component.extend(FindNodeMixin, 
Validations, {
 var workflowXmlDefered=this.getWorkflowFromHdfs(filePath);
 workflowXmlDefered.promise.then(function(response){
   if(response.type === 'xml'){
-this.importWorkflowFromString(response.data);
+var x2js = new X2JS();
+let resData = x2js.json2xml_str(x2js.xml2json(response.data));
+
+this.importWorkflowFromString(resData);
   }else {
 this.importWorkflowFromJSON(response.data);
   }
@@ -423,10 +426,10 @@ export default Ember.Component.extend(FindNodeMixin, 
Validations, {
 Ember.$.ajax({
   url: url,
   method: 'GET',
-  dataType: "text",
   beforeSend: function (xhr) {
 xhr.setRequestHeader("X-XSRF-HEADER", 
Math.round(Math.random()*10));
 xhr.setRequestHeader("X-Requested-By", "Ambari");
+xhr.setRequestHeader("accept", "text/xml");
   }
 }).done(function(data, status, xhr){
   var type = xhr.getResponseHeader("response-type") === "xml" ? 'xml' : 
'json';
@@ -604,9 +607,11 @@ export default Ember.Component.extend(FindNodeMixin, 
Validations, {
   getWorkflowAsJsonJsoGImpl(){
try{
 var json=JSOG.stringify(this.get("workflow")), self = this;
-var actionVersions = 
JSOG.stringify(CommonUtils.toArray(this.get("workflow").schemaVersions.actionVersions));
+var actionVersions = this.get("workflow").schemaVersions ? 
JSOG.stringify(CommonUtils.toArray(this.get("workflow").schemaVersions.actionVersions))
 : [];
 var workflow = JSOG.parse(json);
-workflow.schemaVersions.actionVersions = actionVersions
+if(workflow.schemaVersions) {
+  workflow.schemaVersions.actionVersions = actionVersions
+}
 return JSOG.stringify(workflow);
   }catch(err){
console.error(err);



[ambari] branch AMBARI-25424-branch-2.7 created (now 4dfecf1)

2019-12-06 Thread vsairam
This is an automated email from the ASF dual-hosted git repository.

vsairam pushed a change to branch AMBARI-25424-branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git.


  at 4dfecf1  AMBARI-25424 Failed to edit workflow from Ambari workflow 
Manager while accessing Ambari UI over Knox

This branch includes the following new commits:

 new 4dfecf1  AMBARI-25424 Failed to edit workflow from Ambari workflow 
Manager while accessing Ambari UI over Knox

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[ambari] 01/01: AMBARI-25424 Failed to edit workflow from Ambari workflow Manager while accessing Ambari UI over Knox

2019-12-06 Thread vsairam
This is an automated email from the ASF dual-hosted git repository.

vsairam pushed a commit to branch AMBARI-25424-branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit 4dfecf12158e4f7927bc6d7cea04115baf03c752
Author: vsairam 
AuthorDate: Fri Dec 6 18:50:52 2019 +0530

AMBARI-25424 Failed to edit workflow from Ambari workflow Manager while 
accessing Ambari UI over Knox
---
 .../src/main/resources/ui/app/components/flow-designer.js   | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
index 2c77b5b..c5d2a45 100644
--- 
a/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
+++ 
b/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
@@ -350,7 +350,10 @@ export default Ember.Component.extend(FindNodeMixin, 
Validations, {
 var workflowXmlDefered=this.getWorkflowFromHdfs(filePath);
 workflowXmlDefered.promise.then(function(response){
   if(response.type === 'xml'){
-this.importWorkflowFromString(response.data);
+var x2js = new X2JS();
+let resData = x2js.json2xml_str(x2js.xml2json(response.data));
+
+this.importWorkflowFromString(resData);
   }else {
 this.importWorkflowFromJSON(response.data);
   }
@@ -423,10 +426,10 @@ export default Ember.Component.extend(FindNodeMixin, 
Validations, {
 Ember.$.ajax({
   url: url,
   method: 'GET',
-  dataType: "text",
   beforeSend: function (xhr) {
 xhr.setRequestHeader("X-XSRF-HEADER", 
Math.round(Math.random()*10));
 xhr.setRequestHeader("X-Requested-By", "Ambari");
+xhr.setRequestHeader("accept", "text/xml");
   }
 }).done(function(data, status, xhr){
   var type = xhr.getResponseHeader("response-type") === "xml" ? 'xml' : 
'json';
@@ -604,9 +607,11 @@ export default Ember.Component.extend(FindNodeMixin, 
Validations, {
   getWorkflowAsJsonJsoGImpl(){
try{
 var json=JSOG.stringify(this.get("workflow")), self = this;
-var actionVersions = 
JSOG.stringify(CommonUtils.toArray(this.get("workflow").schemaVersions.actionVersions));
+var actionVersions = this.get("workflow").schemaVersions ? 
JSOG.stringify(CommonUtils.toArray(this.get("workflow").schemaVersions.actionVersions))
 : [];
 var workflow = JSOG.parse(json);
-workflow.schemaVersions.actionVersions = actionVersions
+if(workflow.schemaVersions) {
+  workflow.schemaVersions.actionVersions = actionVersions
+}
 return JSOG.stringify(workflow);
   }catch(err){
console.error(err);



[ambari] branch branch-2.7 updated: AMBARI-25433. Adding VDF fails with paywalled repos/urls (aonishuk)

2019-12-06 Thread aonishuk
This is an automated email from the ASF dual-hosted git repository.

aonishuk pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/branch-2.7 by this push:
 new 4fbcf42  AMBARI-25433. Adding VDF fails with paywalled repos/urls 
(aonishuk)
4fbcf42 is described below

commit 4fbcf42a1a2b630fc4c69c8a50f1c8ae1a50e1f5
Author: Andrew Onishuk 
AuthorDate: Fri Dec 6 14:47:47 2019 +0200

AMBARI-25433. Adding VDF fails with paywalled repos/urls (aonishuk)
---
 .../controller/internal/URLStreamProvider.java | 48 +-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
index 429d5c8..454a5c5 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/URLStreamProvider.java
@@ -24,16 +24,25 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.net.URLConnection;
+import java.security.KeyManagementException;
 import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.cert.X509Certificate;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.net.ssl.HostnameVerifier;
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
 import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
 
 import org.apache.ambari.server.configuration.ComponentSSLConfiguration;
 import org.apache.ambari.server.controller.utilities.StreamProvider;
@@ -288,12 +297,49 @@ public class URLStreamProvider implements StreamProvider {
 return cookies + "; " + newCookie;
   }
 
+  public static class TrustAllHostnameVerifier implements HostnameVerifier
+  {
+public boolean verify(String hostname, SSLSession session) { return true; }
+  }
+
+  public static class TrustAllManager implements X509TrustManager
+  {
+public X509Certificate[] getAcceptedIssuers()
+{
+  return new X509Certificate[0];
+}
+public void checkClientTrusted(X509Certificate[] certs, String authType) {}
+public void checkServerTrusted(X509Certificate[] certs, String authType) {}
+  }
 
   // - helper methods 
 
   // Get a connection
   protected HttpURLConnection getConnection(URL url) throws IOException {
-return (HttpURLConnection) url.openConnection();
+URLConnection connection = url.openConnection();
+
+if (!setupTruststoreForHttps) {
+  HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
+
+  // Create a trust manager that does not validate certificate chains
+  TrustManager[] trustAllCerts = new TrustManager[] {
+  new TrustAllManager()
+  };
+
+  // Ignore differences between given hostname and certificate hostname
+  HostnameVerifier hostnameVerifier = new TrustAllHostnameVerifier();
+  // Install the all-trusting trust manager
+  try {
+SSLContext sc = SSLContext.getInstance("SSL");
+sc.init(null, trustAllCerts, new SecureRandom());
+httpsConnection.setSSLSocketFactory(sc.getSocketFactory());
+httpsConnection.setHostnameVerifier(hostnameVerifier);
+  } catch (NoSuchAlgorithmException | KeyManagementException e) {
+throw new IllegalStateException("Cannot create unverified ssl 
context.", e);
+  }
+}
+
+return (HttpURLConnection) connection;
   }
 
   // Get an ssl connection