ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject [08/28] ambari git commit: AMBARI-20077. Server Error when trying to save and not overwrite. (Madhan Mohan Reddy via gauravn7)
Date Tue, 21 Feb 2017 17:18:48 GMT
AMBARI-20077. Server Error when trying to save and not overwrite. (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/07342bc6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/07342bc6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/07342bc6

Branch: refs/heads/branch-feature-AMBARI-20053
Commit: 07342bc6e4a0e9ba2b2f850f5d8cbf38a948b50c
Parents: ac4f3d1
Author: Gaurav Nagar <grvngr@gmail.com>
Authored: Mon Feb 20 15:40:41 2017 +0530
Committer: Gaurav Nagar <grvngr@gmail.com>
Committed: Mon Feb 20 15:40:41 2017 +0530

----------------------------------------------------------------------
 .../ambari/view/OozieProxyImpersonator.java     | 192 ++++++++++---------
 .../apache/oozie/ambari/view/OozieUtils.java    |  18 ++
 .../org/apache/oozie/ambari/view/Utils.java     |  14 +-
 .../oozie/ambari/view/WorkflowFilesService.java |  22 ++-
 .../workflowmanager/WorkflowManagerService.java |   6 +-
 .../WorkflowsManagerResource.java               |   7 +-
 .../view/workflowmanager/WorkflowsRepo.java     |  40 +++-
 .../ui/app/components/bundle-config.js          |   4 +-
 .../resources/ui/app/components/coord-config.js |   4 +-
 .../ui/app/components/flow-designer.js          |  32 +---
 .../main/resources/ui/app/components/save-wf.js |  11 +-
 .../main/resources/ui/app/domain/workflow.js    |   1 +
 12 files changed, 213 insertions(+), 138 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/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 a119a7e..6603a9c 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
@@ -36,7 +36,6 @@ import javax.ws.rs.HttpMethod;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
@@ -68,26 +67,30 @@ import com.google.inject.Singleton;
 public class OozieProxyImpersonator {
   private final static Logger LOGGER = LoggerFactory
     .getLogger(OozieProxyImpersonator.class);
+  private static final boolean PROJ_MANAGER_ENABLED = true;
+  public static final String RESPONSE_TYPE = "response-type";
+  public static final String OLDER_FORMAT_DRAFT_INGORED = "olderFormatDraftIngored";
 
-  private ViewContext viewContext;
+  private final ViewContext viewContext;
   private final Utils utils = new Utils();
 
 
   private final HDFSFileUtils hdfsFileUtils;
   private final WorkflowFilesService workflowFilesService;
   private WorkflowManagerService workflowManagerService;
-  private static final boolean PROJ_MANAGER_ENABLED = true;
+
   private final OozieDelegate oozieDelegate;
   private final OozieUtils oozieUtils = new OozieUtils();
   private final AssetResource assetResource;
-  private  final AmbariIOUtil ambariIOUtil;
-  private static enum ErrorCodes {
+
+  private enum ErrorCodes {
     OOZIE_SUBMIT_ERROR("error.oozie.submit", "Oozie Submit error"), OOZIE_IO_ERROR(
       "error.oozie.io", "Oozie I/O error"), FILE_ACCESS_ACL_ERROR(
       "error.file.access.control",
       "Access Error to file due to access control"), FILE_ACCESS_UNKNOWN_ERROR(
       "error.file.access", "Error accessing file"), WORKFLOW_PATH_EXISTS(
-      "error.workflow.path.exists", "Worfklow path exists");
+      "error.workflow.path.exists", "Workflow Path exists"), WORKFLOW_XML_DOES_NOT_EXIST(
+      "error.workflow.xml.not.exists", "Workflow Xml does not exist");
     private String errorCode;
     private String description;
 
@@ -104,7 +107,18 @@ public class OozieProxyImpersonator {
       return description;
     }
   }
+  private static enum WorkflowFormat{
+    XML("xml"),
+    DRAFT("draft");
+    String value;
+    WorkflowFormat(String value) {
+      this.value=value;
+    }
 
+    public String getValue() {
+      return value;
+    }
+  }
   @Inject
   public OozieProxyImpersonator(ViewContext viewContext) {
     this.viewContext = viewContext;
@@ -115,7 +129,6 @@ public class OozieProxyImpersonator {
     if (PROJ_MANAGER_ENABLED) {
       workflowManagerService = new WorkflowManagerService(viewContext);
     }
-    ambariIOUtil=new AmbariIOUtil(viewContext);
 
     LOGGER.info(String.format(
       "OozieProxyImpersonator initialized for instance: %s",
@@ -158,6 +171,16 @@ public class OozieProxyImpersonator {
     return Response.ok(viewContext.getUsername()).build();
   }
 
+  @GET
+  @Path("/getWorkflowManagerConfigs")
+  public Response getWorkflowConfigs() {
+    HashMap<String, String> workflowConfigs = new HashMap<String, String>();
+    workflowConfigs.put("nameNode", viewContext.getProperties().get("webhdfs.url"));
+    workflowConfigs.put("resourceManager", viewContext.getProperties().get("yarn.resourcemanager.address"));
+    workflowConfigs.put("userName", viewContext.getUsername());
+    return Response.ok(workflowConfigs).build();
+  }
+
   @POST
   @Path("/submitJob")
   @Consumes({MediaType.TEXT_PLAIN + "," + MediaType.TEXT_XML})
@@ -176,67 +199,64 @@ public class OozieProxyImpersonator {
   @Path("/saveWorkflow")
   @Consumes({MediaType.TEXT_PLAIN + "," + MediaType.TEXT_XML})
   public Response saveWorkflow(String postBody, @Context HttpHeaders headers,
-                               @Context UriInfo ui, @QueryParam("app.path") String appPath,
@QueryParam("description") String description,
-                               @QueryParam("projectId") String projectId, @QueryParam("jobType")
String jobType,
+                               @Context UriInfo ui, @QueryParam("app.path") String appPath,
@QueryParam("jobType") String jobTypeStr,
                                @DefaultValue("false") @QueryParam("overwrite") Boolean overwrite)
{
     LOGGER.info("save workflow  called");
     if (StringUtils.isEmpty(appPath)) {
       throw new RuntimeException("app path can't be empty.");
     }
-
-    JobType deducedJobType = oozieUtils.deduceJobType(postBody);
-    appPath = workflowFilesService.getWorkflowFileName(appPath.trim(),deducedJobType);
-
+    JobType jobType = StringUtils.isEmpty(jobTypeStr) ? JobType.WORKFLOW : JobType.valueOf(jobTypeStr);
+    String workflowFilePath = workflowFilesService.getWorkflowFileName(appPath.trim(), jobType);
     if (!overwrite) {
-      boolean fileExists = hdfsFileUtils.fileExists(appPath);
+      boolean fileExists = hdfsFileUtils.fileExists(workflowFilePath);
       if (fileExists) {
         return getFileExistsResponse();
       }
     }
 
-    postBody = utils.formatXml(postBody);
     try {
-      String filePath = workflowFilesService.createFile(appPath,
-        postBody, overwrite);
-      LOGGER.info(String.format(
-        "submit workflow job done. filePath=[%s]", filePath));
+      if (utils.isXml(postBody)) {
+        saveWorkflowXml(jobType, appPath, postBody, overwrite);
+      } else {
+        saveDraft(jobType, appPath, postBody, overwrite);
+      }
       if (PROJ_MANAGER_ENABLED) {
-        String workflowName = oozieUtils.deduceWorkflowNameFromXml(postBody);
-        workflowManagerService.saveWorkflow(projectId, appPath,
-          deducedJobType, description,
-          viewContext.getUsername(), workflowName);
+        workflowManagerService.saveWorkflow(null, workflowFilePath,
+          jobType, null,
+          viewContext.getUsername(), getWorkflowName(postBody));
       }
-
-      return Response.ok().build();
-    } catch (Exception ex) {
-      LOGGER.error(ex.getMessage(), ex);
+    } catch (IOException ex) {
       return getRespCodeForException(ex);
+    }
 
+    return Response.ok().build();
+  }
+  private String getWorkflowName(String postBody){
+    if (utils.isXml(postBody)) {
+      return oozieUtils.deduceWorkflowNameFromXml(postBody);
+    }else{
+      return oozieUtils.deduceWorkflowNameFromJson(postBody);
     }
   }
 
-  @POST
-  @Path("/saveWorkflowDraft")
-  @Consumes({MediaType.TEXT_PLAIN + "," + MediaType.TEXT_XML})
-  public Response saveDraft(String postBody, @Context HttpHeaders headers,
-                            @Context UriInfo ui, @QueryParam("app.path") String appPath,
-                            @QueryParam("projectId") String projectId, @QueryParam("description")
String description,
-                            @DefaultValue("false") @QueryParam("overwrite") Boolean overwrite,
@QueryParam("jobType") String jobTypeStr)
-    throws IOException {
-    LOGGER.info("save workflow  called");
-    if (StringUtils.isEmpty(appPath)) {
-      throw new RuntimeException("app path can't be empty.");
-    }
-    JobType jobType = StringUtils.isEmpty(jobTypeStr) ? JobType.WORKFLOW : JobType.valueOf(jobTypeStr);
-    appPath = workflowFilesService.getWorkflowDraftFileName(appPath.trim(),jobType);
+  private void saveWorkflowXml(JobType jobType, String appPath, String postBody, Boolean
overwrite) throws IOException {
+    appPath = workflowFilesService.getWorkflowFileName(appPath.trim(), jobType);
+    postBody = utils.formatXml(postBody);
     workflowFilesService.createFile(appPath, postBody, overwrite);
-    if (PROJ_MANAGER_ENABLED) {
-      String name = oozieUtils.deduceWorkflowNameFromJson(postBody);
-      workflowManagerService.saveWorkflow(projectId, appPath,
-        jobType, description,
-        viewContext.getUsername(), name);
+    String workflowDraftPath = workflowFilesService.getWorkflowDraftFileName(appPath.trim(),
jobType);
+    if (hdfsFileUtils.fileExists(workflowDraftPath)) {
+      hdfsFileUtils.deleteFile(workflowDraftPath);
     }
-    return Response.ok().build();
+  }
+
+  private void saveDraft(JobType jobType, String appPath, String postBody, Boolean overwrite)
throws IOException {
+    String workflowFilePath = workflowFilesService.getWorkflowFileName(appPath.trim(), jobType);
+    if (!hdfsFileUtils.fileExists(workflowFilePath)) {
+      String noOpWorkflow = oozieUtils.getNoOpWorkflowXml(postBody, jobType);
+      workflowFilesService.createFile(workflowFilePath, noOpWorkflow, overwrite);
+    }
+    String workflowDraftPath = workflowFilesService.getWorkflowDraftFileName(appPath.trim(),
jobType);
+    workflowFilesService.createFile(workflowDraftPath, postBody, true);
   }
 
   @POST
@@ -415,30 +435,40 @@ public class OozieProxyImpersonator {
   }
 
   @GET
-  @Path("/readWorkflowDetail")
-  public Response getWorkflowDetail(
-    @QueryParam("workflowXmlPath") String workflowPath) {
-    WorkflowFileInfo workflowDetails = workflowFilesService
-      .getWorkflowDetails(workflowPath, null);
-    return Response.ok(workflowDetails).build();
-  }
-
-  @GET
   @Path("/readWorkflow")
   public Response readWorkflow(
-    @QueryParam("workflowPath") String workflowPath,@QueryParam("jobType") String jobTypeStr)
{
-    WorkflowFileInfo workflowDetails = workflowFilesService
-      .getWorkflowDetails(workflowPath,JobType.valueOf(jobTypeStr));
-    String filePath;
-    String responseType;
+    @QueryParam("workflowPath") String workflowPath, @QueryParam("jobType") String jobTypeStr)
{
+    String workflowFileName=workflowFilesService.getWorkflowFileName(workflowPath, JobType.valueOf(jobTypeStr));
+    if (!hdfsFileUtils.fileExists(workflowFileName)){
+      HashMap<String,String> response=new HashMap<>();
+      response.put("status", ErrorCodes.WORKFLOW_XML_DOES_NOT_EXIST.getErrorCode());
+      response.put("message", ErrorCodes.WORKFLOW_XML_DOES_NOT_EXIST.getDescription());
+      return Response.status(Status.BAD_REQUEST).entity(response).build();
+    }
 
-    if (workflowPath.endsWith(Constants.WF_DRAFT_EXTENSION) || workflowDetails.getIsDraftCurrent()){
-      filePath=workflowFilesService.getWorkflowDraftFileName(workflowPath,JobType.valueOf(jobTypeStr));
-      responseType="draft";
-    }else{
-      filePath=workflowFilesService.getWorkflowFileName(workflowPath,JobType.valueOf(jobTypeStr));
-      responseType="xml";
+    WorkflowFileInfo workflowDetails = workflowFilesService
+      .getWorkflowDetails(workflowPath, JobType.valueOf(jobTypeStr));
+    if (workflowPath.endsWith(Constants.WF_DRAFT_EXTENSION) || workflowDetails.getIsDraftCurrent())
{
+      String filePath = workflowFilesService.getWorkflowDraftFileName(workflowPath, JobType.valueOf(jobTypeStr));
+      try {
+        InputStream inputStream = workflowFilesService.readWorkflowXml(filePath);
+        String stringResponse = IOUtils.toString(inputStream);
+        if (!workflowFilesService.isDraftFormatCurrent(stringResponse)) {
+          filePath = workflowFilesService.getWorkflowFileName(workflowPath, JobType.valueOf(jobTypeStr));
+          return getWorkflowResponse(filePath, WorkflowFormat.XML.getValue(), true);
+        } else {
+          return Response.ok(stringResponse).header(RESPONSE_TYPE, WorkflowFormat.DRAFT.getValue()).build();
+        }
+      } catch (IOException e) {
+        return getRespCodeForException(e);
+      }
+    } else {
+      String filePath = workflowFilesService.getWorkflowFileName(workflowPath, JobType.valueOf(jobTypeStr));
+      return getWorkflowResponse(filePath, WorkflowFormat.XML.getValue(), false);
     }
+  }
+
+  private Response getWorkflowResponse(String filePath, String responseType, boolean olderFormatDraftIngored)
{
     try {
       final InputStream is = workflowFilesService
         .readWorkflowXml(filePath);
@@ -451,7 +481,11 @@ public class OozieProxyImpersonator {
           os.close();
         }
       };
-      return Response.ok(streamer).header("response-type",responseType).status(200).build();
+      Response.ResponseBuilder responseBuilder = Response.ok(streamer).header(RESPONSE_TYPE,
responseType);
+      if(olderFormatDraftIngored){
+        responseBuilder.header(OLDER_FORMAT_DRAFT_INGORED,Boolean.TRUE.toString());
+      }
+      return  responseBuilder.build();
     } catch (IOException e) {
       return getRespCodeForException(e);
     }
@@ -497,28 +531,6 @@ public class OozieProxyImpersonator {
   }
 
   @GET
-  @Path("/getDag")
-  @Produces("image/png")
-  public Response getDag(@Context HttpHeaders headers,
-                         @Context UriInfo ui, @QueryParam("jobid") String jobid) {
-    Map<String, String> newHeaders = utils.getHeaders(headers);
-    final InputStream is = oozieDelegate.readFromOozie(headers,
-      oozieDelegate.getDagUrl(jobid), HttpMethod.GET, null,
-      newHeaders);
-    StreamingOutput streamer = new StreamingOutput() {
-      @Override
-      public void write(OutputStream os) throws IOException,
-        WebApplicationException {
-        IOUtils.copy(is, os);
-        is.close();
-        os.close();
-      }
-
-    };
-    return Response.ok(streamer).status(200).build();
-  }
-
-  @GET
   @Path("/{path: .*}")
   public Response handleGet(@Context HttpHeaders headers, @Context UriInfo ui) {
     try {

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieUtils.java
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieUtils.java
b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieUtils.java
index 9791c47..83affd3 100644
--- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieUtils.java
+++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/OozieUtils.java
@@ -106,6 +106,10 @@ public class OozieUtils {
     String name = jsonElement.getAsJsonObject().get("name").getAsString();
     return name;
   }
+  public String deduceWorkflowSchemaVersionFromJson(String json) {
+    JsonElement jsonElement = new JsonParser().parse(json);
+    return jsonElement.getAsJsonObject().get("xmlns").getAsString();
+  }
 
   public String deduceWorkflowNameFromXml(String xml) {
     try {
@@ -172,4 +176,18 @@ public class OozieUtils {
       throw new RuntimeException(e);
     }
   }
+
+  public String getNoOpWorkflowXml(String json,JobType jobType) {
+    String schema=deduceWorkflowSchemaVersionFromJson(json);
+    String name=deduceWorkflowNameFromJson(json);
+    switch (jobType){
+      case WORKFLOW:
+        return String.format("<workflow-app xmlns=\"%s\" name=\"%s\"><start to=\"end\"/><end
name=\"end\"/></workflow-app>",schema,name);
+      case COORDINATOR:
+        return String.format("<coordinator-app xmlns=\"%s\" name=\"%s\"></coordinator-app>",schema,name);
+      case BUNDLE:
+        return String.format("<bundle-app xmlns=\"%s\" name=\"%s\"></bundle-app>",schema,name);
+    }
+    return null;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/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 61d878e..0b9adda 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
@@ -52,8 +52,9 @@ public class Utils {
 	private static final String XML_INDENT_AMT_PROP_NAME = "{http://xml.apache.org/xslt}indent-amount";
 	private final static Logger LOGGER = LoggerFactory
 			.getLogger(Utils.class);
+	private final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 	public String formatXml(String xml) {
-		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+
 		try {
 			DocumentBuilder db = dbf.newDocumentBuilder();
 			StreamResult result = new StreamResult(new StringWriter());
@@ -151,4 +152,15 @@ public class Utils {
 	}
 
 
+  public boolean isXml(String postBody) {
+		try {
+			DocumentBuilder db = dbf.newDocumentBuilder();
+			InputSource is = new InputSource();
+			is.setCharacterStream(new StringReader(postBody));
+			Document doc = db.parse(is);
+			return true;
+		} catch (Exception e) {
+			return false;
+		}
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/WorkflowFilesService.java
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/WorkflowFilesService.java
b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/WorkflowFilesService.java
index 24c263b..cdf4e99 100644
--- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/WorkflowFilesService.java
+++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/WorkflowFilesService.java
@@ -20,6 +20,8 @@ package org.apache.oozie.ambari.view;
 import java.io.IOException;
 import java.io.InputStream;
 
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
 import org.apache.hadoop.fs.FileStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,6 +30,7 @@ public class WorkflowFilesService {
   private final static Logger LOGGER = LoggerFactory
           .getLogger(WorkflowFilesService.class);
   private HDFSFileUtils hdfsFileUtils;
+  private String currentDraftVersion="v1";
 
   public WorkflowFilesService(HDFSFileUtils hdfsFileUtils) {
     super();
@@ -118,8 +121,13 @@ public class WorkflowFilesService {
     if (appPath.endsWith(Constants.WF_ASSET_EXTENSION)) {
       assetFile = appPath;
     } else {
-      assetFile = appPath + (appPath.endsWith("/") ? "" : "/")
-              + Constants.DEFAULT_WORKFLOW_ASSET_FILENAME;
+      String[] paths=appPath.split("/");
+      if (paths[paths.length-1].contains(".")){
+        return appPath;
+      }else{
+        assetFile = appPath + (appPath.endsWith("/") ? "" : "/")
+          + Constants.DEFAULT_WORKFLOW_ASSET_FILENAME;
+      }
     }
     return assetFile;
   }
@@ -144,6 +152,7 @@ public class WorkflowFilesService {
               .getFileStatus(appPath);
       workflowInfo.setWorkflowModificationTime(workflowFileStatus
               .getModificationTime());
+
     }
     if (draftExists) {
       FileStatus draftFileStatus = hdfsFileUtils
@@ -167,4 +176,13 @@ public class WorkflowFilesService {
     }
   }
 
+  public boolean isDraftFormatCurrent(String json) {
+    JsonElement jsonElement = new JsonParser().parse(json);
+    JsonElement draftVersion = jsonElement.getAsJsonObject().get("draftVersion");
+    if (draftVersion != null && currentDraftVersion.equals(draftVersion.getAsString().trim()))
{
+      return true;
+    } else {
+      return false;
+    }
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowManagerService.java
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowManagerService.java
b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowManagerService.java
index fc08b80..dcb82ac 100644
--- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowManagerService.java
+++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowManagerService.java
@@ -53,7 +53,7 @@ public class WorkflowManagerService {
 
     } else {
       String workflowFileName = workflowFilesService.getWorkflowFileName(path, jobType);
-      Workflow workflowByPath = workflowsRepository.getWorkflowByPath(workflowFileName);
+      Workflow workflowByPath = workflowsRepository.getWorkflowByPath(workflowFileName,userName);
       if (workflowByPath != null) {
         setWorkflowAttributes(jobType, userName, name, workflowByPath);
         workflowsRepository.update(workflowByPath);
@@ -74,8 +74,8 @@ public class WorkflowManagerService {
     wf.setType(jobType.name());
   }
 
-  public Collection<Workflow> getAllWorkflows() {
-    return workflowsRepository.findAll();
+  public Collection<Workflow> getAllWorkflows(String username) {
+    return workflowsRepository.getWorkflows(username);
   }
 
   public void deleteWorkflow(String projectId, Boolean deleteDefinition) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsManagerResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsManagerResource.java
b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsManagerResource.java
index 7513107..a0aa234 100644
--- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsManagerResource.java
+++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsManagerResource.java
@@ -30,17 +30,18 @@ import javax.ws.rs.QueryParam;
 import org.apache.ambari.view.ViewContext;
 
 public class WorkflowsManagerResource {
-	private WorkflowManagerService workflowManagerService;
-	
+	private final WorkflowManagerService workflowManagerService;
+	private final ViewContext viewContext;
 	public WorkflowsManagerResource(ViewContext viewContext) {
 		super();
+		this.viewContext=viewContext;
 		this.workflowManagerService=new WorkflowManagerService(viewContext);
 	}
 
 	@GET
 	public Map<String,Object> getWorkflows(){
 	    HashMap<String,Object> result=new HashMap<>();
-	    result.put("wfprojects", workflowManagerService.getAllWorkflows());
+	    result.put("wfprojects", workflowManagerService.getAllWorkflows(viewContext.getUsername()));
 	    return result;
 	}
 	

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsRepo.java
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsRepo.java
b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsRepo.java
index 1fc0c5f..b0fb905 100644
--- a/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsRepo.java
+++ b/contrib/views/wfmanager/src/main/java/org/apache/oozie/ambari/view/workflowmanager/WorkflowsRepo.java
@@ -24,7 +24,9 @@ import org.apache.oozie.ambari.view.workflowmanager.model.Workflow;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 
 public class WorkflowsRepo extends BaseRepo<Workflow> {
   private final static Logger LOGGER = LoggerFactory
@@ -33,21 +35,47 @@ public class WorkflowsRepo extends BaseRepo<Workflow> {
     super(Workflow.class, dataStore);
 
   }
+  public Collection<Workflow> getWorkflows(String userName){
+    try {
+      Collection<Workflow> workflows = this.dataStore.findAll(Workflow.class,
+        "owner='" + userName + "'");
+      return  workflows;
+    } catch (PersistenceException e) {
+      throw new RuntimeException(e);
+    }
+  }
 
-  public Workflow getWorkflowByPath(String path) {
+  public Workflow getWorkflowByPath(String path, String userName) {
     try {
       Collection<Workflow> workflows = this.dataStore.findAll(Workflow.class,
-              "workflowDefinitionPath='" + path + "'");
+        "workflowDefinitionPath='" + path + "'");
       if (workflows == null || workflows.isEmpty()) {
         return null;
-      } else if (workflows.size() > 1) {
-        LOGGER.error("Duplicate workflows found having same path");
-        throw new RuntimeException("Duplicate workflows");
       } else {
-        return workflows.iterator().next();
+        List<Workflow> myWorkflows = filterWorkflows(workflows, userName, true);
+        if (myWorkflows.isEmpty()) {
+          return null;
+        } else if (myWorkflows.size() == 1) {
+          return myWorkflows.get(0);
+        } else {
+          LOGGER.error("Duplicate workflows found having same path");
+          throw new RuntimeException("Duplicate workflows. Remove one in Recent Workflows
Manager");
+        }
       }
     } catch (PersistenceException e) {
       throw new RuntimeException(e);
     }
   }
+
+  private List<Workflow> filterWorkflows(Collection<Workflow> workflows,String
userName,boolean matches ) {
+    List<Workflow> filteredWorkflows = new ArrayList<>();
+    for (Workflow wf : workflows) {
+      if (matches && userName.equals(wf.getOwner())) {
+        filteredWorkflows.add(wf);
+      } else if (!matches && !userName.equals(wf.getOwner())) {
+        filteredWorkflows.add(wf);
+      }
+    }
+    return filteredWorkflows;
+  }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
b/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
index db7a180..9201d5c 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/components/bundle-config.js
@@ -123,7 +123,9 @@ export default Ember.Component.extend(Ember.Evented, Validations, {
       coordinators : null,
       schemaVersions : {
         bundleVersion : this.get('schemaVersions').getDefaultVersion('bundle')
-      }
+      },
+      xmlns : "uri:oozie:bundle:" +this.get('schemaVersions').getDefaultVersion('bundle'),
+      draftVersion: 'v1'
     });
   },
   importSampleBundle (){

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
b/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
index 369481f..c7da381 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/components/coord-config.js
@@ -223,7 +223,9 @@ export default Ember.Component.extend(Validations, Ember.Evented, {
       slainfo : SlaInfo.create({}),
       schemaVersions : {
         coordinatorVersion : this.get('schemaVersions').getDefaultVersion('coordinator')
-      }
+      },
+      xmlns : "uri:oozie:coordinator:" +this.get('schemaVersions').getDefaultVersion('coordinator'),
+      draftVersion: 'v1'
     });
   },
   importSampleCoordinator (){

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/resources/ui/app/components/flow-designer.js
----------------------------------------------------------------------
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 29c9dd2..c1bd4be 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
@@ -145,31 +145,7 @@ export default Ember.Component.extend(FindNodeMixin, Validations, {
   },
 
   importWorkflowFromProjManager(path){
-      var self = this;
-      this.set("showingFileBrowser",false);
-      if(path){
-        self.set("isWorkflowImporting", true);
-        this.isDraftExists(path).promise.then(function(data){
-          var draftData = JSON.parse(data);
-          if(draftData.draftExists && draftData.isDraftCurrent) {
-              self.set("workflowFilePath", path);
-              self.getDraftWorkflowData(path).promise.then(function(data){
-                var workflowImporter = WorkflowJsonImporter.create({});
-                var workflow = workflowImporter.importWorkflow(data);
-                self.resetDesigner();
-                self.set("workflow", workflow);
-                self.initAndRenderWorkflow();
-                self.set("isWorkflowImporting", false);
-                self.doValidation();
-              }.bind(this)).catch(function(data){
-              });
-          } else {
-            self.importWorkflow(path);
-          }
-        }.bind(this)).catch(function(e){
-          console.error(e);
-        });
-      }
+    this.importWorkflow(path);
   },
 
   observeXmlAppPath : Ember.observer('xmlAppPath', function(){
@@ -376,6 +352,7 @@ export default Ember.Component.extend(FindNodeMixin, Validations, {
     var workflow=workflowImporter.importWorkflow(data);
     this.resetDesigner();
     this.set("workflow", workflow);
+    this.initAndRenderWorkflow();
     this.rerender();
     this.doValidation();
   },
@@ -453,7 +430,9 @@ export default Ember.Component.extend(FindNodeMixin, Validations, {
     var actionNodeType = Object.keys(actionNodeXml)[0];
     var currentTransition = this.get("currentTransition.transition");
     this.createSnapshot();
-    var actionNode = this.get("workflow").addNode(this.findTransition(this.get("workflow").startNode,
currentTransition.sourceNodeId, currentTransition.targetNode.id),actionNodeType);
+    var transition = this.get("currentTransition").source.transitions.findBy('targetNode.id',currentTransition.targetNode.id);
+    transition.source=this.get("currentTransition").source;
+    var actionNode = this.get("workflow").addNode(transition,actionNodeType);
     this.rerender();
     this.doValidation();
     this.scrollToNewPosition();
@@ -714,6 +693,7 @@ export default Ember.Component.extend(FindNodeMixin, Validations, {
     }, 1000);
   },
   openSaveWorkflow() {
+    this.get('workflowContext').clearErrors();
     if(Ember.isBlank(this.$('[name=wf_title]').val())) {
       this.set('errors',[{"message":"Workflow name is mandatory"}]);
       return;

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/resources/ui/app/components/save-wf.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/components/save-wf.js b/contrib/views/wfmanager/src/main/resources/ui/app/components/save-wf.js
index 75cdaf9..17ee0fd 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/components/save-wf.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/components/save-wf.js
@@ -17,6 +17,7 @@
 
 import Ember from 'ember';
 import { validator, buildValidations } from 'ember-cp-validations';
+import CommonUtils from "../utils/common-utils";
 
 const Validations = buildValidations({
   'filePath': validator('presence', {
@@ -83,11 +84,11 @@ export default Ember.Component.extend(Validations, {
     }
   },
   saveJob(){
-    var url = Ember.ENV.API_URL + "/saveWorkflowDraft?app.path=" + this.get("filePath") +
"&overwrite=" + this.get("overwritePath") + "&jobType="+this.get('displayName').toUpperCase();
-    this.saveWfJob(url, this.get("jobJson"));
-    if(!this.get('isDraft')){
-       url = Ember.ENV.API_URL + "/saveWorkflow?app.path=" + this.get("filePath") + "&overwrite="
+ this.get("overwritePath");
-       this.saveWfJob(url, this.get("jobXml"));
+    var url = Ember.ENV.API_URL + "/saveWorkflow?app.path=" + this.get("filePath") + "&overwrite="
+ this.get("overwritePath") + "&jobType="+this.get('displayName').toUpperCase();
+    if(this.get('isDraft')){
+       this.saveWfJob(url, this.get("jobJson"));
+    } else {
+      this.saveWfJob(url, this.get("jobXml"));
     }
   },
   saveWfJob(url, workflowData) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/07342bc6/contrib/views/wfmanager/src/main/resources/ui/app/domain/workflow.js
----------------------------------------------------------------------
diff --git a/contrib/views/wfmanager/src/main/resources/ui/app/domain/workflow.js b/contrib/views/wfmanager/src/main/resources/ui/app/domain/workflow.js
index 26e72d5..a563c20 100644
--- a/contrib/views/wfmanager/src/main/resources/ui/app/domain/workflow.js
+++ b/contrib/views/wfmanager/src/main/resources/ui/app/domain/workflow.js
@@ -38,6 +38,7 @@ var Workflow= Ember.Object.extend(FindNodeMixin,{
     var schemaVersions=SchemaVersions.create({});
     this.schemaVersions = {};
     this.schemaVersions.workflowVersion = schemaVersions.getDefaultVersion('workflow');
+    this.set("xmlns","uri:oozie:workflow:"+this.schemaVersions.workflowVersion);
     var actionsMap = new Map();
     Constants.actions.forEach((action)=>{
       if(action.supportsSchema){


Mime
View raw message