Skip to content

Ssrc bugbash fix #1117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: ssrc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class ServerTemplateData {
private Map<String, Parameter> parameters;
private List<ServerCondition> serverConditions;
private Map<String, ParameterGroup> parameterGroups;
private Version version;
private ServerVersion serverVersion;


ServerTemplateData(String etag) {
Expand Down Expand Up @@ -78,7 +78,7 @@ final class ServerTemplateData {
}
}
if (serverTemplateResponse.getVersion() != null) {
this.version = new Version(serverTemplateResponse.getVersion());
this.serverVersion = new ServerVersion(serverTemplateResponse.getVersion());
}
this.etag = serverTemplateResponse.getEtag();
}
Expand Down Expand Up @@ -120,8 +120,8 @@ Map<String, ParameterGroup> getParameterGroups() {
return parameterGroups;
}

Version getVersion() {
return version;
ServerVersion getVersion() {
return serverVersion;
}

ServerTemplateData setParameters(@NonNull Map<String, Parameter> parameters) {
Expand All @@ -144,8 +144,8 @@ ServerTemplateData setParameterGroups(
return this;
}

ServerTemplateData setVersion(Version version) {
this.version = version;
ServerTemplateData setVersion(ServerVersion serverVersion) {
this.serverVersion = serverVersion;
return this;
}

Expand Down Expand Up @@ -178,7 +178,7 @@ ServerTemplateResponse toServerTemplateResponse(boolean includeAll) {
parameterGroupResponse.put(entry.getKey(), entry.getValue().toParameterGroupResponse());
}
TemplateResponse.VersionResponse versionResponse =
(this.version == null) ? null : this.version.toVersionResponse(includeAll);
(this.serverVersion == null) ? null : this.serverVersion.toVersionResponse(includeAll);
ServerTemplateResponse serverTemplateResponse =
new ServerTemplateResponse()
.setParameters(parameterResponses)
Expand All @@ -204,12 +204,12 @@ public boolean equals(Object o) {
&& Objects.equals(parameters, template.parameters)
&& Objects.equals(serverConditions, template.serverConditions)
&& Objects.equals(parameterGroups, template.parameterGroups)
&& Objects.equals(version, template.version);
&& Objects.equals(serverVersion, template.serverVersion);
}

@Override
public int hashCode() {
return Objects.hash(etag, parameters, serverConditions, parameterGroups, version);
return Objects.hash(etag, parameters, serverConditions, parameterGroups, serverVersion);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.api.core.ApiFutures;
import com.google.common.collect.ImmutableMap;
import com.google.firebase.ErrorCode;
import com.google.firebase.internal.Nullable;
import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterValueResponse;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -78,10 +79,11 @@ private ServerTemplateImpl(Builder builder) {
}

@Override
public ServerConfig evaluate(KeysAndValues context) throws FirebaseRemoteConfigException {
public ServerConfig evaluate(@Nullable KeysAndValues context)
throws FirebaseRemoteConfigException {
if (this.cache == null) {
throw new FirebaseRemoteConfigException(ErrorCode.FAILED_PRECONDITION,
"No Remote Config Server template in cache. Call load() before calling evaluate().");
"No Remote Config Server template in cache. Call load() before calling evaluate().");
}

Map<String, Value> configValues = new HashMap<>();
Expand All @@ -93,8 +95,11 @@ public ServerConfig evaluate(KeysAndValues context) throws FirebaseRemoteConfigE
}

ConditionEvaluator conditionEvaluator = new ConditionEvaluator();
ImmutableMap<String, Boolean> evaluatedCondition = ImmutableMap.copyOf(
conditionEvaluator.evaluateConditions(cache.getServerConditions(), context));
ImmutableMap<String, Boolean> evaluatedCondition =
context != null && !cache.getServerConditions().isEmpty()
? ImmutableMap.copyOf(
conditionEvaluator.evaluateConditions(cache.getServerConditions(), context))
: ImmutableMap.of();
ImmutableMap<String, Parameter> parameters = ImmutableMap.copyOf(cache.getParameters());
mergeDerivedConfigValues(evaluatedCondition, parameters, configValues);

Expand All @@ -103,8 +108,7 @@ public ServerConfig evaluate(KeysAndValues context) throws FirebaseRemoteConfigE

@Override
public ServerConfig evaluate() throws FirebaseRemoteConfigException {
KeysAndValues context = new KeysAndValues.Builder().build();
return evaluate(context);
return evaluate(null);
}

@Override
Expand Down
213 changes: 213 additions & 0 deletions src/main/java/com/google/firebase/remoteconfig/ServerVersion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/*
* Copyright 2020 Google LLC
*
* Licensed 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 com.google.firebase.remoteconfig;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.firebase.internal.NonNull;
import com.google.firebase.internal.Nullable;
import com.google.firebase.remoteconfig.internal.TemplateResponse;
import com.google.firebase.remoteconfig.internal.TemplateResponse.VersionResponse;

import java.util.Objects;

/**
* Represents a Server Remote Config template version.
* Output only, except for the version description. Contains metadata about a particular
* version of the Remote Config template. All fields are set at the time the specified Remote
* Config template is published. A version's description field may be specified when
* publishing a template.
*/
public final class ServerVersion {

private final String versionNumber;
private final String updateTime;
private final String updateOrigin;
private final String updateType;
private final User updateUser;
private final String rollbackSource;
private final boolean legacy;
private String description;

private ServerVersion() {
this.versionNumber = null;
this.updateTime = null;
this.updateOrigin = null;
this.updateType = null;
this.updateUser = null;
this.rollbackSource = null;
this.legacy = false;
}

ServerVersion(@NonNull VersionResponse versionResponse) {
checkNotNull(versionResponse);
this.versionNumber = versionResponse.getVersionNumber();
this.updateTime = versionResponse.getUpdateTime();
this.updateOrigin = versionResponse.getUpdateOrigin();
this.updateType = versionResponse.getUpdateType();
TemplateResponse.UserResponse userResponse = versionResponse.getUpdateUser();
this.updateUser = (userResponse != null) ? new User(userResponse) : null;
this.description = versionResponse.getDescription();
this.rollbackSource = versionResponse.getRollbackSource();
this.legacy = versionResponse.isLegacy();
}

/**
* Creates a new {@link Version} with a description.
*/
public static ServerVersion withDescription(String description) {
return new ServerVersion().setDescription(description);
}

/**
* Gets the version number of the template.
*
* @return The version number or null.
*/
@Nullable
public String getVersionNumber() {
return versionNumber;
}

/**
* Gets the update time of the version. The timestamp of when this version of the Remote Config
* template was written to the Remote Config backend.
*
* @return The update time of the version or null.
*/
@Nullable
public String getUpdateTime() {
return updateTime;
}

/**
* Gets the origin of the template update action.
*
* @return The origin of the template update action or null.
*/
@Nullable
public String getUpdateOrigin() {
return updateOrigin;
}

/**
* Gets the type of the template update action.
*
* @return The type of the template update action or null.
*/
@Nullable
public String getUpdateType() {
return updateType;
}

/**
* Gets the update user of the template.
* An aggregation of all metadata fields about the account that performed the update.
*
* @return The update user of the template or null.
*/
@Nullable
public User getUpdateUser() {
return updateUser;
}

/**
* Gets the user-provided description of the corresponding Remote Config template.
*
* @return The description of the template or null.
*/
@Nullable
public String getDescription() {
return description;
}

/**
* Gets the rollback source of the template.
*
* <p>The serverVersion number of the Remote Config template that has become the current
* serverVersion due to a rollback. Only present if this serverVersion is the result of a
* rollback.
*
* @return The rollback source of the template or null.
*/
@Nullable
public String getRollbackSource() {
return rollbackSource;
}

/**
* Indicates whether this Remote Config template was published before serverVersion history was
* supported.
*
* @return true if the template was published before serverVersion history was supported,
* and false otherwise.
*/
public boolean isLegacy() {
return legacy;
}

/**
* Sets the user-provided description of the template.
*
* @param description The description of the template.
* @return This {@link ServerVersion}.
*/
public ServerVersion setDescription(String description) {
this.description = description;
return this;
}

VersionResponse toVersionResponse(boolean includeAll) {
VersionResponse versionResponse = new VersionResponse().setDescription(this.description);
if (includeAll) {
versionResponse.setUpdateTime(this.updateTime)
.setLegacy(this.legacy)
.setRollbackSource(this.rollbackSource)
.setUpdateOrigin(this.updateOrigin)
.setUpdateType(this.updateType)
.setUpdateUser((this.updateUser == null) ? null : this.updateUser.toUserResponse())
.setVersionNumber(this.versionNumber);
}
return versionResponse;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ServerVersion serverVersion = (ServerVersion) o;
return legacy == serverVersion.legacy
&& Objects.equals(updateTime, serverVersion.updateTime)
&& Objects.equals(versionNumber, serverVersion.versionNumber)
&& Objects.equals(updateOrigin, serverVersion.updateOrigin)
&& Objects.equals(updateType, serverVersion.updateType)
&& Objects.equals(updateUser, serverVersion.updateUser)
&& Objects.equals(description, serverVersion.description)
&& Objects.equals(rollbackSource, serverVersion.rollbackSource);
}

@Override
public int hashCode() {
return Objects
.hash(versionNumber, updateTime, updateOrigin, updateType, updateUser, description,
rollbackSource, legacy);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/google/firebase/remoteconfig/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ long asLong() {
try {
return Long.parseLong(value);
} catch (NumberFormatException e) {
logger.warn("Unable to convert %s to long type.", value);
logger.warn("Unable to convert {} to long type.", value);
return DEFAULT_VALUE_FOR_LONG;
}
}
Expand All @@ -118,7 +118,7 @@ long asLong() {
try {
return Double.parseDouble(this.value);
} catch (NumberFormatException e) {
logger.warn("Unable to convert %s to double type.", value);
logger.warn("Unable to convert {} to double type.", value);
return DEFAULT_VALUE_FOR_DOUBLE;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ServerTemplateResponse {
@Key("parameters")
private Map<String, ParameterResponse> parameters;

@Key("conditions")
@Key("serverConditions")
private List<ServerConditionResponse> serverConditions;

@Key("parameterGroups")
Expand Down Expand Up @@ -102,7 +102,7 @@ public static final class ServerConditionResponse {
@Key("name")
private String name;

@Key("condition")
@Key("serverCondition")
private OneOfConditionResponse condition;

public String getName() {
Expand Down Expand Up @@ -248,7 +248,7 @@ public static final class PercentConditionResponse {
@Key("microPercentRange")
private MicroPercentRangeResponse microPercentRange;

@Key("percentOperator")
@Key("percentConditionOperator")
private String percentOperator;

@Key("seed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ private void checkExceptionFromHttpResponse(
}

// Get server template tests

@Test
public void testGetServerTemplate() throws Exception {
response.addHeader("etag", TEST_ETAG);
Expand All @@ -1446,7 +1446,7 @@ public void testGetServerTemplate() throws Exception {
assertEquals(
convertObjectToString(EXPECTED_SERVER_CONDITIONS),
convertObjectToString(serverTemplateData.getServerConditions()));
assertEquals(1605423446000L, serverTemplateData.getVersion().getUpdateTime());
assertEquals("2020-11-15T06:57:26.342763941Z", serverTemplateData.getVersion().getUpdateTime());
checkGetRequestHeaderForServer(interceptor.getLastRequest());
}

Expand All @@ -1473,7 +1473,7 @@ public void testGetServerTemplateWithTimestampUpToNanosecondPrecision() throws E

assertEquals(TEST_ETAG, serverTemplateData.getETag());
assertEquals("17", serverTemplateData.getVersion().getVersionNumber());
assertEquals(1605423446000L, serverTemplateData.getVersion().getUpdateTime());
assertEquals(timestamp, serverTemplateData.getVersion().getUpdateTime());
checkGetRequestHeaderForServer(interceptor.getLastRequest());
}
}
Expand Down
Loading