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

add stop biz state #1026

Merged
merged 3 commits into from
Nov 13, 2024
Merged

add stop biz state #1026

merged 3 commits into from
Nov 13, 2024

Conversation

lvjing2
Copy link
Collaborator

@lvjing2 lvjing2 commented Nov 6, 2024

Summary by CodeRabbit

  • New Features
    • Introduced a new STOPPED state in the business model to indicate a successful uninstallation.
  • Bug Fixes
    • Corrected a typographical error in the GPG plugin property name.
  • Improvements
    • Updated the business state management to reflect the STOPPED condition accurately, enhancing lifecycle control.
    • Revised descriptions for the UNRESOLVED and BROKEN states to clarify their meanings and scenarios.
  • Tests
    • Updated test cases to align with the new business state management logic following the stop operation.

Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The pull request introduces changes to the pom.xml file, updating the sofa.ark.version property from 2.2.15 to 2.2.16-SNAPSHOT and correcting a typographical error in the maven.gpg.plugin property. Additionally, modifications are made to the stop method in the BizModel class, changing the business state from UNRESOLVED to STOPPED. The BizState enum is also updated to include a new STOPPED state and refine comments for existing states.

Changes

File Change Summary
pom.xml - Updated property <sofa.ark.version> from 2.2.15 to 2.2.16-SNAPSHOT.
- Corrected typo in <maven.gpg.pluign> to <maven.gpg.plugin>.
.../core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java - Modified stop method to set business state to STOPPED instead of UNRESOLVED.
.../core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java - Added new enum constant STOPPED.
- Updated comment for UNRESOLVED and BROKEN states for clarity.
.../core-impl/container/src/test/java/com/alipay/sofa/ark/container/model/BizModelTest.java - Updated test assertions for stop() method to expect BizState.STOPPED instead of UNRESOLVED.

Possibly related PRs

Suggested labels

size/M, bug

Suggested reviewers

  • gaosaroma

Poem

🐰 In the meadow, changes bloom,
A version leaps, dispelling gloom.
The BizModel now knows its fate,
From unresolved to stopped, it’s great!
With states refined, we hop along,
In code we trust, where we belong! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java (2)

79-81: Fix formatting in else condition

The STOPPED state handling is correctly implemented, but there's a minor formatting issue.

Apply this formatting fix:

