27
27
import com .netflix .spinnaker .front50 .model .pipeline .PipelineTemplateDAO ;
28
28
import com .netflix .spinnaker .front50 .model .pipeline .TemplateConfiguration ;
29
29
import org .springframework .beans .factory .annotation .Autowired ;
30
- import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
31
30
import org .springframework .web .bind .annotation .PathVariable ;
32
31
import org .springframework .web .bind .annotation .RequestBody ;
33
32
import org .springframework .web .bind .annotation .RequestMapping ;
42
41
import java .util .stream .Collectors ;
43
42
44
43
@ RestController
45
- @ ConditionalOnBean (PipelineTemplateDAO .class )
46
44
@ RequestMapping ("pipelineTemplates" )
47
45
public class PipelineTemplateController {
48
46
49
- @ Autowired
50
- PipelineTemplateDAO pipelineTemplateDAO ;
47
+ @ Autowired ( required = false )
48
+ PipelineTemplateDAO pipelineTemplateDAO = null ;
51
49
52
50
@ Autowired
53
51
PipelineDAO pipelineDAO ;
@@ -59,29 +57,29 @@ public class PipelineTemplateController {
59
57
60
58
@ RequestMapping (value = "" , method = RequestMethod .GET )
61
59
List <PipelineTemplate > list (@ RequestParam (required = false , value = "scopes" ) List <String > scopes ) {
62
- return (List <PipelineTemplate >) pipelineTemplateDAO .getPipelineTemplatesByScope (scopes );
60
+ return (List <PipelineTemplate >) getPipelineTemplateDAO () .getPipelineTemplatesByScope (scopes );
63
61
}
64
62
65
63
@ RequestMapping (value = "" , method = RequestMethod .POST )
66
64
void save (@ RequestBody PipelineTemplate pipelineTemplate ) {
67
65
checkForDuplicatePipelineTemplate (pipelineTemplate .getId ());
68
- pipelineTemplateDAO .create (pipelineTemplate .getId (), pipelineTemplate );
66
+ getPipelineTemplateDAO () .create (pipelineTemplate .getId (), pipelineTemplate );
69
67
}
70
68
71
69
@ RequestMapping (value = "{id}" , method = RequestMethod .GET )
72
70
PipelineTemplate get (@ PathVariable String id ) {
73
- return pipelineTemplateDAO .findById (id );
71
+ return getPipelineTemplateDAO () .findById (id );
74
72
}
75
73
76
74
@ RequestMapping (value = "{id}" , method = RequestMethod .PUT )
77
75
PipelineTemplate update (@ PathVariable String id , @ RequestBody PipelineTemplate pipelineTemplate ) {
78
- PipelineTemplate existingPipelineTemplate = pipelineTemplateDAO .findById (id );
76
+ PipelineTemplate existingPipelineTemplate = getPipelineTemplateDAO () .findById (id );
79
77
if (!pipelineTemplate .getId ().equals (existingPipelineTemplate .getId ())) {
80
78
throw new InvalidRequestException ("The provided id " + id + " doesn't match the pipeline template id " + pipelineTemplate .getId ());
81
79
}
82
80
83
81
pipelineTemplate .setLastModified (System .currentTimeMillis ());
84
- pipelineTemplateDAO .update (id , pipelineTemplate );
82
+ getPipelineTemplateDAO () .update (id , pipelineTemplate );
85
83
86
84
return pipelineTemplate ;
87
85
}
@@ -90,7 +88,7 @@ PipelineTemplate update(@PathVariable String id, @RequestBody PipelineTemplate p
90
88
void delete (@ PathVariable String id ) {
91
89
checkForDependentConfigs (id , true );
92
90
checkForDependentTemplates (id );
93
- pipelineTemplateDAO .delete (id );
91
+ getPipelineTemplateDAO () .delete (id );
94
92
}
95
93
96
94
@ RequestMapping (value = "{id}/dependentPipelines" , method = RequestMethod .GET )
@@ -164,7 +162,7 @@ void checkForDependentConfigs(String templateId, boolean recursive) {
164
162
List <String > getDependentTemplates (String templateId , Optional <Collection <PipelineTemplate >> templates ) {
165
163
List <String > dependentTemplateIds = new ArrayList <>();
166
164
167
- final Collection <PipelineTemplate > pipelineTemplates = templates .orElse (pipelineTemplateDAO .all ());
165
+ final Collection <PipelineTemplate > pipelineTemplates = templates .orElse (getPipelineTemplateDAO () .all ());
168
166
pipelineTemplates .forEach (template -> {
169
167
if (template .getSource () != null
170
168
&& template .getSource ().equalsIgnoreCase ("spinnaker://" + templateId )) {
@@ -186,10 +184,17 @@ void checkForDependentTemplates(String templateId) {
186
184
187
185
private void checkForDuplicatePipelineTemplate (String id ) {
188
186
try {
189
- pipelineTemplateDAO .findById (id );
187
+ getPipelineTemplateDAO () .findById (id );
190
188
} catch (NotFoundException e ) {
191
189
return ;
192
190
}
193
191
throw new DuplicateEntityException ("A pipeline template with the id " + id + " already exists" );
194
192
}
193
+
194
+ private PipelineTemplateDAO getPipelineTemplateDAO () {
195
+ if (pipelineTemplateDAO == null ) {
196
+ throw new BadRequestException ("Pipeline Templates are not supported with your current storage backend" );
197
+ }
198
+ return pipelineTemplateDAO ;
199
+ }
195
200
}
0 commit comments