├── .github ├── labels-manage.yml ├── settings.xml └── workflows │ ├── build-snapshot-worker.yml │ ├── ci-pr.yml │ ├── ci.yml │ ├── issue-handler.yml │ ├── label-manage.yml │ ├── milestone-worker.yml │ ├── next-dev-version-worker.yml │ └── release-worker.yml ├── .gitignore ├── .jdk8 ├── .mvn ├── jvm.config ├── maven.config └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.adoc ├── CONTRIBUTING.adoc ├── LICENSE ├── NOTICE ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── org │ │ └── springframework │ │ └── cloud │ │ └── deployer │ │ └── spi │ │ ├── cloudfoundry │ │ ├── AbstractCloudFoundryDeployer.java │ │ ├── AbstractCloudFoundryTaskLauncher.java │ │ ├── AppNameGenerator.java │ │ ├── CfEnvAwareAppDeploymentRequest.java │ │ ├── CfEnvAwareResource.java │ │ ├── CfEnvConfigurer.java │ │ ├── CloudFoundryActuatorTemplate.java │ │ ├── CloudFoundryAppDeployer.java │ │ ├── CloudFoundryAppInstanceStatus.java │ │ ├── CloudFoundryAppNameGenerator.java │ │ ├── CloudFoundryConnectionProperties.java │ │ ├── CloudFoundryDeployerAutoConfiguration.java │ │ ├── CloudFoundryDeploymentProperties.java │ │ ├── CloudFoundryPlatformSpecificInfo.java │ │ ├── CloudFoundryTaskLauncher.java │ │ ├── DurationConverter.java │ │ ├── ServiceParser.java │ │ └── UnsupportedVersionTaskLauncher.java │ │ └── scheduler │ │ └── cloudfoundry │ │ ├── CloudFoundryAppScheduler.java │ │ ├── CloudFoundryScheduleSSLException.java │ │ ├── CloudFoundrySchedulerProperties.java │ │ └── expression │ │ └── QuartzCronExpression.java └── resources │ └── META-INF │ ├── additional-spring-configuration-metadata.json │ ├── spring.factories │ └── spring │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports ├── scripts ├── next-minor-parent-snapshot-version ├── next-minor-snapshot-version ├── next-parent-snapshot-version └── next-snapshot-version └── test ├── java └── org │ └── springframework │ └── cloud │ └── deployer │ └── spi │ ├── cloudfoundry │ ├── AbstractAppDeployerTestSupport.java │ ├── CfEnvAwareResourceTests.java │ ├── CfEnvConfigurerTests.java │ ├── CloudFoundryActuatorTemplateTests.java │ ├── CloudFoundryAppDeployerIntegrationIT.java │ ├── CloudFoundryAppDeployerTests.java │ ├── CloudFoundryAppNameGeneratorTest.java │ ├── CloudFoundryConnectionPropertiesTests.java │ ├── CloudFoundryDeployerTests.java │ ├── CloudFoundryTaskLauncherCachingTests.java │ ├── CloudFoundryTaskLauncherIntegrationIT.java │ ├── CloudFoundryTaskLauncherTests.java │ └── ServiceParserTests.java │ └── scheduler │ └── cloudfoundry │ ├── CloudFoundryAppSchedulerTests.java │ ├── CloudFoundryScheduleSSLExceptionTests.java │ ├── CloudFoundrySchedulerPropertiesTest.java │ ├── SpringCloudSchedulerIntegrationIT.java │ └── expression │ └── QuartzCronExpressionTests.java └── resources ├── actuator-binding-input.json ├── actuator-bindings.json ├── actuator-info.json ├── batch-job-1.0.0.BUILD-SNAPSHOT.jar ├── demo-0.0.1-SNAPSHOT.jar ├── http-source-rabbit-2.1.5.RELEASE.jar ├── log-sink-rabbit-3.0.0.BUILD-SNAPSHOT.jar ├── logback-test.xml ├── long-running-task-1.0.0.BUILD-SNAPSHOT.jar ├── test-application.zip ├── timestamp-task-1.0.0.BUILD-SNAPSHOT-exec-2.jar ├── timestamp-task-1.0.0.BUILD-SNAPSHOT-exec-3.jar └── timestamp-task-1.0.0.BUILD-SNAPSHOT-exec.jar /.github/labels-manage.yml: -------------------------------------------------------------------------------- 1 | - name: area/dependencies 2 | color: F9D0C4 3 | description: Belongs project dependencies 4 | - name: area/documentation 5 | color: F9D0C4 6 | description: Belongs to documentation 7 | - name: area/tests 8 | color: F9D0C4 9 | description: Belongs to tests 10 | 11 | - name: automation/rlnotes-header 12 | color: EDEDED 13 | description: Belongs to release notes automation 14 | - name: automation/rlnotes-footer 15 | color: EDEDED 16 | description: Belongs to release notes automation 17 | 18 | - name: for/backport 19 | color: E99695 20 | description: For backporting 21 | - name: for/blocker 22 | color: E99695 23 | description: For blocking 24 | - name: for/marketing 25 | color: E99695 26 | description: For marketing 27 | - name: for/spike 28 | color: E99695 29 | description: For spike 30 | - name: for/team-attention 31 | color: E99695 32 | description: For team attention 33 | 34 | - name: status/complete 35 | color: FEF2C0 36 | description: Issue is now complete 37 | - name: status/declined 38 | color: FEF2C0 39 | description: Issue has been declined 40 | - name: status/duplicate 41 | color: FEF2C0 42 | description: There were an existing issue 43 | - name: status/in-progress 44 | color: FEF2C0 45 | description: Something is happening 46 | - name: status/invalid 47 | color: FEF2C0 48 | description: Mistake, bogus, old, bye bye 49 | - name: status/need-design 50 | color: FEF2C0 51 | description: Vague so need some proper design 52 | - name: status/need-feedback 53 | color: FEF2C0 54 | description: Calling participant to provide feedback 55 | - name: status/need-investigation 56 | color: FEF2C0 57 | description: Oh need to look under a hood 58 | - name: status/need-triage 59 | color: FEF2C0 60 | description: Team needs to triage and take a first look 61 | - name: status/on-hold 62 | color: FEF2C0 63 | description: For various reasons is on hold 64 | - name: status/stale 65 | color: FEF2C0 66 | description: Marked as stale 67 | - name: status/closed-as-stale 68 | color: FEF2C0 69 | description: Closed as has been stale 70 | 71 | - name: type/automated-pr 72 | color: D4C5F9 73 | description: Is an automated pr 74 | - name: type/backport 75 | color: D4C5F9 76 | description: Is a issue to track backport, use with branch/xxx 77 | - name: type/bug 78 | color: D4C5F9 79 | description: Is a bug report 80 | - name: type/enhancement 81 | color: D4C5F9 82 | description: Is an enhancement request 83 | - name: type/epic 84 | color: D4C5F9 85 | description: Collection of issues 86 | - name: type/feature 87 | color: D4C5F9 88 | description: Is a feature request 89 | - name: type/help-needed 90 | color: D4C5F9 91 | description: Calling help 92 | - name: type/idea 93 | color: D4C5F9 94 | description: Is just an idea 95 | - name: type/task 96 | color: D4C5F9 97 | description: Something needs to get done 98 | - name: type/technical-debt 99 | color: D4C5F9 100 | description: Techical Dept 101 | - name: type/question 102 | color: D4C5F9 103 | description: Is a question 104 | 105 | - name: branch/1.0.x 106 | color: BFDADC 107 | description: Issue for a branch 108 | - name: branch/1.1.x 109 | color: BFDADC 110 | description: Issue for a branch 111 | - name: branch/1.3.x 112 | color: BFDADC 113 | description: Issue for a branch 114 | - name: branch/1.4.x 115 | color: BFDADC 116 | description: Issue for a branch 117 | - name: branch/2.0.x 118 | color: BFDADC 119 | description: Issue for a branch 120 | - name: branch/2.1.x 121 | color: BFDADC 122 | description: Issue for a branch 123 | - name: branch/2.2.x 124 | color: BFDADC 125 | description: Issue for a branch 126 | - name: branch/2.3.x 127 | color: BFDADC 128 | description: Issue for a branch 129 | - name: branch/2.4.x 130 | color: BFDADC 131 | description: Issue for a branch 132 | - name: branch/2.5.x 133 | color: BFDADC 134 | description: Issue for a branch 135 | - name: branch/2.6.x 136 | color: BFDADC 137 | description: Issue for a branch 138 | - name: branch/2.7.x 139 | color: BFDADC 140 | description: Issue for a branch 141 | -------------------------------------------------------------------------------- /.github/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | stagingmilestone 5 | 6 | 7 | spring-staging 8 | Spring Staging 9 | https://repo.spring.io/staging 10 | 11 | false 12 | 13 | 14 | 15 | spring-milestones 16 | Spring Milestones 17 | https://repo.spring.io/milestone 18 | 19 | false 20 | 21 | 22 | 23 | maven-central 24 | Maven Central 25 | https://repo.maven.apache.org/maven2 26 | 27 | false 28 | 29 | 30 | 31 | 32 | maven-central-spring-milestones 33 | Maven Central Spring Milestones 34 | https://repo.spring.io/libs-milestone 35 | 36 | true 37 | 38 | 39 | 40 | 41 | 42 | spring-staging 43 | Spring Staging 44 | https://repo.spring.io/staging 45 | 46 | false 47 | 48 | 49 | 50 | spring-milestones 51 | Spring Milestones 52 | https://repo.spring.io/milestone 53 | 54 | false 55 | 56 | 57 | 58 | maven-central 59 | Maven Central 60 | https://repo.maven.apache.org/maven2 61 | 62 | false 63 | 64 | 65 | 66 | 67 | 68 | stagingrelease 69 | 70 | 71 | spring-staging 72 | Spring Staging 73 | https://repo.spring.io/staging 74 | 75 | false 76 | 77 | 78 | 79 | maven-central 80 | Maven Central 81 | https://repo.maven.apache.org/maven2 82 | 83 | false 84 | 85 | 86 | 87 | 88 | maven-central-spring-milestones 89 | Maven Central Spring Milestones 90 | https://repo.spring.io/libs-milestone 91 | 92 | true 93 | 94 | 95 | 96 | 97 | 98 | spring-staging 99 | Spring Staging 100 | https://repo.spring.io/staging 101 | 102 | false 103 | 104 | 105 | 106 | maven-central 107 | Maven Central 108 | https://repo.maven.apache.org/maven2 109 | 110 | false 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /.github/workflows/build-snapshot-worker.yml: -------------------------------------------------------------------------------- 1 | # Worker which is dispatched from build-snapshot-controller workflow. 2 | name: Build Snapshot Worker 3 | 4 | on: 5 | workflow_dispatch: 6 | inputs: 7 | build-zoo-handler: 8 | description: 'Build Zoo Handler Payload' 9 | required: true 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | steps: 15 | 16 | - uses: actions/checkout@v2 17 | - uses: actions/setup-java@v1 18 | with: 19 | java-version: 1.8 20 | - uses: jvalkeal/setup-maven@v1 21 | with: 22 | maven-version: 3.6.3 23 | - uses: jfrog/setup-jfrog-cli@v1 24 | with: 25 | version: 1.46.4 26 | env: 27 | JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }} 28 | 29 | # cache maven .m2 30 | - uses: actions/cache@v2 31 | with: 32 | path: ~/.m2/repository 33 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 34 | restore-keys: | 35 | ${{ runner.os }}-m2- 36 | 37 | # target deploy repos 38 | - name: Configure JFrog Cli 39 | run: | 40 | jfrog rt mvnc \ 41 | --server-id-resolve=repo.spring.io \ 42 | --server-id-deploy=repo.spring.io \ 43 | --repo-resolve-releases=libs-milestone \ 44 | --repo-resolve-snapshots=libs-snapshot \ 45 | --repo-deploy-releases=libs-release-local \ 46 | --repo-deploy-snapshots=libs-snapshot-local 47 | echo JFROG_CLI_BUILD_NAME=spring-cloud-deployer-cloudfoundry-main >> $GITHUB_ENV 48 | echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 49 | 50 | # zoo extract and ensure 51 | - name: Extract Zoo Context Properties 52 | uses: jvalkeal/build-zoo-handler@v0.0.4 53 | with: 54 | dispatch-handler-extract-context-properties: true 55 | 56 | # build and publish to configured target 57 | - name: Build and Publish 58 | run: | 59 | jfrog rt mvn -U -B clean install 60 | jfrog rt build-publish 61 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_ENV 62 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildname=spring-cloud-deployer-cloudfoundry-main >> $GITHUB_ENV 63 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildnumber=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 64 | 65 | # zoo success 66 | - name: Notify Build Success Zoo Handler Controller 67 | uses: jvalkeal/build-zoo-handler@v0.0.4 68 | with: 69 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 70 | dispatch-handler-client-payload-data: > 71 | { 72 | "event": "build-succeed" 73 | } 74 | 75 | # zoo failure 76 | - name: Notify Build Failure Zoo Handler Controller 77 | if: ${{ failure() }} 78 | uses: jvalkeal/build-zoo-handler@v0.0.4 79 | with: 80 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 81 | dispatch-handler-client-payload-data: > 82 | { 83 | "event": "build-failed", 84 | "message": "spring-cloud-deployer-cloudfoundry failed" 85 | } 86 | # clean m2 cache 87 | - name: Clean cache 88 | run: | 89 | find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr 90 | -------------------------------------------------------------------------------- /.github/workflows/ci-pr.yml: -------------------------------------------------------------------------------- 1 | name: CI PRs 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | # cache maven repo 12 | - uses: actions/cache@v2 13 | with: 14 | path: ~/.m2/repository 15 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 16 | restore-keys: | 17 | ${{ runner.os }}-m2- 18 | # jdk8 19 | - uses: actions/setup-java@v1 20 | with: 21 | java-version: 1.8 22 | # maven version 23 | - uses: jvalkeal/setup-maven@v1 24 | with: 25 | maven-version: 3.6.2 26 | # build 27 | - name: Build 28 | run: | 29 | mvn -U -B clean package 30 | # clean m2 cache 31 | - name: Clean cache 32 | run: | 33 | find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr 34 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | paths-ignore: 7 | - '.github/**' 8 | 9 | jobs: 10 | build: 11 | if: github.repository_owner == 'spring-cloud' 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | # cache maven repo 16 | - uses: actions/cache@v2 17 | with: 18 | path: ~/.m2/repository 19 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 20 | restore-keys: | 21 | ${{ runner.os }}-m2- 22 | # jdk8 23 | - uses: actions/setup-java@v1 24 | with: 25 | java-version: 1.8 26 | # maven version 27 | - uses: jvalkeal/setup-maven@v1 28 | with: 29 | maven-version: 3.6.2 30 | # jfrog cli 31 | - uses: jfrog/setup-jfrog-cli@v1 32 | with: 33 | version: 1.46.4 34 | env: 35 | JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }} 36 | # setup frog cli 37 | - name: Configure JFrog Cli 38 | run: | 39 | jfrog rt mvnc \ 40 | --server-id-resolve=repo.spring.io \ 41 | --server-id-deploy=repo.spring.io \ 42 | --repo-resolve-releases=libs-milestone \ 43 | --repo-resolve-snapshots=libs-snapshot \ 44 | --repo-deploy-releases=libs-release-local \ 45 | --repo-deploy-snapshots=libs-snapshot-local 46 | echo JFROG_CLI_BUILD_NAME=spring-cloud-deployer-cloudfoundry-main >> $GITHUB_ENV 47 | echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 48 | # build and publish 49 | - name: Build and Publish 50 | run: | 51 | jfrog rt mvn -U -B clean install 52 | jfrog rt build-publish 53 | # clean m2 cache 54 | - name: Clean cache 55 | run: | 56 | find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr 57 | -------------------------------------------------------------------------------- /.github/workflows/issue-handler.yml: -------------------------------------------------------------------------------- 1 | name: Issue Handler 2 | 3 | on: 4 | workflow_dispatch: 5 | issues: 6 | types: [opened, labeled, unlabeled] 7 | issue_comment: 8 | types: [created] 9 | 10 | jobs: 11 | labeler: 12 | runs-on: ubuntu-latest 13 | steps: 14 | 15 | - name: Handle Issues 16 | uses: jvalkeal/issue-handler@v0.0.4 17 | with: 18 | token: ${{ secrets.GITHUB_TOKEN }} 19 | config: > 20 | { 21 | "data": { 22 | "team": [ 23 | "jvalkeal", 24 | "oodamien", 25 | "ilayaperumalg", 26 | "sabbyanandan", 27 | "tzolov", 28 | "chrisjs", 29 | "cppwfs", 30 | "mminella", 31 | "dturanski", 32 | "onobc", 33 | "claudiahub", 34 | "sobychacko" 35 | ] 36 | }, 37 | "recipes": [ 38 | { 39 | "name": "Mark new issue to get triaged", 40 | "type": "ifThen", 41 | "if": "isAction('opened') && !dataInArray('team', actor)", 42 | "then": "labelIssue(['status/need-triage'])" 43 | }, 44 | { 45 | "name": "Switch to team if user comments", 46 | "type": "ifThen", 47 | "if": "isEvent('issue_comment') && isAction('created') && actor == context.payload.issue.user.login && labelsContainsAny('status/need-feedback')", 48 | "then": "[labelIssue('for/team-attention'), removeLabel('status/need-feedback')]" 49 | }, 50 | { 51 | "name": "Switch to user if team comments", 52 | "type": "ifThen", 53 | "if": "isEvent('issue_comment') && isAction('created') && dataInArray('team', actor) && labelsContainsAny('for/team-attention') ", 54 | "then": "[labelIssue('status/need-feedback', removeLabel('for/team-attention'))]" 55 | }, 56 | { 57 | "name": "Manage backport issues", 58 | "type": "manageBackportIssues", 59 | "whenLabeled": "labeledStartsWith(['branch/'])", 60 | "whenUnlabeled": "labeledStartsWith(['branch/'])", 61 | "whenLabels": "labelsContainsAny(['for/backport'])", 62 | "fromLabels": "labeledStartsWith(['branch/'])", 63 | "additionalLabels": "'type/backport'", 64 | "body": "'Backport #' + number" 65 | } 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /.github/workflows/label-manage.yml: -------------------------------------------------------------------------------- 1 | name: Labels Manage 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'main' 7 | paths: 8 | - '.github/labels-manage.yml' 9 | - '.github/workflows/label-manage.yml' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | labeler: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: Mangle Labels 18 | uses: crazy-max/ghaction-github-labeler@v3 19 | with: 20 | github-token: ${{ secrets.GITHUB_TOKEN }} 21 | yaml-file: .github/labels-manage.yml 22 | dry-run: false 23 | skip-delete: true 24 | -------------------------------------------------------------------------------- /.github/workflows/milestone-worker.yml: -------------------------------------------------------------------------------- 1 | name: Milestone Worker 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | build-zoo-handler: 7 | description: 'Build Zoo Handler Payload' 8 | required: true 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-java@v1 17 | with: 18 | java-version: 1.8 19 | - uses: jvalkeal/setup-maven@v1 20 | with: 21 | maven-version: 3.6.3 22 | - uses: jfrog/setup-jfrog-cli@v1 23 | with: 24 | version: 1.46.4 25 | env: 26 | JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }} 27 | - uses: actions/cache@v2 28 | with: 29 | path: ~/.m2/repository 30 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 31 | restore-keys: | 32 | ${{ runner.os }}-m2- 33 | 34 | # target deploy repos 35 | - name: Configure JFrog Cli 36 | run: | 37 | jfrog rt mvnc \ 38 | --server-id-resolve=repo.spring.io \ 39 | --server-id-deploy=repo.spring.io \ 40 | --repo-resolve-releases=libs-milestone \ 41 | --repo-resolve-snapshots=libs-snapshot \ 42 | --repo-deploy-releases=libs-release-local \ 43 | --repo-deploy-snapshots=libs-snapshot-local 44 | echo JFROG_CLI_BUILD_NAME=spring-cloud-deployer-cloudfoundry-main-milestone >> $GITHUB_ENV 45 | echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 46 | 47 | # zoo extract and ensure 48 | - name: Extract Zoo Context Properties 49 | uses: jvalkeal/build-zoo-handler@v0.0.4 50 | with: 51 | dispatch-handler-extract-context-properties: true 52 | ensure-env: | 53 | BUILD_ZOO_HANDLER_milestone_version 54 | BUILD_ZOO_HANDLER_spring_cloud_dataflow_build_version 55 | BUILD_ZOO_HANDLER_spring_cloud_deployer_version 56 | 57 | # build and publish to configured target 58 | - name: Build and Publish 59 | run: | 60 | jfrog rt mvn build-helper:parse-version versions:set \ 61 | -gs .github/settings.xml \ 62 | -Pstagingmilestone \ 63 | -DprocessAllModules=true \ 64 | -DgenerateBackupPoms=false \ 65 | -Dartifactory.publish.artifacts=false \ 66 | -DnewVersion='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-'${BUILD_ZOO_HANDLER_milestone_version} \ 67 | -B 68 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_ENV 69 | jfrog rt mvn versions:update-parent \ 70 | -gs .github/settings.xml \ 71 | -Pstagingmilestone \ 72 | -DgenerateBackupPoms=false \ 73 | -DparentVersion='['${BUILD_ZOO_HANDLER_spring_cloud_deployer_version}']' \ 74 | -B 75 | jfrog rt mvn versions:set-property \ 76 | -gs .github/settings.xml \ 77 | -Pstagingmilestone \ 78 | -DgenerateBackupPoms=false \ 79 | -Dproperty=spring-cloud-deployer.version \ 80 | -DnewVersion=${BUILD_ZOO_HANDLER_spring_cloud_deployer_version} \ 81 | -B 82 | jfrog rt build-clean 83 | jfrog rt mvn clean install \ 84 | -gs .github/settings.xml \ 85 | -P-spring,stagingmilestone \ 86 | -DskipTests -U -B 87 | jfrog rt build-publish 88 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildname=spring-cloud-deployer-cloudfoundry-main-milestone >> $GITHUB_ENV 89 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildnumber=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 90 | 91 | # zoo tag 92 | - name: Tag Release 93 | uses: jvalkeal/build-zoo-handler@v0.0.4 94 | with: 95 | tag-release-branch: ${{ env.BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version }} 96 | tag-release-tag: ${{ env.BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version }} 97 | tag-release-tag-prefix: v 98 | 99 | # zoo success 100 | - name: Notify Build Success Zoo Handler Controller 101 | uses: jvalkeal/build-zoo-handler@v0.0.4 102 | with: 103 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 104 | dispatch-handler-client-payload-data: > 105 | { 106 | "event": "build-succeed" 107 | } 108 | 109 | # zoo failure 110 | - name: Notify Build Failure Zoo Handler Controller 111 | if: ${{ failure() }} 112 | uses: jvalkeal/build-zoo-handler@v0.0.4 113 | with: 114 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 115 | dispatch-handler-client-payload-data: > 116 | { 117 | "event": "build-failed", 118 | "message": "spring-cloud-deployer-cloudfoundry failed" 119 | } 120 | # clean m2 cache 121 | - name: Clean cache 122 | run: | 123 | find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr 124 | -------------------------------------------------------------------------------- /.github/workflows/next-dev-version-worker.yml: -------------------------------------------------------------------------------- 1 | name: Next Dev Version Worker 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | build-zoo-handler: 7 | description: 'Build Zoo Handler Payload' 8 | required: true 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-java@v1 17 | with: 18 | java-version: 1.8 19 | - uses: jvalkeal/setup-maven@v1 20 | with: 21 | maven-version: 3.6.3 22 | - uses: jfrog/setup-jfrog-cli@v1 23 | with: 24 | version: 1.46.4 25 | env: 26 | JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }} 27 | 28 | # cache maven .m2 29 | - uses: actions/cache@v2 30 | with: 31 | path: ~/.m2/repository 32 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 33 | restore-keys: | 34 | ${{ runner.os }}-m2- 35 | 36 | # target deploy repos 37 | - name: Configure JFrog Cli 38 | run: | 39 | jfrog rt mvnc \ 40 | --server-id-resolve=repo.spring.io \ 41 | --server-id-deploy=repo.spring.io \ 42 | --repo-resolve-releases=libs-milestone \ 43 | --repo-resolve-snapshots=libs-snapshot \ 44 | --repo-deploy-releases=libs-release-local \ 45 | --repo-deploy-snapshots=libs-snapshot-local 46 | echo JFROG_CLI_BUILD_NAME=spring-cloud-deployer-cloudfoundry-main-ndv >> $GITHUB_ENV 47 | echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 48 | 49 | # zoo extract and ensure 50 | - name: Extract Zoo Context Properties 51 | uses: jvalkeal/build-zoo-handler@v0.0.4 52 | with: 53 | dispatch-handler-extract-context-properties: true 54 | 55 | # build and publish to configured target 56 | - name: Build and Publish 57 | run: | 58 | jfrog rt mvn build-helper:parse-version versions:set \ 59 | -DprocessAllModules=true \ 60 | -DgenerateBackupPoms=false \ 61 | -Dartifactory.publish.artifacts=false \ 62 | -DnewVersion='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}-SNAPSHOT' \ 63 | -B 64 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_ENV 65 | jfrog rt mvn versions:update-parent \ 66 | -DallowSnapshots=true \ 67 | -DgenerateBackupPoms=false \ 68 | -DparentVersion='['${BUILD_ZOO_HANDLER_spring_cloud_deployer_version}']' \ 69 | -B 70 | jfrog rt mvn versions:set-property \ 71 | -DgenerateBackupPoms=false \ 72 | -Dproperty=spring-cloud-deployer.version \ 73 | -DnewVersion=${BUILD_ZOO_HANDLER_spring_cloud_deployer_version} \ 74 | -B 75 | jfrog rt build-clean 76 | jfrog rt mvn clean install -DskipTests -B 77 | jfrog rt build-publish 78 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildname=spring-cloud-deployer-cloudfoundry-main-ndv >> $GITHUB_ENV 79 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildnumber=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 80 | 81 | # zoo commit 82 | - name: Commit Next Dev Changes 83 | uses: jvalkeal/build-zoo-handler@v0.0.4 84 | with: 85 | commit-changes-branch: main 86 | commit-changes-message: Next development version 87 | 88 | # zoo success 89 | - name: Notify Build Success Zoo Handler Controller 90 | uses: jvalkeal/build-zoo-handler@v0.0.4 91 | with: 92 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 93 | dispatch-handler-client-payload-data: > 94 | { 95 | "event": "next-dev-version-succeed" 96 | } 97 | 98 | # zoo failure 99 | - name: Notify Build Failure Zoo Handler Controller 100 | if: ${{ failure() }} 101 | uses: jvalkeal/build-zoo-handler@v0.0.4 102 | with: 103 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 104 | dispatch-handler-client-payload-data: > 105 | { 106 | "event": "next-dev-version-failed", 107 | "message": "spring-cloud-dataflow-build next version failed" 108 | } 109 | 110 | # clean m2 cache 111 | - name: Clean cache 112 | run: | 113 | find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr 114 | -------------------------------------------------------------------------------- /.github/workflows/release-worker.yml: -------------------------------------------------------------------------------- 1 | name: Release Worker 2 | 3 | on: 4 | workflow_dispatch: 5 | inputs: 6 | build-zoo-handler: 7 | description: 'Build Zoo Handler Payload' 8 | required: true 9 | 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-java@v1 17 | with: 18 | java-version: 1.8 19 | - uses: jvalkeal/setup-maven@v1 20 | with: 21 | maven-version: 3.6.3 22 | - uses: jfrog/setup-jfrog-cli@v1 23 | with: 24 | version: 1.46.4 25 | env: 26 | JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }} 27 | - uses: actions/cache@v2 28 | with: 29 | path: ~/.m2/repository 30 | key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} 31 | restore-keys: | 32 | ${{ runner.os }}-m2- 33 | 34 | # target deploy repos 35 | - name: Configure JFrog Cli 36 | run: | 37 | jfrog rt mvnc \ 38 | --server-id-resolve=repo.spring.io \ 39 | --server-id-deploy=repo.spring.io \ 40 | --repo-resolve-releases=libs-spring-dataflow-private-staging-release \ 41 | --repo-resolve-snapshots=libs-snapshot \ 42 | --repo-deploy-releases=libs-staging-local \ 43 | --repo-deploy-snapshots=libs-snapshot-local 44 | echo JFROG_CLI_BUILD_NAME=spring-cloud-deployer-cloudfoundry-main-release >> $GITHUB_ENV 45 | echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 46 | 47 | # zoo extract and ensure 48 | - name: Extract Zoo Context Properties 49 | uses: jvalkeal/build-zoo-handler@v0.0.4 50 | with: 51 | dispatch-handler-extract-context-properties: true 52 | ensure-env: | 53 | BUILD_ZOO_HANDLER_spring_cloud_dataflow_build_version 54 | BUILD_ZOO_HANDLER_spring_cloud_deployer_version 55 | 56 | # build and publish to configured target 57 | - name: Build and Publish 58 | run: | 59 | jfrog rt mvn build-helper:parse-version versions:set \ 60 | -gs .github/settings.xml \ 61 | -Pstagingrelease \ 62 | -DprocessAllModules=true \ 63 | -DgenerateBackupPoms=false \ 64 | -Dartifactory.publish.artifacts=false \ 65 | -DnewVersion='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}' \ 66 | -B 67 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_ENV 68 | jfrog rt mvn versions:update-parent \ 69 | -gs .github/settings.xml \ 70 | -Pstagingrelease \ 71 | -DgenerateBackupPoms=false \ 72 | -DparentVersion='['${BUILD_ZOO_HANDLER_spring_cloud_deployer_version}']' \ 73 | -B 74 | jfrog rt mvn versions:set-property \ 75 | -gs .github/settings.xml \ 76 | -Pstagingrelease \ 77 | -DgenerateBackupPoms=false \ 78 | -Dproperty=spring-cloud-deployer.version \ 79 | -DnewVersion=${BUILD_ZOO_HANDLER_spring_cloud_deployer_version} \ 80 | -B 81 | jfrog rt build-clean 82 | jfrog rt mvn clean install \ 83 | -gs .github/settings.xml \ 84 | -P-spring,stagingrelease \ 85 | -DskipTests -U -B 86 | jfrog rt build-publish 87 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildname=spring-cloud-deployer-cloudfoundry-main-release >> $GITHUB_ENV 88 | echo BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_buildnumber=$GITHUB_RUN_NUMBER >> $GITHUB_ENV 89 | 90 | # zoo tag 91 | - name: Tag Release 92 | uses: jvalkeal/build-zoo-handler@v0.0.4 93 | with: 94 | tag-release-branch: ${{ env.BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version }} 95 | tag-release-tag: ${{ env.BUILD_ZOO_HANDLER_spring_cloud_deployer_cloudfoundry_version }} 96 | tag-release-tag-prefix: v 97 | 98 | # zoo success 99 | - name: Notify Build Success Zoo Handler Controller 100 | uses: jvalkeal/build-zoo-handler@v0.0.4 101 | with: 102 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 103 | dispatch-handler-client-payload-data: > 104 | { 105 | "event": "build-succeed" 106 | } 107 | 108 | # zoo failure 109 | - name: Notify Build Failure Zoo Handler Controller 110 | if: ${{ failure() }} 111 | uses: jvalkeal/build-zoo-handler@v0.0.4 112 | with: 113 | dispatch-handler-token: ${{ secrets.SCDF_ACCESS_TOKEN }} 114 | dispatch-handler-client-payload-data: > 115 | { 116 | "event": "build-failed", 117 | "message": "spring-cloud-deployer-cloudfoundry failed" 118 | } 119 | # clean m2 cache 120 | - name: Clean cache 121 | run: | 122 | find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr 123 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,maven,intellij,eclipse 3 | 4 | ### Java ### 5 | *.class 6 | 7 | # Mobile Tools for Java (J2ME) 8 | .mtj.tmp/ 9 | 10 | # Package Files # 11 | 12 | # virtual machine crash logs, see https://www.java.com/en/download/help/error_hotspot.xml 13 | hs_err_pid* 14 | 15 | 16 | ### Maven ### 17 | target/ 18 | pom.xml.tag 19 | pom.xml.releaseBackup 20 | pom.xml.versionsBackup 21 | pom.xml.next 22 | release.properties 23 | dependency-reduced-pom.xml 24 | buildNumber.properties 25 | 26 | 27 | ### Intellij ### 28 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 29 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 30 | 31 | # User-specific stuff: 32 | .idea/* 33 | !.idea/codeStyleSettings.xml 34 | 35 | ## File-based project format: 36 | *.iws 37 | *.iml 38 | *.ipr 39 | 40 | ## Plugin-specific files: 41 | 42 | # IntelliJ 43 | /out/ 44 | .idea 45 | 46 | # mpeltonen/sbt-idea plugin 47 | .idea_modules/ 48 | 49 | # JIRA plugin 50 | atlassian-ide-plugin.xml 51 | 52 | # Crashlytics plugin (for Android Studio and IntelliJ) 53 | com_crashlytics_export_strings.xml 54 | crashlytics.properties 55 | crashlytics-build.properties 56 | fabric.properties 57 | 58 | 59 | ### Eclipse ### 60 | 61 | .metadata 62 | bin/ 63 | tmp/ 64 | *.tmp 65 | *.bak 66 | *.swp 67 | *~.nib 68 | local.properties 69 | .settings/ 70 | .loadpath 71 | 72 | # Eclipse Core 73 | .project 74 | 75 | # External tool builders 76 | .externalToolBuilders/ 77 | 78 | # Locally stored "Eclipse launch configurations" 79 | *.launch 80 | 81 | # PyDev specific (Python IDE for Eclipse) 82 | *.pydevproject 83 | 84 | # CDT-specific (C/C++ Development Tooling) 85 | .cproject 86 | 87 | # JDT-specific (Eclipse Java Development Tools) 88 | .classpath 89 | 90 | # Java annotation processor (APT) 91 | .factorypath 92 | 93 | # PDT-specific (PHP Development Tools) 94 | .buildpath 95 | 96 | # sbteclipse plugin 97 | .target 98 | 99 | # Tern plugin 100 | .tern-project 101 | 102 | # TeXlipse plugin 103 | .texlipse 104 | 105 | # STS (Spring Tool Suite) 106 | .springBeans 107 | 108 | # Code Recommenders 109 | .recommenders/ 110 | 111 | .DS_Store 112 | .jfrog/ 113 | 114 | # Visual Studio Code 115 | .vscode/* 116 | !.vscode/settings.json 117 | !.vscode/tasks.json 118 | !.vscode/launch.json 119 | !.vscode/extensions.json 120 | 121 | -------------------------------------------------------------------------------- /.jdk8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/.jdk8 -------------------------------------------------------------------------------- /.mvn/jvm.config: -------------------------------------------------------------------------------- 1 | -Xmx1024m -XX:CICompilerCount=1 -XX:TieredStopAtLevel=1 -Djava.security.egd=file:/dev/./urandom -------------------------------------------------------------------------------- /.mvn/maven.config: -------------------------------------------------------------------------------- 1 | -DaltSnapshotDeploymentRepository=repo.spring.io::default::https://repo.spring.io/libs-snapshot-local -P spring 2 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip 2 | 3 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.completion.importOrder": [ 3 | "java", 4 | "javax", 5 | "", 6 | "org.springframework", 7 | "#" 8 | ], 9 | "java.checkstyle.configuration": "https://raw.githubusercontent.com/spring-cloud/spring-cloud-dataflow-build/main/spring-cloud-dataflow-build-tools/src/main/resources/checkstyle.xml", 10 | "java.checkstyle.properties": { 11 | "checkstyle.suppressions.file": "https://raw.githubusercontent.com/spring-cloud/spring-cloud-dataflow-build/main/spring-cloud-dataflow-build-tools/src/checkstyle/checkstyle-suppressions.xml", 12 | "checkstyle.additional.suppressions.file": "https://raw.githubusercontent.com/spring-cloud/spring-cloud-dataflow-build/main/spring-cloud-dataflow-build-tools/src/checkstyle/checkstyle-suppressions-empty.xml", 13 | "checkstyle.header.file": "https://raw.githubusercontent.com/spring-cloud/spring-cloud-dataflow-build/main/spring-cloud-dataflow-build-tools/src/main/resources/checkstyle-header.txt" 14 | }, 15 | "java.checkstyle.version": "8.29" 16 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.adoc: -------------------------------------------------------------------------------- 1 | = Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, and in the interest of fostering an open 4 | and welcoming community, we pledge to respect all people who contribute through reporting 5 | issues, posting feature requests, updating documentation, submitting pull requests or 6 | patches, and other activities. 7 | 8 | We are committed to making participation in this project a harassment-free experience for 9 | everyone, regardless of level of experience, gender, gender identity and expression, 10 | sexual orientation, disability, personal appearance, body size, race, ethnicity, age, 11 | religion, or nationality. 12 | 13 | Examples of unacceptable behavior by participants include: 14 | 15 | * The use of sexualized language or imagery 16 | * Personal attacks 17 | * Trolling or insulting/derogatory comments 18 | * Public or private harassment 19 | * Publishing other's private information, such as physical or electronic addresses, 20 | without explicit permission 21 | * Other unethical or unprofessional conduct 22 | 23 | Project maintainers have the right and responsibility to remove, edit, or reject comments, 24 | commits, code, wiki edits, issues, and other contributions that are not aligned to this 25 | Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors 26 | that they deem inappropriate, threatening, offensive, or harmful. 27 | 28 | By adopting this Code of Conduct, project maintainers commit themselves to fairly and 29 | consistently applying these principles to every aspect of managing this project. Project 30 | maintainers who do not follow or enforce the Code of Conduct may be permanently removed 31 | from the project team. 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an 34 | individual is representing the project or its community. 35 | 36 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by 37 | contacting a project maintainer at spring-code-of-conduct@pivotal.io . All complaints will 38 | be reviewed and investigated and will result in a response that is deemed necessary and 39 | appropriate to the circumstances. Maintainers are obligated to maintain confidentiality 40 | with regard to the reporter of an incident. 41 | 42 | This Code of Conduct is adapted from the 43 | https://contributor-covenant.org[Contributor Covenant], version 1.3.0, available at 44 | https://contributor-covenant.org/version/1/3/0/[contributor-covenant.org/version/1/3/0/] -------------------------------------------------------------------------------- /CONTRIBUTING.adoc: -------------------------------------------------------------------------------- 1 | = Contributing to Spring Cloud - Cloud Foundry Deployer 2 | 3 | Spring Cloud - Cloud Foundry Deployer is released under the Apache 2.0 license. If you would like to contribute 4 | something, or simply want to hack on the code this document should help you get started. 5 | 6 | == Code of Conduct 7 | This project adheres to the Contributor Covenant link:CODE_OF_CONDUCT.adoc[code of 8 | conduct]. By participating, you are expected to uphold this code. Please report 9 | unacceptable behavior to spring-code-of-conduct@pivotal.io. 10 | 11 | == Using github issues 12 | We use github issues to track bugs and enhancements. If you have a general usage question 13 | please ask on https://stackoverflow.com[Stack Overflow]. The Sprig Cloud team and the 14 | broader community monitor the https://stackoverflow.com/tags/spring-cloud[`spring-cloud`] 15 | tag. 16 | 17 | If you are reporting a bug, please help to speed up problem diagnosis by providing as much 18 | information as possible. Submitting a github-hosted sample project replicating the problem helps. 19 | 20 | == Sign the Contributor License Agreement 21 | Before we accept a non-trivial patch or pull request we will need you to sign the 22 | https://support.springsource.com/spring_committer_signup[contributor's agreement]. 23 | Signing the contributor's agreement does not grant anyone commit rights to the main 24 | repository, but it does mean that we can accept your contributions, and you will get an 25 | author credit if we do. Active contributors might be asked to join the core team, and 26 | given the ability to merge pull requests. Use '`Phillip Webb`' or '`Dave Syer`' in the 27 | project lead field when you complete the form. 28 | 29 | == Code Conventions and Housekeeping 30 | None of these are essential for a pull request, but they help. They can also be 31 | added after the original pull request but before a merge. 32 | 33 | * Use the Spring Framework code format conventions. 34 | * Make sure all new `.java` files to have a simple Javadoc class comment with at least an 35 | `@author` tag identifying you, and preferably at least a paragraph on what the class is 36 | for. 37 | * Add the ASF license header comment to all new `.java` files (copy from existing files 38 | in the project) 39 | * Add yourself as an `@author` to the `.java` files that you modify substantially (more 40 | than cosmetic changes). 41 | * Add some Javadocs. 42 | * A few unit tests would help a lot as well -- someone has to do it. 43 | * If no-one else is using your branch, please rebase it against the current master (or 44 | other target branch in the main project). 45 | * When writing a commit message please follow https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html[these conventions]. 46 | 47 | === Building from source 48 | This project includes the maven wrapper, meaning you don't have to install any CLI tools to compile. Simply clone it and do this: 49 | 50 | ==== Default build 51 | The project can be built from the root directory using the standard maven wrapper command: 52 | 53 | ---- 54 | $ ./mvnw clean package 55 | ---- 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | https://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | https://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | spring-cloud-deployer-cloudfoundry 2 | 3 | Copyright (c) 2016-Present Pivotal Software, Inc. All Rights Reserved. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # :no_entry: Spring Cloud Deployer has moved to a monorepo. 2 | ## This repo is archived and now exists as the [spring-cloud-deployer-cloudfoundry](https://github.com/spring-cloud/spring-cloud-deployer/tree/main/spring-cloud-deployer-cloudfoundry) module in the Deployer monorepo. 3 | ### Please file any issues/PRs in the [Deployer](https://github.com/spring-cloud/spring-cloud-deployer) repo. 4 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # 58 | # Look for the Apple JDKs first to preserve the existing behaviour, and then look 59 | # for the new JDKs provided by Oracle. 60 | # 61 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK ] ; then 62 | # 63 | # Apple JDKs 64 | # 65 | export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home 66 | fi 67 | 68 | if [ -z "$JAVA_HOME" ] && [ -L /System/Library/Java/JavaVirtualMachines/CurrentJDK ] ; then 69 | # 70 | # Apple JDKs 71 | # 72 | export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 73 | fi 74 | 75 | if [ -z "$JAVA_HOME" ] && [ -L "/Library/Java/JavaVirtualMachines/CurrentJDK" ] ; then 76 | # 77 | # Oracle JDKs 78 | # 79 | export JAVA_HOME=/Library/Java/JavaVirtualMachines/CurrentJDK/Contents/Home 80 | fi 81 | 82 | if [ -z "$JAVA_HOME" ] && [ -x "/usr/libexec/java_home" ]; then 83 | # 84 | # Apple JDKs 85 | # 86 | export JAVA_HOME=`/usr/libexec/java_home` 87 | fi 88 | ;; 89 | esac 90 | 91 | if [ -z "$JAVA_HOME" ] ; then 92 | if [ -r /etc/gentoo-release ] ; then 93 | JAVA_HOME=`java-config --jre-home` 94 | fi 95 | fi 96 | 97 | if [ -z "$M2_HOME" ] ; then 98 | ## resolve links - $0 may be a link to maven's home 99 | PRG="$0" 100 | 101 | # need this for relative symlinks 102 | while [ -h "$PRG" ] ; do 103 | ls=`ls -ld "$PRG"` 104 | link=`expr "$ls" : '.*-> \(.*\)$'` 105 | if expr "$link" : '/.*' > /dev/null; then 106 | PRG="$link" 107 | else 108 | PRG="`dirname "$PRG"`/$link" 109 | fi 110 | done 111 | 112 | saveddir=`pwd` 113 | 114 | M2_HOME=`dirname "$PRG"`/.. 115 | 116 | # make it fully qualified 117 | M2_HOME=`cd "$M2_HOME" && pwd` 118 | 119 | cd "$saveddir" 120 | # echo Using m2 at $M2_HOME 121 | fi 122 | 123 | # For Cygwin, ensure paths are in UNIX format before anything is touched 124 | if $cygwin ; then 125 | [ -n "$M2_HOME" ] && 126 | M2_HOME=`cygpath --unix "$M2_HOME"` 127 | [ -n "$JAVA_HOME" ] && 128 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 129 | [ -n "$CLASSPATH" ] && 130 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 131 | fi 132 | 133 | # For Migwn, ensure paths are in UNIX format before anything is touched 134 | if $mingw ; then 135 | [ -n "$M2_HOME" ] && 136 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 137 | [ -n "$JAVA_HOME" ] && 138 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 139 | # TODO classpath? 140 | fi 141 | 142 | if [ -z "$JAVA_HOME" ]; then 143 | javaExecutable="`which javac`" 144 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 145 | # readlink(1) is not available as standard on Solaris 10. 146 | readLink=`which readlink` 147 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 148 | if $darwin ; then 149 | javaHome="`dirname \"$javaExecutable\"`" 150 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 151 | else 152 | javaExecutable="`readlink -f \"$javaExecutable\"`" 153 | fi 154 | javaHome="`dirname \"$javaExecutable\"`" 155 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 156 | JAVA_HOME="$javaHome" 157 | export JAVA_HOME 158 | fi 159 | fi 160 | fi 161 | 162 | if [ -z "$JAVACMD" ] ; then 163 | if [ -n "$JAVA_HOME" ] ; then 164 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 165 | # IBM's JDK on AIX uses strange locations for the executables 166 | JAVACMD="$JAVA_HOME/jre/sh/java" 167 | else 168 | JAVACMD="$JAVA_HOME/bin/java" 169 | fi 170 | else 171 | JAVACMD="`which java`" 172 | fi 173 | fi 174 | 175 | if [ ! -x "$JAVACMD" ] ; then 176 | echo "Error: JAVA_HOME is not defined correctly." >&2 177 | echo " We cannot execute $JAVACMD" >&2 178 | exit 1 179 | fi 180 | 181 | if [ -z "$JAVA_HOME" ] ; then 182 | echo "Warning: JAVA_HOME environment variable is not set." 183 | fi 184 | 185 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 186 | 187 | # For Cygwin, switch paths to Windows format before running java 188 | if $cygwin; then 189 | [ -n "$M2_HOME" ] && 190 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 191 | [ -n "$JAVA_HOME" ] && 192 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 193 | [ -n "$CLASSPATH" ] && 194 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 195 | fi 196 | 197 | # traverses directory structure from process work directory to filesystem root 198 | # first directory with .mvn subdirectory is considered project base directory 199 | find_maven_basedir() { 200 | local basedir=$(pwd) 201 | local wdir=$(pwd) 202 | while [ "$wdir" != '/' ] ; do 203 | if [ -d "$wdir"/.mvn ] ; then 204 | basedir=$wdir 205 | break 206 | fi 207 | wdir=$(cd "$wdir/.."; pwd) 208 | done 209 | echo "${basedir}" 210 | } 211 | 212 | # concatenates all lines of a file 213 | concat_lines() { 214 | if [ -f "$1" ]; then 215 | echo "$(tr -s '\n' ' ' < "$1")" 216 | fi 217 | } 218 | 219 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-$(find_maven_basedir)} 220 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 221 | 222 | # Provide a "standardized" way to retrieve the CLI args that will 223 | # work with both Windows and non-Windows executions. 224 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 225 | export MAVEN_CMD_LINE_ARGS 226 | 227 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 228 | 229 | exec "$JAVACMD" \ 230 | $MAVEN_OPTS \ 231 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 232 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 233 | ${WRAPPER_LAUNCHER} "$@" 234 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 40 | 41 | @REM set %HOME% to equivalent of $HOME 42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 43 | 44 | @REM Execute a user defined script before this one 45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 49 | :skipRcPre 50 | 51 | @setlocal 52 | 53 | set ERROR_CODE=0 54 | 55 | @REM To isolate internal variables from possible post scripts, we use another setlocal 56 | @setlocal 57 | 58 | @REM ==== START VALIDATION ==== 59 | if not "%JAVA_HOME%" == "" goto OkJHome 60 | 61 | echo. 62 | echo Error: JAVA_HOME not found in your environment. >&2 63 | echo Please set the JAVA_HOME variable in your environment to match the >&2 64 | echo location of your Java installation. >&2 65 | echo. 66 | goto error 67 | 68 | :OkJHome 69 | if exist "%JAVA_HOME%\bin\java.exe" goto init 70 | 71 | echo. 72 | echo Error: JAVA_HOME is set to an invalid directory. >&2 73 | echo JAVA_HOME = "%JAVA_HOME%" >&2 74 | echo Please set the JAVA_HOME variable in your environment to match the >&2 75 | echo location of your Java installation. >&2 76 | echo. 77 | goto error 78 | 79 | @REM ==== END VALIDATION ==== 80 | 81 | :init 82 | 83 | set MAVEN_CMD_LINE_ARGS=%* 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | 121 | set WRAPPER_JAR="".\.mvn\wrapper\maven-wrapper.jar"" 122 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 123 | 124 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CMD_LINE_ARGS% 125 | if ERRORLEVEL 1 goto error 126 | goto end 127 | 128 | :error 129 | set ERROR_CODE=1 130 | 131 | :end 132 | @endlocal & set ERROR_CODE=%ERROR_CODE% 133 | 134 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 135 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 136 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 137 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 138 | :skipRcPost 139 | 140 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 141 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 142 | 143 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 144 | 145 | exit /B %ERROR_CODE% -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | spring-cloud-deployer-cloudfoundry 6 | 2.8.4-SNAPSHOT 7 | org.springframework.cloud 8 | jar 9 | 10 | Spring Cloud - Cloud Foundry Deployer 11 | 12 | 13 | org.springframework.cloud 14 | spring-cloud-deployer-parent 15 | 2.8.2-SNAPSHOT 16 | 17 | 18 | 19 | 20 | 1.8 21 | 2.8.4-SNAPSHOT 22 | 4.16.0.RELEASE 23 | 2.2.0.RELEASE 24 | 3.14.9 25 | 26 | 27 | 28 | 29 | org.springframework.cloud 30 | spring-cloud-deployer-spi 31 | ${spring-cloud-deployer.version} 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-loader 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-validation 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-configuration-processor 44 | true 45 | 46 | 47 | org.cloudfoundry 48 | cloudfoundry-client-reactor 49 | ${cloudfoundry-java-lib.version} 50 | 51 | 52 | org.cloudfoundry 53 | cloudfoundry-operations 54 | ${cloudfoundry-java-lib.version} 55 | 56 | 57 | com.github.ben-manes.caffeine 58 | caffeine 59 | 60 | 61 | io.projectreactor.addons 62 | reactor-extra 63 | 64 | 65 | org.yaml 66 | snakeyaml 67 | 68 | 69 | io.pivotal 70 | pivotal-cloudfoundry-client-reactor 71 | ${pivotal-cf-client-reactor.version} 72 | 73 | 74 | org.springframework.retry 75 | spring-retry 76 | 77 | 78 | org.springframework.boot 79 | spring-boot-starter-test 80 | test 81 | 82 | 83 | org.springframework.cloud 84 | spring-cloud-deployer-spi-test 85 | ${spring-cloud-deployer.version} 86 | test 87 | 88 | 89 | org.springframework.cloud 90 | spring-cloud-deployer-resource-docker 91 | ${spring-cloud-deployer.version} 92 | test 93 | 94 | 95 | org.springframework.cloud 96 | spring-cloud-deployer-resource-support 97 | ${spring-cloud-deployer.version} 98 | test 99 | 100 | 101 | org.springframework.cloud 102 | spring-cloud-deployer-autoconfigure 103 | ${spring-cloud-deployer.version} 104 | test 105 | 106 | 107 | com.squareup.okhttp3 108 | okhttp 109 | ${okhttp.version} 110 | test 111 | 112 | 113 | com.squareup.okhttp3 114 | mockwebserver 115 | ${okhttp.version} 116 | test 117 | 118 | 119 | 120 | 121 | 122 | spring 123 | true 124 | 125 | 126 | spring-snapshots 127 | Spring Snapshots 128 | https://repo.spring.io/snapshot 129 | 130 | true 131 | 132 | 133 | 134 | spring-milestones 135 | Spring Milestones 136 | https://repo.spring.io/milestone 137 | 138 | false 139 | 140 | 141 | 142 | maven-central 143 | Maven Central 144 | https://repo.maven.apache.org/maven2 145 | 146 | false 147 | 148 | 149 | 150 | 151 | 152 | spring-snapshots 153 | Spring Snapshots 154 | https://repo.spring.io/snapshot 155 | 156 | true 157 | 158 | 159 | 160 | spring-milestones 161 | Spring Milestones 162 | https://repo.spring.io/milestone 163 | 164 | false 165 | 166 | 167 | 168 | maven-central 169 | Maven Central 170 | https://repo.maven.apache.org/maven2 171 | 172 | false 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/AbstractCloudFoundryTaskLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.time.Duration; 20 | 21 | import io.jsonwebtoken.lang.Assert; 22 | import org.cloudfoundry.client.CloudFoundryClient; 23 | import org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest; 24 | import org.cloudfoundry.client.v2.spaces.ListSpacesRequest; 25 | import org.cloudfoundry.client.v3.tasks.CancelTaskRequest; 26 | import org.cloudfoundry.client.v3.tasks.CancelTaskResponse; 27 | import org.cloudfoundry.client.v3.tasks.GetTaskRequest; 28 | import org.cloudfoundry.client.v3.tasks.GetTaskResponse; 29 | import org.cloudfoundry.client.v3.tasks.ListTasksRequest; 30 | import org.cloudfoundry.client.v3.tasks.TaskState; 31 | import org.slf4j.Logger; 32 | import org.slf4j.LoggerFactory; 33 | import reactor.core.publisher.Mono; 34 | import reactor.util.function.Tuple2; 35 | 36 | import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest; 37 | import org.springframework.cloud.deployer.spi.core.RuntimeEnvironmentInfo; 38 | import org.springframework.cloud.deployer.spi.task.LaunchState; 39 | import org.springframework.cloud.deployer.spi.task.TaskLauncher; 40 | import org.springframework.cloud.deployer.spi.task.TaskStatus; 41 | 42 | /** 43 | * Abstract class to provide base functionality for launching Tasks on Cloud Foundry. This 44 | * class provides the base SPI for the {@link CloudFoundryTaskLauncher}. 45 | * 46 | * Does not override the default no-op implementation for 47 | * {@link TaskLauncher#cleanup(String)} and {@link TaskLauncher#destroy(String)}. 48 | */ 49 | abstract class AbstractCloudFoundryTaskLauncher extends AbstractCloudFoundryDeployer implements TaskLauncher { 50 | 51 | private static final Logger logger = LoggerFactory.getLogger(AbstractCloudFoundryTaskLauncher.class); 52 | 53 | private final CloudFoundryClient client; 54 | 55 | private final Mono organizationId; 56 | 57 | private final Mono spaceId; 58 | 59 | AbstractCloudFoundryTaskLauncher(CloudFoundryClient client, 60 | CloudFoundryDeploymentProperties deploymentProperties, 61 | RuntimeEnvironmentInfo runtimeEnvironmentInfo) { 62 | super(deploymentProperties, runtimeEnvironmentInfo); 63 | this.client = client; 64 | organizationId = organizationId(); 65 | spaceId = spaceId(); 66 | } 67 | 68 | /** 69 | * Setup a reactor flow to cancel a running task. This implementation opts to be 70 | * asynchronous. 71 | * 72 | * @param id the task's id to be canceled as returned from the 73 | * {@link TaskLauncher#launch(AppDeploymentRequest)} 74 | */ 75 | @Override 76 | public void cancel(String id) { 77 | requestCancelTask(id) 78 | .timeout(Duration.ofSeconds(this.deploymentProperties.getApiTimeout())) 79 | .doOnSuccess(r -> logger.info("Task {} cancellation successful", id)) 80 | .doOnError(logError(String.format("Task %s cancellation failed", id))) 81 | .subscribe(); 82 | } 83 | 84 | /** 85 | * Lookup the current status based on task id. 86 | * 87 | * @param id taskId as returned from the {@link TaskLauncher#launch(AppDeploymentRequest)} 88 | * @return the current task status 89 | */ 90 | @Override 91 | public TaskStatus status(String id) { 92 | try { 93 | return getStatus(id) 94 | .doOnSuccess(v -> logger.info("Successfully computed status [{}] for id={}", v, id)) 95 | .doOnError(logError(String.format("Failed to compute status for %s", id))) 96 | .block(Duration.ofMillis(this.deploymentProperties.getStatusTimeout())); 97 | } 98 | catch (Exception timeoutDueToBlock) { 99 | logger.error("Caught exception while querying for status of id={}", id, timeoutDueToBlock); 100 | return createErrorTaskStatus(id); 101 | } 102 | } 103 | 104 | @Override 105 | public int getRunningTaskExecutionCount() { 106 | 107 | Mono> orgAndSpace = Mono.zip(organizationId, spaceId); 108 | 109 | Mono listTasksRequest = orgAndSpace.map(tuple-> 110 | ListTasksRequest.builder() 111 | .state(TaskState.RUNNING) 112 | .organizationId(tuple.getT1()) 113 | .spaceId(tuple.getT2()) 114 | .build()); 115 | 116 | return listTasksRequest.flatMap(request-> this.client.tasks().list(request)) 117 | .map(listTasksResponse -> listTasksResponse.getPagination().getTotalResults()) 118 | .doOnError(logError("Failed to list running tasks")) 119 | .doOnSuccess(count -> logger.info(String.format("There are %d running tasks", count))) 120 | .block(Duration.ofMillis(this.deploymentProperties.getStatusTimeout())); 121 | } 122 | 123 | @Override 124 | public int getMaximumConcurrentTasks() { 125 | return this.deploymentProperties.getMaximumConcurrentTasks(); 126 | } 127 | 128 | protected boolean maxConcurrentExecutionsReached() { 129 | return this.getRunningTaskExecutionCount() >= this.getMaximumConcurrentTasks(); 130 | } 131 | 132 | private Mono getStatus(String id) { 133 | return requestGetTask(id) 134 | .map(this::toTaskStatus) 135 | .onErrorResume(isNotFoundError(), t -> { 136 | logger.debug("Task for id={} does not exist", id); 137 | return Mono.just(new TaskStatus(id, LaunchState.unknown, null)); 138 | }) 139 | .transform(statusRetry(id)) 140 | .onErrorReturn(createErrorTaskStatus(id)); 141 | } 142 | 143 | private TaskStatus createErrorTaskStatus(String id) { 144 | return new TaskStatus(id, LaunchState.error, null); 145 | } 146 | 147 | protected TaskStatus toTaskStatus(GetTaskResponse response) { 148 | switch (response.getState()) { 149 | case SUCCEEDED: 150 | return new TaskStatus(response.getId(), LaunchState.complete, null); 151 | case RUNNING: 152 | return new TaskStatus(response.getId(), LaunchState.running, null); 153 | case PENDING: 154 | return new TaskStatus(response.getId(), LaunchState.launching, null); 155 | case CANCELING: 156 | return new TaskStatus(response.getId(), LaunchState.cancelled, null); 157 | case FAILED: 158 | return new TaskStatus(response.getId(), LaunchState.failed, null); 159 | default: 160 | throw new IllegalStateException(String.format("Unsupported CF task state %s", response.getState())); 161 | } 162 | } 163 | 164 | private Mono requestCancelTask(String taskId) { 165 | return this.client.tasks() 166 | .cancel(CancelTaskRequest.builder() 167 | .taskId(taskId) 168 | .build()); 169 | } 170 | 171 | private Mono requestGetTask(String taskId) { 172 | return this.client.tasks() 173 | .get(GetTaskRequest.builder() 174 | .taskId(taskId) 175 | .build()); 176 | } 177 | 178 | private Mono organizationId() { 179 | String org = this.runtimeEnvironmentInfo.getPlatformSpecificInfo().get(CloudFoundryPlatformSpecificInfo.ORG); 180 | Assert.hasText(org,"Missing runtimeEnvironmentInfo : 'org' required."); 181 | ListOrganizationsRequest listOrganizationsRequest = ListOrganizationsRequest.builder() 182 | .name(org).build(); 183 | return this.client.organizations().list(listOrganizationsRequest) 184 | .doOnError(logError("Failed to list organizations")) 185 | .map(listOrganizationsResponse -> listOrganizationsResponse.getResources().get(0).getMetadata().getId()) 186 | .cache(aValue -> Duration.ofMillis(Long.MAX_VALUE), aValue -> Duration.ZERO, () -> Duration.ZERO); 187 | } 188 | 189 | private Mono spaceId() { 190 | String space = this.runtimeEnvironmentInfo.getPlatformSpecificInfo().get(CloudFoundryPlatformSpecificInfo.SPACE); 191 | Assert.hasText(space,"Missing runtimeEnvironmentInfo : 'space' required."); 192 | ListSpacesRequest listSpacesRequest = ListSpacesRequest.builder() 193 | .name(space).build(); 194 | return this.client.spaces().list(listSpacesRequest) 195 | .doOnError(logError("Failed to list spaces")) 196 | .map(listSpacesResponse -> listSpacesResponse.getResources().get(0).getMetadata().getId()) 197 | .cache(aValue -> Duration.ofMillis(Long.MAX_VALUE), aValue -> Duration.ZERO, () -> Duration.ZERO); 198 | } 199 | 200 | @Override 201 | public void cleanup(String id) { 202 | 203 | } 204 | 205 | @Override 206 | public void destroy(String appName) { 207 | 208 | } 209 | } 210 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/AppNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | /** 20 | * Strategy interface for generating the names of deployed applications. * 21 | * 22 | * @author Soby Chacko 23 | */ 24 | public interface AppNameGenerator { 25 | 26 | /** 27 | * Generate an application name given a base name as the starting point. 28 | * 29 | * @param appName base application name 30 | * @return the generated app name 31 | */ 32 | String generateAppName(String appName); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvAwareAppDeploymentRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest; 20 | 21 | /** 22 | * Copies an {@link AppDeploymentRequest} using a {@link CfEnvAwareResource}. 23 | * 24 | * @author David Turanski 25 | * @since 2.4 26 | */ 27 | class CfEnvAwareAppDeploymentRequest extends AppDeploymentRequest { 28 | 29 | static CfEnvAwareAppDeploymentRequest of(AppDeploymentRequest appDeploymentRequest) { 30 | return new CfEnvAwareAppDeploymentRequest(appDeploymentRequest); 31 | } 32 | 33 | private CfEnvAwareAppDeploymentRequest(AppDeploymentRequest appDeploymentRequest) { 34 | super(appDeploymentRequest.getDefinition(), 35 | CfEnvAwareResource.of(appDeploymentRequest.getResource()), 36 | appDeploymentRequest.getDeploymentProperties(), 37 | appDeploymentRequest.getCommandlineArguments()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvAwareResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.net.MalformedURLException; 23 | import java.net.URI; 24 | import java.net.URL; 25 | import java.net.URLClassLoader; 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | import java.util.Optional; 29 | 30 | import org.apache.commons.logging.Log; 31 | import org.apache.commons.logging.LogFactory; 32 | 33 | import org.springframework.boot.loader.archive.JarFileArchive; 34 | import org.springframework.core.io.Resource; 35 | 36 | /** 37 | * A {@link Resource} implementation that delegates to a resource and keeps the state of a CfEnv dependency 38 | * as an {@link Optional} which may be empty, true, or false. 39 | * 40 | * @author David Turanski 41 | * @since 2.4 42 | */ 43 | class CfEnvAwareResource implements Resource { 44 | private final Resource resource; 45 | 46 | private final boolean hasCfEnv; 47 | 48 | static CfEnvAwareResource of(Resource resource) { 49 | return new CfEnvAwareResource(resource); 50 | } 51 | private CfEnvAwareResource(Resource resource) { 52 | this.resource = resource; 53 | this.hasCfEnv = CfEnvResolver.hasCfEnv(this); 54 | } 55 | 56 | @Override 57 | public boolean exists() { 58 | return resource.exists(); 59 | } 60 | 61 | @Override 62 | public URL getURL() throws IOException { 63 | return resource.getURL(); 64 | } 65 | 66 | @Override 67 | public URI getURI() throws IOException { 68 | return resource.getURI(); 69 | } 70 | 71 | @Override 72 | public File getFile() throws IOException { 73 | return resource.getFile(); 74 | } 75 | 76 | @Override 77 | public long contentLength() throws IOException { 78 | return resource.contentLength(); 79 | } 80 | 81 | @Override 82 | public long lastModified() throws IOException { 83 | return resource.lastModified(); 84 | } 85 | 86 | @Override 87 | public Resource createRelative(String s) throws IOException { 88 | return resource.createRelative(s); 89 | } 90 | 91 | @Override 92 | public String getFilename() { 93 | return resource.getFilename(); 94 | } 95 | 96 | @Override 97 | public String getDescription() { 98 | return resource.getDescription(); 99 | } 100 | 101 | @Override 102 | public InputStream getInputStream() throws IOException { 103 | return resource.getInputStream(); 104 | } 105 | 106 | boolean hasCfEnv() { 107 | return this.hasCfEnv; 108 | } 109 | 110 | /** 111 | * Inspect the {@link CfEnvAwareResource} to determine if it contains a dependency on io.pivotal.cfenv.core.CfEnv. 112 | * Cache the result in the resource. 113 | */ 114 | static class CfEnvResolver { 115 | 116 | private static Log logger = LogFactory.getLog(CfEnvResolver.class); 117 | 118 | private static final String CF_ENV = "io.pivotal.cfenv.core.CfEnv"; 119 | 120 | static boolean hasCfEnv(CfEnvAwareResource app 121 | ) { 122 | try { 123 | String scheme = app.getURI().getScheme().toLowerCase(); 124 | if (scheme.equals("docker")) { 125 | return false; 126 | } 127 | } 128 | catch (IOException e) { 129 | throw new IllegalArgumentException(e.getMessage(), e); 130 | } 131 | 132 | try { 133 | JarFileArchive archive = new JarFileArchive(app.getFile()); 134 | List urls = new ArrayList<>(); 135 | archive.getNestedArchives(entry -> entry.getName().endsWith(".jar"), null).forEachRemaining(a -> { 136 | try { 137 | urls.add(a.getUrl()); 138 | } 139 | catch (MalformedURLException e) { 140 | logger.error("Unable to process nested archive " + e.getMessage()); 141 | } 142 | }); 143 | URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null); 144 | try { 145 | Class.forName(CF_ENV, false, classLoader); 146 | return true; 147 | } 148 | catch (ClassNotFoundException e) { 149 | logger.debug(app.getFilename() + " does not contain " + CF_ENV); 150 | return false; 151 | } 152 | } 153 | catch (Exception e) { 154 | logger.warn("Unable to determine dependencies for " + app.getFilename()); 155 | } 156 | return false; 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | import java.util.stream.Stream; 22 | 23 | import org.apache.commons.logging.Log; 24 | import org.apache.commons.logging.LogFactory; 25 | 26 | import org.springframework.util.StringUtils; 27 | 28 | /** 29 | * Provides methods to configure environment, application properties, and command line 30 | * args if the deployed artifact uses java-cfenv. 31 | * 32 | * @author David Turanski 33 | * @since 2.4 34 | */ 35 | class CfEnvConfigurer { 36 | 37 | private static final Log log = LogFactory.getLog(CfEnvConfigurer.class); 38 | 39 | static final String SPRING_PROFILES_ACTIVE = "SPRING_PROFILES_ACTIVE"; 40 | 41 | static final String SPRING_PROFILES_ACTIVE_FQN = "spring.profiles.active"; 42 | 43 | static final String SPRING_PROFILES_ACTIVE_HYPHENATED = "spring-profiles-active"; 44 | 45 | static final String CLOUD_PROFILE_NAME = "cloud"; 46 | 47 | static final String JBP_CONFIG_SPRING_AUTO_RECONFIGURATION = "JBP_CONFIG_SPRING_AUTO_RECONFIGURATION"; 48 | 49 | static final String ENABLED_FALSE = "{ enabled: false }"; 50 | 51 | /** 52 | * Disable Java Buildpack Spring Auto-reconfiguration. 53 | * 54 | * @param environment a map containing environment variables 55 | * @return an copy of the map setting the environment variable needed to disable 56 | * auto-reconfiguration 57 | */ 58 | static Map disableJavaBuildPackAutoReconfiguration(Map environment) { 59 | log.debug("Disabling 'JBP_CONFIG_SPRING_AUTO_RECONFIGURATION'"); 60 | Map updatedEnvironment = new HashMap<>(environment); 61 | updatedEnvironment.putIfAbsent(JBP_CONFIG_SPRING_AUTO_RECONFIGURATION, ENABLED_FALSE); 62 | return updatedEnvironment; 63 | } 64 | 65 | /** 66 | * Activate the cloud profile. Add to a key that binds to 67 | * spring.profiles.active if one exists. 68 | * @param environment a map containing environment variables or application properties 69 | * @param keyToCreate create a new entry using a preferred key if none exists. 70 | * @return the updated map 71 | */ 72 | static Map activateCloudProfile(Map environment, String keyToCreate) { 73 | log.debug("Activating cloud profile"); 74 | Map updatedEnvironment = new HashMap<>(environment); 75 | 76 | if (appendToExistingEntry(updatedEnvironment, SPRING_PROFILES_ACTIVE, CLOUD_PROFILE_NAME)) { 77 | return updatedEnvironment; 78 | } 79 | else if (appendToExistingEntry(updatedEnvironment, SPRING_PROFILES_ACTIVE_FQN, CLOUD_PROFILE_NAME)) { 80 | return updatedEnvironment; 81 | } 82 | else if (appendToExistingEntry(updatedEnvironment, SPRING_PROFILES_ACTIVE_HYPHENATED, CLOUD_PROFILE_NAME)) { 83 | return updatedEnvironment; 84 | } 85 | // If Key provided, create new spring profiles active entry. 86 | if (StringUtils.hasText(keyToCreate)) { 87 | updatedEnvironment.put(keyToCreate, CLOUD_PROFILE_NAME); 88 | } 89 | 90 | return updatedEnvironment; 91 | } 92 | 93 | /** 94 | * Process a command line argument to append the cloud profile if it binds to 95 | * spring.profiles.active. 96 | * 97 | * @param arg the current value 98 | * @return the updated value 99 | */ 100 | static String appendCloudProfileToSpringProfilesActiveArg(String arg) { 101 | if ((arg.contains(SPRING_PROFILES_ACTIVE_FQN) || 102 | arg.contains(SPRING_PROFILES_ACTIVE_HYPHENATED) || 103 | arg.contains(SPRING_PROFILES_ACTIVE)) && arg.contains("=")) { 104 | String[] tokens = arg.split("="); 105 | arg = String.join("=", tokens[0], appendToValueIfPresent(tokens[1], CLOUD_PROFILE_NAME)); 106 | } 107 | return arg; 108 | } 109 | 110 | private static boolean appendToExistingEntry(Map environment, String key, String value) { 111 | if (environment.containsKey(key)) { 112 | String current = environment.get(key); 113 | environment.put(key, appendToValueIfPresent(current, value)); 114 | return true; 115 | } 116 | return false; 117 | } 118 | 119 | private static String appendToValueIfPresent(String current, String value) { 120 | if (StringUtils.hasText(current)) { 121 | if (!Stream.of(current.split(",")).filter(s -> s.trim().equals(value)).findFirst().isPresent()) { 122 | return current.join(",", current, value); 123 | } 124 | return current; 125 | } 126 | return value; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryActuatorTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.Optional; 20 | 21 | import org.springframework.cloud.deployer.spi.app.AbstractActuatorTemplate; 22 | import org.springframework.cloud.deployer.spi.app.AppAdmin; 23 | import org.springframework.cloud.deployer.spi.app.AppDeployer; 24 | import org.springframework.cloud.deployer.spi.app.AppInstanceStatus; 25 | import org.springframework.http.HttpHeaders; 26 | import org.springframework.web.client.RestTemplate; 27 | import org.springframework.web.util.UriComponentsBuilder; 28 | 29 | /** 30 | * Access the actuator endpoint for an app instance deployed to Cloud Foundry. 31 | * 32 | * @author David Turanski 33 | */ 34 | public class CloudFoundryActuatorTemplate extends AbstractActuatorTemplate { 35 | 36 | public CloudFoundryActuatorTemplate(RestTemplate restTemplate, AppDeployer appDeployer, AppAdmin appAdmin) { 37 | super(restTemplate, appDeployer, appAdmin); 38 | } 39 | 40 | @Override 41 | protected String actuatorUrlForInstance(AppInstanceStatus appInstanceStatus) { 42 | return UriComponentsBuilder.fromHttpUrl(appInstanceStatus.getAttributes().get("url")) 43 | .path("/actuator").toUriString(); 44 | } 45 | 46 | @Override 47 | public Optional httpHeadersForInstance(AppInstanceStatus appInstanceStatus) { 48 | HttpHeaders headers = new HttpHeaders(); 49 | headers.add("X-Cf-App-Instance", String.format("%s:%d", appInstanceStatus.getAttributes() 50 | .get(CloudFoundryAppInstanceStatus.CF_GUID), 51 | Integer.valueOf(appInstanceStatus.getAttributes().get(CloudFoundryAppInstanceStatus.INDEX)))); 52 | return Optional.of(headers); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryAppInstanceStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.TreeMap; 22 | 23 | import org.cloudfoundry.operations.applications.ApplicationDetail; 24 | import org.cloudfoundry.operations.applications.InstanceDetail; 25 | 26 | import org.springframework.cloud.deployer.spi.app.AppInstanceStatus; 27 | import org.springframework.cloud.deployer.spi.app.DeploymentState; 28 | 29 | /** 30 | * Maps status returned by the Cloud Foundry API to {@link AppInstanceStatus}. 31 | * 32 | * @author Eric Bottard 33 | * @author David Turanski 34 | */ 35 | public class CloudFoundryAppInstanceStatus implements AppInstanceStatus { 36 | 37 | private final InstanceDetail instanceDetail; 38 | 39 | private final ApplicationDetail applicationDetail; 40 | 41 | private final int index; 42 | 43 | private final Map attributes = new TreeMap<>(); 44 | 45 | /** 46 | * The deployer assigned unique id for each app instance. 47 | */ 48 | static final String GUID = "guid"; 49 | 50 | /** 51 | * The platform assigned guid - common among app instances with replicas 52 | */ 53 | static final String CF_GUID = "cf-guid"; 54 | 55 | /** 56 | * The app index. 57 | */ 58 | static final String INDEX = "index"; 59 | 60 | public CloudFoundryAppInstanceStatus(ApplicationDetail applicationDetail, InstanceDetail instanceDetail, int index) { 61 | this.applicationDetail = applicationDetail; 62 | this.instanceDetail = instanceDetail; 63 | this.index = index; 64 | } 65 | 66 | @Override 67 | public String getId() { 68 | return applicationDetail.getName() + "-" + index; 69 | } 70 | 71 | @Override 72 | public DeploymentState getState() { 73 | if (instanceDetail == null) { 74 | return DeploymentState.failed; 75 | } 76 | switch (instanceDetail.getState()) { 77 | case "STARTING": 78 | case "DOWN": 79 | return DeploymentState.deploying; 80 | case "CRASHED": 81 | return DeploymentState.failed; 82 | // Seems the client incorrectly reports apps as FLAPPING when they are 83 | // obviously fine. Mapping as RUNNING for now 84 | case "FLAPPING": 85 | case "RUNNING": 86 | return DeploymentState.deployed; 87 | case "UNKNOWN": 88 | return DeploymentState.unknown; 89 | default: 90 | throw new IllegalStateException("Unsupported CF state: " + instanceDetail.getState()); 91 | } 92 | } 93 | 94 | @Override 95 | public Map getAttributes() { 96 | if (instanceDetail != null) { 97 | if (instanceDetail.getCpu() != null) { 98 | attributes.put("metrics.machine.cpu", String.format("%.1f%%", instanceDetail.getCpu() * 100d)); 99 | } 100 | if (instanceDetail.getDiskQuota() != null && instanceDetail.getDiskUsage() != null) { 101 | attributes.put("metrics.machine.disk", String.format("%.1f%%", 100d * instanceDetail.getDiskUsage() / instanceDetail.getDiskQuota())); 102 | } 103 | if (instanceDetail.getMemoryQuota() != null && instanceDetail.getMemoryUsage() != null) { 104 | attributes.put("metrics.machine.memory", String.format("%.1f%%", 100d * instanceDetail.getMemoryUsage() / instanceDetail.getMemoryQuota())); 105 | } 106 | } 107 | List urls = applicationDetail.getUrls(); 108 | if (!urls.isEmpty()) { 109 | attributes.put("url", "http://" + urls.get(0)); 110 | for (int i = 0; i < urls.size() ; i++) { 111 | attributes.put("url." + i, "http://" + urls.get(i)); 112 | } 113 | } 114 | // TODO cf-java-client versions > 2.8 will have an index formally added ot InstanceDetail 115 | /* 116 | The deployer GUID must be unique for each app instance, the CloudFoundry GUID is common to all instances of 117 | the same app. 118 | */ 119 | attributes.put(GUID, applicationDetail.getName() + ":" + index); 120 | attributes.put(CF_GUID, applicationDetail.getId()); 121 | attributes.put(INDEX, String.valueOf(index)); 122 | return attributes; 123 | } 124 | 125 | @Override 126 | public String toString() { 127 | return String.format("%s[%s : %s]" , getClass().getSimpleName(), getId(), getState()); 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryAppNameGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.Random; 20 | 21 | import org.apache.commons.logging.Log; 22 | import org.apache.commons.logging.LogFactory; 23 | 24 | import org.springframework.beans.factory.InitializingBean; 25 | import org.springframework.util.StringUtils; 26 | 27 | /** 28 | * CloudFoundry specific implementation of {@link AppNameGenerator}. This takes into account the 29 | * configuration properties {@code enableRandomAppNamePrefix} and {@code appNamePrefix}. 30 | * 31 | * If {@code enableRandomAppNamePrefix} a random short string is prefixed to the base name. 32 | * It is true by default. If {@code appNamePrefix} is set, it is also prefixed before the random string. 33 | * By default the {@code appNamePrefix} is the value of {@code spring.application.name} if available, 34 | * otherwise the empty string. 35 | * 36 | * As an example, if {@code enableRandomAppNamePrefix=true}, {@code spring.application.name=server}, 37 | * and we are deploying an application whose base name is {@code time}, then the deployed name on Cloud Foundry 38 | * may be {@code server-ug54dh5-time} 39 | * 40 | * @author Soby Chacko 41 | * @author Mark Pollack 42 | */ 43 | public class CloudFoundryAppNameGenerator implements AppNameGenerator, InitializingBean { 44 | 45 | private static final Log logger = LogFactory.getLog(CloudFoundryAppNameGenerator.class); 46 | 47 | /* Given that appnames are by default part of a hostname, limit to 63 chars max. */ 48 | private static final int MAX_APPNAME_LENGTH = 63; 49 | 50 | private String prefixToUse = ""; 51 | 52 | private final CloudFoundryDeploymentProperties properties; 53 | 54 | public CloudFoundryAppNameGenerator(CloudFoundryDeploymentProperties cloudFoundryDeploymentProperties) { 55 | this.properties = cloudFoundryDeploymentProperties; 56 | } 57 | 58 | @Override 59 | public void afterPropertiesSet() throws Exception { 60 | if (properties.isEnableRandomAppNamePrefix()) { 61 | prefixToUse = createUniquePrefix(); 62 | if (!StringUtils.isEmpty(properties.getAppNamePrefix())) { 63 | prefixToUse = String.format("%s-%s", properties.getAppNamePrefix(), prefixToUse); 64 | } 65 | } else { 66 | if (!StringUtils.isEmpty(properties.getAppNamePrefix())) { 67 | prefixToUse = properties.getAppNamePrefix(); 68 | } 69 | } 70 | logger.info(String.format("Prefix to be used for deploying apps: %s", prefixToUse)); 71 | } 72 | 73 | 74 | @Override 75 | public String generateAppName(String appName) { 76 | if (StringUtils.isEmpty(prefixToUse)) { 77 | return appName.substring(0, Math.min(MAX_APPNAME_LENGTH, appName.length())); 78 | } else { 79 | String string = String.format("%s-%s", prefixToUse, appName); 80 | return string.substring(0, Math.min(MAX_APPNAME_LENGTH, string.length())); 81 | } 82 | } 83 | 84 | private String createUniquePrefix() { 85 | String alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 86 | char[] result = new char[7]; 87 | Random random = new Random(); 88 | for (int i = 0 ; i < result.length ; i++) { 89 | result[i] = alphabet.charAt(random.nextInt(alphabet.length())); 90 | } 91 | return new String(result); 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryConnectionProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2020 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.net.URL; 20 | 21 | import javax.validation.constraints.NotNull; 22 | 23 | import org.springframework.validation.annotation.Validated; 24 | 25 | /** 26 | * Holds configuration properties for connecting to a Cloud Foundry runtime. 27 | * 28 | * @author Eric Bottard 29 | * @author Greg Turnquist 30 | */ 31 | @Validated 32 | public class CloudFoundryConnectionProperties { 33 | 34 | /** 35 | * Top level prefix for Cloud Foundry related configuration properties. 36 | */ 37 | public static final String CLOUDFOUNDRY_PROPERTIES = "spring.cloud.deployer.cloudfoundry"; 38 | 39 | /** 40 | * The organization to use when registering new applications. 41 | */ 42 | @NotNull 43 | private String org; 44 | 45 | /** 46 | * The space to use when registering new applications. 47 | */ 48 | @NotNull 49 | private String space; 50 | 51 | /** 52 | * Location of the CloudFoundry REST API endpoint to use. 53 | */ 54 | @NotNull 55 | private URL url; 56 | 57 | /** 58 | * Username to use to authenticate against the Cloud Foundry API. 59 | */ 60 | @NotNull 61 | private String username; 62 | 63 | /** 64 | * Password to use to authenticate against the Cloud Foundry API. 65 | */ 66 | @NotNull 67 | private String password; 68 | 69 | /** 70 | * ClientId to use with token providers, effectively defaults to "cf" in 71 | * cloudfroundry client. 72 | */ 73 | private String clientId; 74 | 75 | /** 76 | * ClientSecret to use with token providers, effectively defaults to empty in 77 | * cloudfroundry client. 78 | */ 79 | private String clientSecret; 80 | 81 | /** 82 | * Indicates the identity provider to be used when accessing the Cloud Foundry API. 83 | * The passed string has to be a URL-Encoded JSON Object, containing the field origin with value as origin_key of an identity provider. 84 | */ 85 | private String loginHint; 86 | 87 | /** 88 | * Allow operation using self-signed certificates. 89 | */ 90 | private boolean skipSslValidation = false; 91 | 92 | public String getOrg() { 93 | return org; 94 | } 95 | 96 | public void setOrg(String org) { 97 | this.org = org; 98 | } 99 | 100 | public String getSpace() { 101 | return space; 102 | } 103 | 104 | public void setSpace(String space) { 105 | this.space = space; 106 | } 107 | 108 | public URL getUrl() { 109 | return url; 110 | } 111 | 112 | public void setUrl(URL url) { 113 | this.url = url; 114 | } 115 | 116 | public String getClientId() { 117 | return clientId; 118 | } 119 | 120 | public void setClientId(String clientId) { 121 | this.clientId = clientId; 122 | } 123 | 124 | public String getClientSecret() { 125 | return clientSecret; 126 | } 127 | 128 | public void setClientSecret(String clientSecret) { 129 | this.clientSecret = clientSecret; 130 | } 131 | 132 | public String getUsername() { 133 | return username; 134 | } 135 | 136 | public void setUsername(String username) { 137 | this.username = username; 138 | } 139 | 140 | public String getPassword() { 141 | return password; 142 | } 143 | 144 | public void setPassword(String password) { 145 | this.password = password; 146 | } 147 | 148 | public boolean isSkipSslValidation() { 149 | return skipSslValidation; 150 | } 151 | 152 | public void setSkipSslValidation(boolean skipSslValidation) { 153 | this.skipSslValidation = skipSslValidation; 154 | } 155 | 156 | public String getLoginHint() { 157 | return loginHint; 158 | } 159 | 160 | public void setLoginHint(String loginHint) { 161 | this.loginHint = loginHint; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryDeployerAutoConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.time.Duration; 20 | 21 | import com.github.zafarkhaja.semver.Version; 22 | import org.cloudfoundry.client.CloudFoundryClient; 23 | import org.cloudfoundry.client.v2.info.GetInfoRequest; 24 | import org.cloudfoundry.operations.CloudFoundryOperations; 25 | import org.cloudfoundry.operations.DefaultCloudFoundryOperations; 26 | import org.cloudfoundry.reactor.ConnectionContext; 27 | import org.cloudfoundry.reactor.DefaultConnectionContext; 28 | import org.cloudfoundry.reactor.TokenProvider; 29 | import org.cloudfoundry.reactor.client.ReactorCloudFoundryClient; 30 | import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider; 31 | import org.cloudfoundry.reactor.tokenprovider.PasswordGrantTokenProvider.Builder; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | import org.springframework.beans.factory.annotation.Autowired; 36 | import org.springframework.boot.autoconfigure.AutoConfigureOrder; 37 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 38 | import org.springframework.boot.context.properties.ConfigurationProperties; 39 | import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; 40 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 41 | import org.springframework.cloud.deployer.spi.app.AppDeployer; 42 | import org.springframework.cloud.deployer.spi.core.RuntimeEnvironmentInfo; 43 | import org.springframework.cloud.deployer.spi.task.TaskLauncher; 44 | import org.springframework.cloud.deployer.spi.util.RuntimeVersionUtils; 45 | import org.springframework.context.annotation.Bean; 46 | import org.springframework.context.annotation.Configuration; 47 | import org.springframework.core.Ordered; 48 | import org.springframework.util.StringUtils; 49 | import org.springframework.web.client.RestTemplate; 50 | 51 | 52 | /** 53 | * Creates a {@link CloudFoundryAppDeployer} 54 | * 55 | * @author Eric Bottard 56 | * @author Ben Hale 57 | * @author David Turanski 58 | */ 59 | @Configuration 60 | @EnableConfigurationProperties 61 | @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) 62 | public class CloudFoundryDeployerAutoConfiguration { 63 | 64 | private static final Logger logger = LoggerFactory.getLogger(CloudFoundryDeployerAutoConfiguration.class); 65 | 66 | @Autowired 67 | private EarlyConnectionConfiguration connectionConfiguration; 68 | 69 | @Bean 70 | @ConditionalOnMissingBean 71 | public CloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient, CloudFoundryConnectionProperties properties) { 72 | return DefaultCloudFoundryOperations.builder() 73 | .cloudFoundryClient(cloudFoundryClient) 74 | .organization(properties.getOrg()) 75 | .space(properties.getSpace()) 76 | .build(); 77 | } 78 | 79 | private RuntimeEnvironmentInfo runtimeEnvironmentInfo(Class spiClass, Class implementationClass) { 80 | CloudFoundryClient client = connectionConfiguration.cloudFoundryClient( 81 | connectionConfiguration.connectionContext(connectionConfiguration.cloudFoundryConnectionProperties()), 82 | connectionConfiguration.tokenProvider(connectionConfiguration.cloudFoundryConnectionProperties())); 83 | Version version = connectionConfiguration.version(client); 84 | 85 | return new CloudFoundryPlatformSpecificInfo(new RuntimeEnvironmentInfo.Builder()) 86 | .apiEndpoint(connectionConfiguration.cloudFoundryConnectionProperties().getUrl().toString()) 87 | .org(connectionConfiguration.cloudFoundryConnectionProperties().getOrg()) 88 | .space(connectionConfiguration.cloudFoundryConnectionProperties().getSpace()) 89 | .builder() 90 | .implementationName(implementationClass.getSimpleName()) 91 | .spiClass(spiClass) 92 | .implementationVersion(RuntimeVersionUtils.getVersion(CloudFoundryAppDeployer.class)) 93 | .platformType("Cloud Foundry") 94 | .platformClientVersion(RuntimeVersionUtils.getVersion(client.getClass())) 95 | .platformApiVersion(version.toString()) 96 | .platformHostVersion("unknown") 97 | .build(); 98 | } 99 | 100 | @Bean 101 | @ConditionalOnMissingBean(AppDeployer.class) 102 | public AppDeployer appDeployer(CloudFoundryOperations operations, 103 | AppNameGenerator applicationNameGenerator) { 104 | return new CloudFoundryAppDeployer( 105 | applicationNameGenerator, 106 | connectionConfiguration.appDeploymentProperties(), 107 | operations, 108 | runtimeEnvironmentInfo(AppDeployer.class, CloudFoundryAppDeployer.class) 109 | ); 110 | } 111 | 112 | @Bean 113 | CloudFoundryActuatorTemplate actuatorOperations(RestTemplate actuatorRestTemplate, AppDeployer appDeployer) { 114 | return new CloudFoundryActuatorTemplate(actuatorRestTemplate, appDeployer, 115 | connectionConfiguration.appDeploymentProperties().getAppAdmin()); 116 | } 117 | 118 | @Bean 119 | RestTemplate actuatorRestTemplate() { 120 | return new RestTemplate(); 121 | } 122 | 123 | @Bean 124 | @ConditionalOnMissingBean(AppNameGenerator.class) 125 | public AppNameGenerator appDeploymentCustomizer() { 126 | return new CloudFoundryAppNameGenerator(connectionConfiguration.appDeploymentProperties()); 127 | } 128 | 129 | @Bean 130 | @ConditionalOnMissingBean(TaskLauncher.class) 131 | public TaskLauncher taskLauncher(CloudFoundryClient client, 132 | CloudFoundryOperations operations, 133 | Version version) { 134 | 135 | if (version.greaterThanOrEqualTo(UnsupportedVersionTaskLauncher.MINIMUM_SUPPORTED_VERSION)) { 136 | RuntimeEnvironmentInfo runtimeEnvironmentInfo = runtimeEnvironmentInfo(TaskLauncher.class, CloudFoundryTaskLauncher.class); 137 | return new CloudFoundryTaskLauncher( 138 | client, 139 | connectionConfiguration.taskDeploymentProperties(), 140 | operations, 141 | runtimeEnvironmentInfo); 142 | } else { 143 | RuntimeEnvironmentInfo runtimeEnvironmentInfo = runtimeEnvironmentInfo(TaskLauncher.class, UnsupportedVersionTaskLauncher.class); 144 | return new UnsupportedVersionTaskLauncher(version, runtimeEnvironmentInfo); 145 | } 146 | } 147 | 148 | @Bean 149 | @ConfigurationPropertiesBinding 150 | public DurationConverter durationConverter() { 151 | return new DurationConverter(); 152 | } 153 | 154 | /** 155 | * A subset of configuration beans that can be used on its own to connect to the Cloud Controller API 156 | * and query it for its version. Automatically applied in CloudFoundryDeployerAutoConfiguration by virtue 157 | * of being a static inner class of it. 158 | * 159 | * @author Eric Bottard 160 | */ 161 | @Configuration 162 | @EnableConfigurationProperties 163 | public static class EarlyConnectionConfiguration { 164 | 165 | @Bean 166 | @ConditionalOnMissingBean(name = "appDeploymentProperties") 167 | public CloudFoundryDeploymentProperties appDeploymentProperties() { 168 | return defaultSharedDeploymentProperties(); 169 | } 170 | 171 | 172 | @Bean 173 | @ConditionalOnMissingBean(name = "taskDeploymentProperties") 174 | public CloudFoundryDeploymentProperties taskDeploymentProperties() { 175 | return defaultSharedDeploymentProperties(); 176 | } 177 | 178 | @Bean 179 | @ConfigurationProperties(prefix = CloudFoundryConnectionProperties.CLOUDFOUNDRY_PROPERTIES) 180 | public CloudFoundryDeploymentProperties defaultSharedDeploymentProperties() { 181 | return new CloudFoundryDeploymentProperties(); 182 | } 183 | 184 | @Bean 185 | @ConditionalOnMissingBean 186 | public Version version(CloudFoundryClient client) { 187 | return client.info() 188 | .get(GetInfoRequest.builder() 189 | .build()) 190 | .map(response -> Version.valueOf(response.getApiVersion())) 191 | .doOnError(e -> { 192 | throw new RuntimeException("Bad credentials connecting to Cloud Foundry.", e); 193 | }) 194 | .doOnNext(version -> logger.info("Connecting to Cloud Foundry with API Version {}", version)) 195 | .block(Duration.ofSeconds(appDeploymentProperties().getApiTimeout())); 196 | } 197 | 198 | @Bean 199 | @ConditionalOnMissingBean 200 | public CloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { 201 | return ReactorCloudFoundryClient.builder() 202 | .connectionContext(connectionContext) 203 | .tokenProvider(tokenProvider) 204 | .build(); 205 | } 206 | 207 | @Bean 208 | @ConditionalOnMissingBean 209 | public TokenProvider tokenProvider(CloudFoundryConnectionProperties properties) { 210 | Builder tokenProviderBuilder = PasswordGrantTokenProvider.builder() 211 | .username(properties.getUsername()) 212 | .password(properties.getPassword()) 213 | .loginHint(properties.getLoginHint()); 214 | if (StringUtils.hasText(properties.getClientId())) { 215 | tokenProviderBuilder.clientId(properties.getClientId()); 216 | } 217 | if (StringUtils.hasText(properties.getClientSecret())) { 218 | tokenProviderBuilder.clientSecret(properties.getClientSecret()); 219 | } 220 | return tokenProviderBuilder.build(); 221 | } 222 | 223 | @Bean 224 | @ConditionalOnMissingBean 225 | @ConfigurationProperties(prefix = CloudFoundryConnectionProperties.CLOUDFOUNDRY_PROPERTIES) 226 | public CloudFoundryConnectionProperties cloudFoundryConnectionProperties() { 227 | return new CloudFoundryConnectionProperties(); 228 | } 229 | 230 | @Bean 231 | @ConditionalOnMissingBean 232 | public ConnectionContext connectionContext(CloudFoundryConnectionProperties properties) { 233 | return DefaultConnectionContext.builder() 234 | .apiHost(properties.getUrl().getHost()) 235 | .skipSslValidation(properties.isSkipSslValidation()) 236 | .build(); 237 | } 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryPlatformSpecificInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import org.springframework.cloud.deployer.spi.core.RuntimeEnvironmentInfo; 20 | import org.springframework.util.Assert; 21 | 22 | /** 23 | * A Provides required platform specific values to {@link RuntimeEnvironmentInfo}. 24 | * 25 | * @author David Turanski 26 | */ 27 | public class CloudFoundryPlatformSpecificInfo { 28 | static final String API_ENDPOINT = "API Endpoint"; 29 | 30 | static final String ORG = "Organization"; 31 | 32 | static final String SPACE = "Space"; 33 | 34 | private final RuntimeEnvironmentInfo.Builder runtimeEnvironmentInfo; 35 | 36 | private String apiEndpoint; 37 | 38 | private String org; 39 | 40 | private String space; 41 | 42 | public CloudFoundryPlatformSpecificInfo(RuntimeEnvironmentInfo.Builder runtimeEnvironmentInfo) { 43 | this.runtimeEnvironmentInfo = runtimeEnvironmentInfo; 44 | } 45 | 46 | public CloudFoundryPlatformSpecificInfo apiEndpoint(String apiEndpoint) { 47 | this.apiEndpoint = apiEndpoint; 48 | return this; 49 | } 50 | 51 | public CloudFoundryPlatformSpecificInfo org(String org) { 52 | this.org = org; 53 | return this; 54 | } 55 | 56 | public CloudFoundryPlatformSpecificInfo space(String space) { 57 | this.space = space; 58 | return this; 59 | } 60 | 61 | public RuntimeEnvironmentInfo.Builder builder() { 62 | Assert.hasText(apiEndpoint, "'apiEndpoint' must contain text"); 63 | Assert.hasText(org, "'org' must contain text"); 64 | Assert.hasText(space, "'space' must contain text"); 65 | runtimeEnvironmentInfo.addPlatformSpecificInfo(API_ENDPOINT, apiEndpoint); 66 | runtimeEnvironmentInfo.addPlatformSpecificInfo(ORG, org); 67 | runtimeEnvironmentInfo.addPlatformSpecificInfo(SPACE, space); 68 | return runtimeEnvironmentInfo; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/DurationConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.time.Duration; 20 | import java.time.format.DateTimeParseException; 21 | 22 | import org.springframework.core.convert.converter.Converter; 23 | import org.springframework.util.StringUtils; 24 | 25 | /** 26 | * Converter from String to {@link java.time.Duration}, accepting human readable forms (without an H or a T). 27 | * 28 | * @author Eric Bottard 29 | */ 30 | public class DurationConverter implements Converter { 31 | 32 | @Override 33 | public Duration convert(String source) { 34 | if (StringUtils.isEmpty(source)) { 35 | return null; 36 | } 37 | try { 38 | return Duration.parse(source); 39 | } 40 | catch (DateTimeParseException ignored) { 41 | return Duration.parse("PT" + source); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/ServiceParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.ArrayList; 20 | import java.util.LinkedHashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Optional; 24 | import java.util.regex.Matcher; 25 | import java.util.regex.Pattern; 26 | import java.util.stream.Stream; 27 | 28 | import org.springframework.util.StringUtils; 29 | 30 | /** 31 | * Parses service instances and parses binding parameters if provided. Accepts Strings like 32 | * 'myservice foo=bar, cat=bat' or 'service foo:bar, cat:bat', White space is required between the 33 | * service name and parameters, but optional between the key-value pairs. 34 | * 35 | * @author David Turanski 36 | */ 37 | abstract class ServiceParser { 38 | 39 | private static Pattern serviceWithParameters = Pattern.compile("([^\\s]+)\\s*?(.*)?"); 40 | 41 | private static Pattern singleQuotedLiteral = Pattern.compile("'([^']*?)'"); 42 | 43 | /** 44 | * @param serviceSpec the service instance followed by optional parameters. 45 | * @return an Option of parameters. 46 | */ 47 | static Optional> getServiceParameters(String serviceSpec) { 48 | Matcher m = serviceWithParameters.matcher(serviceSpec); 49 | 50 | if (m.matches()) { 51 | return parseParameters(m.group(2), serviceSpec); 52 | } 53 | 54 | return Optional.ofNullable(null); 55 | } 56 | 57 | /** 58 | * Extract the service name. 59 | * 60 | * @param serviceSpec the service instance name followed by optional parameters 61 | * @return the service instance 62 | */ 63 | static String getServiceInstanceName(String serviceSpec) { 64 | Matcher m = serviceWithParameters.matcher(serviceSpec); 65 | if (m.matches()) { 66 | return m.group(1); 67 | } else { 68 | throw new IllegalArgumentException("invalid service specification: " + serviceSpec); 69 | } 70 | } 71 | 72 | static List splitServiceProperties(String serviceProperties) { 73 | List serviceInstances = new ArrayList<>(); 74 | 75 | if (StringUtils.hasText(serviceProperties)) { 76 | Matcher m = singleQuotedLiteral.matcher(serviceProperties); 77 | int index = 0; 78 | 79 | while (index >= 0 && m.find(index)) { 80 | String val = m.group().replaceAll("'", ""); 81 | serviceInstances.add(val); 82 | serviceProperties = serviceProperties.replaceAll(m.group(), ""); 83 | index = serviceProperties.indexOf("'"); 84 | m = singleQuotedLiteral.matcher(serviceProperties); 85 | } 86 | 87 | Stream.of(serviceProperties.split(",")) 88 | .filter(StringUtils::hasText) 89 | .map(String::trim) 90 | .forEach(s -> serviceInstances.add(s)); 91 | } 92 | 93 | return serviceInstances; 94 | } 95 | 96 | private static Optional> parseParameters( 97 | String rawParametersString, String serviceSpec) { 98 | if (StringUtils.hasText(rawParametersString)) { 99 | Map parameters = new LinkedHashMap<>(); 100 | String[] entries = rawParametersString.split(","); 101 | Stream.of(entries) 102 | .forEach( 103 | s -> { 104 | String[] pair = s.split("[:|=]"); 105 | if (pair.length != 2) { 106 | throw new IllegalArgumentException( 107 | "invalid service specification: " + serviceSpec); 108 | } 109 | parameters.put(pair[0].trim(), pair[1].trim()); 110 | }); 111 | return Optional.of(parameters); 112 | } 113 | return Optional.ofNullable(null); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/cloudfoundry/UnsupportedVersionTaskLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import com.github.zafarkhaja.semver.Version; 20 | import org.cloudfoundry.operations.CloudFoundryOperations; 21 | 22 | import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest; 23 | import org.springframework.cloud.deployer.spi.core.RuntimeEnvironmentInfo; 24 | import org.springframework.cloud.deployer.spi.task.TaskLauncher; 25 | import org.springframework.cloud.deployer.spi.task.TaskStatus; 26 | import org.springframework.cloud.deployer.spi.util.RuntimeVersionUtils; 27 | 28 | /** 29 | * A failing implementation of {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} for versions of the 30 | * Cloud Controller API below {@link #MINIMUM_SUPPORTED_VERSION}. 31 | * 32 | * @author Eric Bottard 33 | * @see CloudFoundryDeployerAutoConfiguration 34 | */ 35 | public class UnsupportedVersionTaskLauncher implements TaskLauncher { 36 | 37 | public static final Version MINIMUM_SUPPORTED_VERSION = Version.forIntegers(2, 63, 0); 38 | 39 | private final Version actualVersion; 40 | 41 | private final RuntimeEnvironmentInfo info; 42 | 43 | public UnsupportedVersionTaskLauncher(Version actualVersion, RuntimeEnvironmentInfo info) { 44 | this.actualVersion = actualVersion; 45 | this.info = info; 46 | } 47 | 48 | @Override 49 | public String launch(AppDeploymentRequest request) { 50 | throw failure(); 51 | } 52 | 53 | @Override 54 | public void cancel(String id) { 55 | throw failure(); 56 | } 57 | 58 | @Override 59 | public TaskStatus status(String id) { 60 | throw failure(); 61 | } 62 | 63 | @Override 64 | public void cleanup(String id) { 65 | throw failure(); 66 | } 67 | 68 | @Override 69 | public void destroy(String appName) { 70 | throw failure(); 71 | } 72 | 73 | @Override 74 | public RuntimeEnvironmentInfo environmentInfo() { 75 | return info; 76 | } 77 | @Override 78 | public int getMaximumConcurrentTasks() { 79 | throw failure(); 80 | } 81 | @Override 82 | public int getRunningTaskExecutionCount() { 83 | throw failure(); 84 | } 85 | 86 | @Override 87 | public String getLog(String appName) { 88 | throw failure(); 89 | } 90 | 91 | private UnsupportedOperationException failure() { 92 | return new UnsupportedOperationException("Cloud Foundry API version " + actualVersion + " is earlier than " 93 | + MINIMUM_SUPPORTED_VERSION + " and is incompatible with cf-java-client " + 94 | RuntimeVersionUtils.getVersion(CloudFoundryOperations.class)+ ". It is thus unsupported"); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/CloudFoundryScheduleSSLException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.scheduler.cloudfoundry; 18 | 19 | /** 20 | * A {@link RuntimeException} that wraps SSL based exceptions. 21 | * 22 | * @author Glenn Renfro 23 | */ 24 | public class CloudFoundryScheduleSSLException extends RuntimeException { 25 | 26 | public CloudFoundryScheduleSSLException(String message, Throwable t) { 27 | super(message, t); 28 | } 29 | 30 | public CloudFoundryScheduleSSLException(String t) { 31 | super(t); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/CloudFoundrySchedulerProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.scheduler.cloudfoundry; 18 | 19 | import javax.validation.constraints.NotNull; 20 | 21 | import org.springframework.boot.context.properties.ConfigurationProperties; 22 | import org.springframework.validation.annotation.Validated; 23 | 24 | /** 25 | * Holds configuration properties for connecting to a Cloud Foundry Scheduler. 26 | * 27 | * @author Glenn Renfro 28 | */ 29 | @Validated 30 | @ConfigurationProperties(prefix = CloudFoundrySchedulerProperties.CLOUDFOUNDRY_PROPERTIES) 31 | @Deprecated 32 | public class CloudFoundrySchedulerProperties { 33 | 34 | /** 35 | * Top level prefix for Cloud Foundry related configuration properties. 36 | */ 37 | public static final String CLOUDFOUNDRY_PROPERTIES = "spring.cloud.scheduler.cloudfoundry"; 38 | 39 | /** 40 | * Location of the PCF scheduler REST API enpoint ot use. 41 | */ 42 | @NotNull 43 | private String schedulerUrl; 44 | 45 | /** 46 | * The number of retries allowed when scheduling a task if an {@link javax.net.ssl.SSLException} is thrown. 47 | */ 48 | private int scheduleSSLRetryCount = 5; 49 | 50 | /** 51 | * The number of seconds to wait for a unSchedule to complete. 52 | */ 53 | private int unScheduleTimeoutInSeconds = 30; 54 | 55 | /** 56 | * The number of seconds to wait for a schedule to complete. 57 | * This excludes the time it takes to stage the application on Cloud Foundry. 58 | */ 59 | private int scheduleTimeoutInSeconds = 30; 60 | 61 | /** 62 | * The number of seconds to wait for a list of schedules to be returned. 63 | */ 64 | private int listTimeoutInSeconds = 60; 65 | 66 | 67 | public String getSchedulerUrl() { 68 | return schedulerUrl; 69 | } 70 | 71 | public void setSchedulerUrl(String schedulerUrl) { 72 | this.schedulerUrl = schedulerUrl; 73 | } 74 | 75 | public int getScheduleSSLRetryCount() { 76 | return scheduleSSLRetryCount; 77 | } 78 | 79 | public void setScheduleSSLRetryCount(int scheduleSSLRetryCount) { 80 | this.scheduleSSLRetryCount = scheduleSSLRetryCount; 81 | } 82 | 83 | public int getUnScheduleTimeoutInSeconds() { 84 | return unScheduleTimeoutInSeconds; 85 | } 86 | 87 | public void setUnScheduleTimeoutInSeconds(int unScheduleTimeoutInSeconds) { 88 | this.unScheduleTimeoutInSeconds = unScheduleTimeoutInSeconds; 89 | } 90 | 91 | public int getScheduleTimeoutInSeconds() { 92 | return scheduleTimeoutInSeconds; 93 | } 94 | 95 | public void setScheduleTimeoutInSeconds(int scheduleTimeoutInSeconds) { 96 | this.scheduleTimeoutInSeconds = scheduleTimeoutInSeconds; 97 | } 98 | 99 | public int getListTimeoutInSeconds() { 100 | return listTimeoutInSeconds; 101 | } 102 | 103 | public void setListTimeoutInSeconds(int listTimeoutInSeconds) { 104 | this.listTimeoutInSeconds = listTimeoutInSeconds; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "hints": [ 3 | { 4 | "name": "spring.cloud.deployer.cloudfoundry.health-check", 5 | "values": [ 6 | { 7 | "value": "NONE" 8 | }, 9 | { 10 | "value": "HTTP" 11 | }, 12 | { 13 | "value": "PROCESS" 14 | }, 15 | { 16 | "value": "PORT" 17 | } 18 | ] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeployerAutoConfiguration 3 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeployerAutoConfiguration 2 | -------------------------------------------------------------------------------- /src/scripts/next-minor-parent-snapshot-version: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Script maintaining versions 5 | # 6 | # Bump up next minor development version for parents. 7 | # ---------------------------------------------------------------------------- 8 | 9 | find_basedir() { 10 | local basedir=$(cd -P -- "$(dirname -- "$0")" && cd .. && cd .. && pwd -P) 11 | echo "${basedir}" 12 | } 13 | 14 | export PROJECTBASEDIR=$(find_basedir) 15 | 16 | (cd $PROJECTBASEDIR && ./mvnw build-helper:parse-version versions:update-parent -DgenerateBackupPoms=false -DallowSnapshots=true -DparentVersion='${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}' && ./mvnw build-helper:parse-version versions:update-property -DgenerateBackupPoms=false -DallowSnapshots=true -Dproperty=spring-cloud-deployer.version -DnewVersion='${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT') 17 | 18 | -------------------------------------------------------------------------------- /src/scripts/next-minor-snapshot-version: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Script maintaining versions 5 | # 6 | # Bump up next minor development version. 7 | # ---------------------------------------------------------------------------- 8 | 9 | find_basedir() { 10 | local basedir=$(cd -P -- "$(dirname -- "$0")" && cd .. && cd .. && pwd -P) 11 | echo "${basedir}" 12 | } 13 | 14 | export PROJECTBASEDIR=$(find_basedir) 15 | 16 | (cd $PROJECTBASEDIR && ./mvnw build-helper:parse-version versions:set -DprocessAllModules=false -DgenerateBackupPoms=false -DnewVersion='${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion}.0-SNAPSHOT') 17 | 18 | -------------------------------------------------------------------------------- /src/scripts/next-parent-snapshot-version: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Script maintaining versions 5 | # 6 | # Bump up next build development version for parents. 7 | # ---------------------------------------------------------------------------- 8 | 9 | find_basedir() { 10 | local basedir=$(cd -P -- "$(dirname -- "$0")" && cd .. && cd .. && pwd -P) 11 | echo "${basedir}" 12 | } 13 | 14 | export PROJECTBASEDIR=$(find_basedir) 15 | 16 | (cd $PROJECTBASEDIR && ./mvnw build-helper:parse-version versions:update-parent -DgenerateBackupPoms=false -DallowSnapshots=true -DparentVersion='[${parsedVersion.majorVersion}.${parsedVersion.minorVersion},${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion})' && ./mvnw build-helper:parse-version versions:update-property -DgenerateBackupPoms=false -DallowSnapshots=true -Dproperty=spring-cloud-deployer.version -DnewVersion='[${parsedVersion.majorVersion}.${parsedVersion.minorVersion},${parsedVersion.majorVersion}.${parsedVersion.nextMinorVersion})') 17 | -------------------------------------------------------------------------------- /src/scripts/next-snapshot-version: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # ---------------------------------------------------------------------------- 4 | # Script maintaining versions 5 | # 6 | # Bump up next build development version. 7 | # ---------------------------------------------------------------------------- 8 | 9 | find_basedir() { 10 | local basedir=$(cd -P -- "$(dirname -- "$0")" && cd .. && cd .. && pwd -P) 11 | echo "${basedir}" 12 | } 13 | 14 | export PROJECTBASEDIR=$(find_basedir) 15 | 16 | (cd $PROJECTBASEDIR && ./mvnw build-helper:parse-version versions:set -DprocessAllModules=false -DgenerateBackupPoms=false -DnewVersion='${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}-SNAPSHOT') 17 | 18 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/AbstractAppDeployerTestSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.cloudfoundry.operations.CloudFoundryOperations; 23 | import org.cloudfoundry.operations.applications.ApplicationDetail; 24 | import org.cloudfoundry.operations.applications.Applications; 25 | import org.cloudfoundry.operations.applications.DeleteApplicationRequest; 26 | import org.cloudfoundry.operations.applications.GetApplicationRequest; 27 | import org.cloudfoundry.operations.applications.PushApplicationManifestRequest; 28 | import org.cloudfoundry.operations.applications.ScaleApplicationRequest; 29 | import org.cloudfoundry.operations.services.Services; 30 | import org.junit.jupiter.api.BeforeEach; 31 | import org.mockito.Answers; 32 | import org.mockito.Mock; 33 | import org.mockito.MockitoAnnotations; 34 | import reactor.core.publisher.Mono; 35 | 36 | import org.springframework.cloud.deployer.spi.core.RuntimeEnvironmentInfo; 37 | 38 | import static org.mockito.ArgumentMatchers.any; 39 | import static org.mockito.BDDMockito.given; 40 | 41 | /** 42 | * @author David Turanski 43 | */ 44 | public abstract class AbstractAppDeployerTestSupport { 45 | protected final CloudFoundryDeploymentProperties deploymentProperties = new CloudFoundryDeploymentProperties(); 46 | 47 | @Mock(answer = Answers.RETURNS_SMART_NULLS) 48 | protected AppNameGenerator applicationNameGenerator; 49 | 50 | @Mock(answer = Answers.RETURNS_SMART_NULLS) 51 | protected Applications applications; 52 | 53 | protected CloudFoundryAppDeployer deployer; 54 | 55 | @Mock(answer = Answers.RETURNS_SMART_NULLS) 56 | protected CloudFoundryOperations operations; 57 | 58 | @Mock(answer = Answers.RETURNS_SMART_NULLS) 59 | protected Services services; 60 | 61 | @Mock(answer = Answers.RETURNS_SMART_NULLS) 62 | protected RuntimeEnvironmentInfo runtimeEnvironmentInfo; 63 | 64 | @BeforeEach 65 | public void setUp() { 66 | MockitoAnnotations.openMocks(this); 67 | given(this.operations.applications()).willReturn(this.applications); 68 | given(this.operations.services()).willReturn(this.services); 69 | this.deployer = new CloudFoundryAppDeployer(this.applicationNameGenerator, this.deploymentProperties, 70 | this.operations, this.runtimeEnvironmentInfo); 71 | postSetUp(); 72 | } 73 | 74 | protected abstract void postSetUp(); 75 | 76 | protected void givenRequestScaleApplication(String id, Integer count, int memoryLimit, int diskLimit, 77 | Mono response) { 78 | given(this.operations.applications() 79 | .scale(ScaleApplicationRequest.builder().name(id).instances(count).memoryLimit(memoryLimit) 80 | .diskLimit(diskLimit) 81 | .startupTimeout(this.deploymentProperties.getStartupTimeout()) 82 | .stagingTimeout(this.deploymentProperties.getStagingTimeout()).build())).willReturn(response); 83 | } 84 | 85 | protected void givenRequestDeleteApplication(String id, Mono response) { 86 | given(this.operations.applications() 87 | .delete(DeleteApplicationRequest.builder().deleteRoutes(true).name(id).build())).willReturn(response); 88 | } 89 | 90 | @SuppressWarnings("unchecked") 91 | protected void givenRequestGetApplication(String id, Mono response, 92 | Mono... responses) { 93 | given(this.operations.applications().get(GetApplicationRequest.builder().name(id).build())).willReturn(response, 94 | responses); 95 | } 96 | 97 | protected void givenRequestPushApplication(PushApplicationManifestRequest request, Mono response) { 98 | given(this.operations.applications() 99 | .pushManifest(any(PushApplicationManifestRequest.class))) 100 | .willReturn(response); 101 | } 102 | 103 | protected Map defaultEnvironmentVariables() { 104 | Map environmentVariables = new HashMap<>(); 105 | environmentVariables.put("SPRING_APPLICATION_JSON", "{}"); 106 | addGuidAndIndex(environmentVariables); 107 | return environmentVariables; 108 | } 109 | 110 | protected void addGuidAndIndex(Map environmentVariables) { 111 | environmentVariables.put("SPRING_APPLICATION_INDEX", "${vcap.application.instance_index}"); 112 | environmentVariables.put("SPRING_CLOUD_APPLICATION_GUID", 113 | "${vcap.application.name}:${vcap.application.instance_index}"); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvAwareResourceTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | 20 | import java.io.IOException; 21 | import java.net.URI; 22 | import java.net.URISyntaxException; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | import org.springframework.core.io.ClassPathResource; 27 | import org.springframework.core.io.Resource; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | import static org.mockito.Mockito.mock; 31 | import static org.mockito.Mockito.when; 32 | 33 | /** 34 | * @author David Turanski 35 | */ 36 | public class CfEnvAwareResourceTests { 37 | 38 | @Test 39 | public void testCfEnvResolverWithCfEnv() throws IOException { 40 | CfEnvAwareResource resource = CfEnvAwareResource.of(new ClassPathResource("log-sink-rabbit-3.0.0.BUILD-SNAPSHOT.jar")); 41 | assertThat(resource.hasCfEnv()).isTrue(); 42 | } 43 | 44 | @Test 45 | public void testCfEnvResolverWithNoCfEnv() throws IOException { 46 | CfEnvAwareResource resource = CfEnvAwareResource.of(new ClassPathResource("batch-job-1.0.0.BUILD-SNAPSHOT.jar")); 47 | assertThat(resource.hasCfEnv()).isFalse(); 48 | } 49 | 50 | @Test 51 | public void testDoesNothingWithDocker() throws IOException, URISyntaxException { 52 | Resource docker = mock(Resource.class); 53 | when(docker.getURI()).thenReturn(new URI("docker://fake/news")); 54 | assertThat(CfEnvAwareResource.of(docker).hasCfEnv()).isFalse(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CfEnvConfigurerTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.Collections; 20 | import java.util.Map; 21 | 22 | import org.cloudfoundry.util.FluentMap; 23 | import org.junit.jupiter.api.Test; 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | 27 | public class CfEnvConfigurerTests { 28 | 29 | @Test 30 | public void testCfEnvConfigurerActivateCloudProfile() { 31 | Map env = CfEnvConfigurer.activateCloudProfile( 32 | Collections.emptyMap(), CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN); 33 | assertThat(env).containsEntry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, 34 | CfEnvConfigurer.CLOUD_PROFILE_NAME); 35 | assertThat(env).doesNotContainKeys( 36 | CfEnvConfigurer.SPRING_PROFILES_ACTIVE, 37 | CfEnvConfigurer.SPRING_PROFILES_ACTIVE_HYPHENATED); 38 | } 39 | 40 | @Test 41 | public void testCfEnvConfigurerDoNotActivateCloudProfileIfNoneExists() { 42 | Map env = CfEnvConfigurer.activateCloudProfile( 43 | Collections.emptyMap(), null); 44 | assertThat(env).doesNotContainKeys(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, 45 | CfEnvConfigurer.SPRING_PROFILES_ACTIVE, 46 | CfEnvConfigurer.SPRING_PROFILES_ACTIVE_HYPHENATED); 47 | } 48 | 49 | @Test 50 | public void testCfEnvConfigurerActivateCloudProfileWithEmptyValue() { 51 | Map env = CfEnvConfigurer.activateCloudProfile( 52 | FluentMap.builder() 53 | .entry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE, " ") 54 | .build(), 55 | CfEnvConfigurer.SPRING_PROFILES_ACTIVE); 56 | assertThat(env).containsEntry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE, 57 | CfEnvConfigurer.CLOUD_PROFILE_NAME); 58 | assertThat(env).doesNotContainKeys(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, 59 | CfEnvConfigurer.SPRING_PROFILES_ACTIVE_HYPHENATED); 60 | } 61 | 62 | @Test 63 | public void testCfEnvConfigurerAppendToActiveProfiles() { 64 | Map env = CfEnvConfigurer.activateCloudProfile( 65 | FluentMap.builder() 66 | .entry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, "foo,bar") 67 | .build(), null); 68 | assertThat(env).containsEntry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, "foo,bar,cloud"); 69 | assertThat(env).doesNotContainKeys(CfEnvConfigurer.SPRING_PROFILES_ACTIVE, 70 | CfEnvConfigurer.SPRING_PROFILES_ACTIVE_HYPHENATED); 71 | } 72 | 73 | @Test 74 | public void testCfEnvConfigurerDoesNotAppendCloudProfileIfAlreadyThere() { 75 | Map env = CfEnvConfigurer.activateCloudProfile( 76 | FluentMap.builder() 77 | .entry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, "foo,cloud") 78 | .build(), null); 79 | assertThat(env).containsEntry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, "foo,cloud"); 80 | 81 | env = CfEnvConfigurer.activateCloudProfile( 82 | FluentMap.builder() 83 | .entry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, "cloud,foo,bar") 84 | .build(), null); 85 | assertThat(env).containsEntry(CfEnvConfigurer.SPRING_PROFILES_ACTIVE_FQN, "cloud,foo,bar"); 86 | } 87 | 88 | @Test 89 | public void testCloudProfileAppendedToCommandLineArgs() { 90 | assertThat(CfEnvConfigurer.appendCloudProfileToSpringProfilesActiveArg("--spring-profiles-active=foo,bar")) 91 | .isEqualTo("--spring-profiles-active=foo,bar,cloud"); 92 | assertThat(CfEnvConfigurer.appendCloudProfileToSpringProfilesActiveArg("--spring.profiles.active=foo")) 93 | .isEqualTo("--spring.profiles.active=foo,cloud"); 94 | assertThat(CfEnvConfigurer.appendCloudProfileToSpringProfilesActiveArg("--spring.profiles.active=foo,cloud")) 95 | .isEqualTo("--spring.profiles.active=foo,cloud"); 96 | assertThat(CfEnvConfigurer.appendCloudProfileToSpringProfilesActiveArg("--spring.profiles.active=cloud")) 97 | .isEqualTo("--spring.profiles.active=cloud"); 98 | assertThat(CfEnvConfigurer.appendCloudProfileToSpringProfilesActiveArg("--baz=foo")) 99 | .isEqualTo("--baz=foo"); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryActuatorTemplateTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.io.IOException; 20 | import java.nio.charset.StandardCharsets; 21 | import java.util.Collections; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import okhttp3.mockwebserver.Dispatcher; 26 | import okhttp3.mockwebserver.MockResponse; 27 | import okhttp3.mockwebserver.MockWebServer; 28 | import okhttp3.mockwebserver.RecordedRequest; 29 | import org.cloudfoundry.operations.applications.ApplicationDetail; 30 | import org.cloudfoundry.operations.applications.InstanceDetail; 31 | import org.junit.jupiter.api.AfterAll; 32 | import org.junit.jupiter.api.BeforeAll; 33 | import org.junit.jupiter.api.Test; 34 | import reactor.core.publisher.Mono; 35 | 36 | import org.springframework.cloud.deployer.spi.app.ActuatorOperations; 37 | import org.springframework.cloud.deployer.spi.app.AppAdmin; 38 | import org.springframework.core.io.ClassPathResource; 39 | import org.springframework.http.HttpStatus; 40 | import org.springframework.util.StreamUtils; 41 | import org.springframework.util.StringUtils; 42 | import org.springframework.web.client.RestTemplate; 43 | 44 | import static org.assertj.core.api.Assertions.assertThat; 45 | 46 | public class CloudFoundryActuatorTemplateTests extends AbstractAppDeployerTestSupport { 47 | 48 | private ActuatorOperations actuatorOperations; 49 | private static MockWebServer mockActuator; 50 | String appBaseUrl; 51 | 52 | @BeforeAll 53 | static void setupMockServer() throws IOException { 54 | mockActuator = new MockWebServer(); 55 | mockActuator.start(); 56 | mockActuator.setDispatcher(new Dispatcher() { 57 | @Override 58 | public MockResponse dispatch(RecordedRequest recordedRequest) throws InterruptedException { 59 | assertThat(recordedRequest.getHeader("X-Cf-App-Instance")).isEqualTo("test-application-id:0"); 60 | switch (recordedRequest.getPath()) { 61 | case "/actuator/info": 62 | return new MockResponse().setBody(resourceAsString("actuator-info.json")) 63 | .addHeader("Content-Type", "application/json").setResponseCode(200); 64 | case "/actuator/health": 65 | return new MockResponse().setBody("\"status\":\"UP\"}") 66 | .addHeader("Content-Type", "application/json").setResponseCode(200); 67 | case "/actuator/bindings": 68 | return new MockResponse().setBody(resourceAsString("actuator-bindings.json")) 69 | .addHeader("Content-Type", "application/json").setResponseCode(200); 70 | case "/actuator/bindings/input": 71 | if (recordedRequest.getMethod().equals("GET")) { 72 | return new MockResponse().setBody(resourceAsString("actuator-binding-input.json")) 73 | .addHeader("Content-Type", "application/json") 74 | .setResponseCode(200); 75 | } 76 | else if (recordedRequest.getMethod().equals("POST")) { 77 | if (!StringUtils.hasText(recordedRequest.getBody().toString())) { 78 | return new MockResponse().setResponseCode(HttpStatus.BAD_REQUEST.value()); 79 | } 80 | else { 81 | return new MockResponse().setBody(recordedRequest.getBody()) 82 | .addHeader("Content-Type", "application/json").setResponseCode(200); 83 | } 84 | } 85 | else { 86 | return new MockResponse().setResponseCode(HttpStatus.BAD_REQUEST.value()); 87 | } 88 | default: 89 | return new MockResponse().setResponseCode(HttpStatus.NOT_FOUND.value()); 90 | } 91 | } 92 | }); 93 | } 94 | 95 | @AfterAll 96 | static void tearDown() throws IOException { 97 | mockActuator.shutdown(); 98 | } 99 | 100 | @Override 101 | protected void postSetUp() { 102 | this.actuatorOperations = new CloudFoundryActuatorTemplate(new RestTemplate(), this.deployer, new AppAdmin()); 103 | this.appBaseUrl = String.format("localhost:%s", mockActuator.getPort()); 104 | givenRequestGetApplication("test-application-id", Mono.just(ApplicationDetail.builder() 105 | .diskQuota(0) 106 | .id("test-application-id") 107 | .instances(1) 108 | .memoryLimit(0) 109 | .name("test-application") 110 | .requestedState("RUNNING") 111 | .runningInstances(1) 112 | .stack("test-stack") 113 | .urls(appBaseUrl) 114 | .instanceDetail(InstanceDetail.builder().state("RUNNING").index("1").build()) 115 | .build())); 116 | } 117 | 118 | @Test 119 | void actuatorInfo() { 120 | Map info = actuatorOperations 121 | .getFromActuator("test-application-id", "test-application:0", "/info", Map.class); 122 | 123 | assertThat(((Map) (info.get("app"))).get("name")).isEqualTo("log-sink-rabbit"); 124 | } 125 | 126 | @Test 127 | void actuatorBindings() { 128 | List bindings = actuatorOperations 129 | .getFromActuator("test-application-id", "test-application:0", "/bindings", List.class); 130 | 131 | assertThat(((Map) (bindings.get(0))).get("bindingName")).isEqualTo("input"); 132 | } 133 | 134 | @Test 135 | void actuatorBindingInput() { 136 | Map binding = actuatorOperations 137 | .getFromActuator("test-application-id", "test-application:0", "/bindings/input", Map.class); 138 | assertThat(binding.get("bindingName")).isEqualTo("input"); 139 | } 140 | 141 | @Test 142 | void actuatorPostBindingInput() { 143 | Map state = actuatorOperations 144 | .postToActuator("test-application-id", "test-application:0", "/bindings/input", 145 | Collections.singletonMap("state", "STOPPED"), Map.class); 146 | assertThat(state.get("state")).isEqualTo("STOPPED"); 147 | } 148 | 149 | private static String resourceAsString(String path) { 150 | try { 151 | return StreamUtils.copyToString(new ClassPathResource(path).getInputStream(), StandardCharsets.UTF_8); 152 | } 153 | catch (IOException e) { 154 | throw new RuntimeException(e.getMessage(), e); 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryAppDeployerIntegrationIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import org.junit.jupiter.api.BeforeEach; 20 | import org.junit.jupiter.api.Disabled; 21 | 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 24 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 25 | import org.springframework.boot.test.context.SpringBootTest; 26 | import org.springframework.cloud.deployer.spi.app.AppDeployer; 27 | import org.springframework.cloud.deployer.spi.test.AbstractAppDeployerIntegrationJUnit5Tests; 28 | import org.springframework.cloud.deployer.spi.test.Timeout; 29 | import org.springframework.context.annotation.Configuration; 30 | import org.springframework.test.context.ContextConfiguration; 31 | 32 | /** 33 | * Integration tests for CloudFoundryAppDeployer. 34 | * 35 | * @author Eric Bottard 36 | * @author Greg Turnquist 37 | */ 38 | 39 | 40 | @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.NONE, 41 | properties = {"spring.cloud.deployer.cloudfoundry.enableRandomAppNamePrefix=false"}) 42 | @ContextConfiguration(classes = CloudFoundryAppDeployerIntegrationIT.Config.class) 43 | public class CloudFoundryAppDeployerIntegrationIT extends AbstractAppDeployerIntegrationJUnit5Tests { 44 | 45 | @Autowired 46 | private AppDeployer appDeployer; 47 | 48 | @Override 49 | protected AppDeployer provideAppDeployer() { 50 | return appDeployer; 51 | } 52 | 53 | /** 54 | * Execution environments may override this default value to have tests wait longer for a deployment, for example if 55 | * running in an environment that is known to be slow. 56 | */ 57 | protected double timeoutMultiplier = 1.0D; 58 | 59 | protected int maxRetries = 60; 60 | 61 | @BeforeEach 62 | public void init() { 63 | String multiplier = System.getenv("CF_DEPLOYER_TIMEOUT_MULTIPLIER"); 64 | if (multiplier != null) { 65 | timeoutMultiplier = Double.parseDouble(multiplier); 66 | } 67 | } 68 | 69 | @Override 70 | @Disabled("Need to look into args escaping better. Disabling for the time being") 71 | public void testCommandLineArgumentsPassing() { 72 | } 73 | 74 | @Override 75 | protected String randomName() { 76 | // This will become the hostname part and is limited to 63 chars 77 | String name = super.randomName(); 78 | return name.substring(0, Math.min(63, name.length())); 79 | } 80 | 81 | @Override 82 | protected Timeout deploymentTimeout() { 83 | return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier)); 84 | } 85 | 86 | @Override 87 | protected Timeout undeploymentTimeout() { 88 | return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier)); 89 | } 90 | 91 | /** 92 | * This triggers the use of {@link CloudFoundryDeployerAutoConfiguration}. 93 | * 94 | * @author Eric Bottard 95 | */ 96 | @Configuration 97 | @EnableAutoConfiguration 98 | @EnableConfigurationProperties 99 | public static class Config { 100 | 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryAppNameGeneratorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.deployer.spi.cloudfoundry; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.assertj.core.api.Assertions.assertThat; 21 | 22 | 23 | /** 24 | * @author Soby Chacko 25 | * @author Mark Pollack 26 | */ 27 | public class CloudFoundryAppNameGeneratorTest { 28 | 29 | @Test 30 | public void testDeploymentIdWithAppNamePrefixAndRandomAppNamePrefixFalse() throws Exception { 31 | CloudFoundryDeploymentProperties properties = new CloudFoundryDeploymentProperties(); 32 | properties.setEnableRandomAppNamePrefix(false); 33 | properties.setAppNamePrefix("dataflow"); 34 | CloudFoundryAppNameGenerator deploymentCustomizer = 35 | new CloudFoundryAppNameGenerator(properties); 36 | deploymentCustomizer.afterPropertiesSet(); 37 | 38 | assertThat(deploymentCustomizer.generateAppName("foo")).isEqualTo("dataflow-foo"); 39 | } 40 | 41 | @Test 42 | public void testDeploymentIdWithAppNamePrefixAndRandomAppNamePrefixTrue() throws Exception { 43 | CloudFoundryDeploymentProperties properties = new CloudFoundryDeploymentProperties(); 44 | properties.setEnableRandomAppNamePrefix(true); 45 | properties.setAppNamePrefix("dataflow-longername"); 46 | CloudFoundryAppNameGenerator deploymentCustomizer = 47 | new CloudFoundryAppNameGenerator(properties); 48 | deploymentCustomizer.afterPropertiesSet(); 49 | 50 | String deploymentIdWithUniquePrefix = deploymentCustomizer.generateAppName("foo"); 51 | assertThat(deploymentIdWithUniquePrefix).matches("dataflow-longername-\\w+-foo"); 52 | 53 | String deploymentIdWithUniquePrefixAgain = deploymentCustomizer.generateAppName("foo"); 54 | 55 | assertThat(deploymentIdWithUniquePrefix).isEqualTo(deploymentIdWithUniquePrefixAgain); 56 | } 57 | 58 | @Test 59 | public void testDeploymentIdWithoutAppNamePrefixAndRandomAppNamePrefixTrue() throws Exception { 60 | CloudFoundryDeploymentProperties properties = new CloudFoundryDeploymentProperties(); 61 | properties.setEnableRandomAppNamePrefix(true); 62 | properties.setAppNamePrefix(""); 63 | CloudFoundryAppNameGenerator deploymentCustomizer = 64 | new CloudFoundryAppNameGenerator(properties); 65 | deploymentCustomizer.afterPropertiesSet(); 66 | 67 | String deploymentIdWithUniquePrefix = deploymentCustomizer.generateAppName("foo"); 68 | assertThat(deploymentIdWithUniquePrefix).matches("\\w+-foo"); 69 | } 70 | 71 | @Test 72 | public void testDeploymentIdWithoutAppNamePrefixAndRandomAppNamePrefixFalse() throws Exception { 73 | CloudFoundryDeploymentProperties properties = new CloudFoundryDeploymentProperties(); 74 | properties.setEnableRandomAppNamePrefix(false); 75 | properties.setAppNamePrefix(""); 76 | CloudFoundryAppNameGenerator deploymentCustomizer = 77 | new CloudFoundryAppNameGenerator(properties); 78 | deploymentCustomizer.afterPropertiesSet(); 79 | 80 | assertThat(deploymentCustomizer.generateAppName("foo")).isEqualTo("foo"); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryConnectionPropertiesTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import org.springframework.boot.context.properties.ConfigurationProperties; 25 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 26 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 27 | import org.springframework.context.annotation.Bean; 28 | import org.springframework.core.env.StandardEnvironment; 29 | import org.springframework.core.env.SystemEnvironmentPropertySource; 30 | 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | 33 | public class CloudFoundryConnectionPropertiesTests { 34 | 35 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); 36 | 37 | @Test 38 | public void setAllProperties() { 39 | this.contextRunner 40 | .withInitializer(context -> { 41 | Map map = new HashMap<>(); 42 | map.put("spring.cloud.deployer.cloudfoundry.org", "org"); 43 | map.put("spring.cloud.deployer.cloudfoundry.space", "space"); 44 | map.put("spring.cloud.deployer.cloudfoundry.url", "http://example.com"); 45 | map.put("spring.cloud.deployer.cloudfoundry.username", "username"); 46 | map.put("spring.cloud.deployer.cloudfoundry.password", "password"); 47 | map.put("spring.cloud.deployer.cloudfoundry.client-id", "id"); 48 | map.put("spring.cloud.deployer.cloudfoundry.client-secret", "secret"); 49 | map.put("spring.cloud.deployer.cloudfoundry.login-hint", "hint"); 50 | map.put("spring.cloud.deployer.cloudfoundry.skip-ssl-validation", "true"); 51 | context.getEnvironment().getPropertySources().addLast(new SystemEnvironmentPropertySource( 52 | StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, map)); 53 | }) 54 | .withUserConfiguration(Config1.class) 55 | .run((context) -> { 56 | CloudFoundryConnectionProperties properties = context.getBean(CloudFoundryConnectionProperties.class); 57 | assertThat(properties.getOrg()).isEqualTo("org"); 58 | assertThat(properties.getSpace()).isEqualTo("space"); 59 | assertThat(properties.getUrl().toString()).isEqualTo("http://example.com"); 60 | assertThat(properties.getUsername()).isEqualTo("username"); 61 | assertThat(properties.getPassword()).isEqualTo("password"); 62 | assertThat(properties.getClientId()).isEqualTo("id"); 63 | assertThat(properties.getClientSecret()).isEqualTo("secret"); 64 | assertThat(properties.getLoginHint()).isEqualTo("hint"); 65 | assertThat(properties.isSkipSslValidation()).isTrue(); 66 | }); 67 | } 68 | 69 | @EnableConfigurationProperties 70 | private static class Config1 { 71 | 72 | @Bean 73 | @ConfigurationProperties(prefix = CloudFoundryConnectionProperties.CLOUDFOUNDRY_PROPERTIES) 74 | public TestCloudFoundryConnectionProperties testCloudFoundryConnectionProperties() { 75 | return new TestCloudFoundryConnectionProperties(); 76 | } 77 | } 78 | 79 | private static class TestCloudFoundryConnectionProperties extends CloudFoundryConnectionProperties { 80 | // not to get Configuration Processor @Bean Duplicate Prefix Definition error 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryDeployerTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.springframework.cloud.deployer.spi.cloudfoundry; 17 | 18 | import java.util.Arrays; 19 | import java.util.Collections; 20 | import java.util.HashMap; 21 | import java.util.HashSet; 22 | import java.util.Map; 23 | import java.util.Set; 24 | 25 | import org.junit.jupiter.api.Test; 26 | import org.mockito.Answers; 27 | import org.mockito.Mock; 28 | 29 | import org.springframework.cloud.deployer.spi.core.AppDefinition; 30 | import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest; 31 | import org.springframework.cloud.deployer.spi.core.RuntimeEnvironmentInfo; 32 | import org.springframework.core.io.FileSystemResource; 33 | import org.springframework.core.io.Resource; 34 | 35 | import static org.assertj.core.api.Assertions.assertThat; 36 | 37 | public class CloudFoundryDeployerTests { 38 | 39 | @Mock(answer = Answers.RETURNS_SMART_NULLS) 40 | private RuntimeEnvironmentInfo runtimeEnvironmentInfo; 41 | 42 | private Resource resource = new FileSystemResource("src/test/resources/demo-0.0.1-SNAPSHOT.jar"); 43 | private AppDefinition definition = new AppDefinition("test-application", Collections.emptyMap()); 44 | 45 | @Test 46 | public void testBuildpacksDefault() { 47 | CloudFoundryDeploymentProperties props = new CloudFoundryDeploymentProperties(); 48 | TestCloudFoundryDeployer deployer = new TestCloudFoundryDeployer(props, runtimeEnvironmentInfo); 49 | AppDeploymentRequest request = new AppDeploymentRequest(definition, resource); 50 | 51 | Set buildpacks = deployer.buildpacks(request); 52 | assertThat(buildpacks).hasSize(1); 53 | } 54 | 55 | @Test 56 | public void testBuildpacksSingleMultiLogic() { 57 | CloudFoundryDeploymentProperties props = new CloudFoundryDeploymentProperties(); 58 | props.setBuildpack("buildpack1"); 59 | TestCloudFoundryDeployer deployer = new TestCloudFoundryDeployer(props, runtimeEnvironmentInfo); 60 | Map deploymentProperties = new HashMap<>(); 61 | AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, deploymentProperties, null); 62 | 63 | 64 | Set buildpacks = deployer.buildpacks(request); 65 | assertThat(buildpacks).hasSize(1); 66 | assertThat(buildpacks).contains("buildpack1"); 67 | 68 | props.setBuildpacks(new HashSet<>(Arrays.asList("buildpack2", "buildpack3"))); 69 | buildpacks = deployer.buildpacks(request); 70 | assertThat(buildpacks).hasSize(2); 71 | assertThat(buildpacks).contains("buildpack2", "buildpack3"); 72 | 73 | deploymentProperties.put(CloudFoundryDeploymentProperties.BUILDPACK_PROPERTY_KEY, "buildpack4"); 74 | buildpacks = deployer.buildpacks(request); 75 | assertThat(buildpacks).hasSize(1); 76 | assertThat(buildpacks).contains("buildpack4"); 77 | 78 | deploymentProperties.put(CloudFoundryDeploymentProperties.BUILDPACKS_PROPERTY_KEY, "buildpack5,buildpack6"); 79 | buildpacks = deployer.buildpacks(request); 80 | assertThat(buildpacks).hasSize(2); 81 | assertThat(buildpacks).contains("buildpack5", "buildpack6"); 82 | } 83 | 84 | private static class TestCloudFoundryDeployer extends AbstractCloudFoundryDeployer { 85 | 86 | TestCloudFoundryDeployer(CloudFoundryDeploymentProperties deploymentProperties, 87 | RuntimeEnvironmentInfo runtimeEnvironmentInfo) { 88 | super(deploymentProperties, runtimeEnvironmentInfo); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryTaskLauncherCachingTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.time.LocalDateTime; 20 | import java.time.format.DateTimeFormatter; 21 | import java.util.ArrayList; 22 | import java.util.Collections; 23 | import java.util.HashMap; 24 | import java.util.List; 25 | import java.util.Map; 26 | import java.util.UUID; 27 | import java.util.concurrent.atomic.AtomicBoolean; 28 | 29 | import org.cloudfoundry.client.CloudFoundryClient; 30 | import org.cloudfoundry.client.v2.Metadata; 31 | import org.cloudfoundry.client.v2.organizations.ListOrganizationsResponse; 32 | import org.cloudfoundry.client.v2.organizations.OrganizationResource; 33 | import org.cloudfoundry.client.v2.organizations.Organizations; 34 | import org.cloudfoundry.client.v2.spaces.ListSpacesResponse; 35 | import org.cloudfoundry.client.v2.spaces.SpaceResource; 36 | import org.cloudfoundry.client.v2.spaces.Spaces; 37 | import org.cloudfoundry.client.v3.Pagination; 38 | import org.cloudfoundry.client.v3.tasks.ListTasksResponse; 39 | import org.cloudfoundry.client.v3.tasks.TaskResource; 40 | import org.cloudfoundry.client.v3.tasks.TaskState; 41 | import org.cloudfoundry.client.v3.tasks.Tasks; 42 | import org.cloudfoundry.operations.CloudFoundryOperations; 43 | import org.junit.jupiter.api.Test; 44 | import reactor.core.publisher.Mono; 45 | 46 | import org.springframework.cloud.deployer.spi.core.RuntimeEnvironmentInfo; 47 | 48 | import static org.assertj.core.api.Assertions.assertThat; 49 | import static org.assertj.core.api.Assertions.catchThrowable; 50 | import static org.mockito.ArgumentMatchers.any; 51 | import static org.mockito.BDDMockito.given; 52 | import static org.mockito.Mockito.mock; 53 | 54 | public class CloudFoundryTaskLauncherCachingTests { 55 | 56 | @Test 57 | public void testOrgSpaceCachingRetries() { 58 | CloudFoundryClient client = mock(CloudFoundryClient.class); 59 | AtomicBoolean spaceError = new AtomicBoolean(true); 60 | AtomicBoolean orgError = new AtomicBoolean(true); 61 | 62 | Spaces spaces = mock(Spaces.class); 63 | given(client.spaces()).willReturn(spaces); 64 | given(spaces.list(any())).willReturn(listSpacesResponse(spaceError)); 65 | 66 | Organizations organizations = mock(Organizations.class); 67 | given(client.organizations()).willReturn(organizations); 68 | given(organizations.list(any())).willReturn(listOrganizationsResponse(orgError)); 69 | 70 | Tasks tasks = mock(Tasks.class); 71 | given(client.tasks()).willReturn(tasks); 72 | given(tasks.list(any())).willReturn(runningTasksResponse()); 73 | 74 | CloudFoundryDeploymentProperties deploymentProperties = new CloudFoundryDeploymentProperties(); 75 | CloudFoundryOperations operations = mock(CloudFoundryOperations.class); 76 | RuntimeEnvironmentInfo runtimeEnvironmentInfo = mock(RuntimeEnvironmentInfo.class); 77 | Map orgAndSpace = new HashMap<>(); 78 | orgAndSpace.put(CloudFoundryPlatformSpecificInfo.ORG, "this-org"); 79 | orgAndSpace.put(CloudFoundryPlatformSpecificInfo.SPACE, "this-space"); 80 | given(runtimeEnvironmentInfo.getPlatformSpecificInfo()).willReturn(orgAndSpace); 81 | 82 | CloudFoundryTaskLauncher launcher = new CloudFoundryTaskLauncher(client, deploymentProperties, operations, runtimeEnvironmentInfo); 83 | 84 | Throwable thrown1 = catchThrowable(() -> { 85 | launcher.getRunningTaskExecutionCount(); 86 | }); 87 | assertThat(thrown1).isInstanceOf(RuntimeException.class).hasNoCause(); 88 | 89 | // space should still error 90 | orgError.set(false); 91 | Throwable thrown2 = catchThrowable(() -> { 92 | launcher.getRunningTaskExecutionCount(); 93 | }); 94 | assertThat(thrown2).isInstanceOf(RuntimeException.class).hasNoCause(); 95 | 96 | // cache should now be getting cleared as space doesn't error 97 | spaceError.set(false); 98 | Throwable thrown3 = catchThrowable(() -> { 99 | launcher.getRunningTaskExecutionCount(); 100 | }); 101 | assertThat(thrown3).doesNotThrowAnyException(); 102 | assertThat(launcher.getRunningTaskExecutionCount()).isEqualTo(1); 103 | } 104 | 105 | private Mono listOrganizationsResponse(AtomicBoolean error) { 106 | // defer so that we can conditionally throw within mono 107 | return Mono.defer(() -> { 108 | if (error.get()) { 109 | throw new RuntimeException(); 110 | } 111 | ListOrganizationsResponse response = ListOrganizationsResponse.builder() 112 | .addAllResources(Collections.singletonList( 113 | OrganizationResource.builder() 114 | .metadata(Metadata.builder().id("123").build()).build()) 115 | ) 116 | .build(); 117 | return Mono.just(response); 118 | }); 119 | } 120 | 121 | private Mono listSpacesResponse(AtomicBoolean error) { 122 | // defer so that we can conditionally throw within mono 123 | return Mono.defer(() -> { 124 | if (error.get()) { 125 | throw new RuntimeException(); 126 | } 127 | ListSpacesResponse response = ListSpacesResponse.builder() 128 | .addAllResources(Collections.singletonList( 129 | SpaceResource.builder() 130 | .metadata(Metadata.builder().id("123").build()).build()) 131 | ) 132 | .build(); 133 | return Mono.just(response); 134 | }); 135 | } 136 | 137 | private Mono runningTasksResponse() { 138 | List taskResources = new ArrayList<>(); 139 | for (int i = 0; i < 1; i++) { 140 | taskResources.add(TaskResource.builder() 141 | .name("task-" + i) 142 | .dropletId(UUID.randomUUID().toString()) 143 | .id(UUID.randomUUID().toString()) 144 | .diskInMb(2048) 145 | .sequenceId(i) 146 | .state(TaskState.RUNNING) 147 | .memoryInMb(2048) 148 | .createdAt(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))) 149 | .build()); 150 | } 151 | ListTasksResponse listTasksResponse = ListTasksResponse.builder().resources(taskResources) 152 | .pagination(Pagination.builder().totalResults(taskResources.size()).build()) 153 | .build(); 154 | return Mono.just(listTasksResponse); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/CloudFoundryTaskLauncherIntegrationIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import com.github.zafarkhaja.semver.Version; 20 | import org.junit.jupiter.api.AfterEach; 21 | import org.junit.jupiter.api.Assumptions; 22 | import org.junit.jupiter.api.BeforeEach; 23 | import org.junit.jupiter.api.Disabled; 24 | import org.junit.jupiter.api.Test; 25 | 26 | import org.springframework.beans.factory.annotation.Autowired; 27 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 28 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 29 | import org.springframework.cloud.deployer.spi.task.TaskLauncher; 30 | import org.springframework.cloud.deployer.spi.test.AbstractTaskLauncherIntegrationJUnit5Tests; 31 | import org.springframework.cloud.deployer.spi.test.Timeout; 32 | import org.springframework.context.annotation.Configuration; 33 | import org.springframework.test.context.ContextConfiguration; 34 | 35 | /** 36 | * Runs integration tests for {@link CloudFoundryTaskLauncher}, using the production configuration, 37 | * that may be configured via {@link CloudFoundryConnectionProperties}. 38 | * 39 | * Tests are only run if a successful connection can be made at startup. 40 | * 41 | * @author Eric Bottard 42 | * @author Greg Turnquist 43 | * @author Michael Minella 44 | * @author Ben Hale 45 | */ 46 | @ContextConfiguration(classes=CloudFoundryTaskLauncherIntegrationIT.Config.class) 47 | public class CloudFoundryTaskLauncherIntegrationIT extends AbstractTaskLauncherIntegrationJUnit5Tests { 48 | 49 | @Autowired 50 | private TaskLauncher taskLauncher; 51 | 52 | @Autowired 53 | private Version cloudControllerAPIVersion; 54 | 55 | /** 56 | * Execution environments may override this default value to have tests wait longer for a deployment, for example if 57 | * running in an environment that is known to be slow. 58 | */ 59 | protected double timeoutMultiplier = 1.0D; 60 | 61 | protected int maxRetries = 60; 62 | 63 | @BeforeEach 64 | public void init() { 65 | Assumptions.assumeTrue(cloudControllerAPIVersion.greaterThanOrEqualTo(Version.forIntegers(2, 65, 0)), 66 | "Skipping TaskLauncher ITs on PCF<1.9 (2.65.0). Actual API version is " + cloudControllerAPIVersion); 67 | 68 | String multiplier = System.getenv("CF_DEPLOYER_TIMEOUT_MULTIPLIER"); 69 | if (multiplier != null) { 70 | timeoutMultiplier = Double.parseDouble(multiplier); 71 | } 72 | } 73 | 74 | @Override 75 | protected TaskLauncher provideTaskLauncher() { 76 | return taskLauncher; 77 | } 78 | 79 | /* 80 | * Allow for a small pause so that each each TL.destroy() at the end of tests actually completes, 81 | * as this is asynchronous. 82 | */ 83 | @AfterEach 84 | public void pause() throws InterruptedException { 85 | Thread.sleep(500); 86 | } 87 | 88 | @Test 89 | @Override 90 | @Disabled("CF Deployer incorrectly reports status as failed instead of canceled") 91 | public void testSimpleCancel() throws InterruptedException { 92 | super.testSimpleCancel(); 93 | } 94 | 95 | @Override 96 | protected Timeout deploymentTimeout() { 97 | return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier)); 98 | } 99 | 100 | @Override 101 | protected Timeout undeploymentTimeout() { 102 | return new Timeout(maxRetries, (int) (5000 * timeoutMultiplier)); 103 | } 104 | 105 | 106 | 107 | /** 108 | * This triggers the use of {@link CloudFoundryDeployerAutoConfiguration}. 109 | * 110 | * @author Eric Bottard 111 | */ 112 | @Configuration 113 | @EnableAutoConfiguration 114 | @EnableConfigurationProperties 115 | public static class Config { 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/cloudfoundry/ServiceParserTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.cloudfoundry; 18 | 19 | import java.util.Collections; 20 | import java.util.Map; 21 | 22 | import org.junit.jupiter.api.Test; 23 | 24 | import static org.assertj.core.api.Assertions.assertThat; 25 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 26 | import static org.assertj.core.api.Assertions.entry; 27 | 28 | /** @author David Turanski */ 29 | public class ServiceParserTests { 30 | 31 | @Test 32 | public void plainService() { 33 | assertThat(ServiceParser.getServiceParameters("test-service").isPresent()).isFalse(); 34 | assertThat(ServiceParser.getServiceInstanceName("test-service")).isEqualTo("test-service"); 35 | } 36 | 37 | @Test 38 | public void plainServiceWithSpecialCharacters() { 39 | assertThat(ServiceParser.getServiceParameters("test.service.$$").isPresent()).isFalse(); 40 | } 41 | 42 | @Test 43 | public void serviceWithParameters() { 44 | String serviceSpec = "test-service foo:bar"; 45 | assertThat(ServiceParser.getServiceParameters(serviceSpec).get()) 46 | .isEqualTo(Collections.singletonMap("foo", "bar")); 47 | } 48 | 49 | @Test 50 | public void getServiceInstanceName() { 51 | String serviceSpec = "test-service foo:bar"; 52 | assertThat(ServiceParser.getServiceInstanceName(serviceSpec)).isEqualTo("test-service"); 53 | } 54 | 55 | @Test 56 | public void serviceWithSpacesParameters() { 57 | assertThat(ServiceParser.getServiceParameters("test-service foo : bar").get()) 58 | .isEqualTo(Collections.singletonMap("foo", "bar")); 59 | } 60 | 61 | @Test 62 | public void serviceWithEqualsInParameters() { 63 | assertThat(ServiceParser.getServiceParameters("test-service foo=bar").get()) 64 | .isEqualTo(Collections.singletonMap("foo", "bar")); 65 | } 66 | 67 | @Test 68 | public void realWorldExample() { 69 | 70 | Map params = ServiceParser.getServiceParameters( 71 | "nfs share:1.2.3.4/export, uid:65534, gid:65534, mount:/var/scdf") 72 | .get(); 73 | 74 | assertThat(params).containsOnly( 75 | entry("share","1.2.3.4/export"), 76 | entry("uid","65534"), 77 | entry("gid","65534"), 78 | entry("mount","/var/scdf") 79 | ); 80 | } 81 | 82 | @Test 83 | public void anotherRealWorldExample() { 84 | Map params = ServiceParser.getServiceParameters( 85 | "nfs share=1.2.3.4/export, uid=65534, gid=65534, mount=/var/scdf") 86 | .get(); 87 | 88 | assertThat(params).containsOnly( 89 | entry("share","1.2.3.4/export"), 90 | entry("uid","65534"), 91 | entry("gid","65534"), 92 | entry("mount","/var/scdf") 93 | ); 94 | } 95 | 96 | @Test 97 | public void serviceWithInvalidParameters() { 98 | assertThatThrownBy(() -> { 99 | ServiceParser.getServiceParameters("test-service foo bar"); 100 | }).isInstanceOf(IllegalArgumentException.class).hasMessageContaining( 101 | "invalid service specification: test-service foo bar"); 102 | } 103 | 104 | @Test 105 | public void splitServiceProperties() { 106 | 107 | assertThat(ServiceParser.splitServiceProperties( 108 | "'nfs share:10.194.2.6/export,uid:65534,gid:65534,mount:/var/scdf',mysql,'foo bar:baz'")) 109 | .containsExactlyInAnyOrder( 110 | "nfs share:10.194.2.6/export,uid:65534,gid:65534,mount:/var/scdf", 111 | "mysql", 112 | "foo bar:baz"); 113 | 114 | assertThat(ServiceParser.splitServiceProperties("mysql,rabbit,redis")) 115 | .containsExactlyInAnyOrder( 116 | "mysql", 117 | "rabbit", 118 | "redis"); 119 | 120 | assertThat(ServiceParser.splitServiceProperties( 121 | "redis, 'nfs share:10.194.2.6/export,uid:65534,gid:65534,mount:/var/scdf', mysql , 'foo bar:baz'")) 122 | .containsExactlyInAnyOrder( 123 | "redis", 124 | "nfs share:10.194.2.6/export,uid:65534,gid:65534,mount:/var/scdf", 125 | "mysql", 126 | "foo bar:baz"); 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/CloudFoundryScheduleSSLExceptionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.scheduler.cloudfoundry; 18 | 19 | 20 | import org.junit.jupiter.api.Test; 21 | 22 | import static org.assertj.core.api.Assertions.assertThat; 23 | 24 | /** 25 | * Verify that {@linkCloudFoundryScheduleSSLException} has the expected behavior. 26 | * 27 | * @author Glenn Renfro 28 | */ 29 | public class CloudFoundryScheduleSSLExceptionTests { 30 | 31 | @Test 32 | public void testExceptionMessageOnly() { 33 | try { 34 | throw new CloudFoundryScheduleSSLException("oops"); 35 | } 36 | catch (CloudFoundryScheduleSSLException cfe) { 37 | assertThat(cfe.getMessage()).isEqualTo("oops"); 38 | } 39 | } 40 | 41 | @Test 42 | public void testExceptionMessageWithException() { 43 | RuntimeException rte = new RuntimeException("RTE"); 44 | try { 45 | throw new CloudFoundryScheduleSSLException("oops", rte); 46 | } 47 | catch (CloudFoundryScheduleSSLException cfe) { 48 | assertThat(cfe.getMessage()).isEqualTo("oops"); 49 | assertThat(cfe.getCause()).isEqualTo(rte); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/CloudFoundrySchedulerPropertiesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.scheduler.cloudfoundry; 18 | 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.assertj.core.api.Assertions.assertThat; 22 | 23 | /** 24 | * Validate the basic behavior of the {@link CloudFoundrySchedulerProperties}. 25 | * 26 | * @author Glenn Renfro 27 | */ 28 | public class CloudFoundrySchedulerPropertiesTest { 29 | 30 | @Test 31 | public void testProperties() { 32 | CloudFoundrySchedulerProperties props = new CloudFoundrySchedulerProperties(); 33 | props.setSchedulerUrl("testProperty"); 34 | props.setScheduleSSLRetryCount(10); 35 | props.setListTimeoutInSeconds(5); 36 | props.setUnScheduleTimeoutInSeconds(10); 37 | props.setScheduleTimeoutInSeconds(15); 38 | assertThat(props.getSchedulerUrl()).isEqualTo("testProperty"); 39 | assertThat(props.getScheduleSSLRetryCount()).isEqualTo(10); 40 | assertThat(props.getScheduleTimeoutInSeconds()).isEqualTo(15); 41 | assertThat(props.getUnScheduleTimeoutInSeconds()).isEqualTo(10); 42 | assertThat(props.getListTimeoutInSeconds()).isEqualTo(5); 43 | } 44 | 45 | @Test 46 | public void testEmptyProperties() { 47 | CloudFoundrySchedulerProperties props = new CloudFoundrySchedulerProperties(); 48 | assertThat(props.getSchedulerUrl()).isNull(); 49 | assertThat(props.getScheduleSSLRetryCount()).isEqualTo(5); 50 | assertThat(props.getListTimeoutInSeconds()).isEqualTo(60); 51 | assertThat(props.getScheduleTimeoutInSeconds()).isEqualTo(30); 52 | assertThat(props.getUnScheduleTimeoutInSeconds()).isEqualTo(30); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/SpringCloudSchedulerIntegrationIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.scheduler.cloudfoundry; 18 | 19 | import java.util.Collections; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import io.pivotal.reactor.scheduler.ReactorSchedulerClient; 25 | import org.cloudfoundry.operations.CloudFoundryOperations; 26 | import org.cloudfoundry.operations.applications.DeleteApplicationRequest; 27 | import org.cloudfoundry.reactor.ConnectionContext; 28 | import org.cloudfoundry.reactor.TokenProvider; 29 | import org.junit.jupiter.api.AfterEach; 30 | import org.junit.jupiter.api.extension.ExtendWith; 31 | import reactor.core.publisher.Mono; 32 | 33 | import org.springframework.beans.factory.annotation.Autowired; 34 | import org.springframework.beans.factory.annotation.Value; 35 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 36 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 37 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 38 | import org.springframework.boot.test.context.SpringBootTest; 39 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; 40 | import org.springframework.cloud.deployer.resource.maven.MavenProperties; 41 | import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryConnectionProperties; 42 | import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryDeploymentProperties; 43 | import org.springframework.cloud.deployer.spi.cloudfoundry.CloudFoundryTaskLauncher; 44 | import org.springframework.cloud.deployer.spi.scheduler.Scheduler; 45 | import org.springframework.cloud.deployer.spi.scheduler.SchedulerPropertyKeys; 46 | import org.springframework.cloud.deployer.spi.scheduler.test.AbstractSchedulerIntegrationJUnit5Tests; 47 | import org.springframework.cloud.deployer.spi.task.TaskLauncher; 48 | import org.springframework.context.annotation.Bean; 49 | import org.springframework.context.annotation.Configuration; 50 | import org.springframework.test.context.ContextConfiguration; 51 | import org.springframework.test.context.junit.jupiter.SpringExtension; 52 | 53 | /** 54 | * Integration tests for CloudFoundryAppScheduler. 55 | * 56 | * @author Glenn Renfro 57 | */ 58 | @ExtendWith(SpringExtension.class) 59 | @SpringBootTest(webEnvironment = WebEnvironment.NONE) 60 | @ContextConfiguration(classes = {SpringCloudSchedulerIntegrationIT.Config.class}) 61 | public class SpringCloudSchedulerIntegrationIT extends AbstractSchedulerIntegrationJUnit5Tests { 62 | 63 | @Autowired 64 | protected MavenProperties mavenProperties; 65 | 66 | @Autowired 67 | private Scheduler scheduler; 68 | 69 | @Value("${spring.cloud.deployer.cloudfoundry.services}") 70 | private String deployerProps; 71 | 72 | @Override 73 | protected Scheduler provideScheduler() { 74 | return this.scheduler; 75 | } 76 | 77 | @Autowired 78 | private CloudFoundryOperations operations; 79 | 80 | @Override 81 | protected List getCommandLineArgs() { 82 | return null; 83 | } 84 | 85 | @Override 86 | protected Map getSchedulerProperties() { 87 | return Collections.singletonMap(SchedulerPropertyKeys.CRON_EXPRESSION,"41 17 ? * *"); 88 | } 89 | 90 | @Override 91 | protected Map getDeploymentProperties() { 92 | Map deploymentProperties = new HashMap<>(); 93 | deploymentProperties.put(CloudFoundryDeploymentProperties.SERVICES_PROPERTY_KEY, deployerProps); 94 | deploymentProperties.put(CloudFoundryAppScheduler.CRON_EXPRESSION_KEY, "57 13 ? * *"); 95 | return deploymentProperties; 96 | } 97 | 98 | @Override 99 | protected Map getAppProperties() { 100 | return null; 101 | } 102 | 103 | /** 104 | * Remove all pushed apps. This in turn removes the associated schedules. 105 | */ 106 | @AfterEach 107 | public void tearDown() { 108 | try { 109 | operations.applications().list().flatMap(applicationSummary -> { 110 | if (applicationSummary.getName().startsWith("testList") || 111 | applicationSummary.getName().startsWith("testDuplicateSchedule") || 112 | applicationSummary.getName().startsWith("testUnschedule") || 113 | applicationSummary.getName().startsWith("testMultiple") || 114 | applicationSummary.getName().startsWith("testSimpleSchedule")) { 115 | 116 | return operations.applications().delete(DeleteApplicationRequest 117 | .builder() 118 | .name(applicationSummary.getName()) 119 | .build()); 120 | } 121 | return Mono.justOrEmpty(applicationSummary); 122 | }).blockLast(); 123 | } catch (Exception ex) { 124 | log.warn("Attempted cleanup and exception occured: " + ex.getMessage()); 125 | } 126 | } 127 | 128 | @Configuration 129 | @EnableAutoConfiguration 130 | @EnableConfigurationProperties 131 | public static class Config { 132 | @Bean 133 | @ConditionalOnMissingBean 134 | public ReactorSchedulerClient reactorSchedulerClient(ConnectionContext context, 135 | TokenProvider passwordGrantTokenProvider, 136 | CloudFoundryDeploymentProperties taskDeploymentProperties) { 137 | return ReactorSchedulerClient.builder() 138 | .connectionContext(context) 139 | .tokenProvider(passwordGrantTokenProvider) 140 | .root(Mono.just(taskDeploymentProperties.getSchedulerUrl())) 141 | .build(); 142 | } 143 | 144 | @Bean 145 | @ConditionalOnMissingBean 146 | public Scheduler scheduler(ReactorSchedulerClient client, 147 | CloudFoundryOperations operations, 148 | CloudFoundryConnectionProperties properties, 149 | TaskLauncher taskLauncher, 150 | CloudFoundryDeploymentProperties taskDeploymentProperties) { 151 | return new CloudFoundryAppScheduler(client, operations, properties, 152 | (CloudFoundryTaskLauncher) taskLauncher, 153 | taskDeploymentProperties); 154 | } 155 | 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/test/java/org/springframework/cloud/deployer/spi/scheduler/cloudfoundry/expression/QuartzCronExpressionTests.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018-2021 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.springframework.cloud.deployer.spi.scheduler.cloudfoundry.expression; 18 | 19 | import java.text.ParseException; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import static org.assertj.core.api.Assertions.assertThatCode; 24 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 25 | 26 | public class QuartzCronExpressionTests { 27 | 28 | /* 29 | * Verifies that storeExpressionVals correctly calculates the month number 30 | */ 31 | @Test 32 | public void testStoreExpressionVal() { 33 | assertExpression("* * * * Foo ? ", "Invalid Month value:", 34 | "Expected ParseException did not fire for non-existent month"); 35 | assertExpression("* * * * Jan-Foo ? ", "Invalid Month value:", 36 | "Expected ParseException did not fire for non-existent month"); 37 | } 38 | 39 | @Test 40 | public void testWildCard() { 41 | assertExpression("0 0 * * * *", 42 | "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.", 43 | "Expected ParseException did not fire for wildcard day-of-month and day-of-week"); 44 | assertExpression("0 0 * 4 * *", 45 | "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.", 46 | "Expected ParseException did not fire for specified day-of-month and wildcard day-of-week"); 47 | assertExpression("0 0 * * * 4", 48 | "Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.", 49 | "Expected ParseException did not fire for wildcard day-of-month and specified day-of-week"); 50 | } 51 | 52 | @Test 53 | public void testForInvalidLInCronExpression() { 54 | assertExpression("0 43 9 1,5,29,L * ?", 55 | "Support for specifying 'L' and 'LW' with other days of the month is not implemented", 56 | "Expected ParseException did not fire for L combined with other days of the month"); 57 | assertExpression("0 43 9 ? * SAT,SUN,L", 58 | "Support for specifying 'L' with other days of the week is not implemented", 59 | "Expected ParseException did not fire for L combined with other days of the week"); 60 | assertExpression("0 43 9 ? * 6,7,L", 61 | "Support for specifying 'L' with other days of the week is not implemented", 62 | "Expected ParseException did not fire for L combined with other days of the week"); 63 | assertThatCode(() -> { 64 | new QuartzCronExpression("0 43 9 ? * 5L"); 65 | }).as("Unexpected ParseException thrown for supported '5L' expression.").doesNotThrowAnyException(); 66 | } 67 | 68 | @Test 69 | public void testForLargeWVal() { 70 | assertExpression("0/5 * * 32W 1 ?", "The 'W' option does not make sense with values larger than", 71 | "Expected ParseException did not fire for W with value larger than 31"); 72 | } 73 | 74 | @Test 75 | public void testSecRangeIntervalAfterSlash() { 76 | // Test case 1 77 | assertExpression("/120 0 8-18 ? * 2-6", "Increment > 60 : 120", 78 | "Cron did not validate bad range interval in '_blank/xxx' form"); 79 | // Test case 2 80 | assertExpression("0/120 0 8-18 ? * 2-6", "Increment > 60 : 120", 81 | "Cron did not validate bad range interval in in '0/xxx' form"); 82 | // Test case 3 83 | assertExpression("/ 0 8-18 ? * 2-6", "'/' must be followed by an integer.", 84 | "Cron did not validate bad range interval in '_blank/_blank'"); 85 | // Test case 4 86 | assertExpression("0/ 0 8-18 ? * 2-6", "'/' must be followed by an integer.", 87 | "Cron did not validate bad range interval in '0/_blank'"); 88 | } 89 | 90 | @Test 91 | public void testMinRangeIntervalAfterSlash() { 92 | // Test case 1 93 | assertExpression("0 /120 8-18 ? * 2-6", "Increment > 60 : 120", 94 | "Cron did not validate bad range interval in '_blank/xxx' form"); 95 | // Test case 2 96 | assertExpression("0 0/120 8-18 ? * 2-6", "Increment > 60 : 120", 97 | "Cron did not validate bad range interval in in '0/xxx' form"); 98 | // Test case 3 99 | assertExpression("0 / 8-18 ? * 2-6", "'/' must be followed by an integer.", 100 | "Cron did not validate bad range interval in '_blank/_blank'"); 101 | // Test case 4 102 | assertExpression("0 0/ 8-18 ? * 2-6", "'/' must be followed by an integer.", 103 | "Cron did not validate bad range interval in '0/_blank'"); 104 | } 105 | 106 | @Test 107 | public void testHourRangeIntervalAfterSlash() { 108 | // Test case 1 109 | assertExpression("0 0 /120 ? * 2-6", "Increment > 24 : 120", 110 | "Cron did not validate bad range interval in '_blank/xxx' form"); 111 | // Test case 2 112 | assertExpression("0 0 0/120 ? * 2-6", "Increment > 24 : 120", 113 | "Cron did not validate bad range interval in in '0/xxx' form"); 114 | // Test case 3 115 | assertExpression("0 0 / ? * 2-6", "'/' must be followed by an integer.", 116 | "Cron did not validate bad range interval in '_blank/_blank'"); 117 | // Test case 4 118 | assertExpression("0 0 0/ ? * 2-6", "'/' must be followed by an integer.", 119 | "Cron did not validate bad range interval in '0/_blank'"); 120 | } 121 | 122 | @Test 123 | public void testDayOfMonthRangeIntervalAfterSlash() { 124 | // Test case 1 125 | assertExpression("0 0 0 /120 * 2-6", "Increment > 31 : 120", 126 | "Cron did not validate bad range interval in '_blank/xxx' form"); 127 | // Test case 2 128 | assertExpression("0 0 0 0/120 * 2-6", "Increment > 31 : 120", 129 | "Cron did not validate bad range interval in in '0/xxx' form"); 130 | // Test case 3 131 | assertExpression("0 0 0 / * 2-6", "'/' must be followed by an integer.", 132 | "Cron did not validate bad range interval in '_blank/_blank'"); 133 | // Test case 4 134 | assertExpression("0 0 0 0/ * 2-6", "'/' must be followed by an integer.", 135 | "Cron did not validate bad range interval in '0/_blank'"); 136 | } 137 | 138 | @Test 139 | public void testMonthRangeIntervalAfterSlash() { 140 | // Test case 1 141 | assertExpression("0 0 0 ? /120 2-6", "Increment > 12 : 120", 142 | "Cron did not validate bad range interval in '_blank/xxx' form"); 143 | // Test case 2 144 | assertExpression("0 0 0 ? 0/120 2-6", "Increment > 12 : 120", 145 | "Cron did not validate bad range interval in in '0/xxx' form"); 146 | // Test case 3 147 | assertExpression("0 0 0 ? / 2-6", "'/' must be followed by an integer.", 148 | "Cron did not validate bad range interval in '_blank/_blank'"); 149 | // Test case 4 150 | assertExpression("0 0 0 ? 0/ 2-6", "'/' must be followed by an integer.", 151 | "Cron did not validate bad range interval in '0/_blank'"); 152 | } 153 | 154 | @Test 155 | public void testDayOfWeekRangeIntervalAfterSlash() { 156 | // Test case 1 157 | assertExpression("0 0 0 ? * /120", "Increment > 7 : 120", 158 | "Cron did not validate bad range interval in '_blank/xxx' form"); 159 | // Test case 2 160 | assertExpression("0 0 0 ? * 0/120", "Increment > 7 : 120", 161 | "Cron did not validate bad range interval in in '0/xxx' form"); 162 | // Test case 3 163 | assertExpression("0 0 0 ? * /", "'/' must be followed by an integer.", 164 | "Cron did not validate bad range interval in '_blank/_blank'"); 165 | // Test case 4 166 | assertExpression("0 0 0 ? * 0/", "'/' must be followed by an integer.", 167 | "Cron did not validate bad range interval in '0/_blank'"); 168 | } 169 | 170 | private static void assertExpression(String expression, String messageContains, String as) { 171 | assertThatThrownBy(() -> { 172 | new QuartzCronExpression(expression); 173 | }).isInstanceOf(ParseException.class).hasMessageContaining(messageContains).as(as); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /src/test/resources/actuator-binding-input.json: -------------------------------------------------------------------------------- 1 | { 2 | "bindingName": "input", 3 | "name": "tiktok.time", 4 | "group": "tiktok", 5 | "pausable": false, 6 | "state": "running", 7 | "paused": false, 8 | "input": true, 9 | "extendedInfo": { 10 | "bindingDestination": "RabbitConsumerDestination{queue=tiktok.time.tiktok, binding=Binding [destination=tiktok.time.tiktok, exchange=tiktok.time, routingKey=#, arguments={}]}", 11 | "ExtendedConsumerProperties": { 12 | "autoStartup": true, 13 | "concurrency": 1, 14 | "instanceCount": 2, 15 | "maxAttempts": 3, 16 | "backOffInitialInterval": 1000, 17 | "backOffMaxInterval": 10000, 18 | "backOffMultiplier": 2, 19 | "defaultRetryable": true, 20 | "extension": { 21 | "exchangeType": "topic", 22 | "declareExchange": true, 23 | "exchangeDurable": true, 24 | "exchangeAutoDelete": false, 25 | "delayedExchange": false, 26 | "queueNameGroupOnly": false, 27 | "bindQueue": true, 28 | "bindingRoutingKey": null, 29 | "bindingRoutingKeyDelimiter": null, 30 | "ttl": null, 31 | "expires": null, 32 | "maxLength": null, 33 | "maxLengthBytes": null, 34 | "maxPriority": null, 35 | "deadLetterQueueName": null, 36 | "deadLetterExchange": null, 37 | "deadLetterExchangeType": "direct", 38 | "declareDlx": true, 39 | "deadLetterRoutingKey": null, 40 | "dlqTtl": null, 41 | "dlqExpires": null, 42 | "dlqMaxLength": null, 43 | "dlqMaxLengthBytes": null, 44 | "dlqMaxPriority": null, 45 | "dlqDeadLetterExchange": null, 46 | "dlqDeadLetterRoutingKey": null, 47 | "autoBindDlq": false, 48 | "prefix": "", 49 | "lazy": false, 50 | "dlqLazy": false, 51 | "overflowBehavior": null, 52 | "dlqOverflowBehavior": null, 53 | "queueBindingArguments": {}, 54 | "dlqBindingArguments": {}, 55 | "quorum": { 56 | "enabled": false, 57 | "initialGroupSize": null, 58 | "deliveryLimit": null 59 | }, 60 | "dlqQuorum": { 61 | "enabled": false, 62 | "initialGroupSize": null, 63 | "deliveryLimit": null 64 | }, 65 | "singleActiveConsumer": false, 66 | "dlqSingleActiveConsumer": false, 67 | "transacted": false, 68 | "acknowledgeMode": "AUTO", 69 | "maxConcurrency": 1, 70 | "prefetch": 1, 71 | "batchSize": 1, 72 | "durableSubscription": true, 73 | "republishToDlq": true, 74 | "republishDeliveyMode": "PERSISTENT", 75 | "requeueRejected": false, 76 | "headerPatterns": [ 77 | "*" 78 | ], 79 | "recoveryInterval": 5000, 80 | "exclusive": false, 81 | "missingQueuesFatal": false, 82 | "queueDeclarationRetries": null, 83 | "failedDeclarationRetryInterval": null, 84 | "consumerTagPrefix": null, 85 | "frameMaxHeadroom": 20000, 86 | "containerType": "SIMPLE", 87 | "anonymousGroupPrefix": "anonymous.", 88 | "enableBatching": false, 89 | "receiveTimeout": null, 90 | "requestHeaderPatterns": [ 91 | "*" 92 | ], 93 | "txSize": 1 94 | } 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /src/test/resources/actuator-bindings.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "bindingName": "input", 4 | "name": "tiktok.time", 5 | "group": "tiktok", 6 | "pausable": false, 7 | "state": "running", 8 | "paused": false, 9 | "extendedInfo": { 10 | "bindingDestination": "RabbitConsumerDestination{queue=tiktok.time.tiktok, binding=Binding [destination=tiktok.time.tiktok, exchange=tiktok.time, routingKey=#, arguments={}]}", 11 | "ExtendedConsumerProperties": { 12 | "autoStartup": true, 13 | "concurrency": 1, 14 | "instanceCount": 2, 15 | "instanceIndex": 1, 16 | "maxAttempts": 3, 17 | "backOffInitialInterval": 1000, 18 | "backOffMaxInterval": 10000, 19 | "backOffMultiplier": 2, 20 | "defaultRetryable": true, 21 | "extension": { 22 | "exchangeType": "topic", 23 | "declareExchange": true, 24 | "exchangeDurable": true, 25 | "exchangeAutoDelete": false, 26 | "delayedExchange": false, 27 | "queueNameGroupOnly": false, 28 | "bindQueue": true, 29 | "bindingRoutingKey": null, 30 | "bindingRoutingKeyDelimiter": null, 31 | "ttl": null, 32 | "expires": null, 33 | "maxLength": null, 34 | "maxLengthBytes": null, 35 | "maxPriority": null, 36 | "deadLetterQueueName": null, 37 | "deadLetterExchange": null, 38 | "deadLetterExchangeType": "direct", 39 | "declareDlx": true, 40 | "deadLetterRoutingKey": null, 41 | "dlqTtl": null, 42 | "dlqExpires": null, 43 | "dlqMaxLength": null, 44 | "dlqMaxLengthBytes": null, 45 | "dlqMaxPriority": null, 46 | "dlqDeadLetterExchange": null, 47 | "dlqDeadLetterRoutingKey": null, 48 | "autoBindDlq": false, 49 | "prefix": "", 50 | "lazy": false, 51 | "dlqLazy": false, 52 | "overflowBehavior": null, 53 | "dlqOverflowBehavior": null, 54 | "queueBindingArguments": {}, 55 | "dlqBindingArguments": {}, 56 | "quorum": { 57 | "enabled": false, 58 | "initialGroupSize": null, 59 | "deliveryLimit": null 60 | }, 61 | "dlqQuorum": { 62 | "enabled": false, 63 | "initialGroupSize": null, 64 | "deliveryLimit": null 65 | }, 66 | "singleActiveConsumer": false, 67 | "dlqSingleActiveConsumer": false, 68 | "transacted": false, 69 | "acknowledgeMode": "AUTO", 70 | "maxConcurrency": 1, 71 | "prefetch": 1, 72 | "batchSize": 1, 73 | "durableSubscription": true, 74 | "republishToDlq": true, 75 | "republishDeliveyMode": "PERSISTENT", 76 | "requeueRejected": false, 77 | "headerPatterns": [ 78 | "*" 79 | ], 80 | "recoveryInterval": 5000, 81 | "exclusive": false, 82 | "missingQueuesFatal": false, 83 | "queueDeclarationRetries": null, 84 | "failedDeclarationRetryInterval": null, 85 | "consumerTagPrefix": null, 86 | "frameMaxHeadroom": 20000, 87 | "containerType": "SIMPLE", 88 | "anonymousGroupPrefix": "anonymous.", 89 | "enableBatching": false, 90 | "receiveTimeout": null, 91 | "requestHeaderPatterns": [ 92 | "*" 93 | ], 94 | "txSize": 1 95 | } 96 | } 97 | }, 98 | "input": true 99 | } 100 | ] -------------------------------------------------------------------------------- /src/test/resources/actuator-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": { 3 | "description": "Spring Cloud Stream Log Sink Rabbit Binder Application", 4 | "version": "3.1.1", 5 | "name": "log-sink-rabbit" 6 | } 7 | } -------------------------------------------------------------------------------- /src/test/resources/batch-job-1.0.0.BUILD-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/batch-job-1.0.0.BUILD-SNAPSHOT.jar -------------------------------------------------------------------------------- /src/test/resources/demo-0.0.1-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/demo-0.0.1-SNAPSHOT.jar -------------------------------------------------------------------------------- /src/test/resources/http-source-rabbit-2.1.5.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/http-source-rabbit-2.1.5.RELEASE.jar -------------------------------------------------------------------------------- /src/test/resources/log-sink-rabbit-3.0.0.BUILD-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/log-sink-rabbit-3.0.0.BUILD-SNAPSHOT.jar -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | %date{HH:mm:ss.SSS} %-25thread %-37logger %msg%n 7 | 8 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/test/resources/long-running-task-1.0.0.BUILD-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/long-running-task-1.0.0.BUILD-SNAPSHOT.jar -------------------------------------------------------------------------------- /src/test/resources/test-application.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/test-application.zip -------------------------------------------------------------------------------- /src/test/resources/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec-2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec-2.jar -------------------------------------------------------------------------------- /src/test/resources/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec-3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec-3.jar -------------------------------------------------------------------------------- /src/test/resources/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spring-attic/spring-cloud-deployer-cloudfoundry/720b866b2783f2edfd1759761c48ae4eebe12929/src/test/resources/timestamp-task-1.0.0.BUILD-SNAPSHOT-exec.jar --------------------------------------------------------------------------------