-
Notifications
You must be signed in to change notification settings - Fork 826
[JAV-406]add fallback from cache and used customized cache strategies #172
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
453a97f
[JAV-406]add fallback from cache and used customized cache strategies
liubao68 c4f1952
[JAV-406]add fallback from cache and used customized cache strategies
liubao68 b21fae1
[JAV-406]add fallback from cache and used customized cache strategies
liubao68 4a9c5cd
[JAV-406]add fallback from cache and used customized cache strategies
liubao68 6df98c9
[JAV-406]add fallback from cache and used customized cache strat
liubao68 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
37 changes: 37 additions & 0 deletions
37
...gmvc-client/src/main/java/io/servicecomb/demo/springmvc/client/MockedFallbackExample.java
This file contains hidden or 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,37 @@ | ||
/* | ||
* Copyright 2017 Huawei Technologies Co., Ltd | ||
* | ||
* 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 io.servicecomb.demo.springmvc.client; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import io.servicecomb.bizkeeper.FallbackPolicy; | ||
import io.servicecomb.core.Invocation; | ||
import io.servicecomb.swagger.invocation.Response; | ||
|
||
@Component | ||
public class MockedFallbackExample implements FallbackPolicy { | ||
|
||
@Override | ||
public String name() { | ||
return "mycustom"; | ||
} | ||
|
||
@Override | ||
public Response getFallbackResponse(Invocation invocation) { | ||
return Response.succResp("mockedreslut"); | ||
} | ||
|
||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
31 changes: 31 additions & 0 deletions
31
handlers/handler-bizkeeper/src/main/java/io/servicecomb/bizkeeper/BeansHolder.java
This file contains hidden or 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,31 @@ | ||
/* | ||
* Copyright 2017 Huawei Technologies Co., Ltd | ||
* | ||
* 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 io.servicecomb.bizkeeper; | ||
|
||
import java.util.List; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class BeansHolder { | ||
@Inject | ||
private List<FallbackPolicy> policies; | ||
|
||
public void init() { | ||
for (FallbackPolicy policy : this.policies) { | ||
FallbackPolicyManager.addPolicy(policy); | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
handlers/handler-bizkeeper/src/main/java/io/servicecomb/bizkeeper/FallbackPolicy.java
This file contains hidden or 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,29 @@ | ||
/* | ||
* Copyright 2017 Huawei Technologies Co., Ltd | ||
* | ||
* 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 io.servicecomb.bizkeeper; | ||
|
||
import io.servicecomb.core.Invocation; | ||
import io.servicecomb.swagger.invocation.Response; | ||
|
||
public interface FallbackPolicy { | ||
String name(); | ||
|
||
Response getFallbackResponse(Invocation invocation); | ||
|
||
default void record(Invocation invocation, Response response, boolean isSuccess) { | ||
|
||
}; | ||
} |
61 changes: 61 additions & 0 deletions
61
handlers/handler-bizkeeper/src/main/java/io/servicecomb/bizkeeper/FallbackPolicyManager.java
This file contains hidden or 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,61 @@ | ||
/* | ||
* Copyright 2017 Huawei Technologies Co., Ltd | ||
* | ||
* 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 io.servicecomb.bizkeeper; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.servicecomb.core.Invocation; | ||
import io.servicecomb.swagger.invocation.Response; | ||
|
||
public class FallbackPolicyManager { | ||
private static final Map<String, FallbackPolicy> POLICIES = new HashMap<>(); | ||
|
||
public static void addPolicy(FallbackPolicy policy) { | ||
POLICIES.put(policy.name().toLowerCase(), policy); | ||
} | ||
|
||
public static void record(String type, Invocation invocation, Response response, boolean isSuccess) { | ||
FallbackPolicy policy = getPolicy(type, invocation); | ||
if (policy != null) { | ||
policy.record(invocation, response, isSuccess); | ||
} | ||
} | ||
|
||
public static Response getFallbackResponse(String type, Invocation invocation) { | ||
FallbackPolicy policy = getPolicy(type, invocation); | ||
if (policy != null) { | ||
return policy.getFallbackResponse(invocation); | ||
} else { | ||
return Response.failResp(invocation.getInvocationType(), | ||
BizkeeperExceptionUtils | ||
.createBizkeeperException(BizkeeperExceptionUtils.CSE_HANDLER_BK_FALLBACK, | ||
null, | ||
invocation.getOperationMeta().getMicroserviceQualifiedName())); | ||
} | ||
} | ||
|
||
private static FallbackPolicy getPolicy(String type, Invocation invocation) { | ||
String policyKey = Configuration.INSTANCE.getFallbackPolicyPolicy(type, | ||
invocation.getMicroserviceName(), | ||
invocation.getOperationMeta().getMicroserviceQualifiedName()); | ||
FallbackPolicy policy = null; | ||
if (policyKey != null) { | ||
policy = POLICIES.get(policyKey.toLowerCase()); | ||
} | ||
return policy; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use the constant string.