Skip to content

Commit

Permalink
feat(bake/manifest): bake manfest stage (#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwander committed Apr 10, 2018
1 parent 51f452d commit 16acfdd
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ allprojects {
group = "com.netflix.spinnaker.orca"

ext {
spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.148.0'
spinnakerDependenciesVersion = project.hasProperty('spinnakerDependenciesVersion') ? project.property('spinnakerDependenciesVersion') : '0.149.1'
}

def checkLocalVersions = [spinnakerDependenciesVersion: spinnakerDependenciesVersion]
Expand Down
1 change: 1 addition & 0 deletions orca-bakery/orca-bakery.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
compile project(":orca-retrofit")
spinnaker.group('jackson')
compile spinnaker.dependency('jacksonGuava')
compileOnly spinnaker.dependency('lombok')
testCompile project(":orca-test-groovy")
testCompile "com.github.tomakehurst:wiremock:2.15.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.netflix.spinnaker.orca.bakery.api

import com.netflix.spinnaker.kork.artifacts.model.Artifact
import com.netflix.spinnaker.orca.bakery.api.manifests.BakeManifestRequest
import retrofit.http.Body
import retrofit.http.GET
import retrofit.http.POST
Expand All @@ -27,6 +29,8 @@ import rx.Observable
* An interface to the Bakery's REST API.
*/
interface BakeryService {
@POST("/api/v2/manifest/bake")
Artifact bakeManifest(@Body BakeManifestRequest bakeRequest)

@POST("/api/v1/{region}/bake")
Observable<BakeStatus> createBake(@Path("region") String region, @Body BakeRequest bake, @Query("rebake") String rebake)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2018 Google, Inc.
*
* 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.orca.bakery.api.manifests;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import lombok.Data;

import java.util.List;

@Data
public class BakeManifestRequest {
@JsonProperty("templateRenderer")
String templateRenderer;
@JsonProperty("inputArtifact")
Artifact inputArtifact;
List<Artifact> values;
@JsonProperty("outputName")
String outputName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2018 Google, Inc.
*
* 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.orca.bakery.pipeline;

import com.netflix.spinnaker.orca.bakery.tasks.manifests.CreateBakeManifestTask;
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder;
import com.netflix.spinnaker.orca.pipeline.TaskNode;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import com.netflix.spinnaker.orca.pipeline.tasks.artifacts.BindProducedArtifactsTask;
import org.springframework.stereotype.Component;

@Component
public class BakeManifestStage implements StageDefinitionBuilder {
@Override
public void taskGraph(Stage stage, TaskNode.Builder builder) {
builder.withTask("createBake", CreateBakeManifestTask.class)
.withTask("bindProducedArtifacts", BindProducedArtifactsTask.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2018 Google, Inc.
*
* 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.orca.bakery.tasks.manifests;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import com.netflix.spinnaker.orca.ExecutionStatus;
import com.netflix.spinnaker.orca.RetryableTask;
import com.netflix.spinnaker.orca.TaskResult;
import com.netflix.spinnaker.orca.bakery.api.BakeryService;
import com.netflix.spinnaker.orca.bakery.api.manifests.BakeManifestRequest;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import com.netflix.spinnaker.orca.pipeline.util.ArtifactResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Component
@Slf4j
public class CreateBakeManifestTask implements RetryableTask {
@Override
public long getBackoffPeriod() {
return 30000;
}

@Override
public long getTimeout() {
return 300000;
}

@Autowired(required = false)
BakeryService bakery;

@Autowired
ArtifactResolver artifactResolver;

@Autowired
ObjectMapper objectMapper;

@Nonnull
@Override
public TaskResult execute(@Nonnull Stage stage) {
Map<String, Object> context = stage.getContext();

String expectedArtifactId = (String) context.get("expectedArtifactId");

Artifact artifact = artifactResolver.getBoundArtifactForId(stage, expectedArtifactId);
if (artifact == null) {
throw new IllegalArgumentException("An artifact to bake into a manifest must be supplied.");
}

artifact.setArtifactAccount((String) context.get("expectedArtifactAccount"));

BakeManifestRequest request = new BakeManifestRequest();
request.setInputArtifact(artifact);
request.setTemplateRenderer((String) context.get("templateRenderer"));
request.setOutputName((String) context.get("outputName"));

log.info("Requesting {}", request);
Artifact result = bakery.bakeManifest(request);

Map<String, Object> outputs = new HashMap<>();
outputs.put("artifacts", Collections.singleton(result));

return new TaskResult(ExecutionStatus.SUCCEEDED, outputs, outputs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.netflix.spinnaker.orca.clouddriver;

import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import com.netflix.spinnaker.orca.clouddriver.config.SelectableService;
import com.netflix.spinnaker.orca.clouddriver.model.Manifest;
import retrofit.client.Response;
Expand Down Expand Up @@ -88,8 +89,8 @@ public Response getInstance(String account, String region, String instanceId) {
}

@Override
public Response fetchArtifact(String artifactAccount, String type, String reference, String version) {
return getService().fetchArtifact(artifactAccount, type, reference, version);
public Response fetchArtifact(Artifact artifact) {
return getService().fetchArtifact(artifact);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

package com.netflix.spinnaker.orca.clouddriver

import com.netflix.spinnaker.kork.artifacts.model.Artifact
import com.netflix.spinnaker.orca.clouddriver.model.Manifest
import retrofit.client.Response
import retrofit.http.Body
import retrofit.http.GET
import retrofit.http.PUT
import retrofit.http.Path
import retrofit.http.Query
import retrofit.http.QueryMap
Expand Down Expand Up @@ -90,11 +93,8 @@ interface OortService {
@Path("region") String region,
@Path("instanceId") String instanceId)

@GET("/artifacts/fetch/")
Response fetchArtifact(@Query("artifactAccount") String artifactAccount,
@Query("type") String type,
@Query("reference") String reference,
@Query("version") String version)
@PUT("/artifacts/fetch/")
Response fetchArtifact(@Body Artifact artifact)

@GET("/{provider}/loadBalancers/{account}/{region}/{name}")
List<Map> getLoadBalancerDetails(@Path("provider") String provider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ public TaskResult execute(@Nonnull Stage stage) {
log.info("Using {} as the manifest to be deployed", manifestArtifact);

manifestArtifact.setArtifactAccount((String) task.get("manifestArtifactAccount"));
Response manifestText = retrySupport.retry(() -> oort.fetchArtifact(manifestArtifact.getArtifactAccount(),
manifestArtifact.getType(),
manifestArtifact.getReference(),
manifestArtifact.getVersion()
), 5, 1000, true);
Response manifestText = retrySupport.retry(() -> oort.fetchArtifact(manifestArtifact), 5, 1000, true);

try {
Iterable<Object> rawManifests = yamlParser.loadAll(manifestText.getBody().in());
Expand Down

0 comments on commit 16acfdd

Please sign in to comment.