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 2016/11/16 14:39:51 UTC
[21/31] ambari git commit: AMBARI-18866. Stack advisor should limit
call history it preserves (Madhuvanthi Radhakrishnan via smohanty)
AMBARI-18866. Stack advisor should limit call history it preserves (Madhuvanthi Radhakrishnan via smohanty)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8c3ad1d6
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8c3ad1d6
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8c3ad1d6
Branch: refs/heads/branch-feature-AMBARI-18634
Commit: 8c3ad1d6469fbe9c095fcc563f1c1a536892a727
Parents: b7ee658
Author: Sumit Mohanty <sm...@hortonworks.com>
Authored: Tue Nov 15 16:49:14 2016 -0800
Committer: Sumit Mohanty <sm...@hortonworks.com>
Committed: Tue Nov 15 16:50:09 2016 -0800
----------------------------------------------------------------------
.../services/stackadvisor/StackAdvisorHelper.java | 18 +++++++++++++++---
.../server/configuration/Configuration.java | 11 +++++++++++
.../stackadvisor/StackAdvisorHelperTest.java | 10 +++++++++-
3 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8c3ad1d6/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelper.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelper.java
index e175c69..05e7598 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelper.java
@@ -41,6 +41,7 @@ public class StackAdvisorHelper {
private File recommendationsDir;
private String recommendationsArtifactsLifetime;
+ private int recommendationsArtifactsRolloverMax;
private String stackAdvisorScript;
private final AmbariMetaInfo metaInfo;
@@ -53,6 +54,7 @@ public class StackAdvisorHelper {
AmbariMetaInfo metaInfo) throws IOException {
this.recommendationsDir = conf.getRecommendationsDir();
this.recommendationsArtifactsLifetime = conf.getRecommendationsArtifactsLifetime();
+ this.recommendationsArtifactsRolloverMax = conf.getRecommendationsArtifactsRolloverMax();
this.stackAdvisorScript = conf.getStackAdvisorScript();
this.saRunner = saRunner;
this.metaInfo = metaInfo;
@@ -68,7 +70,7 @@ public class StackAdvisorHelper {
*/
public synchronized ValidationResponse validate(StackAdvisorRequest request)
throws StackAdvisorException {
- requestId += 1;
+ requestId = generateRequestId();
StackAdvisorCommand<ValidationResponse> command = createValidationCommand(request
.getRequestType());
@@ -103,9 +105,9 @@ public class StackAdvisorHelper {
*/
public synchronized RecommendationResponse recommend(StackAdvisorRequest request)
throws StackAdvisorException {
- requestId += 1;
+ requestId = generateRequestId();
- StackAdvisorCommand<RecommendationResponse> command = createRecommendationCommand(request
+ StackAdvisorCommand<RecommendationResponse> command = createRecommendationCommand(request
.getRequestType());
return command.invoke(request);
@@ -131,4 +133,14 @@ public class StackAdvisorHelper {
return command;
}
+ /**
+ * Returns an incremented requestId. Rollsover back to 0 in case the requestId >= recommendationsArtifactsrollovermax
+ * @return {int requestId}
+ */
+ private int generateRequestId(){
+ requestId += 1;
+ return requestId % recommendationsArtifactsRolloverMax;
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8c3ad1d6/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index b8b8f54..ff91b36 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -403,6 +403,12 @@ public class Configuration {
public static final ConfigurationProperty<String> RECOMMENDATIONS_ARTIFACTS_LIFETIME = new ConfigurationProperty<>(
"recommendations.artifacts.lifetime", "1w");
+ @Markdown(
+ description = "Maximum number of recommendations artifacts at a given time",
+ examples = {"50","10","100"} )
+ public static final ConfigurationProperty<Integer> RECOMMENDATIONS_ARTIFACTS_ROLLOVER_MAX = new ConfigurationProperty<>(
+ "recommendations.artifacts.rollover.max",100);
+
/**
* The directory on the Ambari Server file system used for storing
* Recommendation API artifacts.
@@ -3179,6 +3185,11 @@ public class Configuration {
return getProperty(RECOMMENDATIONS_ARTIFACTS_LIFETIME);
}
+ public int getRecommendationsArtifactsRolloverMax() {
+ int rollovermax = Integer.parseInt(getProperty(RECOMMENDATIONS_ARTIFACTS_ROLLOVER_MAX));
+ return (rollovermax == 0) ? 100 : rollovermax;
+ }
+
public String areHostsSysPrepped(){
return getProperty(SYS_PREPPED_HOSTS);
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/8c3ad1d6/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelperTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelperTest.java
index 5190dea..5b0fdda 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/stackadvisor/StackAdvisorHelperTest.java
@@ -44,11 +44,11 @@ import org.junit.Test;
* StackAdvisorHelper unit tests.
*/
public class StackAdvisorHelperTest {
-
@Test
@SuppressWarnings("unchecked")
public void testValidate_returnsCommandResult() throws StackAdvisorException, IOException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = spy(new StackAdvisorHelper(configuration, saRunner, metaInfo));
@@ -61,6 +61,7 @@ public class StackAdvisorHelperTest {
when(command.invoke(request)).thenReturn(expected);
doReturn(command).when(helper).createValidationCommand(requestType);
+
ValidationResponse response = helper.validate(request);
assertEquals(expected, response);
@@ -71,6 +72,7 @@ public class StackAdvisorHelperTest {
public void testValidate_commandThrowsException_throwsException() throws StackAdvisorException,
IOException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = spy(new StackAdvisorHelper(configuration, saRunner, metaInfo));
@@ -91,6 +93,7 @@ public class StackAdvisorHelperTest {
@SuppressWarnings("unchecked")
public void testRecommend_returnsCommandResult() throws StackAdvisorException, IOException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = spy(new StackAdvisorHelper(configuration, saRunner, metaInfo));
@@ -113,6 +116,7 @@ public class StackAdvisorHelperTest {
public void testRecommend_commandThrowsException_throwsException() throws StackAdvisorException,
IOException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = spy(new StackAdvisorHelper(configuration, saRunner, metaInfo));
@@ -133,6 +137,7 @@ public class StackAdvisorHelperTest {
public void testCreateRecommendationCommand_returnsComponentLayoutRecommendationCommand()
throws IOException, StackAdvisorException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = new StackAdvisorHelper(configuration, saRunner, metaInfo);
@@ -148,6 +153,7 @@ public class StackAdvisorHelperTest {
public void testCreateValidationCommand_returnsComponentLayoutValidationCommand()
throws IOException, StackAdvisorException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = new StackAdvisorHelper(configuration, saRunner, metaInfo);
@@ -162,6 +168,7 @@ public class StackAdvisorHelperTest {
public void testCreateValidationCommand_returnsConfigurationValidationCommand()
throws IOException, StackAdvisorException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = new StackAdvisorHelper(configuration, saRunner, metaInfo);
@@ -176,6 +183,7 @@ public class StackAdvisorHelperTest {
public void testCreateRecommendationDependencyCommand_returnsConfigurationDependencyRecommendationCommand()
throws IOException, StackAdvisorException {
Configuration configuration = mock(Configuration.class);
+ when(configuration.getRecommendationsArtifactsRolloverMax()).thenReturn(100);
StackAdvisorRunner saRunner = mock(StackAdvisorRunner.class);
AmbariMetaInfo metaInfo = mock(AmbariMetaInfo.class);
StackAdvisorHelper helper = new StackAdvisorHelper(configuration, saRunner, metaInfo);