Skip to content
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

Modify flags DTO & manager object #522

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- development
- SDKS-7440

jobs:
build-app:
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ apply plugin: 'signing'
apply plugin: 'kotlin-android'

ext {
splitVersion = '3.3.1-alpha-1'
splitVersion = '3.3.1-alpha-2'
}

android {
Expand Down Expand Up @@ -225,6 +225,7 @@ afterEvaluate {
release(MavenPublication) {
from components.release

artifactId = 'android-client'
groupId = 'io.split.client'
version = splitVersion
artifact sourcesJar
Expand All @@ -241,6 +242,7 @@ afterEvaluate {
development(MavenPublication) {
from components.release

artifactId = 'android-client'
groupId = 'io.split.client'
version = splitVersion
artifact sourcesJar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private SplitView toSplitView(ParsedSplit parsedSplit) {
splitView.killed = parsedSplit.killed();
splitView.changeNumber = parsedSplit.changeNumber();
splitView.configs = parsedSplit.configurations();
splitView.sets = new ArrayList<>(parsedSplit.sets() == null ? new HashSet<>() : parsedSplit.sets());

Set<String> treatments = new HashSet<>();
for (ParsedCondition condition : parsedSplit.parsedConditions()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/split/android/client/api/SplitView.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public class SplitView {
public List<String> treatments;
public long changeNumber;
public Map<String, String> configs;
public List<String> sets;
}
33 changes: 33 additions & 0 deletions src/main/java/io/split/android/client/dtos/Split.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
package io.split.android.client.dtos;

import androidx.annotation.Nullable;

import com.google.gson.annotations.SerializedName;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class Split {

@SerializedName("name")
public String name;

@SerializedName("seed")
public int seed;

@SerializedName("status")
public Status status;

@SerializedName("killed")
public boolean killed;

@SerializedName("defaultTreatment")
public String defaultTreatment;

@SerializedName("conditions")
public List<Condition> conditions;

@SerializedName("trafficTypeName")
public String trafficTypeName;

@SerializedName("changeNumber")
public long changeNumber;

@SerializedName("trafficAllocation")
public Integer trafficAllocation;

@SerializedName("trafficAllocationSeed")
public Integer trafficAllocationSeed;

@SerializedName("algo")
public int algo;

@SerializedName("configurations")
public Map<String, String> configurations;

@Nullable
@SerializedName("sets")
public Set<String> sets;
}
138 changes: 72 additions & 66 deletions src/main/java/io/split/android/engine/experiments/ParsedSplit.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
package io.split.android.engine.experiments;

import androidx.annotation.NonNull;

import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
* a value class representing an io.codigo.dtos.Experiment. Why are we not using
* that class? Because it does not have the logic of matching. ParsedExperiment
* has the matchers that also encapsulate the logic of matching. We
* can easily cache this object.
*/
@SuppressWarnings("RedundantCast")
public class ParsedSplit {

private final String _split;
private final int _seed;
private final boolean _killed;
private final String _defaultTreatment;
private final ImmutableList<ParsedCondition> _parsedCondition;
private final String _trafficTypeName;
private final long _changeNumber;
private final int _trafficAllocation;
private final int _trafficAllocationSeed;
private final int _algo;
private final Map<String, String> _configurations;
private final String mSplit;
private final int mSeed;
private final boolean mKilled;
private final String mDefaultTreatment;
private final ImmutableList<ParsedCondition> mParsedCondition;
private final String mTrafficTypeName;
private final long mChangeNumber;
private final int mTrafficAllocation;
private final int mTrafficAllocationSeed;
private final int mAlgo;
private final Map<String, String> mConfigurations;
private final Set<String> mSets;

public ParsedSplit(
String feature,
Expand All @@ -37,81 +35,87 @@ public ParsedSplit(
int trafficAllocation,
int trafficAllocationSeed,
int algo,
Map<String, String> configurations
Map<String, String> configurations,
Set<String> sets
) {
_split = feature;
_seed = seed;
_killed = killed;
_defaultTreatment = defaultTreatment;
_parsedCondition = ImmutableList.copyOf(matcherAndSplits);
_trafficTypeName = trafficTypeName;
_changeNumber = changeNumber;
_algo = algo;
_configurations = configurations;

if (_defaultTreatment == null) {
mSplit = feature;
mSeed = seed;
mKilled = killed;
mDefaultTreatment = defaultTreatment;
mParsedCondition = ImmutableList.copyOf(matcherAndSplits);
mTrafficTypeName = trafficTypeName;
mChangeNumber = changeNumber;
mAlgo = algo;
mConfigurations = configurations;

if (mDefaultTreatment == null) {
throw new IllegalArgumentException("DefaultTreatment is null");
}
this._trafficAllocation = trafficAllocation;
this._trafficAllocationSeed = trafficAllocationSeed;
mTrafficAllocation = trafficAllocation;
mTrafficAllocationSeed = trafficAllocationSeed;
mSets = sets;
}


public String feature() {
return _split;
return mSplit;
}

public int trafficAllocation() {
return _trafficAllocation;
return mTrafficAllocation;
}

public int trafficAllocationSeed() {
return _trafficAllocationSeed;
return mTrafficAllocationSeed;
}

public int seed() {
return _seed;
return mSeed;
}

public boolean killed() {
return _killed;
return mKilled;
}

public String defaultTreatment() {
return _defaultTreatment;
return mDefaultTreatment;
}

public List<ParsedCondition> parsedConditions() {
return _parsedCondition;
return mParsedCondition;
}

public String trafficTypeName() {
return _trafficTypeName;
return mTrafficTypeName;
}

public long changeNumber() {
return _changeNumber;
return mChangeNumber;
}

public int algo() {
return _algo;
return mAlgo;
}

public Map<String, String> configurations() {
return _configurations;
return mConfigurations;
}

public Set<String> sets() {
return mSets;
}

@Override
public int hashCode() {
int result = 17;
result = 31 * result + _split.hashCode();
result = 31 * result + (int) (_seed ^ (_seed >>> 32));
result = 31 * result + (_killed ? 1 : 0);
result = 31 * result + _defaultTreatment.hashCode();
result = 31 * result + _parsedCondition.hashCode();
result = 31 * result + (_trafficTypeName == null ? 0 : _trafficTypeName.hashCode());
result = 31 * result + (int) (_changeNumber ^ (_changeNumber >>> 32));
result = 31 * result + (_algo ^ (_algo >>> 32));
result = 31 * result + mSplit.hashCode();
result = 31 * result + (int) (mSeed ^ (mSeed >>> 32));
result = 31 * result + (mKilled ? 1 : 0);
result = 31 * result + mDefaultTreatment.hashCode();
result = 31 * result + mParsedCondition.hashCode();
result = 31 * result + (mTrafficTypeName == null ? 0 : mTrafficTypeName.hashCode());
result = 31 * result + (int) (mChangeNumber ^ (mChangeNumber >>> 32));
result = 31 * result + (mAlgo ^ (mAlgo >>> 32));
result = 31 * result + ((mSets != null) ? mSets.hashCode() : 0);
return result;
}

Expand All @@ -122,25 +126,27 @@ public boolean equals(Object obj) {
if (!(obj instanceof ParsedSplit)) return false;

ParsedSplit other = (ParsedSplit) obj;
return _split.equals(other._split)
&& _seed == other._seed
&& _killed == other._killed
&& _defaultTreatment.equals(other._defaultTreatment)
&& _parsedCondition.equals(other._parsedCondition)
&& (_trafficTypeName == null ? other._trafficTypeName == null : _trafficTypeName.equals(other._trafficTypeName))
&& _changeNumber == other._changeNumber
&& _algo == other._algo
&& (_configurations == null ? other._configurations == null : _configurations.equals(other._configurations));
return mSplit.equals(other.mSplit)
&& mSeed == other.mSeed
&& mKilled == other.mKilled
&& mDefaultTreatment.equals(other.mDefaultTreatment)
&& mParsedCondition.equals(other.mParsedCondition)
&& (Objects.equals(mTrafficTypeName, other.mTrafficTypeName))
&& mChangeNumber == other.mChangeNumber
&& mAlgo == other.mAlgo
&& (Objects.equals(mConfigurations, other.mConfigurations))
&& (Objects.equals(mSets, other.mSets));

}

@NonNull
@Override
public String toString() {
return "name:" + _split + ", seed:" + _seed + ", killed:" + _killed +
", default treatment:" + _defaultTreatment +
", parsedConditions:" + _parsedCondition +
", trafficTypeName:" + _trafficTypeName + ", changeNumber:" + _changeNumber +
", algo:" + _algo + ", config:" + _configurations;
return "name:" + mSplit + ", seed:" + mSeed + ", killed:" + mKilled +
", default treatment:" + mDefaultTreatment +
", parsedConditions:" + mParsedCondition +
", trafficTypeName:" + mTrafficTypeName + ", changeNumber:" + mChangeNumber +
", algo:" + mAlgo + ", config:" + mConfigurations + ", sets:" + mSets;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ParsedSplit parse(@Nullable Split split, @Nullable String matchingKey) {
try {
return parseWithoutExceptionHandling(split, matchingKey);
} catch (Throwable t) {
Logger.e(t, "Could not parse feature flag: %s", split);
Logger.e(t, "Could not parse feature flag: %s", (split != null) ? split.name : "null");
return null;
}
}
Expand Down Expand Up @@ -90,7 +90,18 @@ private ParsedSplit parseWithoutExceptionHandling(Split split, String matchingKe
parsedConditionList.add(new ParsedCondition(condition.conditionType, matcher, partitions, condition.label));
}

return new ParsedSplit(split.name, split.seed, split.killed, split.defaultTreatment, parsedConditionList, split.trafficTypeName, split.changeNumber, split.trafficAllocation, split.trafficAllocationSeed, split.algo, split.configurations);
return new ParsedSplit(split.name,
split.seed,
split.killed,
split.defaultTreatment,
parsedConditionList,
split.trafficTypeName,
split.changeNumber,
split.trafficAllocation,
split.trafficAllocationSeed,
split.algo,
split.configurations,
split.sets);
}

private CombiningMatcher toMatcher(MatcherGroup matcherGroup, String matchingKey) {
Expand Down
Loading