ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject [3/3] git commit: AMBARI-7010. Recommendation and validation hrefs contain null resource number
Date Tue, 26 Aug 2014 05:53:07 GMT
AMBARI-7010. Recommendation and validation hrefs contain null resource number


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a80066ae
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a80066ae
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a80066ae

Branch: refs/heads/trunk
Commit: a80066ae09dc3ccda574b014028a87136573a4c2
Parents: 336a63d
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Mon Aug 25 17:25:15 2014 -0700
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Mon Aug 25 17:41:30 2014 -0700

----------------------------------------------------------------------
 .../stackadvisor/StackAdvisorResponse.java      | 73 ++++++++++++++++++++
 .../commands/StackAdvisorCommand.java           | 10 ++-
 .../recommendations/RecommendationResponse.java | 38 +---------
 .../validations/ValidationResponse.java         | 15 +---
 .../RecommendationResourceProvider.java         |  4 +-
 .../internal/ValidationResourceProvider.java    |  4 +-
 .../commands/StackAdvisorCommandTest.java       |  6 +-
 .../RecommendationResourceProviderTest.java     | 31 +++++++++
 .../ValidationResourceProviderTest.java         | 70 +++++++++++++++++++
 9 files changed, 194 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorResponse.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorResponse.java
new file mode 100644
index 0000000..b6d7de7
--- /dev/null
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorResponse.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.api.services.stackadvisor;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+/**
+ * Abstract stack advisor response POJO.
+ */
+public abstract class StackAdvisorResponse {
+
+  private int id;
+
+  @JsonProperty("Versions")
+  private Version version;
+
+  public int getId() {
+    return id;
+  }
+
+  public void setId(int id) {
+    this.id = id;
+  }
+
+  public Version getVersion() {
+    return version;
+  }
+
+  public void setVersion(Version version) {
+    this.version = version;
+  }
+
+  public static class Version {
+    @JsonProperty("stack_name")
+    private String stackName;
+
+    @JsonProperty("stack_version")
+    private String stackVersion;
+
+    public String getStackName() {
+      return stackName;
+    }
+
+    public void setStackName(String stackName) {
+      this.stackName = stackName;
+    }
+
+    public String getStackVersion() {
+      return stackVersion;
+    }
+
+    public void setStackVersion(String stackVersion) {
+      this.stackVersion = stackVersion;
+    }
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
index 81d4605..bc98c4c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommand.java
@@ -42,6 +42,7 @@ import org.apache.ambari.server.api.services.Request;
 import org.apache.ambari.server.api.services.StacksService.StackUriInfo;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorException;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest;
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorResponse;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRunner;
 import org.apache.ambari.server.controller.spi.Resource;
 import org.apache.commons.collections.CollectionUtils;
@@ -58,7 +59,7 @@ import org.codehaus.jackson.node.TextNode;
 /**
  * Parent for all commands.
  */
-public abstract class StackAdvisorCommand<T> extends BaseService {
+public abstract class StackAdvisorCommand<T extends StackAdvisorResponse> extends BaseService
{
 
   /**
    * Type of response object provided by extending classes when
@@ -233,7 +234,7 @@ public abstract class StackAdvisorCommand<T> extends BaseService
{
       String result = FileUtils.readFileToString(new File(requestDirectory, getResultFileName()));
 
       T response = this.mapper.readValue(result, this.type);
-      return updateResponse(request, response);
+      return updateResponse(request, setRequestId(response));
     } catch (Exception e) {
       String message = "Error occured during stack advisor command invocation";
       LOG.warn(message, e);
@@ -243,6 +244,11 @@ public abstract class StackAdvisorCommand<T> extends BaseService
{
 
   protected abstract T updateResponse(StackAdvisorRequest request, T response);
 
+  private T setRequestId(T response) {
+    response.setId(requestId);
+    return response;
+  }
+
   /**
    * Create request id directory for each call
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/recommendations/RecommendationResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/recommendations/RecommendationResponse.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/recommendations/RecommendationResponse.java
index a34291c..1796f9a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/recommendations/RecommendationResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/recommendations/RecommendationResponse.java
@@ -21,15 +21,13 @@ package org.apache.ambari.server.api.services.stackadvisor.recommendations;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorResponse;
 import org.codehaus.jackson.annotate.JsonProperty;
 
 /**
  * Recommendation response POJO.
  */
-public class RecommendationResponse {
-
-  @JsonProperty("Versions")
-  private Version version;
+public class RecommendationResponse extends StackAdvisorResponse {
 
   @JsonProperty
   private Set<String> hosts;
@@ -40,14 +38,6 @@ public class RecommendationResponse {
   @JsonProperty
   private Recommendation recommendations;
 
-  public Version getVersion() {
-    return version;
-  }
-
-  public void setVersion(Version version) {
-    this.version = version;
-  }
-
   public Set<String> getHosts() {
     return hosts;
   }
@@ -72,30 +62,6 @@ public class RecommendationResponse {
     this.recommendations = recommendations;
   }
 
-  public static class Version {
-    @JsonProperty("stack_name")
-    private String stackName;
-
-    @JsonProperty("stack_version")
-    private String stackVersion;
-
-    public String getStackName() {
-      return stackName;
-    }
-
-    public void setStackName(String stackName) {
-      this.stackName = stackName;
-    }
-
-    public String getStackVersion() {
-      return stackVersion;
-    }
-
-    public void setStackVersion(String stackVersion) {
-      this.stackVersion = stackVersion;
-    }
-  }
-
   public static class Recommendation {
     @JsonProperty
     private Blueprint blueprint;

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/validations/ValidationResponse.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/validations/ValidationResponse.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/validations/ValidationResponse.java
index 145bcd9..d6be483 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/validations/ValidationResponse.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/validations/ValidationResponse.java
@@ -20,28 +20,17 @@ package org.apache.ambari.server.api.services.stackadvisor.validations;
 
 import java.util.Set;
 
-import org.apache.ambari.server.api.services.stackadvisor.recommendations.RecommendationResponse.Version;
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorResponse;
 import org.codehaus.jackson.annotate.JsonProperty;
 
 /**
  * Validation response POJO.
  */
-public class ValidationResponse {
-
-  @JsonProperty("Versions")
-  private Version version;
+public class ValidationResponse extends StackAdvisorResponse {
 
   @JsonProperty
   private Set<ValidationItem> items;
 
-  public Version getVersion() {
-    return version;
-  }
-
-  public void setVersion(Version version) {
-    this.version = version;
-  }
-
   public Set<ValidationItem> getItems() {
     return items;
   }

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RecommendationResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RecommendationResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RecommendationResourceProvider.java
index 3e5aef4..0463076 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RecommendationResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RecommendationResourceProvider.java
@@ -50,7 +50,7 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
 public class RecommendationResourceProvider extends StackAdvisorResourceProvider {
 
   protected static final String RECOMMENDATION_ID_PROPERTY_ID = PropertyHelper.getPropertyId(
-      "Recommendations", "id");
+      "Recommendation", "id");
 
   protected static final String HOSTS_PROPERTY_ID = "hosts";
   protected static final String SERVICES_PROPERTY_ID = "services";
@@ -101,7 +101,7 @@ public class RecommendationResourceProvider extends StackAdvisorResourceProvider
       public Resource invoke() throws AmbariException {
 
         Resource resource = new ResourceImpl(Resource.Type.Recommendation);
-        setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, "1", getPropertyIds());
+        setResourceProperty(resource, RECOMMENDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds());
         setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(),
             getPropertyIds());
         setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion()

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ValidationResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ValidationResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ValidationResourceProvider.java
index bab1473..017abae 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ValidationResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ValidationResourceProvider.java
@@ -49,7 +49,7 @@ import org.apache.ambari.server.controller.utilities.PropertyHelper;
 public class ValidationResourceProvider extends StackAdvisorResourceProvider {
 
   protected static final String VALIDATION_ID_PROPERTY_ID = PropertyHelper.getPropertyId(
-      "Validations", "id");
+      "Validation", "id");
   protected static final String VALIDATE_PROPERTY_ID = "validate";
 
   protected static final String ITEMS_PROPERTY_ID = "items";
@@ -93,7 +93,7 @@ public class ValidationResourceProvider extends StackAdvisorResourceProvider
{
       public Resource invoke() throws AmbariException {
 
         Resource resource = new ResourceImpl(Resource.Type.Validation);
-        setResourceProperty(resource, VALIDATION_ID_PROPERTY_ID, "1", getPropertyIds());
+        setResourceProperty(resource, VALIDATION_ID_PROPERTY_ID, response.getId(), getPropertyIds());
         setResourceProperty(resource, STACK_NAME_PROPERTY_ID, response.getVersion().getStackName(),
getPropertyIds());
         setResourceProperty(resource, STACK_VERSION_PROPERTY_ID, response.getVersion().getStackVersion(),
getPropertyIds());
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
index cf792ff..1a19c46 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/commands/StackAdvisorCommandTest.java
@@ -41,6 +41,7 @@ import org.apache.ambari.server.api.services.AmbariMetaInfo;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorException;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest.StackAdvisorRequestBuilder;
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorResponse;
 import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRunner;
 import org.apache.ambari.server.api.services.stackadvisor.commands.StackAdvisorCommand.StackAdvisorData;
 import org.apache.commons.io.FileUtils;
@@ -150,7 +151,7 @@ public class StackAdvisorCommandTest {
     final String testResourceString = String.format("{\"type\": \"%s\"}", expected);
     final File recommendationsDir = temp.newFolder("recommendationDir");
     String stackAdvisorScript = "echo";
-    final int requestId = 0;
+    final int requestId = 2;
     StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
     AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
     doReturn(Collections.emptyList()).when(metaInfo).getStackParentVersions(anyString(),
anyString());
@@ -180,6 +181,7 @@ public class StackAdvisorCommandTest {
     TestResource result = command.invoke(request);
 
     assertEquals(expected, result.getType());
+    assertEquals(requestId, result.getId());
   }
 
   @Test
@@ -260,7 +262,7 @@ public class StackAdvisorCommandTest {
     }
   }
 
-  public static class TestResource {
+  public static class TestResource extends StackAdvisorResponse {
     @JsonProperty
     private String type;
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RecommendationResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RecommendationResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RecommendationResourceProviderTest.java
new file mode 100644
index 0000000..1810efa
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RecommendationResourceProviderTest.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller.internal;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class RecommendationResourceProviderTest {
+
+  @Test
+  public void testCreateResources() throws Exception {
+
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/a80066ae/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ValidationResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ValidationResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ValidationResourceProviderTest.java
new file mode 100644
index 0000000..cdbf2d7
--- /dev/null
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/ValidationResourceProviderTest.java
@@ -0,0 +1,70 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.controller.internal;
+
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorHelper;
+import org.apache.ambari.server.api.services.stackadvisor.StackAdvisorRequest;
+import org.apache.ambari.server.api.services.stackadvisor.validations.ValidationResponse;
+import org.apache.ambari.server.controller.AmbariManagementController;
+import org.apache.ambari.server.controller.spi.Request;
+import org.apache.ambari.server.controller.spi.RequestStatus;
+import org.apache.ambari.server.controller.spi.Resource;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.ambari.server.api.services.stackadvisor.StackAdvisorResponse.Version;
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.*;
+
+public class ValidationResourceProviderTest {
+
+  @Test
+  public void testCreateResources_checkRequestId() throws Exception {
+    Map<Resource.Type, String> keyPropertyIds = Collections.emptyMap();
+    Set<String> propertyIds = Collections.singleton(ValidationResourceProvider.VALIDATION_ID_PROPERTY_ID);
+    AmbariManagementController ambariManagementController = mock(AmbariManagementController.class);
+    ValidationResourceProvider provider = spy(new ValidationResourceProvider(propertyIds,
+        keyPropertyIds, ambariManagementController));
+    StackAdvisorRequest stackAdvisorRequest = mock(StackAdvisorRequest.class);
+    Request request = mock(Request.class);
+    doReturn(stackAdvisorRequest).when(provider).prepareStackAdvisorRequest(request);
+
+    StackAdvisorHelper saHelper = mock(StackAdvisorHelper.class);
+
+    ValidationResponse response = mock(ValidationResponse.class);
+    Version version = mock(Version.class);
+    doReturn(3).when(response).getId();
+    doReturn(version).when(response).getVersion();
+    doReturn(response).when(saHelper).validate(any(StackAdvisorRequest.class));
+    ValidationResourceProvider.init(saHelper);
+
+    RequestStatus status = provider.createResources(request);
+
+    Set<Resource> associatedResources = status.getAssociatedResources();
+    assertNotNull(associatedResources);
+    assertEquals(1, associatedResources.size());
+    Resource resource = associatedResources.iterator().next();
+    Object requestId = resource.getPropertyValue(ValidationResourceProvider.VALIDATION_ID_PROPERTY_ID);
+    assertNotNull(requestId);
+    assertEquals(3, requestId);
+  }
+}
\ No newline at end of file


Mime
View raw message