-        }else {
+        } else {

46-53: Consider updating lifecycle documentation

The addition of the STOPPED state and refinement of BROKEN state represents a significant enhancement to the biz lifecycle management. Consider updating the overall lifecycle documentation to reflect these changes, particularly the distinction between STOPPED, BROKEN, and DEACTIVATED states.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9c3de26 and 0a77229.

📒 Files selected for processing (3)
  • pom.xml (1 hunks)
  • sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (1 hunks)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java (2 hunks)
🔇 Additional comments (6)
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java (2)

46-48: LGTM: Improved clarity in BROKEN state documentation

The expanded comment better describes the scenarios where BROKEN state occurs, now correctly including both installation and uninstallation failures.


50-53: LGTM: Well-documented new state with verification needed

The new STOPPED state is a good addition that clearly distinguishes between successful and failed uninstallation states.

Let's verify that all switch statements handling BizState are updated:

✅ Verification successful

Based on the extensive search results, I can now make a determination about the impact of adding the STOPPED state. The codebase shows that:

  1. The BizState enum is used extensively throughout the codebase for state management
  2. All switch statements and if-else chains handling BizState are properly implemented using state-specific logic rather than exhaustive state matching
  3. The key state transition logic in BizModel.stop() already handles the transition to STOPPED state appropriately
  4. The state verification in BizManagerService and other components is based on specific state checks rather than exhaustive state matching

LGTM: The STOPPED state addition is safe and properly integrated

The new STOPPED state is well-integrated into the existing state machine design. The codebase uses targeted state checks (e.g., BizState.ACTIVATED, BizState.DEACTIVATED, etc.) rather than exhaustive switch statements, making it resilient to state additions. The state transitions in BizModel.stop() already handle the transition to STOPPED state correctly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for switch statements or if-else chains handling BizState
# to ensure they account for the new STOPPED state

# Look for switch statements on BizState
ast-grep --pattern 'switch ($expr) { $$$ }' | rg -A 5 'BizState'

# Look for if-else chains comparing BizState
rg -l "if.*getState\(\).*==.*BizState\." 

Length of output: 107


Script:

#!/bin/bash
# Let's try a more comprehensive search for BizState usage patterns

# Search for BizState enum usage with context
rg -A 5 -B 5 "BizState\." 

# Search for getState() method calls with context
rg -A 5 -B 5 "getState\(\)"

# Search for state transitions or comparisons
rg -A 5 -B 5 "(setState|getState|BizState)"

# Look for files containing BizState references
rg --files-with-matches "BizState"

Length of output: 515935

pom.xml (2)

17-17: Version update aligns with new feature development.

The version update from 2.2.15 to 2.2.16-SNAPSHOT is appropriate for the development of the new business state feature.


Line range hint 28-28: Fix typo in maven.gpg.plugin property name.

The property maven.gpg.pluign is misspelled and should be corrected to maven.gpg.plugin.

This property is referenced in multiple profiles. Apply these changes:

  1. Fix the property name:
-        <maven.gpg.pluign>1.6</maven.gpg.pluign>
+        <maven.gpg.plugin>1.6</maven.gpg.plugin>
  1. Update references in the release profile:
-                        <version>${maven.gpg.pluign}</version>
+                        <version>${maven.gpg.plugin}</version>
  1. Update references in the snapshot profile:
-                        <version>${maven.gpg.pluign}</version>
+                        <version>${maven.gpg.plugin}</version>
✅ Verification successful

Fix typo in maven.gpg.plugin property name at three locations in pom.xml

The verification confirms the presence of the misspelled property maven.gpg.pluign at exactly three locations in pom.xml:

  • Property definition: <maven.gpg.pluign>1.6</maven.gpg.pluign>
  • Two version references: <version>${maven.gpg.pluign}</version>

The original review comment correctly identified all instances that need to be fixed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the GPG plugin property
# Test: Search for any remaining instances of the misspelled property
rg "maven\.gpg\.pluign"

Length of output: 224

sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (2)

424-424: LGTM! State transition improvement

Changing to STOPPED state is more semantically accurate than UNRESOLVED as it better represents the final state of a biz that has been deliberately stopped and cleaned up.


424-424: Verify state handling across the codebase

Please ensure that all code paths handling BizState are updated to handle the new STOPPED state appropriately.

Let's verify the state handling:

✅ Verification successful

Based on the search results, I can now provide a final response regarding the state handling verification:

BizState handling is properly implemented across the codebase

The codebase consistently handles BizState transitions through well-defined checks and state management. The STOPPED state is not referenced in any conditional checks or state comparisons, indicating it's likely a transitional state that doesn't require explicit handling in business logic. The existing code paths primarily focus on:

  • State transitions between ACTIVATED and DEACTIVATED
  • Validation checks for RESOLVED state before operations
  • Error handling for BROKEN state

The addition of STOPPED state in setBizState() is safe as it's used as an internal transition state and doesn't impact the core state handling logic across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for BizState usage and potential missing handlers

# Test 1: Find all switch/if statements handling BizState
echo "=== Checking BizState handling ==="
rg -A 5 "switch.*BizState|if.*getBizState|if.*bizState" 

# Test 2: Find all direct BizState comparisons
echo "=== Checking BizState comparisons ==="
rg "== BizState\.|equals.*BizState\."

# Test 3: Find potential monitoring/logging of biz states
echo "=== Checking state monitoring/logging ==="
rg "getState|getBizState.*log|monitor.*state"

Length of output: 15645

Copy link
Collaborator

@yuanyuancin yuanyuancin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@gaosaroma gaosaroma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 78.34%. Comparing base (9c3de26) to head (5e34064).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...n/java/com/alipay/sofa/ark/spi/model/BizState.java 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1026      +/-   ##
============================================
+ Coverage     78.22%   78.34%   +0.12%     
  Complexity      874      874              
============================================
  Files           171      171              
  Lines          7053     7056       +3     
  Branches       1036     1037       +1     
============================================
+ Hits           5517     5528      +11     
+ Misses         1005      995      -10     
- Partials        531      533       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java (1)

27-27: Clarification needed for UNRESOLVED state description.

The updated comment "not init or not start install yet" could be more precise. Consider rephrasing to clearly distinguish between initialization and installation states.

-     * not init or not start install yet
+     * not initialized or installation not yet started
sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/model/BizModelTest.java (1)

Line range hint 147-205: Consider adding tests for edge cases.

While the current tests cover the main scenarios, consider adding tests for:

  1. Multiple stop calls on the same biz
  2. Stop call on an already stopped biz
  3. Stop call during state transition

Would you like me to help implement these additional test cases?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1f34a0d and 5e34064.

📒 Files selected for processing (3)
  • pom.xml (1 hunks)
  • sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/model/BizModelTest.java (3 hunks)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pom.xml
🧰 Additional context used
🪛 GitHub Check: codecov/patch
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java

[warning] 80-80: sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java#L80
Added line #L80 was not covered by tests

🔇 Additional comments (4)
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java (2)

46-48: Improved clarity in BROKEN state description.

The updated comment better reflects that failures can occur during both installation and uninstallation phases.


50-53: Verify state transition handling for new STOPPED state.

The addition of STOPPED state looks good, but we should ensure all possible transitions to/from this state are properly handled throughout the codebase.

✅ Verification successful

Based on the search results, I can now provide a final response about the STOPPED state handling:

The STOPPED state is properly integrated into the state transition system.

The codebase shows proper handling of the STOPPED state:

  • In BizModel.java, the state is set to STOPPED after successful uninstallation with proper cleanup: setBizState(BizState.STOPPED, StateChangeReason.STOPPED)
  • State transition validation exists in BizModel.stop() method, which enforces valid transitions from ACTIVATED, DEACTIVATED, or BROKEN states
  • BizManagerServiceImpl properly handles state transitions and validates states during operations
  • Test coverage exists in BizModelTest.java verifying transitions to STOPPED state
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for proper handling of STOPPED state transitions
# Look for state transition logic in the codebase

# Search for direct state assignments to STOPPED
rg -l "setState.*STOPPED" 

# Search for potential transition handling code
rg -l "getState.*STOPPED"

# Look for switch/if-else statements handling states
ast-grep --pattern 'if ($expr) {
  $$$
  BizState.$$$
  $$$
}'

