ConfigInfoImpl: Return raw byte value for effective value

The 'value' field of the info shows the effective value that gets
applied. Set it as the actual byte value rather than the formatted
value which could be using any arbitrary unit suffix (within the
scope of the suffixes actually supported).

In the UI, always show the effective value, rather than only when
there is a global value, and explicitly say when there is no value
configured.

Note that the UI changes are only in GWT because the project info
screen is not implemented for Polygerrit on this branch. The same
changes can be applied to Polygerrit in a follow-up commit after
this has been merged up to stable-2.15/master.

Change-Id: Ibb88d734e6a322ee90f66d1b4c4a3882d2e0654a
This commit is contained in:
David Pursehouse 2018-08-20 12:20:18 +09:00
parent a801ff9d6d
commit 33f544a075
6 changed files with 18 additions and 15 deletions

View File

@ -2805,7 +2805,7 @@ limit] of a project.
|===============================
|Field Name ||Description
|`value` |optional|
The effective value of the max object size limit as a formatted string. +
The effective value in bytes of the max object size limit. +
Not set if there is no limit for the object size.
|`configured_value`|optional|
The max object size limit that is configured on the project as a

View File

@ -151,7 +151,7 @@ public class ProjectIT extends AbstractDaemonTest {
public void maxObjectSizeCanBeSetAndCleared() throws Exception {
// Set a value
ConfigInfo info = setMaxObjectSize("100k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("100k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("102400");
assertThat(info.maxObjectSizeLimit.configuredValue).isEqualTo("100k");
assertThat(info.maxObjectSizeLimit.inheritedValue).isNull();
@ -167,6 +167,7 @@ public class ProjectIT extends AbstractDaemonTest {
Project.NameKey child = createProject(name("child"), project);
ConfigInfo info = setMaxObjectSize("100k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("102400");
assertThat(info.maxObjectSizeLimit.configuredValue).isEqualTo("100k");
assertThat(info.maxObjectSizeLimit.inheritedValue).isNull();
@ -180,7 +181,7 @@ public class ProjectIT extends AbstractDaemonTest {
@GerritConfig(name = "receive.maxObjectSizeLimit", value = "200k")
public void maxObjectSizeIsInheritedFromGlobalConfig() throws Exception {
ConfigInfo info = getConfig();
assertThat(info.maxObjectSizeLimit.value).isEqualTo("200k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("204800");
assertThat(info.maxObjectSizeLimit.configuredValue).isNull();
assertThat(info.maxObjectSizeLimit.inheritedValue).isEqualTo("200k");
}
@ -189,7 +190,7 @@ public class ProjectIT extends AbstractDaemonTest {
@GerritConfig(name = "receive.maxObjectSizeLimit", value = "200k")
public void maxObjectSizeOverridesGlobalConfigWhenLower() throws Exception {
ConfigInfo info = setMaxObjectSize("100k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("100k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("102400");
assertThat(info.maxObjectSizeLimit.configuredValue).isEqualTo("100k");
assertThat(info.maxObjectSizeLimit.inheritedValue).isEqualTo("200k");
}
@ -198,7 +199,7 @@ public class ProjectIT extends AbstractDaemonTest {
@GerritConfig(name = "receive.maxObjectSizeLimit", value = "200k")
public void maxObjectSizeDoesNotOverrideGlobalConfigWhenHigher() throws Exception {
ConfigInfo info = setMaxObjectSize("300k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("200k");
assertThat(info.maxObjectSizeLimit.value).isEqualTo("204800");
assertThat(info.maxObjectSizeLimit.configuredValue).isEqualTo("300k");
assertThat(info.maxObjectSizeLimit.inheritedValue).isEqualTo("200k");
}

View File

@ -38,6 +38,8 @@ public interface AdminMessages extends Messages {
String globalMaxObjectSizeLimit(String globalMaxObjectSizeLimit);
String noMaxObjectSizeLimit();
String pluginProjectOptionsTitle(String pluginName);
String pluginProjectInheritedValue(String value);

View File

@ -5,8 +5,9 @@ project = Project {0}
deletedGroup = Deleted Group {0}
deletedReference = Reference {0} was deleted
deletedSection = Section {0} was deleted
effectiveMaxObjectSizeLimit = effective: {0}
effectiveMaxObjectSizeLimit = effective: {0} bytes
globalMaxObjectSizeLimit = The global max object size limit is set to {0}. The limit cannot be increased on project level.
noMaxObjectSizeLimit = No max object size limit is set.
pluginProjectOptionsTitle = {0} Plugin Options
pluginProjectOptionsTitle = {0} Plugin
pluginProjectInheritedValue = inherited: {0}

View File

@ -401,14 +401,15 @@ public class ProjectInfoScreen extends ProjectScreen {
setSubmitType(result.submitType());
setState(result.state());
maxObjectSizeLimit.setText(result.maxObjectSizeLimit().configuredValue());
if (result.maxObjectSizeLimit().inheritedValue() != null) {
effectiveMaxObjectSizeLimit.setVisible(true);
if (result.maxObjectSizeLimit().value() != null) {
effectiveMaxObjectSizeLimit.setText(
AdminMessages.I.effectiveMaxObjectSizeLimit(result.maxObjectSizeLimit().value()));
effectiveMaxObjectSizeLimit.setTitle(
AdminMessages.I.globalMaxObjectSizeLimit(result.maxObjectSizeLimit().inheritedValue()));
if (result.maxObjectSizeLimit().inheritedValue() != null) {
effectiveMaxObjectSizeLimit.setTitle(
AdminMessages.I.globalMaxObjectSizeLimit(result.maxObjectSizeLimit().inheritedValue()));
}
} else {
effectiveMaxObjectSizeLimit.setVisible(false);
effectiveMaxObjectSizeLimit.setText(AdminMessages.I.noMaxObjectSizeLimit());
}
saveProject.setEnabled(false);

View File

@ -125,10 +125,8 @@ public class ConfigInfoImpl extends ConfigInfo {
private MaxObjectSizeLimitInfo getMaxObjectSizeLimit(
ProjectState projectState, TransferConfig transferConfig, Project p) {
MaxObjectSizeLimitInfo info = new MaxObjectSizeLimitInfo();
info.value =
projectState.getEffectiveMaxObjectSizeLimit() == transferConfig.getMaxObjectSizeLimit()
? transferConfig.getFormattedMaxObjectSizeLimit()
: p.getMaxObjectSizeLimit();
long value = projectState.getEffectiveMaxObjectSizeLimit();
info.value = value == 0 ? null : String.valueOf(value);
info.configuredValue = p.getMaxObjectSizeLimit();
info.inheritedValue = transferConfig.getFormattedMaxObjectSizeLimit();
return info;