Skip to content

Commit

Permalink
feat(web): Adding resolve pipeline template endpoint (#1284)
Browse files Browse the repository at this point in the history
  • Loading branch information
robzienert committed Apr 19, 2017
1 parent 5852d53 commit 0bd8410
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2017 Netflix, 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.pipelinetemplate;

import com.netflix.spinnaker.orca.pipelinetemplate.loader.TemplateLoader;
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.TemplateMerge;
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.PipelineTemplate;
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.TemplateConfiguration.TemplateSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class PipelineTemplateService {

private final TemplateLoader templateLoader;

@Autowired
public PipelineTemplateService(TemplateLoader templateLoader) {
this.templateLoader = templateLoader;
}

public PipelineTemplate resolveTemplate(TemplateSource templateSource) {
List<PipelineTemplate> templates = templateLoader.load(templateSource);
return TemplateMerge.merge(templates);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static class Variable implements NamedContent {
private String name;
private String group = "Ungrouped";
private String description;
private String type;
private String type = "string";
private Object defaultValue;
private String example;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2017 Netflix, 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.controllers

import com.netflix.spinnaker.orca.pipelinetemplate.PipelineTemplateService
import com.netflix.spinnaker.orca.pipelinetemplate.exceptions.TemplateLoaderException
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.PipelineTemplate
import com.netflix.spinnaker.orca.pipelinetemplate.v1schema.model.TemplateConfiguration.TemplateSource
import groovy.transform.InheritConstructors
import groovy.util.logging.Slf4j
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController

@ConditionalOnProperty("pipelineTemplate.enabled")
@RestController
@Slf4j
class PipelineTemplateController {

@Autowired
PipelineTemplateService pipelineTemplateService

@RequestMapping(value = "/pipelineTemplate", method = RequestMethod.GET)
PipelineTemplate getPipelineTemplate(@RequestParam("source") String source) {
if (source == null || source?.empty) {
throw new InvalidTemplateSourceException("template source must not be empty")
}

pipelineTemplateService.resolveTemplate(new TemplateSource(source: source))
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(InvalidTemplateSourceException)
Map invalidTemplateSourceHandler(InvalidTemplateSourceException e) {
return [message: e.message, status: HttpStatus.BAD_REQUEST]
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(TemplateLoaderException)
Map templateLoadingErrorHandler(TemplateLoaderException e) {
return [message: e.message, status: HttpStatus.BAD_REQUEST]
}

@InheritConstructors
static class InvalidTemplateSourceException extends RuntimeException {}
}

0 comments on commit 0bd8410

Please sign in to comment.