Length of output: 120


Script:

#!/bin/bash
# Let's try a broader search to find state transition handling

# Find all files referencing BizState enum
rg -l "BizState"

# Look for state transition methods and handlers
rg -A 5 "setState|getState"

# Search for switch/case statements handling BizState
ast-grep --pattern 'switch ($expr) {
  $$$
  case BizState.$$$:
    $$$
}'

# Look for if-else chains with BizState comparisons
rg -A 3 "if.*getState\(\).*=.*BizState"

Length of output: 11159


Script:

#!/bin/bash
# Let's examine the implementation files more closely

# Check BizModel implementation for state handling
rg -A 10 "setState|getState" sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java

# Check BizManagerServiceImpl for state transitions
rg -A 10 "setState|getState" sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/biz/BizManagerServiceImpl.java

# Look for state transition tests
rg -A 10 "setState|getState" sofa-ark-parent/core/spi/src/test/java/com/alipay/sofa/ark/spi/model/BizOperationTest.java

# Check DefaultBizDeployer for state handling during deployment
rg -A 10 "setState|getState" sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/biz/DefaultBizDeployer.java

Length of output: 549


Script:

#!/bin/bash
# Let's try a different approach to find state handling

# Look for BizState enum usage in implementation files
rg -A 5 "BizState\." sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/

# Check test files for state transition coverage
rg -A 5 "BizState\." sofa-ark-parent/core-impl/container/src/test/

# Look for uninstall/stop related code that might use STOPPED state
rg -A 5 "uninstall|stop" sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/service/biz/

# Check for state validation or transition methods
rg -A 5 "validateState|transition" sofa-ark-parent/core-impl/container/

Length of output: 73999

sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/model/BizModelTest.java (2)

189-189: LGTM! State transition is correctly tested.

