-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
279 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/FooService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FooService { | ||
|
||
private final VendorServiceFactory vendorServiceFactory; | ||
|
||
public String step1(RequestModel request) { | ||
VendorService vendorService = vendorServiceFactory.findTargetVendor(request); | ||
try { | ||
return vendorService.step1() + " -> "; | ||
} catch (Exception e) { | ||
return "X -> "; | ||
} | ||
} | ||
|
||
public String step2(RequestModel request) { | ||
VendorService vendorService = vendorServiceFactory.findTargetVendor(request); | ||
try { | ||
return vendorService.step2() + " -> "; | ||
} catch (Exception e) { | ||
return "X -> "; | ||
} | ||
} | ||
|
||
public String step3(RequestModel request) { | ||
VendorService vendorService = vendorServiceFactory.findTargetVendor(request); | ||
try { | ||
return vendorService.step3(); | ||
} catch (Exception e) { | ||
return "X"; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/LargeScaleChangeDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LargeScaleChangeDemo { | ||
public static final String FLAG_KEY = "lsc"; | ||
public static final String USER_ID_KEY = "userId"; | ||
|
||
private final FooService fooService; | ||
|
||
public void iteration(int times) { | ||
// release toggle for non-prepared feature | ||
// permission toggle for tester to test | ||
// operation toggle for canary release | ||
|
||
int i = 1; | ||
while (i <= times) { | ||
RequestModel request = getRequestModel(i); | ||
System.out.print(i + "\t:"); | ||
// step1 | ||
System.out.print(fooService.step1(request)); | ||
|
||
// step2 | ||
System.out.print(fooService.step2(request)); | ||
|
||
// step3 | ||
System.out.print(fooService.step3(request)); | ||
if (i % 5 == 0) { | ||
System.out.println(); | ||
} else { | ||
System.out.print("\t\t"); | ||
} | ||
i++; | ||
} | ||
|
||
|
||
} | ||
|
||
private static RequestModel getRequestModel(int i) { | ||
return new RequestModel( | ||
String.valueOf(i), | ||
getA(i)); | ||
} | ||
|
||
private static LevelName getA(int i) { | ||
if (i %10 == 0) return LevelName.VIP; | ||
return LevelName.NORMAL; | ||
} | ||
|
||
|
||
} |
13 changes: 13 additions & 0 deletions
13
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/LevelName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
public enum LevelName { | ||
NORMAL, VIP; | ||
|
||
public boolean isNormal() { | ||
return this == NORMAL; | ||
} | ||
|
||
public boolean isVip() { | ||
return this == VIP; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/RequestModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
public record RequestModel(String userId, LevelName vendor) { | ||
} |
46 changes: 46 additions & 0 deletions
46
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/VendorAV1ServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
import dev.openfeature.sdk.Client; | ||
import dev.openfeature.sdk.MutableContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.example.open.feature.openflagr.client.FeatureToggleApiProvider; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static org.example.open.feature.openflagr.demo.DemoHelper.BLUE; | ||
import static org.example.open.feature.openflagr.demo.DemoHelper.RESET; | ||
import static org.example.open.feature.openflagr.demo.lsc.LargeScaleChangeDemo.FLAG_KEY; | ||
import static org.example.open.feature.openflagr.demo.lsc.LargeScaleChangeDemo.USER_ID_KEY; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class VendorAV1ServiceImpl implements VendorService { | ||
|
||
private final FeatureToggleApiProvider featureToggleApiProvider; | ||
|
||
@Override | ||
public boolean accept(RequestModel request) { | ||
Client client = featureToggleApiProvider.getFlagrApiClient(); | ||
MutableContext evaluationContext = new MutableContext(request.userId()); | ||
evaluationContext.add(USER_ID_KEY, request.userId()); | ||
|
||
boolean isToggleOn = client.getBooleanValue(FLAG_KEY, false, evaluationContext); | ||
|
||
return !isToggleOn && request.vendor().isNormal(); | ||
} | ||
|
||
@Override | ||
public String step1() { | ||
return BLUE + "A1" + RESET; | ||
} | ||
|
||
@Override | ||
public String step2() { | ||
return BLUE + "A2" + RESET; | ||
} | ||
|
||
@Override | ||
public String step3() { | ||
return BLUE + "A3" + RESET; | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/VendorBV1ServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
import dev.openfeature.sdk.Client; | ||
import dev.openfeature.sdk.MutableContext; | ||
import lombok.RequiredArgsConstructor; | ||
import org.example.open.feature.openflagr.client.FeatureToggleApiProvider; | ||
import org.springframework.stereotype.Service; | ||
|
||
import static org.example.open.feature.openflagr.demo.DemoHelper.GREEN; | ||
import static org.example.open.feature.openflagr.demo.DemoHelper.RESET; | ||
import static org.example.open.feature.openflagr.demo.lsc.LargeScaleChangeDemo.FLAG_KEY; | ||
import static org.example.open.feature.openflagr.demo.lsc.LargeScaleChangeDemo.USER_ID_KEY; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class VendorBV1ServiceImpl implements VendorService { | ||
|
||
private final FeatureToggleApiProvider featureToggleApiProvider; | ||
|
||
@Override | ||
public boolean accept(RequestModel request) { | ||
Client client = featureToggleApiProvider.getFlagrApiClient(); | ||
MutableContext evaluationContext = new MutableContext(request.userId()); | ||
evaluationContext.add(USER_ID_KEY, request.userId()); | ||
|
||
boolean isToggleOn = client.getBooleanValue(FLAG_KEY, false, evaluationContext); | ||
|
||
return isToggleOn && request.vendor().isNormal(); | ||
} | ||
|
||
@Override | ||
public String step1() { | ||
return GREEN + "B1" + RESET; | ||
} | ||
|
||
@Override | ||
public String step2() { | ||
// throw new UnsupportedOperationException("not implements yes"); | ||
return GREEN + "B2" + RESET; | ||
} | ||
|
||
@Override | ||
public String step3() { | ||
// throw new UnsupportedOperationException("not implements yes"); | ||
return GREEN + "B3" + RESET; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/VendorSV1ServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import static org.example.open.feature.openflagr.demo.DemoHelper.*; | ||
|
||
@Service | ||
public class VendorSV1ServiceImpl implements VendorService{ | ||
@Override | ||
public boolean accept(RequestModel request) { | ||
return request.vendor().isVip(); | ||
} | ||
|
||
@Override | ||
public String step1() { | ||
return PURPLE + "S1" + RESET; | ||
} | ||
|
||
@Override | ||
public String step2() { | ||
return PURPLE + "S2" + RESET; | ||
} | ||
|
||
@Override | ||
public String step3() { | ||
return PURPLE + "S3" + RESET; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/VendorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
public interface VendorService { | ||
|
||
boolean accept(RequestModel request); | ||
|
||
String step1(); | ||
|
||
String step2(); | ||
|
||
String step3(); | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
demo/src/main/java/org/example/open/feature/openflagr/demo/lsc/VendorServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.example.open.feature.openflagr.demo.lsc; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class VendorServiceFactory { | ||
|
||
private final List<VendorService> vendorServices; | ||
|
||
VendorService findTargetVendor(RequestModel request) { | ||
for (VendorService strategy : vendorServices) { | ||
if (strategy.accept(request)) { | ||
return strategy; | ||
} | ||
} | ||
throw new RuntimeException("no match strategy"); | ||
} | ||
|
||
} |