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

feat: undeploy endpoints #14456

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

feat: undeploy endpoints #14456

wants to merge 5 commits into from

Conversation

mirkoSekulic
Copy link
Collaborator

@mirkoSekulic mirkoSekulic commented Jan 20, 2025

  • add quartz and quartz migrations script
  • quartz migrations pipeline

Description

Related Issue(s)

  • #{issue number}

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

Release Notes

  • New Features

    • Added an endpoint for undeploying applications
    • Introduced Quartz library for job scheduling
  • Infrastructure

    • Added GitHub Actions workflow to check Quartz library updates
    • Updated Quartz library to version 3.13.1
    • Added new database tables for Quartz scheduling
  • Technical Improvements

    • Created new data transfer object for undeploy requests

Copy link

coderabbitai bot commented Jan 20, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive update to the Quartz library and related infrastructure in the Altinn Studio Designer project. The changes include adding a new GitHub Actions workflow to check Quartz library updates, updating the Quartz package version to 3.13.1, creating new PostgreSQL database tables for Quartz scheduling, and adding an initial implementation for an application undeployment endpoint. The workflow ensures that SQL migration files are consistent with the library update.

Changes

File Change Summary
.github/workflows/desiger-check-quartz-update.yml New GitHub Actions workflow to validate Quartz library updates
backend/packagegroups/NuGet.props Added Quartz package reference (v3.13.1), removed upgrade comment
backend/src/Designer/Controllers/DeploymentsController.cs Added Undeploy method with placeholder implementation
backend/src/Designer/Designer.csproj Added Quartz package reference
backend/src/Designer/Migrations/SqlScripts/QuartzTables/tables_postgres.sql Created new Quartz-related database tables for PostgreSQL
backend/src/Designer/Models/Dto/UndeployRequest.cs New DTO class for undeploy request with EnvironmentName property

Possibly related PRs

Suggested labels

area/app-deploy, solution/studio/designer, quality/testing, backend

Suggested reviewers

  • framitdavid
  • github-actions

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@mirkoSekulic mirkoSekulic marked this pull request as draft January 20, 2025 11:21
@github-actions github-actions bot added area/app-deploy Area: Related to deploying apps from Altinn Studio to Altinn Apps. solution/studio/designer Issues related to the Altinn Studio Designer solution. skip-releasenotes Issues that do not make sense to list in our release notes backend kind/dependencies Used for issues or pull requests that are dependency updates labels Jan 20, 2025
@mirkoSekulic mirkoSekulic force-pushed the feature/undeploy-endpoint branch from b9ce245 to 38baac0 Compare January 20, 2025 11:23
Copy link

@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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 7

🧹 Nitpick comments (2)
backend/src/Designer/Controllers/DeploymentsController.cs (1)

120-123: Implement the undeploy functionality.

The current implementation throws NotImplementedException. Please implement the actual undeployment logic or create a tracking issue for this task.

Would you like me to help create a tracking issue for implementing the undeployment logic?

backend/src/Designer/Migrations/SqlScripts/QuartzTables/tables_postgres.sql (1)

15-158: Consider adding table partitioning for qrtz_fired_triggers.

The table structure is correct and follows Quartz's schema. However, for large-scale deployments, the qrtz_fired_triggers table can grow significantly. Consider implementing table partitioning by fired_time to improve query performance and maintenance.

🛑 Comments failed to post (7)
backend/src/Designer/Models/Dto/UndeployRequest.cs (1)

3-9: 🛠️ Refactor suggestion

Add validation attributes to ensure data integrity.

Consider adding validation attributes to ensure the EnvironmentName is not null or empty:

 public class UndeployRequest
 {
     /// <summary>
     /// Environment name in which the deployment should be undeployed
     /// </summary>
+    [Required(ErrorMessage = "Environment name is required")]
+    [StringLength(50, ErrorMessage = "Environment name cannot exceed 50 characters")]
     public string EnvironmentName { get; set; }
 }
📝 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.

public class UndeployRequest
{
    /// <summary>
    /// Environment name in which the deployment should be undeployed
    /// </summary>
    [Required(ErrorMessage = "Environment name is required")]
    [StringLength(50, ErrorMessage = "Environment name cannot exceed 50 characters")]
    public string EnvironmentName { get; set; }
}
backend/packagegroups/NuGet.props (1)

52-52: 💡 Codebase verification

Fix invalid fetch-depth value in Quartz update workflow

The workflow file has an invalid fetch-depth: 0d value that would cause checkout failures. Additionally, the Git diff command implementation could be more robust.

  • .github/workflows/desiger-check-quartz-update.yml:
    • Remove the 'd' suffix from fetch-depth: 0d
    • Consider using a more robust diff command: git diff -U0 HEAD^ HEAD -- backend/packagegroups/NuGet.props | grep '^[+].*Quartz.*Version'