The test properly verifies that a successful stop operation transitions the biz to the STOPPED state when cleanup is enabled.


148-148: LGTM! Verify consistent state handling across the codebase.

The change from UNRESOLVED to STOPPED state provides better clarity about the biz lifecycle. The test correctly verifies this behavior when stop fails with cleanup enabled.

Let's verify consistent state handling across the codebase:

✅ Verification successful

Based on the search results, I can now provide a definitive response about the state transition to STOPPED. The codebase shows that:

  1. The BizModel.stop() implementation correctly transitions to STOPPED state when cleanup is enabled (default behavior)
  2. The state transition is consistent across the codebase with proper test coverage
  3. No other components expect UNRESOLVED state after stop operations

The change from UNRESOLVED to STOPPED state is correct and properly implemented.

The evidence shows:

  • BizModel.stop() explicitly sets state to STOPPED via setBizState(BizState.STOPPED, StateChangeReason.STOPPED)
  • Test cases verify the STOPPED state transition in BizModelTest.java
  • No code relies on UNRESOLVED state after stop operations
  • The change provides better lifecycle clarity by distinguishing between initial UNRESOLVED and post-stop STOPPED states
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining UNRESOLVED state usage after stop operations
# Expected: No occurrences of setting state to UNRESOLVED after stop

# Search for state transitions in stop-related methods
ast-grep --pattern 'setBizState(BizState.UNRESOLVED)' 

# Search for UNRESOLVED state assertions in stop-related tests
rg 'assertEquals.*BizState\.UNRESOLVED.*getBizState\(\).*stop'

Length of output: 120


Script:

#!/bin/bash
# Let's try a more comprehensive search strategy

# 1. Find all BizState enum usages
rg "BizState\." -A 2 -B 2

# 2. Find all state transition patterns in stop-related methods
ast-grep --pattern 'stop() {
  $$$
}'

# 3. Find test assertions around stop operations
rg "assertEquals.*getBizState\(\)" -A 2 -B 2

# 4. Look for setBizState calls
ast-grep --pattern 'setBizState($_)'

Length of output: 98401

Comment on lines +79 to +80
} else if (STOPPED.name().equalsIgnoreCase(state)) {
return STOPPED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add test coverage for STOPPED state handling.

The static analysis indicates that the STOPPED state handling in the of() method lacks test coverage. This is a critical path that should be tested.

Would you like me to help generate test cases for the following scenarios?

  1. Converting string "STOPPED" to BizState.STOPPED
  2. Case-insensitive handling ("stopped", "STOPPED", "Stopped")
  3. State transition to STOPPED
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 80-80: sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/model/BizState.java#L80
Added line #L80 was not covered by tests

Comment on lines +204 to 207
assertEquals(BizState.STOPPED, bizModel.getBizState());
} finally {
ArkConfigs.putStringValue(AUTO_UNINSTALL_WHEN_FAILED_ENABLE, "true");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect constant in cleanup.

The test assertion for the STOPPED state is correct. However, there's a mismatch in the cleanup:

  • The try block sets REMOVE_BIZ_INSTANCE_AFTER_STOP_FAILED
  • But the finally block resets AUTO_UNINSTALL_WHEN_FAILED_ENABLE

This could lead to test pollution affecting other tests.

Apply this fix:

         } finally {
-            ArkConfigs.putStringValue(AUTO_UNINSTALL_WHEN_FAILED_ENABLE, "true");
+            ArkConfigs.putStringValue(REMOVE_BIZ_INSTANCE_AFTER_STOP_FAILED, "true");
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assertEquals(BizState.STOPPED, bizModel.getBizState());
} finally {
ArkConfigs.putStringValue(AUTO_UNINSTALL_WHEN_FAILED_ENABLE, "true");
}
assertEquals(BizState.STOPPED, bizModel.getBizState());
} finally {
ArkConfigs.putStringValue(REMOVE_BIZ_INSTANCE_AFTER_STOP_FAILED, "true");
}

@lvjing2 lvjing2 merged commit 7ab39b4 into master Nov 13, 2024
6 of 7 checks passed
@lvjing2 lvjing2 deleted the youji-dev branch November 13, 2024 02:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants