-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cf): Add Sharing / Unsharing of services (#2750)
- Also removed Autowired fields from com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker.*ServiceStage - Also converted all service-related tests from Spock to JUnit spinnaker/spinnaker#4065 Co-Authored-By: Jason Chu <jchu@pivotal.io>
- Loading branch information
1 parent
808f7fd
commit ab75780
Showing
33 changed files
with
1,021 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ker/orca/clouddriver/pipeline/providers/cf/CloudFoundryShareServiceStagePreprocessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2019 Pivotal, 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.clouddriver.pipeline.providers.cf; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker.ShareServiceStagePreprocessor; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryMonitorKatoServicesTask; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryShareServiceTask; | ||
import com.netflix.spinnaker.orca.kato.pipeline.support.StageData; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CloudFoundryShareServiceStagePreprocessor implements ShareServiceStagePreprocessor { | ||
@Override | ||
public boolean supports(Stage stage) { | ||
return "cloudfoundry".equals(stage.mapTo(StageData.class).getCloudProvider()); | ||
} | ||
|
||
@Override | ||
public void addSteps(TaskNode.Builder builder, Stage stage) { | ||
builder | ||
.withTask("shareService", CloudFoundryShareServiceTask.class) | ||
.withTask("monitorShareService", CloudFoundryMonitorKatoServicesTask.class); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...r/orca/clouddriver/pipeline/providers/cf/CloudFoundryUnshareServiceStagePreprocessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2019 Pivotal, 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.clouddriver.pipeline.providers.cf; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.pipeline.servicebroker.UnshareServiceStagePreprocessor; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryMonitorKatoServicesTask; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.providers.cf.CloudFoundryUnshareServiceTask; | ||
import com.netflix.spinnaker.orca.kato.pipeline.support.StageData; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class CloudFoundryUnshareServiceStagePreprocessor implements UnshareServiceStagePreprocessor { | ||
@Override | ||
public boolean supports(Stage stage) { | ||
return "cloudfoundry".equals(stage.mapTo(StageData.class).getCloudProvider()); | ||
} | ||
|
||
@Override | ||
public void addSteps(TaskNode.Builder builder, Stage stage) { | ||
builder | ||
.withTask("unshareService", CloudFoundryUnshareServiceTask.class) | ||
.withTask("monitorUnshareService", CloudFoundryMonitorKatoServicesTask.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...oovy/com/netflix/spinnaker/orca/clouddriver/pipeline/servicebroker/ShareServiceStage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2019 Pivotal, 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.clouddriver.pipeline.servicebroker; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.utils.CloudProviderAware; | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Component | ||
class ShareServiceStage implements StageDefinitionBuilder, CloudProviderAware { | ||
public static final String PIPELINE_CONFIG_TYPE = "shareService"; | ||
|
||
List<ShareServiceStagePreprocessor> shareServiceStagePreprocessors = new ArrayList<>(); | ||
|
||
@Nonnull | ||
@Override | ||
public String getType() { | ||
return PIPELINE_CONFIG_TYPE; | ||
} | ||
|
||
@Override | ||
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) { | ||
shareServiceStagePreprocessors | ||
.stream() | ||
.filter(it -> it.supports(stage)) | ||
.forEach(it -> it.addSteps(builder, stage)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...flix/spinnaker/orca/clouddriver/pipeline/servicebroker/ShareServiceStagePreprocessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2019 Pivotal, 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.clouddriver.pipeline.servicebroker; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
|
||
/** | ||
* Supports generic modification of a Share Service stage. | ||
* | ||
* Common use-cases: | ||
* - injecting cloud-aware steps | ||
*/ | ||
public interface ShareServiceStagePreprocessor { | ||
boolean supports(Stage stage); | ||
|
||
void addSteps(TaskNode.Builder builder, Stage stage); | ||
} |
50 changes: 50 additions & 0 deletions
50
...vy/com/netflix/spinnaker/orca/clouddriver/pipeline/servicebroker/UnshareServiceStage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2019 Pivotal, 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.clouddriver.pipeline.servicebroker; | ||
|
||
import com.netflix.spinnaker.orca.clouddriver.utils.CloudProviderAware; | ||
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder; | ||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Component | ||
class UnshareServiceStage implements StageDefinitionBuilder, CloudProviderAware { | ||
public static final String PIPELINE_CONFIG_TYPE = "unshareService"; | ||
|
||
List<UnshareServiceStagePreprocessor> unshareServiceStagePreprocessors = new ArrayList<>(); | ||
|
||
@Nonnull | ||
@Override | ||
public String getType() { | ||
return PIPELINE_CONFIG_TYPE; | ||
} | ||
|
||
@Override | ||
public void taskGraph(@Nonnull Stage stage, @Nonnull TaskNode.Builder builder) { | ||
unshareServiceStagePreprocessors | ||
.stream() | ||
.filter(it -> it.supports(stage)) | ||
.forEach(it -> it.addSteps(builder, stage)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ix/spinnaker/orca/clouddriver/pipeline/servicebroker/UnshareServiceStagePreprocessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2019 Pivotal, 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.clouddriver.pipeline.servicebroker; | ||
|
||
import com.netflix.spinnaker.orca.pipeline.TaskNode; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
|
||
/** | ||
* Supports generic modification of an Unshare Service stage. | ||
* | ||
* Common use-cases: | ||
* - injecting cloud-aware steps | ||
*/ | ||
public interface UnshareServiceStagePreprocessor { | ||
boolean supports(Stage stage); | ||
|
||
void addSteps(TaskNode.Builder builder, Stage stage); | ||
} |
60 changes: 60 additions & 0 deletions
60
...etflix/spinnaker/orca/clouddriver/tasks/providers/cf/AbstractCloudFoundryServiceTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2019 Pivotal, 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.clouddriver.tasks.providers.cf; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.netflix.spinnaker.orca.ExecutionStatus; | ||
import com.netflix.spinnaker.orca.TaskResult; | ||
import com.netflix.spinnaker.orca.clouddriver.KatoService; | ||
import com.netflix.spinnaker.orca.clouddriver.model.TaskId; | ||
import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask; | ||
import com.netflix.spinnaker.orca.pipeline.model.Stage; | ||
import org.springframework.stereotype.Component; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Component | ||
abstract class AbstractCloudFoundryServiceTask extends AbstractCloudProviderAwareTask { | ||
private KatoService kato; | ||
|
||
public AbstractCloudFoundryServiceTask(KatoService kato) { | ||
this.kato = kato; | ||
} | ||
|
||
abstract String getStageName(); | ||
|
||
@Nonnull | ||
@Override | ||
public TaskResult execute(@Nonnull Stage stage) { | ||
String cloudProvider = getCloudProvider(stage); | ||
String account = getCredentials(stage); | ||
Map<String, Map> operation = new ImmutableMap.Builder<String, Map>() | ||
.put(getStageName(), stage.getContext()) | ||
.build(); | ||
TaskId taskId = kato.requestOperations(cloudProvider, Collections.singletonList(operation)).toBlocking().first(); | ||
Map<String, Object> outputs = new ImmutableMap.Builder<String, Object>() | ||
.put("notification.type", getStageName()) | ||
.put("kato.last.task.id", taskId) | ||
.put("service.region", Optional.ofNullable(stage.getContext().get("region")).orElse("")) | ||
.put("service.account", account) | ||
.build(); | ||
return new TaskResult(ExecutionStatus.SUCCEEDED, outputs); | ||
} | ||
} |
Oops, something went wrong.