🔗 Analysis chain

Fix the Git diff command in the Quartz update check workflow.

The pipeline failure indicates an issue with the Git diff command. This needs to be addressed in the workflow file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the Quartz package reference exists and is properly formatted
rg -U 'PackageReference.*Quartz.*Version="[0-9]+\.[0-9]+\.[0-9]+"' backend/packagegroups/NuGet.props

Length of output: 160


Script:

#!/bin/bash
# Find workflow files containing Quartz-related update checks
fd -e yml -e yaml . .github/workflows/ -x rg -l -i 'quartz.*diff|diff.*quartz' {}

Length of output: 135


Script:

#!/bin/bash
# Display the content of the Quartz update check workflow
cat .github/workflows/desiger-check-quartz-update.yml

Length of output: 2115

🧰 Tools
🪛 GitHub Actions: Dotnet format check

[error] Git diff command failed while checking for Quartz version updates, resulting in a non-zero exit code (1)

backend/src/Designer/Controllers/DeploymentsController.cs (1)

117-123: 🛠️ Refactor suggestion

Add XML documentation for the new endpoint.

Add XML documentation to describe the endpoint's purpose, parameters, and return type:

+        /// <summary>
+        /// Undeploys an application from the specified environment
+        /// </summary>
+        /// <param name="org">Organisation name</param>
+        /// <param name="app">Application name</param>
+        /// <param name="undeployRequest">Request containing the environment name</param>
+        /// <param name="cancellationToken">Cancellation token</param>
+        /// <returns>IActionResult indicating success or failure</returns>
         [HttpPost("undeploy")]
         [Authorize(Policy = AltinnPolicy.MustHaveGiteaDeployPermission)]
         public async Task<IActionResult> Undeploy(string org, string app, [FromBody] UndeployRequest undeployRequest, CancellationToken cancellationToken)
📝 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.

        /// <summary>
        /// Undeploys an application from the specified environment
        /// </summary>
        /// <param name="org">Organisation name</param>
        /// <param name="app">Application name</param>
        /// <param name="undeployRequest">Request containing the environment name</param>
        /// <param name="cancellationToken">Cancellation token</param>
        /// <returns>IActionResult indicating success or failure</returns>
        [HttpPost("undeploy")]
        [Authorize(Policy = AltinnPolicy.MustHaveGiteaDeployPermission)]
        public async Task<IActionResult> Undeploy(string org, string app, [FromBody] UndeployRequest undeployRequest, CancellationToken cancellationToken)
        {
            await Task.CompletedTask;
            throw new NotImplementedException();
        }
.github/workflows/desiger-check-quartz-update.yml (3)

20-22: ⚠️ Potential issue

Update the checkout action version and fix the fetch-depth value.

The current version of actions/checkout is outdated, and there's a typo in the fetch-depth value:

-        uses: actions/checkout@v2
+        uses: actions/checkout@v4
         with:
-          fetch-depth: 0d
+          fetch-depth: 0
📝 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.

        uses: actions/checkout@v4
        with:
          fetch-depth: 0
🧰 Tools
🪛 actionlint (1.7.4)

20-20: the runner of "actions/checkout@v2" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


26-32: ⚠️ Potential issue

Fix shell script quoting and error handling.

Add proper quoting and error handling to prevent word splitting and ensure script reliability:

         run: |
+          set -euo pipefail
-          diff=$(git diff --unified=0 backend/packagegroups/NuGet.props | grep + | grep Quartz | grep Version)
+          diff="$(git diff --unified=0 "backend/packagegroups/NuGet.props" | grep "+" | grep "Quartz" | grep "Version" || true)"
           if [ -n "$diff" ]; then
-            echo "is-updated=true" >> $GITHUB_OUTPUT
+            echo "is-updated=true" >> "$GITHUB_OUTPUT"
           else
-            echo "is-updated=false" >> $GITHUB_OUTPUT
+            echo "is-updated=false" >> "$GITHUB_OUTPUT"
           fi
📝 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.

        run: |
          set -euo pipefail
          diff="$(git diff --unified=0 "backend/packagegroups/NuGet.props" | grep "+" | grep "Quartz" | grep "Version" || true)"
          if [ -n "$diff" ]; then
            echo "is-updated=true" >> "$GITHUB_OUTPUT"
          else
            echo "is-updated=false" >> "$GITHUB_OUTPUT"
          fi
🧰 Tools
🪛 actionlint (1.7.4)

26-26: shellcheck reported issue in this script: SC2086:info:3:29: Double quote to prevent globbing and word splitting

(shellcheck)


26-26: shellcheck reported issue in this script: SC2086:info:5:30: Double quote to prevent globbing and word splitting

(shellcheck)


44-57: 🛠️ Refactor suggestion

Improve error handling and add descriptive error messages.

