From 858cf33e6f9b4abcf038f17711a3bc7f3fcc7106 Mon Sep 17 00:00:00 2001 From: Anders Brujordet Date: Thu, 2 Nov 2017 17:29:21 +0100 Subject: [PATCH] fix(rosco) Make baked artifacts adhere to the proposed standard (#222) --- build.gradle | 3 +- gradle/wrapper/gradle-wrapper.properties | 4 +-- rosco-core/rosco-core.gradle | 1 + .../spinnaker/rosco/api/Artifact.groovy | 31 ------------------- .../netflix/spinnaker/rosco/api/Bake.groovy | 1 + .../rosco/executor/BakePoller.groovy | 3 +- .../providers/CloudProviderBakeHandler.groovy | 10 +++--- .../rosco/executor/BakePollerSpec.groovy | 19 ++++++------ .../CloudProviderBakeHandlerSpec.groovy | 12 ++++--- .../rosco/providers/util/TestDefaults.groovy | 1 + 10 files changed, 30 insertions(+), 55 deletions(-) delete mode 100644 rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Artifact.groovy diff --git a/build.gradle b/build.gradle index 000a80dbc5..9d38817f06 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ allprojects { group = "com.netflix.spinnaker.rosco" ext { - spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.109.2' + spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.113.1' } def checkLocalVersions = [spinnakerDependenciesVersion: spinnakerDependenciesVersion] @@ -60,6 +60,7 @@ allprojects { compile spinnaker.dependency("groovy") compile spinnaker.dependency("korkSwagger") compile spinnaker.dependency("spectatorReg") + compile spinnaker.dependency("korkArtifacts") } test { testLogging { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7221797d00..c141e8a7ab 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Nov 13 10:25:29 PST 2015 +#Fri Oct 13 09:56:27 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip diff --git a/rosco-core/rosco-core.gradle b/rosco-core/rosco-core.gradle index 128c82344d..ac41b1e669 100644 --- a/rosco-core/rosco-core.gradle +++ b/rosco-core/rosco-core.gradle @@ -7,4 +7,5 @@ dependencies { compile spinnaker.dependency("frigga") compile spinnaker.dependency('jacksonGuava') compile spinnaker.dependency('jedis') + compile spinnaker.dependency("korkArtifacts") } diff --git a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Artifact.groovy b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Artifact.groovy deleted file mode 100644 index 88bf11f9b1..0000000000 --- a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Artifact.groovy +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2017 Schibsted ASA. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.netflix.spinnaker.rosco.api - -import groovy.transform.CompileStatic -import groovy.transform.EqualsAndHashCode -import groovy.transform.ToString - -@EqualsAndHashCode -@ToString(includeNames = true) -class Artifact { - String name - String type - String version - String reference - Map metadata -} diff --git a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Bake.groovy b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Bake.groovy index 2e52b5c1b0..c3f628a1e2 100644 --- a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Bake.groovy +++ b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/api/Bake.groovy @@ -20,6 +20,7 @@ import groovy.transform.CompileStatic import groovy.transform.EqualsAndHashCode import groovy.transform.ToString import io.swagger.annotations.ApiModelProperty +import com.netflix.spinnaker.kork.artifacts.model.Artifact; /** * The details of a completed bake. diff --git a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/executor/BakePoller.groovy b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/executor/BakePoller.groovy index 676853c26c..d3be828856 100644 --- a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/executor/BakePoller.groovy +++ b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/executor/BakePoller.groovy @@ -17,7 +17,6 @@ package com.netflix.spinnaker.rosco.executor import com.netflix.spectator.api.Registry -import com.netflix.spinnaker.rosco.api.Artifact import com.netflix.spinnaker.rosco.api.Bake import com.netflix.spinnaker.rosco.api.BakeRequest import com.netflix.spinnaker.rosco.api.BakeStatus @@ -218,7 +217,7 @@ class BakePoller implements ApplicationListener { BakeRequest bakeRequest = bakeStore.retrieveBakeRequestById(bakeId) BakeRecipe bakeRecipe = bakeStore.retrieveBakeRecipeById(bakeId) bakeDetails.artifact = cloudProviderBakeHandler.produceArtifactDecorationFrom( - bakeRequest, bakeRecipe, bakeDetails, cloudProvider + bakeRequest, bakeRecipe, bakeDetails, cloudProvider, region ) } diff --git a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandler.groovy b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandler.groovy index 124247b018..f28f48003f 100644 --- a/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandler.groovy +++ b/rosco-core/src/main/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandler.groovy @@ -16,7 +16,7 @@ package com.netflix.spinnaker.rosco.providers -import com.netflix.spinnaker.rosco.api.Artifact +import com.netflix.spinnaker.kork.artifacts.model.Artifact import com.netflix.spinnaker.rosco.api.Bake import com.netflix.spinnaker.rosco.api.BakeOptions import com.netflix.spinnaker.rosco.api.BakeOptions.BaseImage @@ -110,16 +110,18 @@ abstract class CloudProviderBakeHandler { * Returns a decorated artifact for a given bake. Right now this is a generic approach * but it could be useful to override this method for specific providers. */ - def Artifact produceArtifactDecorationFrom(BakeRequest bakeRequest, BakeRecipe bakeRecipe, Bake bakeDetails, String cloudProvider) { + def Artifact produceArtifactDecorationFrom(BakeRequest bakeRequest, BakeRecipe bakeRecipe, Bake bakeDetails, String cloudProvider, String region) { Artifact bakedArtifact = new Artifact( name: bakeRecipe?.name, version: bakeRecipe?.version, - type: cloudProvider, + type: "${cloudProvider}/image", + location: region, reference: bakeDetails.ami ?: bakeDetails.image_name, metadata: [ build_info_url: bakeRequest?.build_info_url, build_number: bakeRequest?.build_number - ] + ], + uuid: bakeDetails.id ) return bakedArtifact diff --git a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/executor/BakePollerSpec.groovy b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/executor/BakePollerSpec.groovy index 1417911857..1eab5c7f36 100644 --- a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/executor/BakePollerSpec.groovy +++ b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/executor/BakePollerSpec.groovy @@ -17,7 +17,7 @@ package com.netflix.spinnaker.rosco.executor import com.netflix.spectator.api.DefaultRegistry -import com.netflix.spinnaker.rosco.api.Artifact +import com.netflix.spinnaker.kork.artifacts.model.Artifact import com.netflix.spinnaker.rosco.api.Bake import com.netflix.spinnaker.rosco.api.BakeRequest import com.netflix.spinnaker.rosco.api.BakeStatus @@ -33,7 +33,6 @@ import spock.lang.Unroll class BakePollerSpec extends Specification implements TestDefaults { - private static final String REGION = "some-region" private static final String JOB_ID = "123" private static final String AMI_ID = "ami-3cf4a854" private static final String IMAGE_NAME = "some-image" @@ -63,7 +62,7 @@ class BakePollerSpec extends Specification implements TestDefaults { then: 1 * jobExecutorMock.updateJob(JOB_ID) >> incompleteBakeStatus 1 * bakeStoreMock.updateBakeStatus(incompleteBakeStatus) - numStatusLookups * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION + numStatusLookups * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION numStatusLookups * bakeStoreMock.retrieveBakeStatusById(JOB_ID) >> incompleteBakeStatus where: @@ -100,8 +99,8 @@ class BakePollerSpec extends Specification implements TestDefaults { 1 * jobExecutorMock.updateJob(JOB_ID) >> completeBakeStatus 1 * bakeStoreMock.retrieveCloudProviderById(JOB_ID) >> BakeRequest.CloudProviderType.gce.toString() 1 * cloudProviderBakeHandlerRegistryMock.lookup(BakeRequest.CloudProviderType.gce) >> cloudProviderBakeHandlerMock - 2 * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION // 1 for metrics - 1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(REGION, JOB_ID, "$LOGS_CONTENT\n$LOGS_CONTENT") >> bakeDetails + 2 * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION // 1 for metrics + 1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(SOME_REGION, JOB_ID, "$LOGS_CONTENT\n$LOGS_CONTENT") >> bakeDetails 1 * bakeStoreMock.retrieveBakeRequestById(JOB_ID) >> bakeRequest 1 * bakeStoreMock.retrieveBakeRecipeById(JOB_ID) >> bakeRecipe 1 * bakeStoreMock.updateBakeDetails(bakeDetails) @@ -132,7 +131,7 @@ class BakePollerSpec extends Specification implements TestDefaults { 1 * jobExecutorMock.updateJob(JOB_ID) >> null 1 * bakeStoreMock.storeBakeError(JOB_ID, "Unable to retrieve status for '$JOB_ID'.") 1 * bakeStoreMock.cancelBakeById(JOB_ID) - 1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION + 1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION 1 * bakeStoreMock.retrieveBakeStatusById(JOB_ID) >> new BakeStatus() } @@ -147,7 +146,7 @@ class BakePollerSpec extends Specification implements TestDefaults { def bakedArtifact = new Artifact( name: bakeRecipe.name, version: bakeRecipe.version, - type: DOCKER_CLOUD_PROVIDER, + type: "${DOCKER_CLOUD_PROVIDER}/image", reference: AMI_ID, metadata: [ build_info_url: bakeRequest.build_info_url, @@ -170,9 +169,9 @@ class BakePollerSpec extends Specification implements TestDefaults { then: 1 * bakeStoreMock.retrieveCloudProviderById(JOB_ID) >> DOCKER_CLOUD_PROVIDER.toString() 1 * cloudProviderBakeHandlerRegistryMock.lookup(DOCKER_CLOUD_PROVIDER) >> cloudProviderBakeHandlerMock - 1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> REGION - 1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(REGION, JOB_ID, LOGS_CONTENT) >> bakeDetails - 1 * cloudProviderBakeHandlerMock.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, bakeDetails, DOCKER_CLOUD_PROVIDER.toString()) >> bakedArtifact + 1 * bakeStoreMock.retrieveRegionById(JOB_ID) >> SOME_REGION + 1 * cloudProviderBakeHandlerMock.scrapeCompletedBakeResults(SOME_REGION, JOB_ID, LOGS_CONTENT) >> bakeDetails + 1 * cloudProviderBakeHandlerMock.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, bakeDetails, DOCKER_CLOUD_PROVIDER.toString(), SOME_REGION) >> bakedArtifact 1 * bakeStoreMock.retrieveBakeRequestById(JOB_ID) >> bakeRequest 1 * bakeStoreMock.retrieveBakeRecipeById(JOB_ID) >> bakeRecipe 1 * bakeStoreMock.updateBakeDetails(decoratedBakeDetails) diff --git a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandlerSpec.groovy b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandlerSpec.groovy index 5ee27b86ea..fec25c920c 100644 --- a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandlerSpec.groovy +++ b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/CloudProviderBakeHandlerSpec.groovy @@ -16,7 +16,7 @@ package com.netflix.spinnaker.rosco.providers -import com.netflix.spinnaker.rosco.api.Artifact +import com.netflix.spinnaker.kork.artifacts.model.Artifact import com.netflix.spinnaker.rosco.providers.util.TestDefaults import spock.lang.Specification import spock.lang.Subject @@ -30,19 +30,21 @@ class CloudProviderBakeHandlerSpec extends Specification implements TestDefaults def expectedArtifact = new Artifact ( name: SOME_BAKE_RECIPE.name, version: SOME_BAKE_RECIPE.version, - type: SOME_CLOUD_PROVIDER, + location: SOME_REGION, + type: "${SOME_CLOUD_PROVIDER}/image", reference: SOME_BAKE_DETAILS.ami, metadata: [ build_info_url: SOME_BAKE_REQUEST.build_info_url, build_number: SOME_BAKE_REQUEST.build_number - ] + ], + uuid: SOME_BAKE_DETAILS.id ) @Subject CloudProviderBakeHandler bakeHandler = Spy(CloudProviderBakeHandler) when: - Artifact producedArtifact = bakeHandler.produceArtifactDecorationFrom(SOME_BAKE_REQUEST, SOME_BAKE_RECIPE, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER) + Artifact producedArtifact = bakeHandler.produceArtifactDecorationFrom(SOME_BAKE_REQUEST, SOME_BAKE_RECIPE, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER, SOME_REGION) then: producedArtifact == expectedArtifact @@ -53,7 +55,7 @@ class CloudProviderBakeHandlerSpec extends Specification implements TestDefaults expect: @Subject CloudProviderBakeHandler bakeHandler = Spy(CloudProviderBakeHandler) - def decoratedArtifact = bakeHandler.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER) + def decoratedArtifact = bakeHandler.produceArtifactDecorationFrom(bakeRequest, bakeRecipe, SOME_BAKE_DETAILS, SOME_CLOUD_PROVIDER, SOME_REGION) decoratedArtifact.name == expectedName decoratedArtifact.version == expectedVersion decoratedArtifact.reference == expectedReference diff --git a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/util/TestDefaults.groovy b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/util/TestDefaults.groovy index 36e116c7cc..727df20364 100644 --- a/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/util/TestDefaults.groovy +++ b/rosco-core/src/test/groovy/com/netflix/spinnaker/rosco/providers/util/TestDefaults.groovy @@ -26,6 +26,7 @@ trait TestDefaults { static final String SOME_AMI_ID = "ami-3cf4a854" static final String SOME_IMAGE_NAME = "ubuntu/trusty" static final String SOME_CLOUD_PROVIDER = "aws" + static final String SOME_REGION = "eu-west-1" static final Bake SOME_BAKE_DETAILS = new Bake(id: SOME_JOB_ID, ami: SOME_AMI_ID, image_name: SOME_IMAGE_NAME) static final BakeRequest SOME_BAKE_REQUEST = new BakeRequest(build_info_url: SOME_BUILD_INFO_URL, build_number: SOME_BUILD_NR)