-
Notifications
You must be signed in to change notification settings - Fork 705
/
EditFeaturesCommand.java
157 lines (135 loc) · 5.93 KB
/
EditFeaturesCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright 2017 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.halyard.cli.command.v1.config;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.netflix.spinnaker.halyard.cli.services.v1.Daemon;
import com.netflix.spinnaker.halyard.cli.services.v1.OperationHandler;
import com.netflix.spinnaker.halyard.cli.ui.v1.AnsiUi;
import com.netflix.spinnaker.halyard.config.model.v1.node.Features;
import lombok.AccessLevel;
import lombok.Getter;
@Parameters(separators = "=")
public class EditFeaturesCommand extends AbstractConfigCommand {
@Getter(AccessLevel.PUBLIC)
private String commandName = "edit";
@Getter(AccessLevel.PUBLIC)
private String shortDescription = "Enable and disable Spinnaker feature flags.";
@Parameter(
names = "--chaos",
description =
"Enable Chaos Monkey support. For this to work, you'll need a running Chaos Monkey deployment. "
+ "Currently, Halyard doesn't configure Chaos Monkey for you; read more instructions here "
+ "https://github.com/Netflix/chaosmonkey/wiki.",
arity = 1)
private Boolean chaos = null;
@Parameter(
names = "--jobs",
description =
"Allow Spinnaker to run containers in Kubernetes and Titus as Job stages in pipelines.",
arity = 1)
private Boolean jobs = null;
@Parameter(
names = "--pipeline-templates",
description =
"Enable pipeline template support. Read more at https://github.com/spinnaker/dcd-spec.",
arity = 1)
private Boolean pipelineTemplates = null;
@Parameter(
names = "--artifacts",
description =
"Enable artifact support. Read more at https://spinnaker.io/reference/artifacts/",
arity = 1)
private Boolean artifacts = null;
@Parameter(
names = "--artifacts-rewrite",
description =
"Enable new artifact support. Read more at https://www.spinnaker.io/reference/artifacts-with-artifactsrewrite/",
arity = 1)
private Boolean artifactsRewrite = null;
@Parameter(
names = "--mine-canary",
description =
"Enable canary support. For this to work, you'll need a canary judge configured. "
+ "Currently, Halyard does not configure canary judge for you.",
arity = 1)
private Boolean mineCanary = null;
@Parameter(
names = "--infrastructure-stages",
description =
"Enable infrastructure stages. Allows for creating Load Balancers as part of pipelines.",
arity = 1)
private Boolean infrastructureStages = null;
@Parameter(
names = "--appengine-container-image-url-deployments",
description = "Enable appengine deployments using a container image URL from gcr.io.",
arity = 1)
private Boolean appengineContainerImageUrlDeployments = null;
@Parameter(names = "--travis", description = "Enable the Travis CI stage.", arity = 1)
private Boolean travis = null;
@Parameter(names = "--wercker", description = "Enable the Wercker CI stage.", arity = 1)
private Boolean wercker = null;
@Parameter(
names = "--managed-pipeline-templates-v2-ui",
description = "Enable managed pipeline templates v2 UI support.",
arity = 1)
private Boolean managedPipelineTemplatesV2UI = null;
@Parameter(
names = "--gremlin",
description = "Enable Gremlin fault-injection support.",
arity = 1)
private Boolean gremlin = null;
@Override
protected void executeThis() {
String currentDeployment = getCurrentDeployment();
Features features =
new OperationHandler<Features>()
.setOperation(Daemon.getFeatures(currentDeployment, false))
.setFailureMesssage("Failed to load features.")
.get();
int originalHash = features.hashCode();
features.setChaos(chaos != null ? chaos : features.isChaos());
features.setJobs(jobs != null ? jobs : features.isJobs());
features.setPipelineTemplates(
pipelineTemplates != null ? pipelineTemplates : features.getPipelineTemplates());
features.setArtifacts(artifacts != null ? artifacts : features.getArtifacts());
features.setArtifactsRewrite(
artifactsRewrite != null ? artifactsRewrite : features.getArtifactsRewrite());
features.setMineCanary(mineCanary != null ? mineCanary : features.getMineCanary());
features.setInfrastructureStages(
infrastructureStages != null ? infrastructureStages : features.getInfrastructureStages());
features.setAppengineContainerImageUrlDeployments(
appengineContainerImageUrlDeployments != null
? appengineContainerImageUrlDeployments
: features.getAppengineContainerImageUrlDeployments());
features.setTravis(travis != null ? travis : features.getTravis());
features.setWercker(wercker != null ? wercker : features.getWercker());
features.setManagedPipelineTemplatesV2UI(
managedPipelineTemplatesV2UI != null
? managedPipelineTemplatesV2UI
: features.getManagedPipelineTemplatesV2UI());
features.setGremlin(gremlin != null ? gremlin : features.getGremlin());
if (originalHash == features.hashCode()) {
AnsiUi.failure("No changes supplied.");
return;
}
new OperationHandler<Void>()
.setOperation(Daemon.setFeatures(currentDeployment, !noValidate, features))
.setSuccessMessage("Successfully updated features.")
.setFailureMesssage("Failed to edit features.")
.get();
}
}