Add better error handling and descriptive messages for the SQL verification:

         run: |
+          set -euo pipefail
+
           download_url=$(curl https://api.github.com/repos/quartznet/quartznet/releases/tags/v${{ steps.get-quartz-version.outputs.quartz-version }} | \
             jq -r '.assets[] | select(.name | contains("Quartz.NET-${{ steps.get-quartz-version.outputs.quartz-version }}.zip")) | .browser_download_url')
 
+          if [ -z "$download_url" ]; then
+            echo "Error: Failed to get download URL for Quartz.NET release"
+            exit 1
+          fi
+
           mkdir qdwn
           curl -L -o qdwn/quartz.zip $download_url && unzip qdwn/quartz.zip && rm qdwn/quartz.zip
 
-          diff=$(diff -u backend/src/Designer/Migrations/Quartz/tables_postgres.sql qdwn/database/tables/tables_postgres.sql)
+          if ! diff -u "backend/src/Designer/Migrations/Quartz/tables_postgres.sql" "qdwn/database/tables/tables_postgres.sql" > diff.txt; then
+            echo "Error: SQL tables are not in sync with Quartz.NET release"
+            cat diff.txt
+            exit 1
+          fi
 
-          if [ -n "$diff" ]; then
-            exit 1;
-          else
-            echo "Tables file is up to date"
-          fi
+          echo "Tables file is up to date"
📝 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.

        run: |
          set -euo pipefail

          download_url=$(curl https://api.github.com/repos/quartznet/quartznet/releases/tags/v${{ steps.get-quartz-version.outputs.quartz-version }} | \
            jq -r '.assets[] | select(.name | contains("Quartz.NET-${{ steps.get-quartz-version.outputs.quartz-version }}.zip")) | .browser_download_url')

          if [ -z "$download_url" ]; then
            echo "Error: Failed to get download URL for Quartz.NET release"
            exit 1
          fi

          mkdir qdwn
          curl -L -o qdwn/quartz.zip $download_url && unzip qdwn/quartz.zip && rm qdwn/quartz.zip

          if ! diff -u "backend/src/Designer/Migrations/Quartz/tables_postgres.sql" "qdwn/database/tables/tables_postgres.sql" > diff.txt; then
            echo "Error: SQL tables are not in sync with Quartz.NET release"
            cat diff.txt
            exit 1
          fi

          echo "Tables file is up to date"
🧰 Tools
🪛 actionlint (1.7.4)

44-44: shellcheck reported issue in this script: SC2086:info:5:28: Double quote to prevent globbing and word splitting

(shellcheck)

backend/src/Designer/Designer.csproj (1)

58-58: 💡 Codebase verification

Quartz implementation is missing

The Quartz package is referenced in the project file, but the required implementation is missing. You need to:

  1. Add Quartz services configuration in Program.cs
  2. Configure PostgreSQL job store
  3. Register job classes with dependency injection

Example configuration to add in ConfigureServices:

services.AddQuartz(q => {
    q.UsePersistentStore(s => {
        s.UsePostgres();
    });
});
services.AddQuartzHostedService();
🔗 Analysis chain

Verify Quartz configuration in startup code.

The Quartz package is properly referenced. However, ensure that:

  1. Quartz is properly configured in the startup code
  2. PostgreSQL job store is configured
  3. Job classes are registered with dependency injection
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for Quartz configuration in startup code
rg -l "AddQuartz|UseQuartz" --type cs

# Search for job store configuration
ast-grep --pattern 'UsePostgres($$$)' 

Length of output: 79


Script:

#!/bin/bash
# Find Program.cs and Startup.cs files
fd "Program.cs|Startup.cs" --type f

# Search for Quartz namespace usage
rg "using.*Quartz" --type cs

# Search for IJob implementations
ast-grep --pattern 'class $_ : IJob'

# Search for any Quartz-related configuration
rg "services\..*Quartz" --type cs

Length of output: 219


Script:

#!/bin/bash
# Check Program.cs content
cat backend/src/Designer/Program.cs

Length of output: 14857

@mirkoSekulic mirkoSekulic force-pushed the feature/undeploy-endpoint branch from 88da021 to d434869 Compare January 20, 2025 11:51
@mirkoSekulic mirkoSekulic force-pushed the feature/undeploy-endpoint branch 10 times, most recently from b9f580a to 321dacd Compare January 20, 2025 12:43
@mirkoSekulic mirkoSekulic force-pushed the feature/undeploy-endpoint branch from 321dacd to a590794 Compare January 20, 2025 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/app-deploy Area: Related to deploying apps from Altinn Studio to Altinn Apps. backend kind/dependencies Used for issues or pull requests that are dependency updates skip-releasenotes Issues that do not make sense to list in our release notes solution/studio/designer Issues related to the Altinn Studio Designer solution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant