You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2014/05/30 16:17:56 UTC
git commit: AMBARI-5954. Incorrect href in async response from
cluster create via blueprint (Jonathan Hurley via ncole)
Repository: ambari
Updated Branches:
refs/heads/trunk b625ae435 -> 4d4b62f80
AMBARI-5954. Incorrect href in async response from cluster create via blueprint (Jonathan Hurley via ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4d4b62f8
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4d4b62f8
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4d4b62f8
Branch: refs/heads/trunk
Commit: 4d4b62f8067cde79e72e48a5d2576c692e0446af
Parents: b625ae4
Author: Nate Cole <nc...@hortonworks.com>
Authored: Fri May 30 10:17:42 2014 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Fri May 30 10:17:42 2014 -0400
----------------------------------------------------------------------
.../resources/RequestResourceDefinition.java | 49 ++++++++++++++++----
1 file changed, 39 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/4d4b62f8/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java
index f26d1b8..a3920d1 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/resources/RequestResourceDefinition.java
@@ -19,14 +19,16 @@
package org.apache.ambari.server.api.resources;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
import org.apache.ambari.server.api.services.Request;
import org.apache.ambari.server.api.util.TreeNode;
-import org.apache.ambari.server.controller.internal.RepositoryResourceProvider;
import org.apache.ambari.server.controller.internal.RequestResourceProvider;
import org.apache.ambari.server.controller.spi.Resource;
-import java.util.*;
-
/**
* Request resource definition.
@@ -62,15 +64,42 @@ public class RequestResourceDefinition extends BaseResourceDefinition {
private class RequestHrefPostProcessor implements PostProcessor {
@Override
- public void process(Request request, TreeNode<Resource> resultNode, String href) {
-
- Object requestId = resultNode.getObject().getPropertyValue(getClusterController().
- getSchema(Resource.Type.Request).getKeyPropertyId(Resource.Type.Request));
+ public void process(Request request, TreeNode<Resource> resultNode,
+ String href) {
+ Object requestId = resultNode.getObject().getPropertyValue(
+ getClusterController().getSchema(Resource.Type.Request)
+ .getKeyPropertyId(Resource.Type.Request));
+
+ // sanity check for a trailing slash since this would cause problems
+ // with string-based URL matching
+ if (href.endsWith("/")) {
+ href = href.substring(0, href.length() - 1);
+ }
- StringBuilder sb = new StringBuilder(href);
- if (href.endsWith("/requests"))
+ // if the original href was for a "request", then shortcut and just
+ // append the ID onto the URL
+ StringBuilder sb = new StringBuilder();
+ if (href.endsWith("/requests")) {
+ sb.append(href);
sb.append('/').append(requestId);
-
+ } else {
+ // split the href up into its parts, intercepting "clusers" in order
+ // to rewrite the href to be scoped for requests
+ String[] tokens = href.split("/");
+
+ for (int i = 0; i < tokens.length; ++i) {
+ String fragment = tokens[i];
+ sb.append(fragment).append('/');
+
+ if ("clusters".equals(fragment) && i + 1 < tokens.length) {
+ String clusterName = tokens[i + 1];
+ sb.append(clusterName).append("/");
+ sb.append("requests/").append(requestId);
+ break;
+ }
+ }
+ }
+
resultNode.setProperty("href", sb.toString());
}
}